KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > util > SynchronizedSymbolTable


1 /*
2  * Copyright 2000-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.util;
18
19 /**
20  * Synchronized symbol table.
21  *
22  * This class moved into the util package since it's needed by multiple
23  * other classes (CachingParserPool, XMLGrammarCachingConfiguration).
24  *
25  * @author Andy Clark, IBM
26  * @version $Id: SynchronizedSymbolTable.java,v 1.3 2004/02/24 23:15:53 mrglavas Exp $
27  */

28
29 public final class SynchronizedSymbolTable
30     extends SymbolTable {
31         
32     //
33
// Data
34
//
35

36     /** Main symbol table. */
37     protected SymbolTable fSymbolTable;
38
39     //
40
// Constructors
41
//
42

43     /** Constructs a synchronized symbol table. */
44     public SynchronizedSymbolTable(SymbolTable symbolTable) {
45         fSymbolTable = symbolTable;
46     } // <init>(SymbolTable)
47

48     // construct synchronized symbol table of default size
49
public SynchronizedSymbolTable() {
50         fSymbolTable = new SymbolTable();
51     } // init()
52

53     // construct synchronized symbol table of given size
54
public SynchronizedSymbolTable(int size) {
55         fSymbolTable = new SymbolTable(size);
56     } // init(int)
57

58     //
59
// SymbolTable methods
60
//
61

62     /**
63      * Adds the specified symbol to the symbol table and returns a
64      * reference to the unique symbol. If the symbol already exists,
65      * the previous symbol reference is returned instead, in order
66      * guarantee that symbol references remain unique.
67      *
68      * @param symbol The new symbol.
69      */

70     public String JavaDoc addSymbol(String JavaDoc symbol) {
71
72         synchronized (fSymbolTable) {
73             return fSymbolTable.addSymbol(symbol);
74         }
75
76     } // addSymbol(String)
77

78     /**
79      * Adds the specified symbol to the symbol table and returns a
80      * reference to the unique symbol. If the symbol already exists,
81      * the previous symbol reference is returned instead, in order
82      * guarantee that symbol references remain unique.
83      *
84      * @param buffer The buffer containing the new symbol.
85      * @param offset The offset into the buffer of the new symbol.
86      * @param length The length of the new symbol in the buffer.
87      */

88     public String JavaDoc addSymbol(char[] buffer, int offset, int length) {
89
90         synchronized (fSymbolTable) {
91             return fSymbolTable.addSymbol(buffer, offset, length);
92         }
93
94     } // addSymbol(char[],int,int):String
95

96     /**
97      * Returns true if the symbol table already contains the specified
98      * symbol.
99      *
100      * @param symbol The symbol to look for.
101      */

102     public boolean containsSymbol(String JavaDoc 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
127
Popular Tags