1 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 ; 49 50 public class ParserVocabulary extends Vocabulary { 51 public static final String IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY = 52 "com.sun.xml.fastinfoset.vocab.ParserVocabulary.IdentifyingStringTable.maximumItems"; 53 public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY = 54 "com.sun.xml.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumItems"; 55 public static final String 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 property) { 72 String 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 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 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 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 |