SpecificationReader { protected Application<Task, Dependency> toApplication(nu.xom.Element eApplication) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { Application<Task, Dependency> application = new Application<Task, Dependency>(); nu.xom.Elements eTasks = eApplication.getChildElements("task", SpecificationWriter.NS); for (nu.xom.Element eTask : iterable(eTasks)) { Task task = toNode(eTask, null); application.addVertex(task); } nu.xom.Elements eCommunications = eApplication.getChildElements("communication", SpecificationWriter.NS); for (nu.xom.Element eCommunication : iterable(eCommunications)) { Communication communication = toNode(eCommunication, null); application.addVertex(communication); } nu.xom.Elements eDependencies = eApplication.getChildElements("dependency", SpecificationWriter.NS); for (nu.xom.Element eDependency : iterable(eDependencies)) { parseDependency(eDependency, application); } nu.xom.Element eFunctions = eApplication.getFirstChildElement("functions", SpecificationWriter.NS); if (eFunctions != null) { nu.xom.Elements eFuncs = eFunctions.getChildElements("function", SpecificationWriter.NS); for (nu.xom.Element eFunc : iterable(eFuncs)) { Task task = application.getVertex(eFunc.getAttributeValue("anchor")); Function<Task, Dependency> function = application.getFunction(task); Attributes attributes = toAttributes(eFunc.getFirstChildElement("attributes", SpecificationWriter.NS)); setAttributes(function, attributes); } } return application; }  Specification read(String filename); Specification read(File file); Specification read(InputStream in); Specification toSpecification(nu.xom.Element eSpecification);  }
@Test public void toApplicationTest() throws ValidityException, ParsingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { nu.xom.Element eApp = new nu.xom.Element("application", SpecificationWriter.NS); nu.xom.Element r1 = new nu.xom.Element("task", SpecificationWriter.NS); r1.addAttribute(new Attribute("id", "r1")); eApp.appendChild(r1); nu.xom.Element r2 = new nu.xom.Element("communication", SpecificationWriter.NS); r2.addAttribute(new Attribute("id", "r2")); eApp.appendChild(r2); nu.xom.Element l = new nu.xom.Element("dependency", SpecificationWriter.NS); l.addAttribute(new Attribute("id", "l")); l.addAttribute(new Attribute("source", "r1")); l.addAttribute(new Attribute("destination", "r2")); eApp.appendChild(l); SpecificationReader r = new SpecificationReader(); Application<Task, Dependency> application = r.toApplication(eApp); Assert.assertNotNull(application.getVertex("r1")); Assert.assertNotNull(application.getVertex("r2")); Assert.assertNotNull(application.getEdge("l")); }