1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.util; 23 24 /** 25 * Synchronized symbol table. 26 * 27 * This class moved into the util package since it's needed by multiple 28 * other classes (CachingParserPool, XMLGrammarCachingConfiguration). 29 * 30 * @author Andy Clark, IBM 31 */ 32 33 public final class SynchronizedSymbolTable 34 extends SymbolTable { 35 36 // 37 // Data 38 // 39 40 /** Main symbol table. */ 41 protected SymbolTable fSymbolTable; 42 43 // 44 // Constructors 45 // 46 47 /** Constructs a synchronized symbol table. */ SynchronizedSymbolTable(SymbolTable symbolTable)48 public SynchronizedSymbolTable(SymbolTable symbolTable) { 49 fSymbolTable = symbolTable; 50 } // <init>(SymbolTable) 51 52 // construct synchronized symbol table of default size SynchronizedSymbolTable()53 public SynchronizedSymbolTable() { 54 fSymbolTable = new SymbolTable(); 55 } // init() 56 57 // construct synchronized symbol table of given size SynchronizedSymbolTable(int size)58 public SynchronizedSymbolTable(int size) { 59 fSymbolTable = new SymbolTable(size); 60 } // init(int) 61 62 // 63 // SymbolTable methods 64 // 65 66 /** 67 * Adds the specified symbol to the symbol table and returns a 68 * reference to the unique symbol. If the symbol already exists, 69 * the previous symbol reference is returned instead, in order 70 * guarantee that symbol references remain unique. 71 * 72 * @param symbol The new symbol. 73 */ addSymbol(String symbol)74 public String addSymbol(String symbol) { 75 76 synchronized (fSymbolTable) { 77 return fSymbolTable.addSymbol(symbol); 78 } 79 80 } // addSymbol(String) 81 82 /** 83 * Adds the specified symbol to the symbol table and returns a 84 * reference to the unique symbol. If the symbol already exists, 85 * the previous symbol reference is returned instead, in order 86 * guarantee that symbol references remain unique. 87 * 88 * @param buffer The buffer containing the new symbol. 89 * @param offset The offset into the buffer of the new symbol. 90 * @param length The length of the new symbol in the buffer. 91 */ addSymbol(char[] buffer, int offset, int length)92 public String addSymbol(char[] buffer, int offset, int length) { 93 94 synchronized (fSymbolTable) { 95 return fSymbolTable.addSymbol(buffer, offset, length); 96 } 97 98 } // addSymbol(char[],int,int):String 99 100 /** 101 * Returns true if the symbol table already contains the specified 102 * symbol. 103 * 104 * @param symbol The symbol to look for. 105 */ containsSymbol(String symbol)106 public boolean containsSymbol(String symbol) { 107 108 synchronized (fSymbolTable) { 109 return fSymbolTable.containsSymbol(symbol); 110 } 111 112 } // containsSymbol(String):boolean 113 114 /** 115 * Returns true if the symbol table already contains the specified 116 * symbol. 117 * 118 * @param buffer The buffer containing the symbol to look for. 119 * @param offset The offset into the buffer. 120 * @param length The length of the symbol in the buffer. 121 */ containsSymbol(char[] buffer, int offset, int length)122 public boolean containsSymbol(char[] buffer, int offset, int length) { 123 124 synchronized (fSymbolTable) { 125 return fSymbolTable.containsSymbol(buffer, offset, length); 126 } 127 128 } // containsSymbol(char[],int,int):boolean 129 130 } // class SynchronizedSymbolTable 131