Changeset 31

Show
Ignore:
Timestamp:
07/26/05 15:20:20 (3 years ago)
Author:
schst
Message:

Pass the ClassLoader? to all methods that are loading classes, added new Example for interfaces

Files:

Legend:

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

    r30 r31  
    149149     * @return  Class object 
    150150     */ 
    151     public Class getValueType(Tag tag) { 
     151    public Class getValueType(Tag tag, ClassLoader loader) { 
    152152        try { 
    153             return this.vConverter.getType(); 
     153            return this.vConverter.getType(loader); 
    154154        } catch (Exception e) { 
    155155            throw new RuntimeException("Could not return type."); 
  • trunk/src/net/schst/XJConf/CDataDefinition.java

    r30 r31  
    9494     * @return  Class object 
    9595     */ 
    96     public Class getValueType(Tag tag) { 
     96    public Class getValueType(Tag tag, ClassLoader loader) { 
    9797        try { 
    98             return this.vConverter.getType(); 
     98            return this.vConverter.getType(loader); 
    9999        } catch (Exception e) { 
    100100            throw new RuntimeException("Could not return type."); 
  • trunk/src/net/schst/XJConf/ChildDefinition.java

    r25 r31  
    4848     * @return  Class object 
    4949     */ 
    50     public Class getValueType(Tag tag) { 
     50    public Class getValueType(Tag tag, ClassLoader loader) { 
    5151        Tag child = tag.getChild(this.getName()); 
    5252        if (child == null) { 
    5353            throw new RuntimeException("Child element " + this.getName() + " does not exist"); 
    5454        } 
    55         return child.getValueType(tag); 
     55        return child.getValueType(tag, loader); 
    5656    } 
    5757     
  • trunk/src/net/schst/XJConf/ConstructorDefinition.java

    r28 r31  
    5252     * @return  Always returns null  
    5353     */ 
    54     public Class getValueType(Tag tag) { 
     54    public Class getValueType(Tag tag, ClassLoader loader) { 
    5555        return null; 
    5656    } 
  • trunk/src/net/schst/XJConf/Definition.java

    r25 r31  
    3333     * @return 
    3434     */ 
    35     public Class getValueType(Tag tag); 
     35    public Class getValueType(Tag tag, ClassLoader loader); 
    3636     
    3737    /** 
  • trunk/src/net/schst/XJConf/ObjectValueConverter.java

    r30 r31  
    6464     * @return    Class object 
    6565     */ 
    66     public Class getType() throws Exception { 
    67         return Class.forName(this.className); 
     66    public Class getType(ClassLoader loader) throws Exception { 
     67        return Class.forName(this.className, true, loader); 
    6868    } 
    6969} 
  • trunk/src/net/schst/XJConf/PrimitiveValueConverter.java

    r30 r31  
    5252     * Get the type 
    5353     */ 
    54     public Class getType() throws Exception { 
     54    public Class getType(ClassLoader loader) throws Exception { 
    5555        if (this.type.equals("int")) { 
    5656            return Integer.TYPE; 
  • trunk/src/net/schst/XJConf/Tag.java

    r25 r31  
    168168     * @return  Class object 
    169169     */ 
    170     public Class getValueType(Tag tag) { 
    171         return this.def.getValueType(tag); 
     170    public Class getValueType(Tag tag, ClassLoader loader) { 
     171        return this.def.getValueType(tag, loader); 
    172172    } 
    173173     
  • trunk/src/net/schst/XJConf/TagDefinition.java

    r30 r31  
    136136     * @return  Class object 
    137137     */ 
    138     public Class getValueType(Tag tag) { 
     138    public Class getValueType(Tag tag, ClassLoader loader) { 
    139139        try { 
    140             return this.vConverter.getType(); 
     140            return this.vConverter.getType(loader); 
    141141        } catch (Exception e) { 
    142142            throw new RuntimeException("Could not return type."); 
     
    207207            paramDef       = (Definition)conParams.get(i); 
    208208            cParams[i]     = paramDef.convertValue(tag,loader); 
    209             cParamTypes[i] = paramDef.getValueType(tag); 
     209            cParamTypes[i] = paramDef.getValueType(tag, loader); 
    210210        } 
    211211        Object instance = this.vConverter.convertValue(cParams, cParamTypes, loader); 
     
    246246            try { 
    247247                methodName           = att.getSetterMethod(); 
    248                 Class meParamTypes[] = {att.getValueType(tag)}; 
     248                Class meParamTypes[] = {att.getValueType(tag, loader)}; 
    249249                Method me         = cl.getMethod(methodName, meParamTypes); 
    250250                Object meParams[] = {val}; 
     
    297297                    Class childParamTypes[] = {String.class, String.class}; 
    298298                    Method childMethod = cl.getMethod("setProperty", childParamTypes); 
    299                     String params[] = {key, (String)childValue}; 
     299                    Object params[] = {key, (String)childValue}; 
    300300                    childMethod.invoke(instance, params); 
    301301 
     
    315315                    childMethod.invoke(instance, childParams); 
    316316                     
    317                 // instance is any generic object 
     317                // instance is any object 
    318318                } else { 
    319                     Class childParamTypes[] = {child.getValueType(child)}; 
     319                    Class childParamTypes[] = {child.getValueType(child, loader)}; 
    320320                    Method childMethod = null; 
    321321                     
     
    323323                        childMethod = cl.getMethod(methodName, childParamTypes); 
    324324                    } catch (NoSuchMethodException e) { 
    325                         Class interfaces[] = (Class[])  this.determineAllInterfaces(new ArrayList(), child.getValueType(child)).toArray(new Class[0]); 
     325                        Class interfaces[] = (Class[])  this.determineAllInterfaces(new ArrayList(), child.getValueType(child, loader)).toArray(new Class[0]); 
    326326                        for (int j = 0; j < interfaces.length; j++) { 
    327327                            try { 
     
    340340                } 
    341341            } catch (Exception e) { 
    342                 throw new ValueConversionException("Could not add child " + child.getKey() + " to " + this.getType() + " using "+methodName+"().", e); 
     342                throw new ValueConversionException("Could not add child " + child.getKey() + " to " + this.getType() + " using "+methodName+"(), exception message: " + e.getMessage() + ".", e); 
    343343            } 
    344344        } 
  • trunk/src/net/schst/XJConf/ValueConverter.java

    r30 r31  
    66public interface ValueConverter { 
    77    public Object convertValue(Object[] values, Class[] types, ClassLoader loader) throws ValueConversionException; 
    8     public Class getType() throws Exception; 
     8    public Class getType(ClassLoader loader) throws Exception; 
    99}