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: * Shadowed symbol table.
022: *
023: * The table has a reference to the main symbol table and is
024: * not allowed to add new symbols to the main symbol table.
025: * New symbols are added to the shadow symbol table and are local
026: * to the component using this table.
027: *
028: * @author Andy Clark IBM
029: * @version $Id: ShadowedSymbolTable.java 447241 2006-09-18 05:12:57Z mrglavas $
030: */
031:
032: public final class ShadowedSymbolTable extends SymbolTable {
033:
034: //
035: // Data
036: //
037:
038: /** Main symbol table. */
039: protected SymbolTable fSymbolTable;
040:
041: //
042: // Constructors
043: //
044:
045: /** Constructs a shadow of the specified symbol table. */
046: public ShadowedSymbolTable(SymbolTable symbolTable) {
047: fSymbolTable = symbolTable;
048: } // <init>(SymbolTable)
049:
050: //
051: // SymbolTable methods
052: //
053:
054: /**
055: * Adds the specified symbol to the symbol table and returns a
056: * reference to the unique symbol. If the symbol already exists,
057: * the previous symbol reference is returned instead, in order
058: * guarantee that symbol references remain unique.
059: *
060: * @param symbol The new symbol.
061: */
062: public String addSymbol(String symbol) {
063:
064: if (fSymbolTable.containsSymbol(symbol)) {
065: return fSymbolTable.addSymbol(symbol);
066: }
067: return super .addSymbol(symbol);
068:
069: } // addSymbol(String)
070:
071: /**
072: * Adds the specified symbol to the symbol table and returns a
073: * reference to the unique symbol. If the symbol already exists,
074: * the previous symbol reference is returned instead, in order
075: * guarantee that symbol references remain unique.
076: *
077: * @param buffer The buffer containing the new symbol.
078: * @param offset The offset into the buffer of the new symbol.
079: * @param length The length of the new symbol in the buffer.
080: */
081: public String addSymbol(char[] buffer, int offset, int length) {
082:
083: if (fSymbolTable.containsSymbol(buffer, offset, length)) {
084: return fSymbolTable.addSymbol(buffer, offset, length);
085: }
086: return super .addSymbol(buffer, offset, length);
087:
088: } // addSymbol(char[],int,int):String
089:
090: /**
091: * Returns a hashcode value for the specified symbol. The value
092: * returned by this method must be identical to the value returned
093: * by the <code>hash(char[],int,int)</code> method when called
094: * with the character array that comprises the symbol string.
095: *
096: * @param symbol The symbol to hash.
097: */
098: public int hash(String symbol) {
099: return fSymbolTable.hash(symbol);
100: } // hash(String):int
101:
102: /**
103: * Returns a hashcode value for the specified symbol information.
104: * The value returned by this method must be identical to the value
105: * returned by the <code>hash(String)</code> method when called
106: * with the string object created from the symbol information.
107: *
108: * @param buffer The character buffer containing the symbol.
109: * @param offset The offset into the character buffer of the start
110: * of the symbol.
111: * @param length The length of the symbol.
112: */
113: public int hash(char[] buffer, int offset, int length) {
114: return fSymbolTable.hash(buffer, offset, length);
115: } // hash(char[],int,int):int
116:
117: } // class ShadowedSymbolTable
|