01: /*
02: * Copyright 2001-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
27: import java.io.PrintWriter;
28: import java.util.Iterator;
29: import java.util.Map;
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 fileName;
51:
52: /**
53: * Constructor.
54: */
55: public MyListPortsWriter(Emitter emitter, ServiceEntry sEntry,
56: SymbolTable symbolTable) {
57: super (emitter, "service list");
58: this .service = sEntry.getService();
59:
60: // Create the fully-qualified file name
61: String javaName = sEntry.getName();
62: fileName = emitter.getNamespaces().toDir(
63: Utils.getJavaPackageName(javaName))
64: + Utils.getJavaLocalName(javaName) + ".lst";
65: } // ctor
66:
67: protected String getFileName() {
68: return fileName;
69: } // getFileName
70:
71: /**
72: * Override the common JavaWriter header to a no-op.
73: */
74: protected void writeFileHeader(PrintWriter pw) throws IOException {
75: } // writeFileHeader
76:
77: /**
78: * Write the service list file.
79: */
80: protected void writeFileBody(PrintWriter pw) throws IOException {
81: Map portMap = service.getPorts();
82: Iterator portIterator = portMap.values().iterator();
83:
84: while (portIterator.hasNext()) {
85: Port p = (Port) portIterator.next();
86: pw.println(p.getName());
87: }
88: pw.close(); // Note: this really should be done in JavaWriter.
89: } // writeFileBody
90:
91: } // class MyListPortsWriter
|