KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > symbolTable > SymTabEntry


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.symbolTable;
17
18 import javax.xml.namespace.QName JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * SymTabEntry is the base class for all symbol table entries. It contains four things:
25  * - a QName
26  * - space for a Writer-specific name (for example, in Wsdl2java, this will be the Java name)
27  * - isReferenced flag indicating whether this entry is referenced by other entries
28  * - dynamicVars; a mechanism for Writers to add additional context information onto entries.
29  */

30 public abstract class SymTabEntry {
31
32     // The QName of this entry is immutable. There is no setter for it.
33

34     /** Field qname */
35     protected QName JavaDoc qname;
36
37     // The name is Writer implementation dependent. For example, in Wsdl2java, this will become
38
// the Java name.
39

40     /** Field name */
41     protected String JavaDoc name;
42
43     // Is this entry referenced by any other entry?
44

45     /** Field isReferenced */
46     private boolean isReferenced = false;
47
48     /** Field dynamicVars */
49     private HashMap JavaDoc dynamicVars = new HashMap JavaDoc();
50
51     /**
52      * Construct a symbol table entry with the given QName.
53      *
54      * @param qname
55      */

56     protected SymTabEntry(QName JavaDoc qname) {
57         this.qname = qname;
58     } // ctor
59

60     /**
61      * Get the QName of this entry.
62      *
63      * @return
64      */

65     public final QName JavaDoc getQName() {
66         return qname;
67     } // getQName
68

69     /**
70      * Get the name of this entry. The name is Writer-implementation-dependent. For example, in
71      * Wsdl2java, this will become the Java name.
72      *
73      * @return
74      */

75     public String JavaDoc getName() {
76         return name;
77     } // getName
78

79     /**
80      * Set the name of this entry. This method is not called by the framework, it is only called
81      * by the Writer implementation.
82      *
83      * @param name
84      */

85     public void setName(String JavaDoc name) {
86         this.name = name;
87     } // setName
88

89     /**
90      * Is this entry referenced by any other entry in the symbol table?
91      *
92      * @return
93      */

94     public final boolean isReferenced() {
95         return isReferenced;
96     } // isReferenced
97

98     /**
99      * Set the isReferenced variable, default value is true.
100      *
101      * @param isReferenced
102      */

103     public final void setIsReferenced(boolean isReferenced) {
104         this.isReferenced = isReferenced;
105     } // setIsReferenced
106

107     /**
108      * There may be information that does not exist in WSDL4J/DOM
109      * structures and does not exist in
110      * our additional structures, but that Writer implementation
111      * will need. This information is
112      * most likely context-relative, so the DynamicVar map is
113      * provided for the Writers to store and
114      * retrieve their particular information.
115      *
116      * @param key
117      * @return
118      */

119     public Object JavaDoc getDynamicVar(Object JavaDoc key) {
120         return dynamicVars.get(key);
121     } // getDynamicVar
122

123     /**
124      * Method setDynamicVar
125      *
126      * @param key
127      * @param value
128      */

129     public void setDynamicVar(Object JavaDoc key, Object JavaDoc value) {
130         dynamicVars.put(key, value);
131     } // setDynamicVar
132

133     /**
134      * Collate the info in this object in string form.
135      *
136      * @return
137      */

138     public String JavaDoc toString() {
139         return toString("");
140     } // toString
141

142     /**
143      * Collate the info in this object in string form with indentation.
144      *
145      * @param indent
146      * @return
147      */

148     protected String JavaDoc toString(String JavaDoc indent) {
149
150         String JavaDoc string = indent + "QName: " + qname + '\n' + indent
151                 + "name: " + name + '\n' + indent
152                 + "isReferenced? " + isReferenced + '\n';
153         String JavaDoc prefix = indent + "dynamicVars: ";
154         Iterator JavaDoc entries = dynamicVars.entrySet().iterator();
155
156         while (entries.hasNext()) {
157             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) entries.next();
158             Object JavaDoc key = entry.getKey();
159
160             string += prefix + key + " = " + entry.getValue() + '\n';
161             prefix = indent + " ";
162         }
163
164         return string;
165     } // toString
166
} // abstract class SymTabEntry
167
Popular Tags