Changeset 45

Show
Ignore:
Timestamp:
08/22/05 21:45:26 (3 years ago)
Author:
schst
Message:

Fix ticket #11: Check for all required attributes

Files:

Legend:

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

    r35 r45  
    1010import javax.xml.parsers.SAXParserFactory; 
    1111 
     12import net.schst.XJConf.exceptions.InvalidTagDefinitionException; 
    1213import net.schst.XJConf.exceptions.XJConfException; 
    1314 
     15import org.omg.PortableInterceptor.INACTIVE; 
    1416import org.xml.sax.Attributes; 
    1517import org.xml.sax.SAXException; 
     
    7981        // define a tag 
    8082        if (qName.equals("namespace")) { 
    81             this.currentNamespace = atts.getValue("uri"); 
     83            String uri = atts.getValue("uri"); 
     84            if (uri == null) { 
     85                throw new InvalidTagDefinitionException("The <namespace> tag is missing the uri attribute."); 
     86            } 
     87            this.currentNamespace = uri; 
    8288            return; 
    8389        } 
     
    9197                type = atts.getValue("primitive"); 
    9298            } 
    93             def = new TagDefinition(atts.getValue("name"), type); 
     99            if (type == null) { 
     100                type = "java.lang.String"; 
     101            } 
     102            String name = atts.getValue("name"); 
     103            if (name == null) { 
     104                throw new InvalidTagDefinitionException("The <tag> tag is missing the name attribute."); 
     105            } 
     106            def = new TagDefinition(name, type); 
    94107            // key attribute 
    95108            String keyAtt = atts.getValue("keyAttribute"); 
     
    136149        // define a child tag data 
    137150        if (qName.equals("child")) { 
    138             ChildDefinition def = new ChildDefinition(atts.getValue("name")); 
     151            String name = atts.getValue("name"); 
     152            if (name == null) { 
     153                throw new InvalidTagDefinitionException("The <child> tag is missing the name attribute."); 
     154            } 
     155            ChildDefinition def = new ChildDefinition(name); 
    139156            this.defStack.push(def); 
    140157        } 
     
    144161            // get the current tag 
    145162            Definition def = (Definition)this.defStack.pop(); 
    146             try { 
    147                 String type = atts.getValue("type"); 
    148                 if (type == null) { 
    149                     type = atts.getValue("primitive"); 
    150                 } 
    151                 AttributeDefinition attDef = new AttributeDefinition(atts.getValue("name"), type); 
    152                  
    153                 // setter method 
    154                 String setter = atts.getValue("setter"); 
    155                 if (setter != null) { 
    156                     attDef.setSetterMethod(setter); 
    157                 } 
    158                  
    159                 // default value 
    160                 String defaultValue = atts.getValue("default"); 
    161                 if (defaultValue != null) { 
    162                     attDef.setDefault(defaultValue); 
    163                 } 
    164                  
    165                 // required 
    166                 String requiredAtt = atts.getValue("required"); 
    167                 if (requiredAtt != null && requiredAtt.equals("true")) { 
    168                     attDef.setRequired(true); 
    169                 } 
     163            String type = atts.getValue("type"); 
     164            if (type == null) { 
     165                type = atts.getValue("primitive"); 
     166            } 
     167            String name = atts.getValue("name"); 
     168            if (name == null) { 
     169                throw new InvalidTagDefinitionException("The <attribute> tag is missing the name attribute."); 
     170            } 
     171            AttributeDefinition attDef = new AttributeDefinition(name, type); 
     172             
     173            // setter method 
     174            String setter = atts.getValue("setter"); 
     175            if (setter != null) { 
     176                attDef.setSetterMethod(setter); 
     177            } 
     178             
     179            // default value 
     180            String defaultValue = atts.getValue("default"); 
     181            if (defaultValue != null) { 
     182                attDef.setDefault(defaultValue); 
     183            } 
     184             
     185            // required 
     186            String requiredAtt = atts.getValue("required"); 
     187            if (requiredAtt != null && requiredAtt.equals("true")) { 
     188                attDef.setRequired(true); 
     189            } 
     190            try { 
    170191                def.addChildDefinition(attDef); 
    171  
    172             } catch (Exception e) { 
    173                 throw new XJConfException("Could not process attribute", e); 
     192            } catch (Exception e) { 
     193                throw new InvalidTagDefinitionException("Could not register attribute", e); 
    174194            } 
    175195            this.defStack.push(def); 
     
    198218                tagDef.addChildDefinition(constructorDef); 
    199219            } catch (Exception e) { 
    200                 throw new RuntimeException(e.getMessage(), e); 
     220                throw new InvalidTagDefinitionException("Could not register the constructor", e); 
    201221            } 
    202222        } 
     
    209229                parentDef.addChildDefinition(cdataDef); 
    210230            } catch (Exception e) { 
    211                 throw new RuntimeException(e.getMessage(), e); 
     231                throw new InvalidTagDefinitionException("Could not register CData handling", e); 
    212232            } 
    213233        } 
     
    220240                parentDef.addChildDefinition(childDef); 
    221241            } catch (Exception e) { 
    222                 throw new RuntimeException(e.getMessage(), e); 
     242                throw new InvalidTagDefinitionException("Could not handle child definition", e); 
    223243            } 
    224244        }