KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > toJava > JavaBuildFileWriter


1 /*
2  * Copyright 2001-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
17 package org.apache.axis.wsdl.toJava;
18
19 import org.apache.axis.wsdl.symbolTable.SymbolTable;
20
21 import javax.wsdl.Definition;
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 /**
27  * <p>This is Wsdl2java's build file Writer. It writes the build.xml file.
28  * The build.xml file is a ant build file. After run the WSDL2Java and filling
29  * the implementation the user just have to cd to the out dir and type
30  * and "ant" (of course you must have ant installed). Then the ant will genarate a
31  * jar file which named after the wsdl file you used for WSDL2Java.
32  * (named after wsdl file ??? I do not get anything better .. the wsdl file may have
33  * more than one service ect ... so we can use them.)</p>
34  *
35  * <p>This build file work on the where it is created ... User can not move the genarated code
36  * to another mechine and try to build. (class path is broken). But of cource user can
37  * move genarated build file at his will.</p>
38  *
39  * <p>deploy the webservice using the AdminClient and drop the jar to servlet Container.
40  * We might even add another task to deploy the WS as well.</p>
41  *
42  * <p>This feature can be on and off using the -B option default is off</p>
43  * @author Srinath Perera(hemapani@opensource.lk)
44  */

45 public class JavaBuildFileWriter extends JavaWriter
46 {
47     protected Definition definition;
48
49     /** Field symbolTable */
50     protected SymbolTable symbolTable;
51
52
53     /**
54      * Constructor
55      */

56     public JavaBuildFileWriter(Emitter emitter, Definition definition,
57                                SymbolTable symbolTable) {
58
59         super(emitter, "build");
60
61         this.definition = definition;
62         this.symbolTable = symbolTable;
63     }
64
65     protected String JavaDoc getFileName() {
66         String JavaDoc dir = emitter.getOutputDir();
67         if (dir == null) {
68             dir = ".";
69         }
70         return dir + "/build.xml";
71     }
72
73     protected void writeFileBody(PrintWriter JavaDoc out) throws IOException JavaDoc {
74         out.write("<?xml version=\"1.0\"?>\n");
75
76         out.write("<project basedir=\".\" default=\"jar\">\n");
77         out.write(" <property name=\"src\" location=\".\"/>\n");
78         out.write(" <property name=\"build.classes\" location=\"classes\"/>\n");
79
80         out.write(" <path id=\"classpath\">\n");
81         StringTokenizer JavaDoc tok = getClasspathComponets();
82         while (tok.hasMoreTokens()) {
83             out.write(" <pathelement location=\"" + tok.nextToken() + "\"/>\n");
84         }
85         out.write(" </path>\n");
86
87         out.write(" <target name=\"compile\">\n");
88         out.write(" <mkdir dir=\"${build.classes}\"/>\n");
89         out.write(" <javac destdir=\"${build.classes}\" debug=\"on\">\n");
90         out.write(" <classpath refid=\"classpath\" />\n");
91         out.write(" <src path=\"${src}\"/>\n");
92         out.write(" </javac>\n");
93         out.write(" </target>\n");
94
95         out.write(" <target name=\"jar\" depends=\"compile\">\n");
96         out.write(" <copy todir=\"${build.classes}\">\n");
97         out.write(" <fileset dir=\".\" casesensitive=\"yes\" >\n");
98         out.write(" <include name=\"**/*.wsdd\"/>\n");
99         out.write(" </fileset>\n");
100         out.write(" </copy>\n");
101
102         out.write(" <jar jarfile=\"" + getJarFileName(symbolTable.getWSDLURI()) + ".jar\" basedir=\"${build.classes}\" >\n");
103         out.write(" <include name=\"**\" />\n");
104         out.write(" <manifest>\n");
105         out.write(" <section name=\"org/apache/ws4j2ee\">\n");
106         out.write(" <attribute name=\"Implementation-Title\" value=\"Apache Axis\"/>\n");
107         out.write(" <attribute name=\"Implementation-Vendor\" value=\"Apache Web Services\"/>\n");
108         out.write(" </section>\n");
109         out.write(" </manifest>\n");
110         out.write(" </jar>\n");
111         out.write(" <delete dir=\"${build.classes}\"/>\n");
112         out.write(" </target>\n");
113         out.write("</project>\n");
114         out.close();
115     }
116
117     private StringTokenizer JavaDoc getClasspathComponets() {
118         String JavaDoc classpath = System.getProperty("java.class.path");
119         String JavaDoc spearator = ";";
120         if (classpath.indexOf(';') < 0) {
121             //t hen it is UNIX
122
spearator = ":";
123         }
124
125         return new StringTokenizer JavaDoc(classpath, spearator);
126     }
127
128     private String JavaDoc getJarFileName(String JavaDoc wsdlFile) {
129         int index = 0;
130         if ((index = wsdlFile.lastIndexOf("/")) > 0) {
131             wsdlFile = wsdlFile.substring(index + 1);
132         }
133         if ((index = wsdlFile.lastIndexOf("?")) > 0) {
134             wsdlFile = wsdlFile.substring(0, index);
135         }
136         if ((index = wsdlFile.indexOf('.')) != -1) {
137             return wsdlFile.substring(0, index);
138         } else {
139             return wsdlFile;
140         }
141     }
142
143     /* (non-Javadoc)
144      * @see org.apache.axis.wsdl.gen.Generator#generate()
145      */

146     public void generate() throws IOException JavaDoc {
147         if (emitter.isBuildFileWanted()) {
148             super.generate();
149         }
150     }
151
152 }
153
Popular Tags