View Javadoc

1   /***
2   * Copyright 2004 The Apache Software Foundation.
3   * 
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   * 
8   *      http://www.apache.org/licenses/LICENSE-2.0
9   * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  package org.apache.commons.jelly.tags.jaxme;
17  
18  import java.io.File;
19  import java.io.IOException;
20  
21  import org.apache.commons.jelly.TagSupport;
22  import org.apache.commons.jelly.XMLOutput;
23  import org.apache.commons.jelly.MissingAttributeException;
24  import org.apache.commons.jelly.JellyTagException;
25  
26  import org.apache.ws.jaxme.generator.Generator;
27  import org.apache.ws.jaxme.generator.SchemaReader;
28  import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
29  import org.apache.ws.jaxme.generator.sg.SchemaSG;
30  import org.apache.ws.jaxme.generator.impl.GeneratorImpl;
31  import org.apache.ws.jaxme.js.JavaSourceFactory;
32  
33  /*** 
34   * Generates java objects using JaxMe.
35   * This object can be marshalled into xml and the results unmarshalled 
36   * using JaxMe.
37   *
38   * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
39   * @author <a href="mailto:commons-dev at jakarta.apache.org">Apache Commons Development Team</a>
40   * @version $Revision: 155420 $
41   */
42  public class GeneratorTag extends TagSupport {
43          
44      private String schemaUrl;
45      private String target;
46      
47      public String getSchemaUrl() {
48          return schemaUrl;
49      }
50          
51      /***
52       * Defines the schema against which the java object representations
53       * should be generated.
54       */
55      public void setSchemaUrl(String schemaUrl) {
56          this.schemaUrl = schemaUrl;
57      }
58      
59      public String getTarget() {
60          return target;
61      }
62      
63      /***
64       * Defines the target directory into which 
65       * the generated objects will be placed.
66       */
67      public void setTarget(String target) {
68          this.target = target;
69      }
70      
71          
72      private File getSchemaFile() throws JellyTagException {
73          return new File(schemaUrl);
74      }
75      
76      private File getTargetDirectory() throws JellyTagException {
77          return new File(target);
78      }
79      
80      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
81      
82          if (schemaUrl == null) {
83              throw new MissingAttributeException( "schemaUrl" );
84          }
85          
86          if (target == null) {
87              throw new MissingAttributeException( "target" );
88          }    
89          
90          
91          
92          Generator generator = new GeneratorImpl();
93          
94          JAXBSchemaReader reader = new JAXBSchemaReader();
95          generator.setSchemaReader(reader);
96          reader.setGenerator(generator);
97          generator.setTargetDirectory(getTargetDirectory());
98          
99          System.out.println("Target: " + getTargetDirectory());
100         
101         try
102         {
103             SchemaSG schemaSG = generator.generate(getSchemaFile());
104         }
105         catch (Exception e) 
106         {
107             throw new JellyTagException(e);
108         }
109     }
110 }