KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > ejb > ejbqlc > SymbolTable


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25
26 /*
27  * SymbolTable.java
28  *
29  * Created on November 19, 2001
30  */

31
32 package com.sun.jdo.spi.persistence.support.ejb.ejbqlc;
33
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36
37 /**
38  * The symbol table handling declared identifies.
39  *
40  * @author Michael Bouschen
41  */

42 public class SymbolTable
43 {
44     /**
45      * The table of declared identifier (symbols).
46      */

47     protected Map JavaDoc symbols = new HashMap JavaDoc();
48
49     /**
50      * This method adds the specified identifier to this SymbolTable.
51      * The specified decl object provides details anbout the declaration.
52      * If this SymbolTable already defines an identifier with the same name,
53      * the SymbolTable is not changed and the existing declaration is returned.
54      * Otherwise <code>null</code> is returned.
55      * @param ident identifier to be declared
56      * @param definition new definition of identifier
57      * @return the old definition if the identifier was already declared;
58      * <code>null</code> otherwise
59      */

60     public Object JavaDoc declare(String JavaDoc ident, Object JavaDoc decl)
61     {
62         Object JavaDoc old = symbols.get(ident);
63         if (old == null) {
64             symbols.put(ident.toUpperCase(), decl);
65         }
66         return old;
67     }
68
69     /**
70      * Checks whether the specified identifier is declared.
71      * @param ident the name of identifier to be tested
72      * @return <code>true</code> if the identifier is declared;
73      * <code>false</code> otherwise.
74      */

75     public boolean isDeclared(String JavaDoc ident)
76     {
77         return (getDeclaration(ident) != null);
78     }
79
80     /**
81      * Checks the symbol table for the actual declaration of the specified
82      * identifier. The method returns the declaration object if available or
83      * <code>null</code> for an undeclared identifier.
84      * @param ident the name of identifier
85      * @return the declaration object if ident is declared;
86      * <code>null</code> otherise.
87      */

88     public Object JavaDoc getDeclaration(String JavaDoc ident)
89     {
90         return symbols.get(ident.toUpperCase());
91     }
92     
93 }
94
Popular Tags