KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.axis.wsdl.toJava;
17
18 import org.apache.axis.deployment.wsdd.WSDDConstants;
19 import org.apache.axis.utils.Messages;
20 import org.apache.axis.wsdl.symbolTable.SymbolTable;
21
22 import javax.wsdl.Definition;
23 import javax.wsdl.Port;
24 import javax.wsdl.Service;
25 import java.io.File JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.OutputStreamWriter JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Map JavaDoc;
32
33 /**
34  * This is Wsdl2java's deploy Writer. It writes the deploy.java file.
35  */

36 public class JavaUndeployWriter extends JavaWriter {
37
38     /** Field definition */
39     protected Definition definition;
40
41     /**
42      * Constructor.
43      *
44      * @param emitter
45      * @param definition
46      * @param notUsed
47      */

48     public JavaUndeployWriter(Emitter emitter, Definition definition,
49                               SymbolTable notUsed) {
50
51         super(emitter, "undeploy");
52
53         this.definition = definition;
54     } // ctor
55

56     /**
57      * Generate undeploy.wsdd. Only generate it if the emitter
58      * is generating server-side mappings.
59      *
60      * @throws IOException
61      */

62     public void generate() throws IOException JavaDoc {
63
64         if (emitter.isServerSide()) {
65             super.generate();
66         }
67     } // generate
68

69     /**
70      * Return the fully-qualified name of the undeploy.wsdd file
71      * to be generated.
72      *
73      * @return
74      */

75     protected String JavaDoc getFileName() {
76
77         String JavaDoc dir =
78                 emitter.getNamespaces().getAsDir(definition.getTargetNamespace());
79
80         return dir + "undeploy.wsdd";
81     } // getFileName
82

83     /**
84      * Replace the default file header with the deployment doc file header.
85      *
86      * @param pw
87      * @throws IOException
88      */

89     protected void writeFileHeader(PrintWriter JavaDoc pw) throws IOException JavaDoc {
90
91         pw.println(Messages.getMessage("deploy01"));
92         pw.println(Messages.getMessage("deploy02"));
93         pw.println(Messages.getMessage("deploy04"));
94         pw.println(Messages.getMessage("deploy05"));
95         pw.println(Messages.getMessage("deploy06"));
96         pw.println(Messages.getMessage("deploy08"));
97         pw.println(Messages.getMessage("deploy09"));
98         pw.println();
99         pw.println("<undeployment");
100         pw.println(" xmlns=\"" + WSDDConstants.URI_WSDD + "\">");
101     } // writeFileHeader
102

103     /**
104      * Write the body of the deploy.wsdd file.
105      *
106      * @param pw
107      * @throws IOException
108      */

109     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
110         writeDeployServices(pw);
111         pw.println("</undeployment>");
112     } // writeFileBody
113

114     /**
115      * Write out deployment and undeployment instructions for each WSDL service
116      *
117      * @param pw
118      * @throws IOException
119      */

120     protected void writeDeployServices(PrintWriter JavaDoc pw) throws IOException JavaDoc {
121
122         // deploy the ports on each service
123
Map JavaDoc serviceMap = definition.getServices();
124
125         for (Iterator JavaDoc mapIterator = serviceMap.values().iterator();
126              mapIterator.hasNext();) {
127             Service myService = (Service) mapIterator.next();
128
129             pw.println();
130             pw.println(
131                     " <!-- "
132                     + Messages.getMessage(
133                             "wsdlService00", myService.getQName().getLocalPart()) + " -->");
134             pw.println();
135
136             for (Iterator JavaDoc portIterator = myService.getPorts().values().iterator();
137                  portIterator.hasNext();) {
138                 Port myPort = (Port) portIterator.next();
139
140                 writeDeployPort(pw, myPort);
141             }
142         }
143     } // writeDeployServices
144

145     /**
146      * Write out deployment and undeployment instructions for given WSDL port
147      *
148      * @param pw
149      * @param port
150      * @throws IOException
151      */

152     protected void writeDeployPort(PrintWriter JavaDoc pw, Port port) throws IOException JavaDoc {
153
154         String JavaDoc serviceName = port.getName();
155
156         pw.println(" <service name=\"" + serviceName + "\"/>");
157     } // writeDeployPort
158

159     /**
160      * Method getPrintWriter
161      *
162      * @param filename
163      * @return
164      * @throws IOException
165      */

166     protected PrintWriter JavaDoc getPrintWriter(String JavaDoc filename) throws IOException JavaDoc {
167
168         File JavaDoc file = new File JavaDoc(filename);
169         File JavaDoc parent = new File JavaDoc(file.getParent());
170
171         parent.mkdirs();
172
173         FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(file);
174         OutputStreamWriter JavaDoc writer = new OutputStreamWriter JavaDoc(out, "UTF-8");
175
176         return new PrintWriter JavaDoc(writer);
177     }
178 } // class JavaUndeployWriter
179
Popular Tags