Changeset 5

Show
Ignore:
Timestamp:
06/23/05 11:26:28 (3 years ago)
Author:
schst
Message:

added decent support for collections

Files:

Legend:

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

    r3 r5  
    1414 
    1515    public static void main(String[] args) { 
    16          
    1716        DefinitionParser tagParser = new DefinitionParser(); 
    1817        NamespaceDefinitions defs = tagParser.parse("xml/defines-hashmap.xml"); 
    19  
    2018 
    2119        XmlReader conf = new XmlReader(); 
  • trunk/src/net/schst/XJConf/TagDefinition.java

    r4 r5  
    128128        // no name, the parent should be a collection 
    129129        if (this.name.equals("__none")) { 
    130             return "add"
     130            return null
    131131        } 
    132132        return "set" + this.name.substring(0,1).toUpperCase() + this.name.substring(1); 
     
    239239                // Check, whether the current instance is a HashMap 
    240240                } else if (instance instanceof java.util.AbstractMap) { 
    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                 } else if (methodName.equals("add")) { 
    248                     // nasty workaround for Collections  
    249                     // needs to be fixed 
     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                // Check, whether the current instance is a collection 
     248                } else if (methodName == null && instance instanceof java.util.AbstractCollection) { 
    250249                    Class childParamTypes[] = {Class.forName("java.lang.Object")}; 
    251                     Method childMethod = cl.getMethod(methodName, childParamTypes); 
     250                    Method childMethod = cl.getMethod("add", childParamTypes); 
    252251                    childMethod.invoke(instance, childParams); 
    253  
    254                } else { 
     252                // instance is any generic object 
     253                } else { 
    255254                    Class childParamTypes[] = {childValue.getClass()}; 
    256255