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 r = field.getAnnotation(Property.class);
               boolean annotationRedefinesName = r.name().length() > 0
                        && r.deprecatedMessage().length() == 0;
               if (annotationRedefinesName) {
                  property = r.name();
               }
               if(property == null || property.length()==0) {
                   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", 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(r.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 = 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.length() > 0) {
               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


                            .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

        this.properties = properties ;
        this.stringValue = stringValue ;
        this.convertedValue = convertedValue ;
       
        // set the property name
        Property annotation=fieldOrMethod.getAnnotation(Property.class);       
        if (isField())
            propertyName=PropertyHelper.getPropertyName((Field)fieldOrMethod, properties) ;
        else
            propertyName=PropertyHelper.getPropertyName((Method)fieldOrMethod) ;
       
View Full Code Here

      // iterate overall properties marked by @Property
      for(int i = 0; i < objects.size(); i++) {
       
        // get the Property annotation
        AccessibleObject ao = objects.get(i) ;
        Property annotation = ao.getAnnotation(Property.class) ;
            if (annotation == null) {
              throw new IllegalArgumentException("@Property annotation is required for checking dependencies;" +
                  " annotation is missing for Field/Method " + ao.toString()) ;
            }
       
        String dependsClause = annotation.dependsUpon() ;
        if (dependsClause.trim().length() == 0)
          continue ;
       
        // split dependsUpon specifier into tokens; trim each token; search for token in list
        StringTokenizer st = new StringTokenizer(dependsClause, ",") ;
        while (st.hasMoreTokens()) {
          String token = st.nextToken().trim() ;
         
          // check that the string representing a property name is in the list
          boolean found = false ;
          Set<String> keyset = props.keySet();
          for (Iterator<String> iter = keyset.iterator(); iter.hasNext();) {
            if (iter.next().equals(token)) {
              found = true ;
              break ;
            }
          }
          if (!found) {
            throw new IllegalArgumentException("@Property annotation " + annotation.name() +
                " has an unresolved dependsUpon property: " + token) ;
          }
        }
      }
     
View Full Code Here

        }
    }

    public static void resolveAndInvokePropertyMethod(Object obj, Method method, Map<String,String> props) throws Exception {
      String methodName=method.getName();
        Property annotation=method.getAnnotation(Property.class);
      if(annotation != null && isSetPropertyMethod(method)) {
        String propertyName=PropertyHelper.getPropertyName(method) ;
        String propertyValue=props.get(propertyName);

            // if there is a systemProperty attribute defined in the annotation, set the property value from the system property
            String tmp=grabSystemProp(method.getAnnotation(Property.class));
            if(tmp != null)
                propertyValue=tmp;

            if(propertyName != null && propertyValue != null) {
                String deprecated_msg=annotation.deprecatedMessage();
                if(deprecated_msg != null && deprecated_msg.length() > 0) {
                    log.warn(method.getDeclaringClass().getSimpleName() + "." + methodName + ": " + deprecated_msg);
                }
            }
View Full Code Here

            }
        }
    }

    public static void resolveAndAssignField(Object obj, Field field, Map<String,String> props) throws Exception {
        Property annotation=field.getAnnotation(Property.class);
      if(annotation != null) {
        String propertyName = PropertyHelper.getPropertyName(field, props) ;
        String propertyValue=props.get(propertyName);

            // if there is a systemProperty attribute defined in the annotation, set the property value from the system property
            String tmp=grabSystemProp(field.getAnnotation(Property.class));
            if(tmp != null)
                propertyValue=tmp;

            if(propertyName != null && propertyValue != null) {
                String deprecated_msg=annotation.deprecatedMessage();
                if(deprecated_msg != null && deprecated_msg.length() > 0) {
                    log.warn(field.getDeclaringClass().getSimpleName() + "." + field.getName() + ": " + deprecated_msg);
                }
            }
           
View Full Code Here

        this.properties = properties ;
        this.stringValue = stringValue ;
        this.convertedValue = convertedValue ;
       
        // set the property name
        Property annotation=fieldOrMethod.getAnnotation(Property.class);       
        if (isField())
            propertyName=PropertyHelper.getPropertyName((Field)fieldOrMethod, properties) ;
        else
            propertyName=PropertyHelper.getPropertyName((Method)fieldOrMethod) ;
       
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

        throw new RuntimeException("Deadlock in @Property dependency processing") ;
      }
      // record the fact that we are processing obj
      stack.push(obj) ;
      // process dependencies for this object before adding it to the list
      Property annotation = obj.getAnnotation(Property.class) ;
      String dependsClause = annotation.dependsUpon() ;
      StringTokenizer st = new StringTokenizer(dependsClause, ",") ;
      while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
        AccessibleObject dep = props.get(token) ;
        // if null, throw exception
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=Util.methodNameToAttributeName(method.getName());
                        }
                        nameToDescription.put(name, desc);
                    }
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.