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