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