Package org.jgroups.annotations

Examples of org.jgroups.annotations.Property


            if(obj == null)
                throw new IllegalArgumentException("Cannot get converted value: Object is null");
            if(field == null)
                throw new IllegalArgumentException("Cannot get converted value: Field 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();
            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.isEmpty()) {
                                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);
                                }
                                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.isEmpty()) {
                            // condition for invoking converter
                            if(defaultValue != null || !PropertyHelper.usesDefaultConverter(fields[j])) {
                                Object converted=null;
                                try {
View Full Code Here

                // get the default value for the field - check for InetAddress types
                if(InetAddressInfo.isInetAddressRelated(protocol, fields[j])) {
                    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);

                        String defaultValue=ip_version == StackType.IPv4? annotation.defaultValueIPv4() : annotation.defaultValueIPv6();
                        if(defaultValue != null && !defaultValue.isEmpty()) {
                            // condition for invoking converter
                            Object converted=null;
                            try {
                                if(defaultValue.equalsIgnoreCase(Global.NON_LOOPBACK_ADDRESS))
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

      // 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().isEmpty())
          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.isEmpty()) {
                    log.warn(Util.getMessage("Deprecated"), 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
            // only do this if the property value hasn't yet been set
            if(propertyValue == null) {
                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.isEmpty()) {
                    log.warn(Util.getMessage("Deprecated"), field.getDeclaringClass().getSimpleName() + "." + field.getName(),
                             deprecated_msg);
                }
            }
View Full Code Here

        for(Class<?> clazz=obj.getClass(); clazz != null && clazz != Object.class; clazz=clazz.getSuperclass()) {

            Field[] fields=clazz.getDeclaredFields();
            for(Field field: fields) {
                ManagedAttribute attr=field.getAnnotation(ManagedAttribute.class);
                Property prop=field.getAnnotation(Property.class);
                boolean expose_prop=prop != null && prop.exposeAsManagedAttribute();
                boolean expose=attr != null || expose_prop;

                if(expose) {
                    String fieldName=attr != null? attr.name() : (prop != null? prop.name() : null);
                    if(fieldName != null && fieldName.trim().isEmpty())
                        fieldName=field.getName();

                    String descr=attr != null? attr.description() : prop.description();
                    boolean writable=attr != null? attr.writable() : prop.writable();

                    MBeanAttributeInfo info=new MBeanAttributeInfo(fieldName,
                                                                   field.getType().getCanonicalName(),
                                                                   descr,
                                                                   true,
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.