Changeset 61

Show
Ignore:
Timestamp:
05/20/06 00:03:32 (3 years ago)
Author:
schst
Message:

Started implementing the 'extends' functionality, used generics, where possible

Files:

Legend:

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

    r39 r61  
    1515     * Parameters of the constructor  
    1616     */ 
    17     private ArrayList params = new ArrayList(); 
     17    private ArrayList<Definition> params = new ArrayList<Definition>(); 
    1818 
    1919    /** 
     
    7575     */ 
    7676    public ArrayList getUsedChildrenNames() { 
    77         ArrayList childrenNames = new ArrayList(); 
     77        ArrayList<String> childrenNames = new ArrayList<String>(); 
    7878        Definition def; 
    7979        for (int i = 0; i < this.params.size(); i++) { 
  • trunk/src/main/java/net/schst/XJConf/DefinedTag.java

    r39 r61  
    3535    * attributes of the tag 
    3636    */ 
    37     private HashMap atts = new HashMap(); 
     37    private HashMap<String,String> atts = new HashMap<String,String>(); 
    3838     
    3939   /** 
    4040    * Children of the tag 
    4141    */ 
    42     private ArrayList children = new ArrayList(); 
     42    private ArrayList<Tag> children = new ArrayList<Tag>(); 
    4343 
    4444    /** 
  • trunk/src/main/java/net/schst/XJConf/DefinitionParser.java

    r57 r61  
    2626     * Stack for currently open definitions 
    2727     */ 
    28     private Stack defStack = new Stack(); 
     28    private Stack<Definition> defStack = new Stack<Definition>(); 
    2929     
    3030    /** 
     
    117117        // define a tag 
    118118        if (qName.equals("tag")) { 
    119  
    120119            TagDefinition def; 
     120 
     121            // ensure that the name has been set 
     122            String name = atts.getValue("name"); 
     123            if (name == null) { 
     124                throw new InvalidTagDefinitionException("The <tag> tag is missing the name attribute."); 
     125            } 
     126             
     127            //  
    121128            String type = atts.getValue("type"); 
    122129            if (type == null) { 
    123130                type = atts.getValue("primitive"); 
    124131            } 
    125             if (type == null) { 
    126                 type = "java.lang.String"; 
    127             } 
    128             String name = atts.getValue("name"); 
    129             if (name == null) { 
    130                 throw new InvalidTagDefinitionException("The <tag> tag is missing the name attribute."); 
    131             } 
    132             def = new TagDefinition(name, type); 
     132 
     133            // The definition extends another definition 
     134            if (atts.getValue("extends") != null) { 
     135                NamespaceDefinition nsDef = (NamespaceDefinition)this.defs.getNamespaceDefinition(this.currentNamespace); 
     136                TagDefinition extendedDef = nsDef.getDefinition(atts.getValue("extends")); 
     137                def = (TagDefinition)extendedDef.clone(); 
     138                def.setName(name); 
     139                def.setTagName(name); 
     140                if (type != null) { 
     141                    def.setType(type); 
     142                } 
     143            } else { 
     144                // Create a definition from scratch 
     145                if (type == null) { 
     146                    type = "java.lang.String"; 
     147                } 
     148                 
     149                def = new TagDefinition(name, type); 
     150            } 
    133151            // key attribute 
    134152            String keyAtt = atts.getValue("keyAttribute"); 
  • trunk/src/main/java/net/schst/XJConf/GenericTag.java

    r39 r61  
    3535     * attributes of the tag 
    3636     */ 
    37     private HashMap atts = new HashMap(); 
     37    private HashMap<String,String> atts = new HashMap<String,String>(); 
    3838 
    3939    /** 
    4040     * Children of the tag 
    4141     */ 
    42     private ArrayList children = new ArrayList(); 
     42    private ArrayList<Tag> children = new ArrayList<Tag>(); 
    4343 
    4444    /** 
  • trunk/src/main/java/net/schst/XJConf/NamespaceDefinition.java

    r34 r61  
    1010public class NamespaceDefinition { 
    1111     
    12     private HashMap tagDefinitions = new HashMap(); 
     12    private HashMap<String,TagDefinition> tagDefinitions = new HashMap<String,TagDefinition>(); 
    1313     
    1414    /** 
  • trunk/src/main/java/net/schst/XJConf/NamespaceDefinitions.java

    r57 r61  
    1212public class NamespaceDefinitions { 
    1313 
    14     private HashMap namespaces = new HashMap(); 
     14    private HashMap<String,NamespaceDefinition> namespaces = new HashMap<String,NamespaceDefinition>(); 
    1515     
    1616   /** 
  • trunk/src/main/java/net/schst/XJConf/TagDefinition.java

    r55 r61  
    1414 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 
    1515 */ 
    16 public class TagDefinition implements Definition
     16public class TagDefinition implements Definition, Cloneable
    1717 
    1818    private String name = null; 
    1919    private String tagName = null; 
    2020    private String type = null; 
    21     private ArrayList atts = new ArrayList(); 
     21    private ArrayList<AttributeDefinition> atts = new ArrayList<AttributeDefinition>(); 
    2222    private String setter = null; 
    2323    private String nameAttribute = null; 
     
    2727     
    2828    // TODO: Eventually call the setter method for the cdata 
    29     private CDataDefinition cdata = null; 
    30  
    31     /** 
    32      * Constructor for simple types 
    33      * @param type 
    34      */ 
     29    @SuppressWarnings("unused") 
     30    private CDataDefinition cdata = null; 
     31 
     32    /** 
     33     * Create a new tag definition 
     34     *  
     35     * @param name 
     36     * @param type 
     37     * @throws XJConfException 
     38     */ 
    3539    public TagDefinition(String name, String type) 
    3640        throws XJConfException { 
     
    4549        this.name    = name; 
    4650        this.tagName = name; 
     51        this.setType(type); 
     52    } 
     53 
     54    /** 
     55     * Set the type of the tag 
     56     *  
     57     * @param type 
     58     */ 
     59    public void setType(String type) { 
    4760        this.type    = type; 
    4861        if (this.type.indexOf(".") == -1) { 
     
    5265        } 
    5366    } 
    54  
     67     
    5568    /** 
    5669     * Add a new child definition 
     
    93106    public void setName(String name) { 
    94107        this.name = name; 
     108    } 
     109 
     110    /** 
     111     * Set the name of the tag 
     112     *  
     113     * @param name 
     114     */ 
     115    public void setTagName(String name) { 
     116        this.tagName = name; 
    95117    } 
    96118     
     
    342364                        childMethod = cl.getMethod(methodName, childParamTypes); 
    343365                    } catch (NoSuchMethodException e) { 
    344                         Class interfaces[] = (Class[])  this.determineAllInterfaces(new ArrayList(), child.getValueType(child, loader)).toArray(new Class[0]); 
     366                        Class interfaces[] = (Class[])  this.determineAllInterfaces(new ArrayList<Class>(), child.getValueType(child, loader)).toArray(new Class[0]); 
    345367                        for (int j = 0; j < interfaces.length; j++) { 
    346368                            try { 
     
    384406     * @return 
    385407     */ 
    386     private List determineAllInterfaces(List result, Class superClass) { 
     408    private List determineAllInterfaces(List<Class> result, Class superClass) { 
    387409        Class[] subinterfaces = superClass.getInterfaces(); 
    388410        for (int i=0;i<subinterfaces.length;i++) { 
     
    398420        return result;  
    399421    } 
     422 
     423    /** 
     424     * Clone the tag definition 
     425     */ 
     426    public Object clone() { 
     427        TagDefinition copy; 
     428        try { 
     429            copy = (TagDefinition)super.clone(); 
     430            copy.atts = (ArrayList<AttributeDefinition>)this.atts.clone(); 
     431        } catch (CloneNotSupportedException e) { 
     432            throw new RuntimeException("Could not extend a tag definition.", e); 
     433        } 
     434        return copy; 
     435    } 
    400436} 
  • trunk/src/main/java/net/schst/XJConf/XmlReader.java

    r47 r61  
    3737    * contains the tag objects 
    3838    */ 
    39     private Stack tagStack = new Stack(); 
     39    private Stack<Tag> tagStack = new Stack<Tag>(); 
    4040     
    4141    /** 
     
    5757     * Extensions used by the parser 
    5858     */ 
    59     private HashMap extensions = new HashMap(); 
     59    private HashMap<String,Extension> extensions = new HashMap<String,Extension>(); 
    6060     
    6161    /** 
     
    6767     * all files that currently are being processed 
    6868     */ 
    69     private Stack openFiles = new Stack(); 
     69    private Stack<File> openFiles = new Stack<File>(); 
    7070     
    7171    /**