CVS update: JGroups/src/org/jgroups/conf PropertyHelper.java

"Bela Ban" <[email protected]> Wed, 6 Oct 2010 09:46:45 +0000
Newsgroups gmane.comp.java.javagroups.cvs
Message-ID <[email protected]>
  User: belaban 
  Date: 10/10/06 09:46:45

  Modified:    src/org/jgroups/conf PropertyHelper.java
  Log:
  first impl of programmatic API (https://jira.jboss.org/browse/JGRP-1245)
  
  Revision  Changes    Path
  1.8       +36 -6     JGroups/src/org/jgroups/conf/PropertyHelper.java
  
  Index: PropertyHelper.java
  ===================================================================
  RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/conf/PropertyHelper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PropertyHelper.java	1 Oct 2010 09:42:30 -0000	1.7
  +++ PropertyHelper.java	6 Oct 2010 09:46:45 -0000	1.8
  @@ -56,15 +56,12 @@
       	}
       	
       	public static Object getConvertedValue(Object obj, Field field, Map<String, String> props, String prop, boolean check_scope) throws Exception {
  -    		if (obj == null) {
  +    		if (obj == null)
       			throw new IllegalArgumentException("Cannot get converted value: Object is null") ;
  -    		}
  -    		if (field == null) {
  +    		if (field == null)
       			throw new IllegalArgumentException("Cannot get converted value: Field is null") ;
  -    		}
  -    		if (props == null) {
  +    		if (props == null)
       			throw new IllegalArgumentException("Cannot get converted value: Properties is null") ;
  -    		}
   
       		Property annotation=field.getAnnotation(Property.class);
       		if (annotation == null) {
  @@ -91,6 +88,39 @@
   			return converted ;
       	}
   
  +
  +        public static Object getConvertedValue(Object obj, Field field, String value, boolean check_scope) throws Exception {
  +            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;
  +            try {
  +                String tmp=obj instanceof Protocol? ((Protocol)obj).getName() + "." + propertyName : propertyName;
  +                converted=propertyConverter.convert(obj, field.getType(), tmp, value, check_scope);
  +            }
  +            catch(Exception e) {
  +                throw new Exception("Conversion of " + propertyName + " in " + name +
  +                        " with original property value " + value + " failed", e);
  +            }
  +            return converted;
  +        }
  +
  +
       	public static Object getConvertedValue(Object obj, Method method, Map<String, String> props, String prop, boolean check_scope) throws Exception {
       		if (obj == null) {
       			throw new IllegalArgumentException("Cannot get converted value: Object is null") ;
  
  
  

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb