001: /*
002: *
003: *
004: * Copyright 1990-2007 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.satsa.jcrmic.classfile.constants;
028:
029: import java.io.IOException;
030: import java.io.DataInputStream;
031:
032: /**
033: * This class is the base class for all constants.
034: * It also defines a factory method for creating a constant based
035: * on the constant type
036: */
037:
038: abstract public class JConstant {
039:
040: /**
041: * Constant pool entry tag.
042: */
043: public static final int CONSTANT_UTF8 = 1;
044: /**
045: * Constant pool entry tag.
046: */
047: public static final int CONSTANT_INTEGER = 3;
048: /**
049: * Constant pool entry tag.
050: */
051: public static final int CONSTANT_FLOAT = 4;
052: /**
053: * Constant pool entry tag.
054: */
055: public static final int CONSTANT_LONG = 5;
056: /**
057: * Constant pool entry tag.
058: */
059: public static final int CONSTANT_DOUBLE = 6;
060: /**
061: * Constant pool entry tag.
062: */
063: public static final int CONSTANT_CLASS = 7;
064: /**
065: * Constant pool entry tag.
066: */
067: public static final int CONSTANT_STRING = 8;
068: /**
069: * Constant pool entry tag.
070: */
071: public static final int CONSTANT_FIELDREF = 9;
072: /**
073: * Constant pool entry tag.
074: */
075: public static final int CONSTANT_METHODREF = 10;
076: /**
077: * Constant pool entry tag.
078: */
079: public static final int CONSTANT_INTERFACE_METHODREF = 11;
080: /**
081: * Constant pool entry tag.
082: */
083: public static final int CONSTANT_NAME_AND_TYPE = 12;
084:
085: /**
086: * Constant pool reference.
087: */
088: protected JConstantPool cp;
089:
090: /**
091: * Constructor.
092: * @param cp constant pool reference
093: */
094: public JConstant(JConstantPool cp) {
095: this .cp = cp;
096: }
097:
098: /**
099: * 'Resolved' flag.
100: */
101: protected boolean resolved = false;
102:
103: /**
104: * Factory method for constant pool entry creation.
105: * @param tag constant pool entry type tag
106: * @param cp constant pool reference
107: * @return constant pool entry object
108: */
109: public static final JConstant create(int tag, JConstantPool cp) {
110:
111: switch (tag) {
112: case CONSTANT_CLASS:
113: return new JConstantClass(cp);
114: case CONSTANT_UTF8:
115: return new JConstantUtf8(cp);
116: case CONSTANT_FIELDREF:
117: return new JConstantFieldRef(cp);
118: case CONSTANT_METHODREF:
119: return new JConstantMethodRef(cp);
120: case CONSTANT_INTERFACE_METHODREF:
121: return new JConstantInterfaceMethodRef(cp);
122: case CONSTANT_NAME_AND_TYPE:
123: return new JConstantNameAndType(cp);
124: case CONSTANT_STRING:
125: return new JConstantString(cp);
126: case CONSTANT_INTEGER:
127: return new JConstantInteger(cp);
128: case CONSTANT_FLOAT:
129: return new JConstantFloat(cp);
130: case CONSTANT_LONG:
131: return new JConstantLong(cp);
132: case CONSTANT_DOUBLE:
133: return new JConstantDouble(cp);
134: default:
135: return null;
136:
137: }
138: }
139:
140: /**
141: * Parses constant pool entry.
142: * @param dis input stream
143: * @throws IOException if I/O exception occurs
144: */
145: abstract public void parse(DataInputStream dis) throws IOException;
146: }
|