KickJava   Java API By Example, From Geeks To Geeks.

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


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.wsdl.symbolTable.TypeEntry;
19
20 import java.io.IOException JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22
23 /**
24  * This is Wsdl2java's Holder Writer. It writes the <typeName>Holder.java file.
25  */

26 public class JavaHolderWriter extends JavaClassWriter {
27
28     /** Field type */
29     private TypeEntry type;
30
31     /**
32      * Constructor.
33      *
34      * @param emitter
35      * @param type
36      */

37     protected JavaHolderWriter(Emitter emitter, TypeEntry type) {
38
39         super(emitter, Utils.holder(type, emitter), "holder");
40
41         this.type = type;
42     } // ctor
43

44     /**
45      * Return "public final ".
46      *
47      * @return
48      */

49     protected String JavaDoc getClassModifiers() {
50         return super.getClassModifiers() + "final ";
51     } // getClassModifiers
52

53     /**
54      * Return "implements javax.xml.rpc.holders.Holder ".
55      *
56      * @return
57      */

58     protected String JavaDoc getImplementsText() {
59         return "implements javax.xml.rpc.holders.Holder ";
60     } // getImplementsText
61

62     /**
63      * Generate the holder for the given complex type.
64      *
65      * @param pw
66      * @throws IOException
67      */

68     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
69
70         String JavaDoc holderType = type.getName();
71
72         pw.println(" public " + holderType + " value;");
73         pw.println();
74         pw.println(" public " + className + "() {");
75         pw.println(" }");
76         pw.println();
77         pw.println(" public " + className + "(" + holderType + " value) {");
78         pw.println(" this.value = value;");
79         pw.println(" }");
80         pw.println();
81     } // writeOperation
82

83     /** Generate a java source file for the holder class.
84      * If the emitter works in deploy mode and the class already exists, the source wull not be generated.
85      */

86     public void generate() throws IOException JavaDoc {
87         String JavaDoc fqcn = getPackage() + "." + getClassName();
88         if (emitter.isDeploy()) {
89             if (!emitter.doesExist(fqcn)) {
90                 super.generate();
91             }
92         } else {
93             super.generate();
94         }
95     }
96 } // class JavaHolderWriter
97
Popular Tags