Changeset 87 for java/main/src/main/java/com/framsticks/parsers/Schema.java
- Timestamp:
- 06/28/13 11:56:03 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/parsers/Schema.java
r85 r87 8 8 9 9 import com.framsticks.params.*; 10 import com.framsticks.params.annotations.AutoAppendAnnotation; 11 import com.framsticks.params.annotations.FramsClassAnnotation; 12 import com.framsticks.util.FramsticksException; 10 13 import com.framsticks.util.lang.Numbers; 11 14 import org.apache.log4j.Logger; … … 30 33 * (please replace name and surname with my personal data) 31 34 */ 35 @FramsClassAnnotation 32 36 public class Schema { 33 37 … … 42 46 //return new FileInputStream(new File(Schema.class.getResource("/parsers/f0def.xml").getPath())); 43 47 return Schema.class.getResourceAsStream("/parsers/f0def.xml"); 48 } 49 50 public Schema() { 51 } 52 53 @AutoAppendAnnotation 54 public void addNeuroClass(NeuroClass neuroClass) { 44 55 } 45 56 … … 52 63 * the exception if one occurred while reading the stream 53 64 */ 54 public Schema(InputStream inputStream) throws Exception{65 public Schema(InputStream inputStream) { 55 66 56 67 DocumentBuilderFactory factory; … … 105 116 106 117 } catch (IOException | ParserConfigurationException | SAXException e) { 107 logger.fatal("unexpected exception occurred: ", e); 108 throw e; 109 } 110 118 throw new FramsticksException().msg("unexpected exception occurred").cause(e); 119 } 111 120 } 112 121 … … 170 179 * the exception in case of any error 171 180 */ 172 private static FramsClass processClass(Node classNode) throws Exception{181 private static FramsClass processClass(Node classNode) { 173 182 String classId = null; 174 183 String className = ""; 175 184 String classDescription = ""; 176 185 try { 177 classId = classNode.getAttributes().getNamedItem("ID") 178 .getNodeValue(); 186 classId = classNode.getAttributes().getNamedItem("ID").getNodeValue(); 179 187 } catch (NullPointerException e) { 180 throw new Exception("Class getId is not defined!");188 throw new FramsticksException().msg("class id is not defined"); 181 189 } 182 190 … … 184 192 classDescription = getAttributeFromNode("DESCRIPTION", classNode); 185 193 186 FramsClass framsClass = new FramsClass(classId, className,classDescription);194 FramsClassBuilder builder = FramsClass.build().id(classId).name(className).description(classDescription); 187 195 188 196 NodeList classProperties = classNode.getChildNodes(); … … 195 203 String name = getAttribute(attributes, "NAME"); 196 204 if (name == null) { 197 logger.warn("Group name in class \"" + classId + "\" (" 198 + className + ") is undefined"); 205 logger.warn("Group name in class \"" + classId + "\" (" + className + ") is undefined"); 199 206 } else { 200 framsClass.appendGroup(new Group(name));207 builder.group(new Group(name)); 201 208 } 202 209 } else if ("PROP".equals(node.getNodeName()) … … 204 211 205 212 NamedNodeMap attributes = node.getAttributes(); 206 Param param = processParameter(attributes, classId); 207 framsClass.append(param); 213 processParameter(attributes, classId, builder); 208 214 } 209 215 210 216 } 211 217 212 return framsClass;218 return builder.finish(); 213 219 } 214 220 … … 231 237 * the exception in case of any error 232 238 */ 233 private static Param processParameter(NamedNodeMap attributes, String classId) 234 throws Exception { 239 private static void processParameter(NamedNodeMap attributes, String classId, FramsClassBuilder classBuilder) { 235 240 236 241 String id = getAttribute(attributes, "ID"); 237 if (id == null) 238 throw new Exception("Property ID in class \"" + classId239 + "\" is undefined");242 if (id == null) { 243 throw new FramsticksException().msg("Property ID in class \"" + classId + "\" is undefined"); 244 } 240 245 String type = getAttribute(attributes, "TYPE"); 241 if (type == null) 242 throw new Exception("TYPE of property \"" + id + "\" is undefined"); 246 if (type == null) { 247 throw new FramsticksException().msg("TYPE of property \"" + id + "\" is undefined"); 248 } 243 249 244 250 String name = getAttribute(attributes, "NAME"); … … 261 267 } 262 268 263 ParamBuilder builder = Param.build(); 264 builder.id(id).name(name).help(description).group(group).flags(flags); 269 ParamBuilder builder = classBuilder.param(id).name(name).help(description).group(group).flags(flags); 265 270 266 271 builder.type(type); … … 282 287 builder.type(type); 283 288 } 284 return builder.finish(); 289 290 classBuilder.param(builder); 285 291 } 286 292
Note: See TracChangeset
for help on using the changeset viewer.