001: /*
002: * @(#)ConstantSetNode.java 1.17 06/10/25
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.tools.jdwpgen;
028:
029: import java.util.*;
030: import java.io.*;
031:
032: class ConstantSetNode extends AbstractNamedNode {
033:
034: /**
035: * The mapping between a constant and its value.
036: */
037: protected static Map constantMap;
038:
039: ConstantSetNode() {
040: if (constantMap == null) {
041: constantMap = new HashMap();
042: }
043: }
044:
045: void prune() {
046: List addons = new ArrayList();
047:
048: for (Iterator it = components.iterator(); it.hasNext();) {
049: Node node = (Node) it.next();
050: }
051: if (!addons.isEmpty()) {
052: components.addAll(addons);
053: }
054: super .prune();
055: }
056:
057: void constrainComponent(Context ctx, Node node) {
058: if (node instanceof ConstantNode) {
059: node.constrain(ctx);
060: constantMap.put(name + "_"
061: + ((ConstantNode) node).getName(), node.comment());
062: } else {
063: error("Expected 'Constant', got: " + node);
064: }
065: }
066:
067: void document(PrintWriter writer) {
068: writer.println("<h4><a name=\"" + context.whereC + "\">" + name
069: + " Constants</a></h4>");
070: writer.println(comment());
071: writer
072: .println("<dd><table border=1 cellpadding=3 cellspacing=0 width=\"90%\" summary=\"\"><tr>");
073: writer
074: .println("<th width=\"20%\"><th width=\"5%\"><th width=\"65%\">");
075: ConstantNode n;
076: for (Iterator it = components.iterator(); it.hasNext();) {
077: n = ((ConstantNode) it.next());
078: writer.println("<a NAME=\"" + name + "_" + n.name
079: + "\"></a>");
080: n.document(writer);
081: }
082: writer.println("</table>");
083: }
084:
085: void documentIndex(PrintWriter writer) {
086: writer.print("<li><a href=\"#" + context.whereC + "\">");
087: writer.println(name() + "</a> Constants");
088: // writer.println("<ul>");
089: // for (Iterator it = components.iterator(); it.hasNext();) {
090: // ((Node)it.next()).documentIndex(writer);
091: // }
092: // writer.println("</ul>");
093: }
094:
095: void genJavaClassSpecifics(PrintWriter writer, int depth) {
096: }
097:
098: void genJava(PrintWriter writer, int depth) {
099: genJavaClass(writer, depth);
100: }
101:
102: public static String getConstant(String key) {
103: if (constantMap == null) {
104: return "";
105: }
106: String com = (String) constantMap.get(key);
107: if (com == null) {
108: return "";
109: } else {
110: return com;
111: }
112: }
113:
114: }
|