Package org.jgroups.conf

Examples of org.jgroups.conf.PropertyConverter


        System.out.println("str = " + str);
        assert str.equals(loopback_name) || str.equals("lo0");
    }

    public static void testStringProperties() throws Exception {
        PropertyConverter c = new PropertyConverters.StringProperties();

        String value = "com.sun.security.sasl.digest.realm=MyRealm,qop=true";
        Map<String, String> map = (Map<String, String>) c.convert(null, Map.class, "props", value, false);
        assert map.size() == 2;
        assert map.get("qop").equals("true");
        assert map.get("com.sun.security.sasl.digest.realm").equals("MyRealm");
    }
View Full Code Here


                if(field.isAnnotationPresent(Property.class)) {
                    Object value=Configurator.getField(field, prot);
                    if(value != null) {
                        annotation=field.getAnnotation(Property.class);
                        Class<?> conv_class=annotation.converter();
                        PropertyConverter conv=null;
                        try {
                            conv=(PropertyConverter)conv_class.newInstance();
                        }
                        catch(Exception e) {
                        }
                        String tmp=conv != null? conv.toString(value) : value.toString();
                        retval.put(field.getName(), tmp);
                    }
                }
            }

            // copy all setters marked with @Property
            Method[] methods=clazz.getDeclaredMethods();
            for(Method method: methods) {
                String methodName=method.getName();
                if(method.isAnnotationPresent(Property.class) && Configurator.isSetPropertyMethod(method)) {
                    annotation=method.getAnnotation(Property.class);
                    List<String> possible_names=new LinkedList<String>();
                    if(annotation.name() != null)
                        possible_names.add(annotation.name());
                    possible_names.add(methodName.substring(3));
                    possible_names.add(Configurator.renameFromJavaCodingConvention(methodName.substring(3)));
                    Field field=findField(prot, possible_names);
                    if(field != null) {
                        Object value=Configurator.getField(field, prot);
                        if(value != null) {
                            Class<?> conv_class=annotation.converter();
                            PropertyConverter conv=null;
                            try {
                                conv=(PropertyConverter)conv_class.newInstance();
                            }
                            catch(Exception e) {
                            }
                            String tmp=conv != null? conv.toString(value) : value.toString();
                            retval.put(field.getName(), tmp);
                        }
                    }
                }
            }
View Full Code Here

                Property annotation=method.getAnnotation(Property.class);
                String propertyName=annotation.name().length() > 0? annotation.name() : methodName.substring(3);
                propertyName=renameFromJavaCodingConvention(propertyName);
                String prop=props.getProperty(propertyName);
                if(prop != null) {
                    PropertyConverter propertyConverter=(PropertyConverter)annotation.converter().newInstance();
                    if(propertyConverter == null) {
                        String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
                        throw new Exception("Could not find property converter for field " + propertyName
                                + " in " + name);
                    }
                    Object converted=null;
                    try {
                        converted=propertyConverter.convert(method.getParameterTypes()[0], props, prop);
                        method.invoke(obj, converted);
                    }
                    catch(Exception e) {
                        String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
                        throw new Exception("Could not assign property " + propertyName + " in "
View Full Code Here

                            log.warn(annotation.deprecatedMessage());
                        }
                    }
                    String propertyValue=props.getProperty(propertyName);
                    if(propertyValue != null || !annotation.converter().equals(PropertyConverters.Default.class)){
                        PropertyConverter propertyConverter=(PropertyConverter)annotation.converter().newInstance();
                        if(propertyConverter == null) {
                            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
                            throw new Exception("Could not find property converter for field " + propertyName
                                    + " in " + name);
                        }
                        Object converted=null;
                        try {
                            converted=propertyConverter.convert(field.getType(), props, propertyValue);
                            if(converted != null)
                                setField(field, obj, converted);
                        }
                        catch(Exception e) {
                            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
View Full Code Here

        Property annotation=method.getAnnotation(Property.class);
        String propertyName=annotation.name().length() > 0? annotation.name() : methodName.substring(3);
        propertyName=renameFromJavaCodingConvention(propertyName);
        String prop=props.getProperty(propertyName);
        if(prop != null) {
          PropertyConverter propertyConverter=(PropertyConverter)annotation.converter().newInstance();
          if(propertyConverter == null) {
            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
            throw new Exception("Could not find property converter for field " + propertyName
                + " in " + name);
          }
          Object converted=null;
          try {
            converted=propertyConverter.convert((Protocol)obj, method.getParameterTypes()[0], props, prop);
            method.invoke(obj, converted);
          }
          catch(Exception e) {
            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
            throw new Exception("Could not assign property " + propertyName + " in "
View Full Code Here

            log.warn(annotation.deprecatedMessage());
          }
        }
        String propertyValue=props.getProperty(propertyName);
        if(propertyValue != null || !annotation.converter().equals(PropertyConverters.Default.class)){
          PropertyConverter propertyConverter=(PropertyConverter)annotation.converter().newInstance();
          if(propertyConverter == null) {
            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
            throw new Exception("Could not find property converter for field " + propertyName
                + " in " + name);
          }
          Object converted=null;
          try {
            converted=propertyConverter.convert((Protocol)obj, field.getType(), props, propertyValue);
            if(converted != null)
              setField(field, obj, converted);
          }
          catch(Exception e) {
            String name=obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();
View Full Code Here

TOP

Related Classes of org.jgroups.conf.PropertyConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.