Changeset 45
- Timestamp:
- 08/22/05 21:45:26 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/net/schst/XJConf/DefinitionParser.java
r35 r45 10 10 import javax.xml.parsers.SAXParserFactory; 11 11 12 import net.schst.XJConf.exceptions.InvalidTagDefinitionException; 12 13 import net.schst.XJConf.exceptions.XJConfException; 13 14 15 import org.omg.PortableInterceptor.INACTIVE; 14 16 import org.xml.sax.Attributes; 15 17 import org.xml.sax.SAXException; … … 79 81 // define a tag 80 82 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; 82 88 return; 83 89 } … … 91 97 type = atts.getValue("primitive"); 92 98 } 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); 94 107 // key attribute 95 108 String keyAtt = atts.getValue("keyAttribute"); … … 136 149 // define a child tag data 137 150 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); 139 156 this.defStack.push(def); 140 157 } … … 144 161 // get the current tag 145 162 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 { 170 191 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); 174 194 } 175 195 this.defStack.push(def); … … 198 218 tagDef.addChildDefinition(constructorDef); 199 219 } catch (Exception e) { 200 throw new RuntimeException(e.getMessage(), e);220 throw new InvalidTagDefinitionException("Could not register the constructor", e); 201 221 } 202 222 } … … 209 229 parentDef.addChildDefinition(cdataDef); 210 230 } catch (Exception e) { 211 throw new RuntimeException(e.getMessage(), e);231 throw new InvalidTagDefinitionException("Could not register CData handling", e); 212 232 } 213 233 } … … 220 240 parentDef.addChildDefinition(childDef); 221 241 } catch (Exception e) { 222 throw new RuntimeException(e.getMessage(), e);242 throw new InvalidTagDefinitionException("Could not handle child definition", e); 223 243 } 224 244 }
