Package org.jgroups.annotations

Examples of org.jgroups.annotations.Property


                // 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)) {
                        Property 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);
View Full Code Here


        for(Class<?> clazz=prot.getClass(); clazz != null; clazz=clazz.getSuperclass()) {

            // copy all fields marked with @Property
            Field[] fields=clazz.getDeclaredFields();
            Property annotation;
            for(Field field: fields) {
                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) {
View Full Code Here

    public static void resolveAndInvokePropertyMethods(Object obj, Properties props) throws Exception {
        Method[] methods=obj.getClass().getMethods();
        for(Method method: methods) {
            String methodName=method.getName();
            if(method.isAnnotationPresent(Property.class) && isSetPropertyMethod(method)) {
                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);
                    }
View Full Code Here

        //traverse class hierarchy and find all annotated fields
        for(Class<?> clazz=obj.getClass(); clazz != null; clazz=clazz.getSuperclass()) {
            Field[] fields=clazz.getDeclaredFields();
            for(Field field: fields) {
                if(field.isAnnotationPresent(Property.class)) {
                    Property annotation=field.getAnnotation(Property.class);
                    String propertyName=field.getName();
                    if(props.containsKey(annotation.name())) {
                        propertyName=annotation.name();
                        boolean isDeprecated=annotation.deprecatedMessage().length() > 0;
                        if(isDeprecated && log.isWarnEnabled()) {
                            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);
                        }
View Full Code Here

            for(Class clazzInLoop=clazz;clazzInLoop != null;clazzInLoop=clazzInLoop.getSuperclass()) {
                Field[] fields=clazzInLoop.getDeclaredFields();
                for(Field field:fields) {
                    if(field.isAnnotationPresent(Property.class)) {                                  
                        String property=field.getName();                      
                        Property annotation=field.getAnnotation(Property.class);
                        String desc=annotation.description();     
                        nameToDescription.put(property, desc);                                          
                    }
                }
            }
           
            //iterate methods           
            Method[] methods=clazz.getMethods();
            for(Method method:methods) {
                if(method.isAnnotationPresent(Property.class) && method.getName()
                                                                       .startsWith("set")) {

                    Property annotation=method.getAnnotation(Property.class);
                    String desc=annotation.description();

                    if(desc.length() > 0) {

                        String name=annotation.name();
                        if(name.length() < 1) {
                            name=Configurator.renameFromJavaCodingConvention(method.getName()
                                                                                   .substring(3));
                        }
                        nameToDescription.put(name, desc);
View Full Code Here

        for (Class<?> clazzInLoop = clazz; clazzInLoop != null; clazzInLoop = clazzInLoop.getSuperclass()) {
            Field[] fields = clazzInLoop.getDeclaredFields();
            for (Field field : fields) {
                if (field.isAnnotationPresent(Property.class)) {
                    String property = field.getName();
                    Property r = field.getAnnotation(Property.class);
                    boolean annotationRedefinesName =!r.name().isEmpty()
                      && r.deprecatedMessage().isEmpty();
                    if (annotationRedefinesName) {
                        property = r.name();
                    }
                    if(property == null || property.isEmpty()) {
                        throw new IllegalArgumentException("Cannot create empty attribute name for element xs:attribute, field is " + field);
                    }
                    Element attributeElement = xmldoc.createElement("xs:attribute");
                    attributeElement.setAttribute("name", property);

                    // Agreement with Bela Ban on Jan-20-2009 (Go Obama!!!) to treat all types as
                    // xs:string since we do not know where users are going to use
                    // replacement tokens in configuration files. Therefore, the type becomes
                    // indeterminate.
                    attributeElement.setAttribute("type", "xs:string");
                    complexType.appendChild(attributeElement);

                    Element annotationElement = xmldoc.createElement("xs:annotation");
                    attributeElement.appendChild(annotationElement);

                    Element documentationElement = xmldoc.createElement("xs:documentation");
                    documentationElement.setTextContent(r.description());
                    annotationElement.appendChild(documentationElement);
                }
            }
        }

        // iterate methods
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(Property.class)) {

                Property annotation = method.getAnnotation(Property.class);
                String name = annotation.name();
                if (name.length() < 1) {
                    name = Util.methodNameToAttributeName(method.getName());
                }
                Element attributeElement = xmldoc.createElement("xs:attribute");
                attributeElement.setAttribute("name", name);
                attributeElement.setAttribute("type", "xs:string");
                complexType.appendChild(attributeElement);

                String desc = annotation.description();
                if (!desc.isEmpty()) {
                    Element annotationElement = xmldoc.createElement("xs:annotation");
                    attributeElement.appendChild(annotationElement);

                    Element documentationElement = xmldoc.createElement("xs:documentation");
                    documentationElement.setTextContent(annotation.description());
                    annotationElement.appendChild(documentationElement);
                }
            }
        }
        return classElement;
View Full Code Here

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (field.isAnnotationPresent(Property.class)) {
                String property = field.getName();
                Property annotation = field.getAnnotation(Property.class);
                String desc = annotation.description();
                nameToDescription.put(property, desc);
            }
        }

        // iterate methods
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(Property.class)) {

                Property annotation = method.getAnnotation(Property.class);
                String desc = annotation.description();

                if(desc == null || desc.isEmpty())
                    desc="n/a";

                String name = annotation.name();
                if (name.length() < 1) {
                    name = Util.methodNameToAttributeName(method.getName());
                }
                nameToDescription.put(name, desc);
            }
View Full Code Here

          throw new IllegalArgumentException("Cannot get property name: field is null") ;
        }
        if (props == null) {
          throw new IllegalArgumentException("Cannot get property name: properties map is null") ;
        }       
        Property annotation=field.getAnnotation(Property.class);
        if (annotation == null) {
          throw new IllegalArgumentException("Cannot get property name for field " +
              field.getName() + " which is not annotated with @Property") ;
        }
        String propertyName=field.getName();
        if(props.containsKey(annotation.name())) {
          propertyName=annotation.name();
          boolean isDeprecated=!annotation.deprecatedMessage().isEmpty();
          if(isDeprecated)
                    log.warn(Util.getMessage("Deprecated"), propertyName, annotation.deprecatedMessage());
        }
        return propertyName ;
      }
View Full Code Here

     
      public static String getPropertyName(Method method) throws IllegalArgumentException {
        if (method == null) {
          throw new IllegalArgumentException("Cannot get property name: field is null") ;
        }
        Property annotation=method.getAnnotation(Property.class);
        if (annotation == null) {
          throw new IllegalArgumentException("Cannot get property name for method " +
              method.getName() + " which is not annotated with @Property") ;
        }       
        String propertyName=!annotation.name().isEmpty()? annotation.name() : method.getName();
        propertyName=Util.methodNameToAttributeName(propertyName);
        return propertyName ;
      }
View Full Code Here

        if (field == null)
          throw new IllegalArgumentException("Cannot get converted value: Field is null") ;
        if (props == null)
          throw new IllegalArgumentException("Cannot get converted value: Properties is null") ;

        Property annotation=field.getAnnotation(Property.class);
        if (annotation == null) {
          throw new IllegalArgumentException("Cannot get property name for field " +
              field.getName() + " which is not annotated with @Property") ;
        }
      String propertyName = getPropertyName(field, props) ;
      String name = obj instanceof Protocol? ((Protocol)obj).getName() : obj.getClass().getName();

        PropertyConverter propertyConverter=(PropertyConverter)annotation.converter().newInstance();
        if(propertyConverter == null) {           
          throw new Exception("Could not find property converter for field " + propertyName
              + " in " + name);
        }
        Object converted = null ;
View Full Code Here

TOP

Related Classes of org.jgroups.annotations.Property

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.