001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.util;
019:
020: /**
021: * Synchronized symbol table.
022: *
023: * This class moved into the util package since it's needed by multiple
024: * other classes (CachingParserPool, XMLGrammarCachingConfiguration).
025: *
026: * @author Andy Clark, IBM
027: * @version $Id: SynchronizedSymbolTable.java 447241 2006-09-18 05:12:57Z mrglavas $
028: */
029:
030: public final class SynchronizedSymbolTable extends SymbolTable {
031:
032: //
033: // Data
034: //
035:
036: /** Main symbol table. */
037: protected SymbolTable fSymbolTable;
038:
039: //
040: // Constructors
041: //
042:
043: /** Constructs a synchronized symbol table. */
044: public SynchronizedSymbolTable(SymbolTable symbolTable) {
045: fSymbolTable = symbolTable;
046: } // <init>(SymbolTable)
047:
048: // construct synchronized symbol table of default size
049: public SynchronizedSymbolTable() {
050: fSymbolTable = new SymbolTable();
051: } // init()
052:
053: // construct synchronized symbol table of given size
054: public SynchronizedSymbolTable(int size) {
055: fSymbolTable = new SymbolTable(size);
056: } // init(int)
057:
058: //
059: // SymbolTable methods
060: //
061:
062: /**
063: * Adds the specified symbol to the symbol table and returns a
064: * reference to the unique symbol. If the symbol already exists,
065: * the previous symbol reference is returned instead, in order
066: * guarantee that symbol references remain unique.
067: *
068: * @param symbol The new symbol.
069: */
070: public String addSymbol(String symbol) {
071:
072: synchronized (fSymbolTable) {
073: return fSymbolTable.addSymbol(symbol);
074: }
075:
076: } // addSymbol(String)
077:
078: /**
079: * Adds the specified symbol to the symbol table and returns a
080: * reference to the unique symbol. If the symbol already exists,
081: * the previous symbol reference is returned instead, in order
082: * guarantee that symbol references remain unique.
083: *
084: * @param buffer The buffer containing the new symbol.
085: * @param offset The offset into the buffer of the new symbol.
086: * @param length The length of the new symbol in the buffer.
087: */
088: public String addSymbol(char[] buffer, int offset, int length) {
089:
090: synchronized (fSymbolTable) {
091: return fSymbolTable.addSymbol(buffer, offset, length);
092: }
093:
094: } // addSymbol(char[],int,int):String
095:
096: /**
097: * Returns true if the symbol table already contains the specified
098: * symbol.
099: *
100: * @param symbol The symbol to look for.
101: */
102: public boolean containsSymbol(String symbol) {
103:
104: synchronized (fSymbolTable) {
105: return fSymbolTable.containsSymbol(symbol);
106: }
107:
108: } // containsSymbol(String):boolean
109:
110: /**
111: * Returns true if the symbol table already contains the specified
112: * symbol.
113: *
114: * @param buffer The buffer containing the symbol to look for.
115: * @param offset The offset into the buffer.
116: * @param length The length of the symbol in the buffer.
117: */
118: public boolean containsSymbol(char[] buffer, int offset, int length) {
119:
120: synchronized (fSymbolTable) {
121: return fSymbolTable.containsSymbol(buffer, offset, length);
122: }
123:
124: } // containsSymbol(char[],int,int):boolean
125:
126: } // class SynchronizedSymbolTable
|