View Javadoc

1   /*$Id: GroovyTransformers.java,v 1.3 2004/09/16 21:46:54 nw Exp $
2    * Created on 11-May-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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 $Log: GroovyTransformers.java,v $
104 Revision 1.3  2004/09/16 21:46:54  nw
105 made sure all streams are closed
106 
107 Revision 1.2  2004/07/30 15:42:34  nw
108 merged in branch nww-itn06-bz#441 (groovy scripting)
109 
110 Revision 1.1.2.2  2004/07/27 23:37:59  nw
111 refactoed framework.
112 experimented with betwixt - can't get it to work.
113 got XStream working in 5 mins.
114 about to remove betwixt code.
115 
116 Revision 1.1.2.1  2004/07/26 15:51:19  nw
117 first stab at a groovy scheduler.
118 transcribed all the classes in the python prototype, and took copies of the
119 classes in the 'scripting' package.
120 
121 Revision 1.1  2004/07/09 09:30:28  nw
122 merged in scripting workflow interpreter from branch
123 nww-x-workflow-extensions
124 
125 Revision 1.1.2.1  2004/05/21 11:25:19  nw
126 first checkin of prototype scrpting workflow interpreter
127  
128 */