Source code: org/embl/ebi/escience/scuflworkers/java/LocalServiceProcessor.java
1 /**
2 * This file is a component of the Taverna project,
3 * and is licensed under the GNU LGPL.
4 * Copyright Tom Oinn, EMBL-EBI
5 */
6 package org.embl.ebi.escience.scuflworkers.java;
7
8 import org.embl.ebi.escience.scufl.*;
9
10 // Utility Imports
11 import java.util.Properties;
12
13 /**
14 * A processor that runs the quick Java plugins defined by the
15 * LocalService interface in this package.
16 * @author Tom Oinn
17 */
18 public class LocalServiceProcessor extends Processor {
19
20 private String workerClassName;
21 private LocalWorker theImplementation;
22
23 public String getWorkerClassName() {
24 return this.workerClassName;
25 }
26
27 protected LocalWorker getWorker() {
28 return this.theImplementation;
29 }
30
31 public LocalServiceProcessor(ScuflModel model, String name, String workerClassName)
32 throws ProcessorCreationException,
33 DuplicateProcessorNameException {
34 super(model, name);
35 this.workerClassName = workerClassName;
36 try {
37 // Get the instance of the worker and interrogate it for the available ports
38 Class theClass = Class.forName(workerClassName);
39 theImplementation = (LocalWorker)theClass.newInstance();
40 for (int i = 0; i < theImplementation.inputNames().length; i++) {
41 // Create input ports
42 Port p = new InputPort(this, theImplementation.inputNames()[i]);
43 p.setSyntacticType(theImplementation.inputTypes()[i]);
44 addPort(p);
45 }
46 for (int i = 0; i < theImplementation.outputNames().length; i++) {
47 // Create output ports
48 Port p = new OutputPort(this, theImplementation.outputNames()[i]);
49 p.setSyntacticType(theImplementation.outputTypes()[i]);
50 SemanticMarkup m = p.getMetadata();
51 String[] mimeTypes = ((theImplementation.outputTypes()[i].split("\\'"))[1]).split(",");
52 for (int j = 0; j < mimeTypes.length; j++) {
53 System.out.println(mimeTypes[j]);
54 m.addMIMEType(mimeTypes[j]);
55 }
56 addPort(p);
57 }
58 }
59 catch (DuplicatePortNameException dpne) {
60 throw new ProcessorCreationException("The supplied specification for the local service processor '"+
61 name+"' contained a duplicate port '"+
62 dpne.getMessage()+"'");
63 }
64 catch (PortCreationException pce) {
65 throw new ProcessorCreationException("An error occured whilst generating ports for the local service processor "+pce.getMessage());
66 }
67 catch (Exception e) {
68 ProcessorCreationException pce = new ProcessorCreationException("Unable to instantiate processor for local service class "+workerClassName);
69 pce.initCause(e);
70 throw pce;
71 }
72 }
73
74 /**
75 * Get the properties for this processor
76 */
77 public Properties getProperties() {
78 Properties props = new Properties();
79 props.put("WorkerClass",this.workerClassName);
80 return props;
81 }
82
83
84 }