KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > vocab > ParserVocabulary


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39
40 package com.sun.xml.fastinfoset.vocab;
41
42 import com.sun.xml.fastinfoset.util.CharArrayArray;
43 import com.sun.xml.fastinfoset.util.ContiguousCharArrayArray;
44 import com.sun.xml.fastinfoset.util.PrefixArray;
45 import com.sun.xml.fastinfoset.util.QualifiedNameArray;
46 import com.sun.xml.fastinfoset.util.StringArray;
47 import com.sun.xml.fastinfoset.util.ValueArray;
48 import java.net.URI JavaDoc;
49
50 public class ParserVocabulary extends Vocabulary {
51     public static final String JavaDoc IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
52         "com.sun.xml.fastinfoset.vocab.ParserVocabulary.IdentifyingStringTable.maximumItems";
53     public static final String JavaDoc NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
54         "com.sun.xml.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumItems";
55     public static final String JavaDoc NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY =
56         "com.sun.xml.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumCharacters";
57
58     protected static int IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS;
59     protected static int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS;
60     protected static int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS;
61     
62     static {
63         IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
64                 getIntegerValueFromProperty(IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
65         NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
66                 getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
67         NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS =
68                 getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY);
69     }
70     
71     private static int getIntegerValueFromProperty(String JavaDoc property) {
72         String JavaDoc value = System.getProperty(property);
73         if (value == null) {
74             return Integer.MAX_VALUE;
75         }
76         
77         try {
78             return Math.max(Integer.parseInt(value), ValueArray.DEFAULT_CAPACITY);
79         } catch (NumberFormatException JavaDoc e) {
80             return Integer.MAX_VALUE;
81         }
82     }
83     
84     public final CharArrayArray restrictedAlphabet = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, 256);
85     public final StringArray encodingAlgorithm = new StringArray(ValueArray.DEFAULT_CAPACITY, 256);
86
87     public final StringArray namespaceName;
88     public final PrefixArray prefix;
89     public final StringArray localName;
90     public final StringArray otherNCName ;
91     public final StringArray otherURI;
92     public final StringArray attributeValue;
93     public final CharArrayArray otherString;
94
95     public final ContiguousCharArrayArray characterContentChunk;
96
97     public final QualifiedNameArray elementName;
98     public final QualifiedNameArray attributeName;
99
100     public final ValueArray[] tables = new ValueArray[12];
101     
102     protected SerializerVocabulary _readOnlyVocabulary;
103     
104     /** Creates a new instance of ParserVocabulary */
105     public ParserVocabulary() {
106         namespaceName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
107         prefix = new PrefixArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
108         localName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
109         otherNCName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
110         otherURI = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
111         attributeValue = new StringArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
112         otherString = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
113
114         characterContentChunk = new ContiguousCharArrayArray(ValueArray.DEFAULT_CAPACITY,
115                 NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS,
116                 ContiguousCharArrayArray.INITIAL_CHARACTER_SIZE,
117                 NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS);
118
119         elementName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
120         attributeName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
121
122         tables[RESTRICTED_ALPHABET] = restrictedAlphabet;
123         tables[ENCODING_ALGORITHM] = encodingAlgorithm;
124         tables[PREFIX] = prefix;
125         tables[NAMESPACE_NAME] = namespaceName;
126         tables[LOCAL_NAME] = localName;
127         tables[OTHER_NCNAME] = otherNCName;
128         tables[OTHER_URI] = otherURI;
129         tables[ATTRIBUTE_VALUE] = attributeValue;
130         tables[OTHER_STRING] = otherString;
131         tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk;
132         tables[ELEMENT_NAME] = elementName;
133         tables[ATTRIBUTE_NAME] = attributeName;
134     }
135
136     
137     public ParserVocabulary(SerializerVocabulary vocab) {
138         this();
139         
140     }
141     
142     void setReadOnlyVocabulary(ParserVocabulary readOnlyVocabulary, boolean clear) {
143         for (int i = 0; i < tables.length; i++) {
144             tables[i].setReadOnlyArray(readOnlyVocabulary.tables[i], clear);
145         }
146     }
147     
148     public void setInitialVocabulary(ParserVocabulary initialVocabulary, boolean clear) {
149         setExternalVocabularyURI(null);
150         setInitialReadOnlyVocabulary(true);
151         setReadOnlyVocabulary(initialVocabulary, clear);
152     }
153     
154     public void setReferencedVocabulary(URI JavaDoc referencedVocabularyURI, ParserVocabulary referencedVocabulary, boolean clear) {
155         setInitialReadOnlyVocabulary(false);
156         setExternalVocabularyURI(referencedVocabularyURI);
157         setReadOnlyVocabulary(referencedVocabulary, clear);
158     }
159     
160     public void clear() {
161         for (int i = 0; i < tables.length; i++) {
162             tables[i].clear();
163         }
164     }
165 }
166
Popular Tags