1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.util;
  23 
  24 
  25 /**
  26  * Shadowed symbol table.
  27  *
  28  * The table has a reference to the main symbol table and is
  29  * not allowed to add new symbols to the main symbol table.
  30  * New symbols are added to the shadow symbol table and are local
  31  * to the component using this table.
  32  *
  33  * @author Andy Clark IBM
  34  */
  35 
  36 public final class ShadowedSymbolTable
  37 extends SymbolTable {
  38 
  39     //
  40     // Data
  41     //
  42 
  43     /** Main symbol table. */
  44     protected SymbolTable fSymbolTable;
  45 
  46     //
  47     // Constructors
  48     //
  49 
  50     /** Constructs a shadow of the specified symbol table. */
  51     public ShadowedSymbolTable(SymbolTable symbolTable) {
  52         fSymbolTable = symbolTable;
  53     } // <init>(SymbolTable)
  54 
  55     //
  56     // SymbolTable methods
  57     //
  58 
  59     /**
  60      * Adds the specified symbol to the symbol table and returns a
  61      * reference to the unique symbol. If the symbol already exists,
  62      * the previous symbol reference is returned instead, in order
  63      * guarantee that symbol references remain unique.
  64      *
  65      * @param symbol The new symbol.
  66      */
  67     public String addSymbol(String symbol) {
  68 
  69         if (fSymbolTable.containsSymbol(symbol)) {
  70             return fSymbolTable.addSymbol(symbol);
  71         }
  72         return super.addSymbol(symbol);
  73 
  74     } // addSymbol(String)
  75 
  76     /**
  77      * Adds the specified symbol to the symbol table and returns a
  78      * reference to the unique symbol. If the symbol already exists,
  79      * the previous symbol reference is returned instead, in order
  80      * guarantee that symbol references remain unique.
  81      *
  82      * @param buffer The buffer containing the new symbol.
  83      * @param offset The offset into the buffer of the new symbol.
  84      * @param length The length of the new symbol in the buffer.
  85      */
  86     public String addSymbol(char[] buffer, int offset, int length) {
  87 
  88         if (fSymbolTable.containsSymbol(buffer, offset, length)) {
  89             return fSymbolTable.addSymbol(buffer, offset, length);
  90         }
  91         return super.addSymbol(buffer, offset, length);
  92 
  93     } // addSymbol(char[],int,int):String
  94 
  95     /**
  96      * Returns a hashcode value for the specified symbol. The value
  97      * returned by this method must be identical to the value returned
  98      * by the <code>hash(char[],int,int)</code> method when called
  99      * with the character array that comprises the symbol string.
 100      *
 101      * @param symbol The symbol to hash.
 102      */
 103     public int hash(String symbol) {
 104         return fSymbolTable.hash(symbol);
 105     } // hash(String):int
 106 
 107     /**
 108      * Returns a hashcode value for the specified symbol information.
 109      * The value returned by this method must be identical to the value
 110      * returned by the <code>hash(String)</code> method when called
 111      * with the string object created from the symbol information.
 112      *
 113      * @param buffer The character buffer containing the symbol.
 114      * @param offset The offset into the character buffer of the start
 115      *               of the symbol.
 116      * @param length The length of the symbol.
 117      */
 118     public int hash(char[] buffer, int offset, int length) {
 119         return fSymbolTable.hash(buffer, offset, length);
 120     } // hash(char[],int,int):int
 121 
 122 } // class ShadowedSymbolTable