public Namespace readNamespace(String path) { try { File fXmlFile = new File(path); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); String topTag = doc.getDocumentElement().getNodeName(); if (topTag.equals("Namespace")) { Namespace result = createNamespace(doc.getDocumentElement()); for (ForwardDeclaration decl : forwardDeclarationMap.keySet()) { decl.setDeclaration((Declaration) findIrObject(forwardDeclarationMap.get(decl))); } return result; } else { throw new RuntimeException("Invalid top tag in XML ir document"); } // As a last step, patch the forward declarations } catch (Exception e) { System.err.println("[IrXmlReader. Error reading '" + path + "' message = " + e.getMessage()); e.printStackTrace(); return null; } }
public AbstractActor readActor(String path) { try { File fXmlFile = new File(path); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); String topTag = doc.getDocumentElement().getNodeName(); AbstractActor result; if (topTag.equals("Actor")) { result = createActor(doc.getDocumentElement()); } else if (topTag.equals("Network")) { result = createNetwork(doc.getDocumentElement()); } else if (topTag.equals("ExternalActor")) { result = createExternalActor(doc.getDocumentElement()); } else { throw new RuntimeException("Invalid top tag in XML ir document"); } // As a last step, patch the forward declarations for (ForwardDeclaration decl : forwardDeclarationMap.keySet()) { decl.setDeclaration((Declaration) findIrObject(forwardDeclarationMap.get(decl))); } return result; } catch (Exception x) { System.err.println("[ActorDirectory]ÊError reading '" + path + "' x " + x.getMessage()); return null; } }