KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-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 /**
21  * Shadowed symbol table.
22  *
23  * The table has a reference to the main symbol table and is
24  * not allowed to add new symbols to the main symbol table.
25  * New symbols are added to the shadow symbol table and are local
26  * to the component using this table.
27  *
28  * @author Andy Clark IBM
29  * @version $Id: ShadowedSymbolTable.java,v 1.3 2004/02/24 23:15:53 mrglavas Exp $
30  */

31
32 public final class ShadowedSymbolTable
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 shadow of the specified symbol table. */
47     public ShadowedSymbolTable(SymbolTable symbolTable) {
48         fSymbolTable = symbolTable;
49     } // <init>(SymbolTable)
50

51     //
52
// SymbolTable methods
53
//
54

55     /**
56      * Adds the specified symbol to the symbol table and returns a
57      * reference to the unique symbol. If the symbol already exists,
58      * the previous symbol reference is returned instead, in order
59      * guarantee that symbol references remain unique.
60      *
61      * @param symbol The new symbol.
62      */

63     public String JavaDoc addSymbol(String JavaDoc symbol) {
64
65         if (fSymbolTable.containsSymbol(symbol)) {
66             return fSymbolTable.addSymbol(symbol);
67         }
68         return super.addSymbol(symbol);
69
70     } // addSymbol(String)
71

72     /**
73      * Adds the specified symbol to the symbol table and returns a
74      * reference to the unique symbol. If the symbol already exists,
75      * the previous symbol reference is returned instead, in order
76      * guarantee that symbol references remain unique.
77      *
78      * @param buffer The buffer containing the new symbol.
79      * @param offset The offset into the buffer of the new symbol.
80      * @param length The length of the new symbol in the buffer.
81      */

82     public String JavaDoc addSymbol(char[] buffer, int offset, int length) {
83
84         if (fSymbolTable.containsSymbol(buffer, offset, length)) {
85             return fSymbolTable.addSymbol(buffer, offset, length);
86         }
87         return super.addSymbol(buffer, offset, length);
88
89     } // addSymbol(char[],int,int):String
90

91     /**
92      * Returns a hashcode value for the specified symbol. The value
93      * returned by this method must be identical to the value returned
94      * by the <code>hash(char[],int,int)</code> method when called
95      * with the character array that comprises the symbol string.
96      *
97      * @param symbol The symbol to hash.
98      */

99     public int hash(String JavaDoc symbol) {
100         return fSymbolTable.hash(symbol);
101     } // hash(String):int
102

103     /**
104      * Returns a hashcode value for the specified symbol information.
105      * The value returned by this method must be identical to the value
106      * returned by the <code>hash(String)</code> method when called
107      * with the string object created from the symbol information.
108      *
109      * @param buffer The character buffer containing the symbol.
110      * @param offset The offset into the character buffer of the start
111      * of the symbol.
112      * @param length The length of the symbol.
113      */

114     public int hash(char[] buffer, int offset, int length) {
115         return fSymbolTable.hash(buffer, offset, length);
116     } // hash(char[],int,int):int
117

118 } // class ShadowedSymbolTable
119
Popular Tags