1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.jobscheduler.impl.groovy;
12
13 import org.astrogrid.component.descriptor.ComponentDescriptor;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17
18 import javax.xml.transform.Source;
19 import javax.xml.transform.Templates;
20 import javax.xml.transform.Transformer;
21 import javax.xml.transform.TransformerConfigurationException;
22 import javax.xml.transform.TransformerFactory;
23 import javax.xml.transform.stream.StreamSource;
24
25 import junit.framework.Test;
26
27 /*** Default implementation of the transformers interface.
28 * @author Noel Winstanley nw@jb.man.ac.uk 11-May-2004
29 *
30 */
31 public class GroovyTransformers implements GroovySchedulerImpl.Transformers, ComponentDescriptor {
32 /*** Construct a new DefaultTransformers
33 *
34 */
35 public GroovyTransformers() throws TransformerConfigurationException {
36 TransformerFactory fac = TransformerFactory.newInstance();
37 InputStream compilerXSL = null;
38 InputStream annotatorXSL = null;
39 try {
40 compilerXSL = this.getClass().getResourceAsStream(COMPILER_XSL);
41 Source compilerSource = new StreamSource(compilerXSL);
42 compilerTemplate = fac.newTemplates(compilerSource);
43 annotatorXSL = this.getClass().getResourceAsStream(ANNOTATOR_XSL);
44 Source annotatorSource = new StreamSource(annotatorXSL);
45 annotatorTemplate = fac.newTemplates(annotatorSource);
46 } finally {
47 if (compilerXSL != null) {
48 try {
49 compilerXSL.close();
50 } catch (IOException ioe) {
51 }
52 }
53 if (annotatorXSL != null) {
54 try {
55 annotatorXSL.close();
56 } catch (IOException ioe) {
57 }
58 }
59 }
60 }
61 public static final String COMPILER_XSL = "workflow-compiler.xsl";
62 public static final String ANNOTATOR_XSL = "id-annotate.xsl";
63
64 protected final Templates compilerTemplate;
65 protected final Templates annotatorTemplate;
66 /***
67 * @see org.astrogrid.jes.jobscheduler.impl.ScriptedSchedulerImpl.Transformers#getCompiler()
68 */
69 public Transformer getCompiler() throws TransformerConfigurationException {
70 return compilerTemplate.newTransformer();
71 }
72
73 /***
74 * @see org.astrogrid.jes.jobscheduler.impl.ScriptedSchedulerImpl.Transformers#getWorkflowAnnotator()
75 */
76 public Transformer getWorkflowAnnotator() throws TransformerConfigurationException {
77 return annotatorTemplate.newTransformer();
78 }
79 /***
80 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
81 */
82 public String getName() {
83 return "Groovy transformers";
84 }
85 /***
86 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
87 */
88 public String getDescription() {
89 return "XSLT transformers used in Groovy Scheduler impl\n"
90 + this.getClass().getResource(COMPILER_XSL).toString() + "\n"
91 + this.getClass().getResource(ANNOTATOR_XSL).toString();
92 }
93 /*** @todo add test to verify all xslts are present and compile.
94 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
95 */
96 public Test getInstallationTest() {
97 return null;
98 }
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128