/** * Adds a {@link NodeSource} to this list. * * @param source the {@link NodeSource} */ public void addSource(NodeSource source) { final String sourceName = source.getName(); for (NodeSource nodeSource : sourceList) { if (nodeSource.getName().equals(sourceName)) { throw new IllegalArgumentException("duplicated source node name"); } } sourceList.add(source); }
@Override public void marshal(Object object, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { SourceList sourceList = (SourceList) object; NodeSource[] sources = sourceList.getSources(); for (NodeSource source : sources) { hierarchicalStreamWriter.startNode(source.getName()); hierarchicalStreamWriter.addAttribute("refid", source.getSourceNodeId()); hierarchicalStreamWriter.endNode(); } }
@Test public void testAddSource() throws Exception { final Node node = new Node("myId", "opName"); node.addSource(new NodeSource("nodeName", "source1")); node.addSource(new NodeSource("anotherName", "source2")); node.addSource(new NodeSource("thirdName", "source3")); assertEquals(3, node.getSources().length); assertEquals("nodeName", node.getSources()[0].getName()); assertEquals("anotherName", node.getSources()[1].getName()); assertEquals("thirdName", node.getSources()[2].getName()); }
private void initNodeContext(final NodeContext nodeContext, Operator graphOp) throws GraphException { if (nodeContext.isInitialized()) { return; } for (NodeSource source : nodeContext.getNode().getSources()) { NodeContext sourceNodeContext = getNodeContext(source.getSourceNode()); Product sourceProduct = null; if (sourceNodeContext != null) { initNodeContext(sourceNodeContext, graphOp); sourceProduct = sourceNodeContext.getTargetProduct(); } else { if (graphOp != null) { sourceProduct = graphOp.getSourceProduct(source.getSourceNodeId()); } } if (sourceProduct == null) { throw new GraphException(getMissingSourceMessage(nodeContext.getNode(), source)); } nodeContext.addSourceProduct(source.getName(), sourceProduct); } Node node = nodeContext.getNode(); DomElement configuration = node.getConfiguration(); OperatorConfiguration opConfiguration = this.createOperatorConfiguration(configuration, new HashMap<String, Object>()); nodeContext.setOperatorConfiguration(opConfiguration); nodeContext.initTargetProduct(); getInitNodeContextDeque().addFirst(nodeContext); }