KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > xs > models > CMNodeFactory


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  */

51
52 package com.sun.org.apache.xerces.internal.impl.xs.models;
53
54 import com.sun.org.apache.xerces.internal.impl.Constants;
55 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
56 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
57 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
58
59 /**
60  * <p>Creates nodes.</p>
61  *
62  * @author Neeraj Bajaj
63  * @version $Revision: 1.2 $, $Date: 2004/01/22 20:36:54 $
64  */

65 public class CMNodeFactory {
66
67     /**
68      * Property identifier: error reporter.
69      */

70     private static final String JavaDoc ERROR_REPORTER =
71         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
72     
73     /**
74      * <p>Output extra debugging messages to {@link System.err}.</p>
75      */

76     private static final boolean DEBUG = false;
77     
78     /**
79      * <p>Count of number of nodes created.</p>
80      */

81     private int nodeCount = 0;
82     
83     /**
84      * Error reporter. This property identifier is:
85      * http://apache.org/xml/properties/internal/error-reporter
86      */

87     private XMLErrorReporter fErrorReporter = null;
88     
89     /**
90      * Default constructor.
91      */

92     public CMNodeFactory() {
93
94         if (DEBUG) {
95             System.err.println("CMNodeFactory()");
96         }
97     }
98     
99     /**
100      * <p>Reset internal state using <code>componentManager</code> provided values.</p>
101      *
102      * @param componentManager {@link XMLComponentManager} to provide new values for internal state.
103      */

104     public void reset(XMLComponentManager componentManager) {
105         
106         if (DEBUG) {
107             System.err.println("CMNodeFactory#reset("
108             + "componentManager[" + componentManager.toString() + "])");
109         }
110
111         // error reporter
112
fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
113     } //reset()
114

115     /**
116      * <p>Create a new leaf node as defined by the params.</p>
117      *
118      * @param type Type of leaf node to return.
119      * @param leaf Leaf <code>Object</code>
120      * @param id ID of leaf to return.
121      * @param position Position of leaf to return.
122      *
123      * @return New node as defined by the params.
124      */

125     public CMNode getCMLeafNode(int type, Object JavaDoc leaf, int id, int position) {
126         
127         // this is a new node
128
nodeCount++;
129
130         if (DEBUG) {
131             System.err.println("CMNodeFactory#getCMLeafNode("
132             + "type[" + type + "], "
133             + "leaf[" + leaf.toString() + "], "
134             + "id[" + id + "], "
135             + "position[" + position + "])\n"
136             + "\tnodeCount=" + nodeCount);
137         }
138                 
139         // create new node as defined by the params
140
return new XSCMLeaf(type, leaf, id, position);
141     }
142     
143     /**
144      * <p>Create a leaf node as defined by the params.</p>
145      *
146      * @param type Type of node to create.
147      * @param childNode Child node.
148      *
149      * @return New node as defined by the params.
150      */

151     public CMNode getCMUniOpNode(int type, CMNode childNode) {
152
153         // this is a new node
154
nodeCount++;
155
156         if (DEBUG) {
157             System.err.println("CMNodeFactory#getCMUniOpNode("
158             + "type[" + type + "], "
159             + "childNode[" + childNode.toString() + "])\n"
160             + "\tnodeCount=" + nodeCount);
161         }
162         
163         // create new node as defined by the params
164
return new XSCMUniOp(type, childNode);
165     }
166
167     /**
168      * <p>Create a leaf node as defined by the params.</p>
169      *
170      * @param type Type of node to create.
171      * @param leftNode Left node.
172      * @param rightNode Right node.
173      *
174      * @return New node as defined by the params.
175      */

176     public CMNode getCMBinOpNode(int type, CMNode leftNode, CMNode rightNode) {
177
178         // this is a new node
179
nodeCount++;
180
181         if (DEBUG) {
182             System.err.println("CMNodeFactory#getCMBinOpNode("
183             + "type[" + type + "], "
184             + "leftNode[" + leftNode.toString() + "], "
185             + "rightNode[" + rightNode.toString() + "])\n"
186             + "\tnodeCount=" + nodeCount);
187         }
188         
189         // create new node as defined by the params
190
return new XSCMBinOp(type, leftNode, rightNode);
191     }
192
193     /**
194      * <p>Reset the internal node count to 0.</p>
195      */

196     public void resetNodeCount() {
197         nodeCount = 0;
198         
199         if (DEBUG) {
200             System.err.println("CMNodeFactory#resetNodeCount: "
201                 + "nodeCount=" + nodeCount + " (after reset)");
202         }
203     }
204     
205     /**
206      * <p>Sets the value of a property. This method is called by the component
207      * manager any time after reset when a property changes value.</p>
208      *
209      * <p> <strong>Note:</strong> Components should silently ignore properties
210      * that do not affect the operation of the component.</p>
211      *
212      * @param propertyId The property identifier.
213      * @param value The value of the property.
214      */

215     public void setProperty(String JavaDoc propertyId, Object JavaDoc value) {
216         
217         if (DEBUG) {
218             System.err.println("CMNodeFactory#setProperty("
219             + "propertyId[" + propertyId + "], "
220             + "value[" + value.toString() + "])");
221         }
222
223         // Xerces properties?
224
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
225             String JavaDoc property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
226                         
227             // error reporter?
228
if (property.equals(Constants.ERROR_REPORTER_PROPERTY)) {
229                 fErrorReporter = (XMLErrorReporter) value;
230                 return;
231             }
232             
233             // silently ignore unknown Xerces property
234
return;
235         } else {
236             // silently ignore unknown non-Xerces property
237
return;
238         }
239
240     } // setProperty(String,Object)
241
} // CMNodeFactory()
242
Popular Tags