/** * Create a Sequence process for the processes of given services. Creates the data flow assuming * each service has one output and one input (except first and last one). */ CompositeProcess createSequenceProcess( final CompositeProcess compositeProcess, final List<Service> services) { final Sequence sequence = ont.createSequence(null); compositeProcess.setComposedOf(sequence); final Perform[] performs = new Perform[services.size()]; for (int i = 0; i < services.size(); i++) { final Service s = services.get(i); final Process p = s.getProcess(); performs[i] = ont.createPerform(null); performs[i].setProcess(p); sequence.addComponent(performs[i]); if (i > 0) { final Perform prevPerform = performs[i - 1]; final Input input = p.getInputs().get(0); final Output output = prevPerform.getProcess().getOutputs().get(0); // the value of 'input' is the value of 'output' from 'prevPerform' performs[i].addBinding(input, prevPerform, output); } } final Perform firstPerform = performs[0]; final Perform lastPerform = performs[services.size() - 1]; final boolean createInput = firstPerform.getProcess().getInputs().size() > 0; final boolean createOutput = lastPerform.getProcess().getOutputs().size() > 0; if (createInput) { final Input input = firstPerform.getProcess().getInputs().get(0); final Input newInput = ont.createInput(URIUtils.createURI(baseURI, "TestInput")); newInput.setLabel(input.getLabel(null), null); newInput.setParamType(input.getParamType()); newInput.setProcess(compositeProcess); // input of the first perform is directly read from the input of the composite process performs[0].addBinding(input, OWLS.Process.ThisPerform, newInput); } if (createOutput) { final Output output = lastPerform.getProcess().getOutputs().get(0); final Output newOutput = ont.createOutput(URIUtils.createURI(baseURI, "TestOutput")); newOutput.setLabel(output.toPrettyString(), null); newOutput.setParamType(output.getParamType()); newOutput.setProcess(compositeProcess); // the output of the composite process is the output pf last process final Result result = ont.createResult(null); result.addBinding(newOutput, lastPerform, output); compositeProcess.addResult(result); } return compositeProcess; }