/** * Tries to extract compositions of nodes and primitives from the connectors of the module <code> * module</code>, throwing an exception if something goes wrong. * * @param connector The connector. Not <code>null</code>. * @return A nonempty list of compositions. Never <code>null</code>. * @throws NullPointerException If <code>connector==null</code>. * @throws XMLExtractorException If something goes wrong while extracting. */ public static Collection< Composition<Connector<DefaultConstraintAutomaton>, DefaultConstraintAutomaton>> tryExtractFrom(final XMLModule module) throws XMLExtractorException { if (module == null) throw new NullPointerException(); try { if (!module.hasConnectors()) throw new XMLExtractorException("Every module should contain at least one connector."); final List<Composition<Connector<DefaultConstraintAutomaton>, DefaultConstraintAutomaton>> compositions = new ArrayList< Composition<Connector<DefaultConstraintAutomaton>, DefaultConstraintAutomaton>>(); for (final XMLConnector c : module.getConnectors()) compositions.add(tryExtractFrom(c)); return compositions; } catch (final Exception e) { throw new XMLExtractorException( "I failed to extract compositions from " + (module.hasName() ? "the module named \"" + module.getName() + "\"" : "a nameless module") + ".", e); } }
/** * Extracts the links between the components and the connectors of the module <code>module</code> * from that module. * * @param module The module. Not <code>null</code>. * @return A collection of links. Never <code>null</code>. * @throws NullPointerException If <code>module==null</code>. */ public static Collection<Link> extractLinksFrom(final XMLModule module) { if (module == null) throw new NullPointerException(); final Collection<Link> links = new ArrayList<Link>(); String connectorName, connectorVertexName, componentName, componentVertexName; for (final XMLConnector c : module.getConnectors()) c.getNodes(); for (final XMLComponent c : module.getComponents()) { for (final Entry<String, XMLNode> e : c.getLinkedNodes().entrySet()) { connectorName = e.getValue().getConnector().getName(); connectorVertexName = e.getValue().getName(); componentName = c.getName(); componentVertexName = e.getKey(); links.add(new Link(connectorName, connectorVertexName, componentName, componentVertexName)); } } return links; }