Changeset 3

Show
Ignore:
Timestamp:
06/22/05 16:54:19 (4 years ago)
Author:
schst
Message:

Added support for java.util.Properties and java.util.HashMap?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/net/schst/XJConf/TagDefinition.java

    r1 r3  
    228228             
    229229            try { 
    230                  
    231                 // nasty workaround for Collections  
    232                 // needs to be fixed 
    233                 if (methodName.equals("add")) { 
     230 
     231                // Check, whether the current instance is a Properties object 
     232                if (Class.forName("java.util.Properties").isAssignableFrom(instance.getClass())) { 
     233                    String key = (String)child.getKey();  
     234                    Class childParamTypes[] = {Class.forName("java.lang.String"), Class.forName("java.lang.String")}; 
     235                    Method childMethod = cl.getMethod("setProperty", childParamTypes); 
     236                    String params[] = {key, (String)childValue}; 
     237                    childMethod.invoke(instance, params); 
     238 
     239                // Check, whether the current instance is a HashMap 
     240                } else if (Class.forName("java.util.AbstractMap").isAssignableFrom(instance.getClass())) { 
     241                        Object name = (Object)child.getKey();  
     242                        Class childParamTypes[] = {Class.forName("java.lang.Object"), Class.forName("java.lang.Object")}; 
     243                        Method childMethod = cl.getMethod("put", childParamTypes); 
     244 
     245                        Object params[] = {name, childValue}; 
     246                        childMethod.invoke(instance, params); 
     247 
     248                } else if (methodName.equals("add")) { 
     249                    // nasty workaround for Collections  
     250                    // needs to be fixed 
    234251                    Class childParamTypes[] = {Class.forName("java.lang.Object")}; 
    235252                    Method childMethod = cl.getMethod(methodName, childParamTypes); 
    236                     childMethod.invoke(instance, childParams);                            
     253                    childMethod.invoke(instance, childParams); 
     254 
    237255                } else { 
    238256                    Class childParamTypes[] = {childValue.getClass()}; 
     
    241259                    childMethod.invoke(instance, childParams); 
    242260                } 
    243                  
    244261            } catch (Throwable t) { 
    245262                throw new ValueConversionException("Could not add child " + child.getKey() + " to " + this.getType() + ".", t);