Package org.jgroups.annotations

Examples of org.jgroups.annotations.Property


    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);
          boolean annotationRedefinesName = annotation.name().length() > 0;
          if(annotationRedefinesName){
            property = annotation.name();
          }
          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", fieldToXMLSchemaAttributeType(field));
          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(annotation.description());
          annotationElement.appendChild(documentationElement);
        }
      }
    }

    // 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 name = annotation.name();
        if (name.length() < 1) {
          name = Configurator.renameFromJavaCodingConvention(method.getName().substring(3));
        }
        Element attributeElement = xmldoc.createElement("xs:attribute");
        attributeElement.setAttribute("name", name);
        attributeElement.setAttribute("type", "xs:string");
        complexType.appendChild(attributeElement);
       
        String desc = annotation.description();
        if (desc.length() > 0) {
          Element annotationElement = xmldoc.createElement("xs:annotation");
          attributeElement.appendChild(annotationElement);
         
          Element documentationElement = xmldoc.createElement("xs:documentation");
          documentationElement.setTextContent(annotation.description());
          annotationElement.appendChild(documentationElement);
        }
      }
    }
   
View Full Code Here


                // 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

                            .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 = 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().length() > 0;
          if(isDeprecated && log.isWarnEnabled()) {
            log.warn(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().length() > 0? annotation.name() : method.getName();
        propertyName=Util.methodNameToAttributeName(propertyName);
        return propertyName ;
      }
View Full Code Here

        }
        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

          throw new IllegalArgumentException("Cannot get converted value: Method is not set property method") ;
        }
        if (props == null) {
          throw new IllegalArgumentException("Cannot get converted value: Properties 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 = getPropertyName(method) ;
        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 method " + propertyName
              + " in " + name);
        }
        Object converted = null ;
View Full Code Here

     
        public static boolean usesDefaultConverter(Field field) throws IllegalArgumentException {
        if (field == null) {
          throw new IllegalArgumentException("Cannot check converter: field is null") ;
        }
        Property annotation=field.getAnnotation(Property.class);
        if (annotation == null) {
          throw new IllegalArgumentException("Cannot check converter for field " +
              field.getName() + " which is not annotated with @Property") ;
        }
          return annotation.converter().equals(PropertyConverters.Default.class) ;
        }
View Full Code Here

                if(isSetPropertyMethod(methods[j])) {
                    String propertyName=PropertyHelper.getPropertyName(methods[j]);

                    Object propertyValue=getValueFromProtocol(protocol, propertyName);
                    if(propertyValue == null) { // if propertyValue is null, check if there is a we can use
                        Property annotation=methods[j].getAnnotation(Property.class);

                        // get the default value for the method- check for InetAddress types
                        String defaultValue=null;
                        if(InetAddressInfo.isInetAddressRelated(methods[j])) {
                            defaultValue=ip_version == StackType.IPv4? annotation.defaultValueIPv4() : annotation.defaultValueIPv6();
                            if(defaultValue != null && defaultValue.length() > 0) {
                                Object converted=null;
                                try {
                                    if(defaultValue.equalsIgnoreCase(Global.NON_LOOPBACK_ADDRESS))
                                        converted=default_ip_address;
                                    else
                                        converted=PropertyHelper.getConvertedValue(protocol, methods[j], properties, defaultValue, true);
                                    methods[j].invoke(protocol, converted);
                                }
                                catch(Exception e) {
                                    throw new Exception("default could not be assigned for method " + propertyName + " in "
                                            + protocolName + " with default " + defaultValue, e);
                                }
                                if(log.isDebugEnabled())
                                    log.debug("set property " + protocolName + "." + propertyName + " to default value " + converted);
                            }
                        }
                    }
                }
            }

            //traverse class hierarchy and find all annotated fields and add them to the list if annotated
            Field[] fields=Util.getAllDeclaredFieldsWithAnnotations(protocol.getClass(), Property.class);
            for(int j=0; j < fields.length; j++) {
                String propertyName=PropertyHelper.getPropertyName(fields[j], properties);
                Object propertyValue=getValueFromProtocol(protocol, fields[j]);
                if(propertyValue == null) {
                    // add to collection of @Properties with no user specified value
                    Property annotation=fields[j].getAnnotation(Property.class);

                    // get the default value for the field - check for InetAddress types
                    String defaultValue=null;
                    if(InetAddressInfo.isInetAddressRelated(protocol, fields[j])) {
                        defaultValue=ip_version == StackType.IPv4? annotation.defaultValueIPv4() : annotation.defaultValueIPv6();
                        if(defaultValue != null && defaultValue.length() > 0) {
                            // condition for invoking converter
                            if(defaultValue != null || !PropertyHelper.usesDefaultConverter(fields[j])) {
                                Object converted=null;
                                try {
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.