KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > integrationGuide > example1 > MyListPortsWriter


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 samples.integrationGuide.example1;
17
18 import org.apache.axis.wsdl.symbolTable.ServiceEntry;
19 import org.apache.axis.wsdl.symbolTable.SymbolTable;
20 import org.apache.axis.wsdl.toJava.Emitter;
21 import org.apache.axis.wsdl.toJava.JavaWriter;
22 import org.apache.axis.wsdl.toJava.Utils;
23
24 import javax.wsdl.Port;
25 import javax.wsdl.Service;
26 import java.io.IOException JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32 * This is my example of a class that writes a list of a service's
33 * ports to a file named <serviceName>Lst.lst.
34 *
35 * Note: because of a name clash problem, I add the suffix "Lst".
36 * I hope to remove this in a future version of this example.
37 *
38 * Details of the JavaWriter bug: JavaWriter looks to make sure a
39 * class doesn't already exist before creating a file, but not all
40 * files that we generate are .class files! This works with
41 * deploy.wsdd and undeploy.wsdd because these files just happen
42 * to begin with lowercase letters, where Java classes begin with
43 * uppercase letters. But this example shows the problem quite
44 * well. I would LIKE to call the file <serviceName>.lst, but
45 * JavaWriter sees that we already have a class called
46 * <serviceName> and won't let me proceed.
47 */

48 public class MyListPortsWriter extends JavaWriter {
49     private Service service;
50     private String JavaDoc fileName;
51
52     /**
53      * Constructor.
54      */

55     public MyListPortsWriter(
56             Emitter emitter,
57             ServiceEntry sEntry,
58             SymbolTable symbolTable) {
59         super(emitter, "service list");
60         this.service = sEntry.getService();
61
62         // Create the fully-qualified file name
63
String JavaDoc javaName = sEntry.getName();
64         fileName = emitter.getNamespaces().toDir(
65                 Utils.getJavaPackageName(javaName))
66                 + Utils.getJavaLocalName(javaName) + ".lst";
67     } // ctor
68

69     protected String JavaDoc getFileName() {
70         return fileName;
71     } // getFileName
72

73     /**
74      * Override the common JavaWriter header to a no-op.
75      */

76     protected void writeFileHeader(PrintWriter JavaDoc pw) throws IOException JavaDoc {
77     } // writeFileHeader
78

79     /**
80      * Write the service list file.
81      */

82     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
83         Map JavaDoc portMap = service.getPorts();
84         Iterator JavaDoc portIterator = portMap.values().iterator();
85
86         while (portIterator.hasNext()) {
87             Port p = (Port) portIterator.next();
88             pw.println(p.getName());
89         }
90         pw.close(); // Note: this really should be done in JavaWriter.
91
} // writeFileBody
92

93 } // class MyListPortsWriter
94
Popular Tags