svn commit: r158176 [6/79] - in incubator/jdo/trunk/ri11: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/ src/java/org/apache/jdo/enhancer/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/enhancer/ src/java/org/apache/jdo/impl/enhancer/classfile/ src/java/org/apache/jdo/impl/enhancer/core/ src/java/org/apache/jdo/impl/enhancer/generator/ src/java/org/apache/jdo/impl/enhancer/meta/ src/java/org/apache/jdo/impl/enhancer/meta/model/ src/java/org/apache/jdo/impl/enhancer/meta/prop/ src/java/org/apache/jdo/impl/enhancer/meta/util/ src/java/org/apache/jdo/impl/enhancer/util/ src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/runtime/ src/java/org/apache/jdo/impl/model/jdo/ src/java/org/apache/jdo/impl/model/jdo/caching/ src/java/org/apache/jdo/impl/model/jdo/util/ src/java/org/apache/jdo/impl/model/jdo/xml/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/ src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/ src/java/org/apache/jdo/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/pm/ src/java/org/apache/jdo/sco/ src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/ src/java/org/apache/jdo/util/ test/ test/conf/ test/enhancer/ test/enhancer/sempdept/ test/enhancer/sempdept/src/ test/enhancer/sempdept/src/empdept/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ xdocs/

19 Mar 2005 05:33:09 -0000

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeAttribute.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeAttribute.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeAttribute.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeAttribute.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,440 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.util.Stack;
+import java.util.Vector;
+import java.io.*;
+
+/**
+ * Subtype of ClassAttribute which describes the "Code" attribute
+ * associated with a method.
+ */
+public class CodeAttribute extends ClassAttribute {
+    public final static String expectedAttrName = "Code";
+
+    /* The java class file contents defining this code attribute.
+       If non-null, this must be disassembled before the remaining 
+       fields of this instance may be accessed. */
+    private byte theDataBytes[];
+
+    /* The maximum number of stack entries used by this method */
+    private int maxStack;
+
+    /* The maximum number of local variables used by this method */
+    private int maxLocals;
+
+    /* The java VM byte code sequence for this method - null for native
+       and abstract methods */
+    private byte theCodeBytes[];
+
+    /* The instruction sequence for this method - initially derived from
+       the byte code array, but may later be modified */
+    private Insn theCode;
+
+    /* The exception ranges and handlers which apply to the code in this
+       method */
+    private ExceptionTable exceptionTable;
+
+    /* The attributes which apply to this method */
+    private AttributeVector codeAttributes;
+
+    /* The method environment used for decompiling this code attribute */
+    CodeEnv codeEnv;
+
+    /* public accessors */
+
+    /**
+     * Return the maximum number of stack entries used by this method
+     */
+    public int stackUsed() {
+        makeValid();
+        return maxStack;
+    }
+
+    /**
+     * Set the maximum number of stack entries used by this method
+     */
+    public void setStackUsed(int used) {
+        makeValid();
+        maxStack = used;
+    }
+
+    /**
+     * Return the maximum number of local variables used by this method
+     */
+    public int localsUsed() {
+        makeValid();
+        return maxLocals;
+    }
+
+    /**
+     * Set the maximum number of local variables used by this method
+     */
+    public void setLocalsUsed(int used) {
+        makeValid();
+        maxLocals = used;
+    }
+
+    /**
+     * Return the java VM byte code sequence for this method - null for
+     * native and abstract methods
+     */
+    public byte[] byteCodes() {
+        makeValid();
+        return theCodeBytes;
+    }
+
+    /**
+     * Return the instruction sequence for this method - initially derived
+     * from the byte code array, but may later be modified
+     */
+    public Insn theCode() {
+        makeValid();
+        if (theCode == null && codeEnv != null) {
+            buildInstructions(codeEnv);
+        }
+        return theCode;
+    }
+
+    /**
+     * Install the instruction sequence for this method - the byte code array
+     * is later updated.
+     */
+    public void setTheCode(Insn insn) {
+        makeValid();
+        if (insn != null && insn.opcode() != Insn.opc_target)
+            throw new InsnError(
+                "The initial instruction in all methods must be a target");
+        theCode = insn;
+    }
+
+    /**
+     * Return the exception ranges and handlers which apply to the code in
+     * this method.
+     */
+    public ExceptionTable exceptionHandlers() {
+        makeValid();
+        return exceptionTable;
+    }
+
+    /**
+     * Return the attributes which apply to this code
+     */
+    public AttributeVector attributes() {
+        makeValid();
+        return codeAttributes;
+    }
+
+    /**
+     * Constructs a CodeAttribute object for construction from scratch
+     */
+    public CodeAttribute(ConstUtf8 attrName,
+                         int maxStack, int maxLocals,
+                         Insn code, 
+                         ExceptionTable excTable,
+                         AttributeVector codeAttrs) {
+        this(attrName, maxStack, maxLocals, code, null, /* byteCodes */
+             excTable, codeAttrs, null /* CodeEnv */ );
+    }
+
+    /**
+     * Constructs a CodeAttribute object 
+     */
+    public CodeAttribute(ConstUtf8 attrName,
+                         int maxStack, int maxLocals,
+                         Insn code, byte[] codeBytes,
+                         ExceptionTable excTable,
+                         AttributeVector codeAttrs,
+                         CodeEnv codeEnv) {
+        super(attrName);
+        this.maxStack = maxStack;
+        this.maxLocals = maxLocals;
+        theCode = code;
+        theCodeBytes = codeBytes;
+        exceptionTable = excTable;
+        codeAttributes = codeAttrs;
+        this.codeEnv = codeEnv;
+    }
+
+    /**
+     * Constructs a CodeAttribute object for later disassembly
+     */
+    public CodeAttribute(ConstUtf8 attrName, byte[] dataBytes, CodeEnv 
codeEnv) {
+        super(attrName);
+        this.theDataBytes = dataBytes;
+        this.codeEnv = codeEnv;
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof CodeAttribute)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        CodeAttribute other = (CodeAttribute)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (this.stackUsed() != other.stackUsed()) {
+            msg.push(String.valueOf("stackUsed() = "
+                                    + other.stackUsed()));
+            msg.push(String.valueOf("stackUsed() = "
+                                    + this.stackUsed()));
+            return false;
+        }
+        if (this.localsUsed() != other.localsUsed()) {
+            msg.push(String.valueOf("localsUsed() = "
+                                    + other.localsUsed()));
+            msg.push(String.valueOf("localsUsed() = "
+                                    + this.localsUsed()));
+            return false;
+        }
+
+        // iterate over the instructions
+        Insn theCode1 = this.theCode();
+        Insn theCode2 = other.theCode();
+        while (theCode1 != null && theCode2 != null) {
+            // ignore targets (ignore line numbers)
+            if (theCode1.opcode() == Insn.opc_target) {
+                theCode1 = theCode1.next();
+                continue;
+            }
+            if (theCode2.opcode() == Insn.opc_target) {
+                theCode2 = theCode2.next();
+                continue;
+            }
+            if (!theCode1.isEqual(msg, theCode2)) {
+                msg.push("theCode()[i] = " + String.valueOf(theCode2));
+                msg.push("theCode()[i] = " + String.valueOf(theCode1));
+                return false;
+            }
+            theCode1 = theCode1.next();
+            theCode2 = theCode2.next();
+        }
+        if (theCode1 == null ^ theCode2 == null) {
+            msg.push("theCode()[i] = " + String.valueOf(theCode2));
+            msg.push("theCode()[i] = " + String.valueOf(theCode1));
+            return false;
+        }
+
+        if (!this.exceptionHandlers().isEqual(msg, other.exceptionHandlers())) 
{
+            msg.push(String.valueOf("exceptionHandlers() = "
+                                    + other.exceptionHandlers()));
+            msg.push(String.valueOf("exceptionHandlers() = "
+                                    + this.exceptionHandlers()));
+            return false;
+        }
+        if (!this.attributes().isEqual(msg, other.attributes())) {
+            msg.push(String.valueOf("attributes() = "
+                                    + other.attributes()));
+            msg.push(String.valueOf("attributes() = "
+                                    + this.attributes()));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    static CodeAttribute read(ConstUtf8 attrName,
+                              DataInputStream data, ConstantPool pool)
+        throws IOException {
+        int maxStack = data.readUnsignedShort();
+        int maxLocals = data.readUnsignedShort();
+        int codeLength = data.readInt();
+        byte codeBytes[] = new byte[codeLength];
+        data.readFully(codeBytes);
+        Insn code = null;
+        CodeEnv codeEnv = new CodeEnv(pool);
+
+        ExceptionTable excTable = ExceptionTable.read(data, codeEnv);
+    
+        AttributeVector codeAttrs = 
+            AttributeVector.readAttributes(data, codeEnv);
+
+        return new CodeAttribute(attrName, maxStack, maxLocals, code, 
codeBytes,
+                                 excTable, codeAttrs, codeEnv);
+    } 
+
+    /* This version reads the attribute into a byte array for later 
+       consumption */
+    static CodeAttribute read(ConstUtf8 attrName, int attrLength,
+                              DataInputStream data, ConstantPool pool)
+        throws IOException {
+        byte dataBytes[] = new byte[attrLength];
+        data.readFully(dataBytes);
+        return new CodeAttribute(attrName, dataBytes, new CodeEnv(pool));
+    } 
+
+    void write(DataOutputStream out) throws IOException {
+        out.writeShort(attrName().getIndex());
+        if (theDataBytes == null) {
+            buildInstructionBytes();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            DataOutputStream tmpOut = new DataOutputStream(baos);
+            tmpOut.writeShort(maxStack);
+            tmpOut.writeShort(maxLocals);
+            tmpOut.writeInt(theCodeBytes.length);
+            tmpOut.write(theCodeBytes, 0, theCodeBytes.length);
+            exceptionTable.write(tmpOut);
+            codeAttributes.write(tmpOut);
+
+            tmpOut.flush();
+            byte tmpBytes[] = baos.toByteArray();
+            out.writeInt(tmpBytes.length);
+            out.write(tmpBytes, 0, tmpBytes.length);
+        } else {
+            out.writeInt(theDataBytes.length);
+            out.write(theDataBytes, 0, theDataBytes.length);
+        }
+    }
+
+    void print(PrintStream out, int indent) {
+        makeValid();
+        ClassPrint.spaces(out, indent);
+        out.print("Code:");
+        out.print(" max_stack = " + Integer.toString(maxStack));
+        out.print(" max_locals = " + Integer.toString(maxLocals));
+        out.println(" Exceptions:");
+        exceptionTable.print(out, indent+2);
+        ClassPrint.spaces(out, indent);
+        out.println("Code Attributes:");
+        codeAttributes.print(out, indent+2);
+
+        Insn insn = theCode();
+        if (insn != null) {
+            ClassPrint.spaces(out, indent);
+            out.println("Instructions:");
+            while (insn != null) {
+                insn.print(out, indent+2);
+                insn = insn.next();
+            }
+        }
+    }
+
+    /**
+     *  Assign offsets to instructions and return the number of bytes.
+     *  theCode must be non-null.
+     */
+    private int resolveOffsets() {
+        Insn insn = theCode;
+        int currPC = 0;
+        while (insn != null) {
+            currPC = insn.resolveOffset(currPC);
+            insn = insn.next();
+        }
+        return currPC;
+    }
+
+    int codeSize() {
+        makeValid();
+        return theCodeBytes.length;
+    }
+
+    /**
+     * Derive the instruction list from the instruction byte codes
+     */
+    private void buildInstructions(CodeEnv codeEnv) {
+        if (theCodeBytes != null) {
+            InsnReadEnv insnEnv = new InsnReadEnv(theCodeBytes, codeEnv);
+            theCode = insnEnv.getTarget(0);
+            Insn currInsn = theCode;
+
+            /* First, create instructions */
+            while (insnEnv.more()) {
+                Insn newInsn = Insn.read(insnEnv);
+                currInsn.setNext(newInsn);
+                currInsn = newInsn;
+            }
+
+            /* Now, insert targets */
+            InsnTarget targ;
+            currInsn = theCode;
+            Insn prevInsn = null;
+            while (currInsn != null) {
+                int off = currInsn.offset();
+
+                /* We always insert a target a 0 to start so ignore that one */
+                if (off > 0) {
+                    targ = codeEnv.findTarget(off);
+                    if (targ != null)
+                        prevInsn.setNext(targ);
+                }
+                prevInsn = currInsn;
+                currInsn = currInsn.next();
+            }
+
+            /* And follow up with a final target if needed */
+            targ = codeEnv.findTarget(insnEnv.currentPC());
+            if (targ != null)
+                prevInsn.setNext(targ);
+        }
+    }
+
+    /**
+     * Derive the instruction byte codes from the instruction list
+     * This should also recompute stack and variables but for now we
+     * assume that this isn't needed
+     */
+    private void buildInstructionBytes() {
+        if (theCode != null) {
+            /* Make sure instructions have correct offsets */
+            int size = resolveOffsets();
+            theCodeBytes = new byte[size];
+
+            Insn insn = theCode;
+            int index = 0;
+            while (insn != null) {
+                index = insn.store(theCodeBytes, index);
+                insn = insn.next();
+            }
+        }
+    }
+
+    /** If theDataBytes is non-null, disassemble this code attribute
+     *  from the data bytes. */
+    private void makeValid() {
+        if (theDataBytes != null) {
+            DataInputStream dis = new DataInputStream(
+               new ByteArrayInputStream(theDataBytes));
+            try {
+                maxStack = dis.readUnsignedShort();
+                maxLocals = dis.readUnsignedShort();
+                int codeLength = dis.readInt();
+                theCodeBytes = new byte[codeLength];
+                dis.readFully(theCodeBytes);
+                exceptionTable = ExceptionTable.read(dis, codeEnv);
+                codeAttributes = AttributeVector.readAttributes(dis, codeEnv);
+            } catch (java.io.IOException ioe) {
+                throw new ClassFormatError("IOException while reading code 
attribute");
+            }
+
+            theDataBytes = null;
+        }
+    }
+}
+

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeEnv.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeEnv.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeEnv.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/CodeEnv.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.util.Hashtable;
+
+/**
+ * Environment in which to decode the attributes of a CodeAttribute.
+ */
+class CodeEnv {
+    /* The constant pool */
+    private ConstantPool constantPool;
+
+    /* hash table mapping byte code offset to InsnTarget */
+    private Hashtable targets = new Hashtable(7);
+
+    CodeEnv(ConstantPool constantPool) {
+        this.constantPool = constantPool;
+    }
+
+    final InsnTarget getTarget(int offset) {
+        Integer off = new Integer(offset);
+        InsnTarget targ = (InsnTarget)targets.get(off);
+        if (targ == null) {
+            targ = new InsnTarget(offset);
+            targets.put(off, targ);
+        }
+        return targ;
+    }
+
+    final InsnTarget findTarget(int offset) {
+        Integer off = new Integer(offset);
+        return (InsnTarget)targets.get(off);
+    }
+
+    final ConstantPool pool() {
+        return constantPool;
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasic.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasic.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasic.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasic.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Abstract base class of the types which represent entries in
+ * the class constant pool.
+ */
+abstract public class ConstBasic implements VMConstants {
+    /* The index of the constant entry in the constant pool */
+    protected int index = 0;
+
+    /* public accessors */
+
+    /* Get the index of this constant entry */
+    public int getIndex() { return index; }
+
+    /* Return the type of the constant entry - see VMConstants */
+    public abstract int tag();
+
+    /* package local methods */
+
+    /**
+     * Sets the index of this constant with its containing constant pool
+     */
+    void setIndex(int ind) { index = ind; }
+
+    /**
+     * Write this Constant pool entry to the output stream
+     */
+    abstract void formatData(DataOutputStream b) throws IOException;
+
+    /**
+     * Resolve integer index references to the actual constant pool
+     * entries that they represent.  This is used during class file 
+     * reading because a constant pool entry could have a forward
+     * reference to a higher numbered constant.
+     */
+    abstract void resolve(ConstantPool p);
+
+    /**
+     * Return the index of this constant in the constant pool as
+     * a decimal formatted String.
+     */
+    String indexAsString() { return Integer.toString(index); }
+
+    /**
+     * The constructor for subtypes
+     */
+    ConstBasic() {}
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstBasic)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstBasic other = (ConstBasic)obj;
+
+        return true;
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasicMemberRef.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasicMemberRef.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasicMemberRef.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstBasicMemberRef.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * The abstract base class used to represent the various type of
+ * references to members (fields/methods) within the constant pool. 
+ */
+public abstract class ConstBasicMemberRef extends ConstBasic {
+    /* The name of the class on which the member is defined */
+    protected ConstClass theClassName;
+
+    /* The index of the class on which the member is defined
+     *   - used temporarily while reading from a class file */
+    protected int theClassNameIndex;
+
+    /* The name and type of the member */
+    protected ConstNameAndType theNameAndType;
+
+    /* The index of the name and type of the member
+     *   - used temporarily while reading from a class file */
+    protected int theNameAndTypeIndex;
+
+    /* public accessors */
+
+    /**
+     * Return the name of the class defining the member 
+     */
+    public ConstClass className() {
+        return theClassName;
+    }
+
+    /**
+     * Return the name and type of the member 
+     */
+    public ConstNameAndType nameAndType() {
+        return theNameAndType;
+    }
+
+    public String toString () {
+        return "className(" + theClassName.toString() + ")" +
+            " nameAndType(" + theNameAndType.toString() + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstBasicMemberRef)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstBasicMemberRef other = (ConstBasicMemberRef)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.theClassName.isEqual(msg, other.theClassName)) {
+            msg.push(String.valueOf("theClassName = "
+                                    + other.theClassName));
+            msg.push(String.valueOf("theClassName = "
+                                    + this.theClassName));
+            return false;
+        }
+        if (!this.theNameAndType.isEqual(msg, other.theNameAndType)) {
+            msg.push(String.valueOf("theNameAndType = "
+                                    + other.theNameAndType));
+            msg.push(String.valueOf("theNameAndType = "
+                                    + this.theNameAndType));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    /**
+     * Constructor for "from scratch" creation
+     */
+    ConstBasicMemberRef (ConstClass cname, ConstNameAndType NT) {
+        theClassName = cname;
+        theNameAndType = NT;
+    }
+
+    /**
+     * Constructor for reading from a class file
+     */
+    ConstBasicMemberRef (int cnameIndex, int NT_index) {
+        theClassNameIndex = cnameIndex;
+        theNameAndTypeIndex = NT_index;
+    }
+
+    void formatData (DataOutputStream b) throws IOException {
+        b.writeShort(theClassName.getIndex());
+        b.writeShort(theNameAndType.getIndex());
+    }
+    void resolve (ConstantPool p) {
+        theClassName = (ConstClass) p.constantAt(theClassNameIndex);
+        theNameAndType = (ConstNameAndType) p.constantAt(theNameAndTypeIndex);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstClass.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstClass.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstClass.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstClass.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a class reference in the constant pool
+ */
+public class ConstClass extends ConstBasic {
+    /* The tag associated with ConstClass entries */
+    public static final int MyTag = CONSTANTClass;
+
+    /* The name of the class being referred to */
+    private ConstUtf8 theClassName;
+
+    /* The index of name of the class being referred to
+     *  - used while reading from a class file */
+    private int theClassNameIndex;
+
+    /* public accessors */
+
+    /**
+     * Return the tag for this constant
+     */
+    public int tag() { return MyTag; }
+
+    /**
+     * Return the class name
+     */
+    public ConstUtf8 className() {
+        return theClassName;
+    }
+
+    /**
+     * Return the class name in simple string form
+     */
+    public String asString() {
+        return theClassName.asString();
+    }
+
+    /**
+     * A printable representation 
+     */
+    public String toString() {
+        return "CONSTANTClass(" + indexAsString() + "): " + 
+            "className(" + theClassName.toString() + ")";
+    }
+
+    /**
+     * Change the class reference (not to be done lightly)
+     */
+    public void changeClass(ConstUtf8 newName) {
+        theClassName = newName;
+        theClassNameIndex = newName.getIndex();
+    }
+
+    /**
+     * Construct a ConstClass
+     */
+    public ConstClass(ConstUtf8 cname) {
+        theClassName = cname;
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstClass)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstClass other = (ConstClass)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.theClassName.isEqual(msg, other.theClassName)) {
+            msg.push(String.valueOf("theClassName = "
+                                    + other.theClassName));
+            msg.push(String.valueOf("theClassName = "
+                                    + this.theClassName));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstClass(int cname) {
+        theClassNameIndex = cname;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeShort(theClassName.getIndex());
+    }
+
+    static ConstClass read(DataInputStream input) throws IOException {
+        return new ConstClass(input.readUnsignedShort());
+    }
+
+    void resolve(ConstantPool p) {
+        theClassName = (ConstUtf8)p.constantAt(theClassNameIndex);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstDouble.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstDouble.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstDouble.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstDouble.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a double constant in the constant pool of a class file
+ */
+public class ConstDouble extends ConstValue {
+    /* The tag value associated with ConstDouble */
+    public static final int MyTag = CONSTANTDouble;
+
+    /* The value */
+    private double doubleValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag() {
+        return MyTag;
+    }
+
+    /**
+     * return the value associated with the entry
+     */
+    public double value() {
+        return doubleValue;
+    }
+
+    /**
+     * Return the descriptor string for the constant type.
+     */
+    public String descriptor() {
+        return "D";
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString() {
+        return "CONSTANTDouble(" + indexAsString() + "): " + 
+            "doubleValue(" + Double.toString(doubleValue) + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstDouble)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstDouble other = (ConstDouble)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (this.doubleValue != other.doubleValue) {
+            msg.push(String.valueOf("doubleValue = "
+                                    + other.doubleValue));
+            msg.push(String.valueOf("doubleValue = "
+                                    + this.doubleValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    /**
+     * Construct a ConstDouble object 
+     */
+    ConstDouble(double f) {
+        doubleValue = f;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeDouble(doubleValue);
+    }
+
+    static ConstDouble read(DataInputStream input) throws IOException {
+        return new ConstDouble(input.readDouble());
+    }
+
+    void resolve(ConstantPool p) { }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFieldRef.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFieldRef.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFieldRef.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFieldRef.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+
+/**
+ * ConstFieldRef represents a reference to a field of some class
+ * in the constant pool of a class file.
+ */
+public class ConstFieldRef extends ConstBasicMemberRef {
+    /* The tag associated with ConstFieldRef */
+    public static final int MyTag = CONSTANTFieldRef;
+
+    /* public accessors */
+    public int tag () { return MyTag; }
+
+    public String toString () {
+        return "CONSTANTFieldRef(" + indexAsString() + "): " + 
+            super.toString();
+    }
+
+    /* package local methods */
+
+    ConstFieldRef (ConstClass cname, ConstNameAndType NT) {
+        super(cname, NT);
+    }
+
+    ConstFieldRef (int cnameIndex, int NT_index) {
+        super(cnameIndex, NT_index);
+    }
+
+    static ConstFieldRef read (DataInputStream input) throws IOException {
+        int cname = input.readUnsignedShort();
+        int NT = input.readUnsignedShort();
+        return new ConstFieldRef (cname, NT);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFloat.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFloat.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFloat.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstFloat.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a float constant in the constant pool of a class file
+ */
+public class ConstFloat extends ConstValue {
+    /* The tag value associated with ConstFloat */
+    public static final int MyTag = CONSTANTFloat;
+
+    /* The value */
+    private float floatValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag() { return MyTag; }
+
+    /**
+     * return the value associated with the entry
+     */
+    public float value() {
+        return floatValue;
+    }
+
+    /**
+     * Return the descriptor string for the constant type.
+     */
+    public String descriptor() {
+        return "F";
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString() {
+        return "CONSTANTFloat(" + indexAsString() + "): " + 
+            "floatValue(" + Float.toString(floatValue) + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstFloat)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstFloat other = (ConstFloat)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (this.floatValue != other.floatValue) {
+            msg.push(String.valueOf("floatValue = "
+                                    + other.floatValue));
+            msg.push(String.valueOf("floatValue = "
+                                    + this.floatValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstFloat(float f) {
+        floatValue = f;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeFloat(floatValue);
+    }
+
+    static ConstFloat read(DataInputStream input) throws IOException {
+        return new ConstFloat(input.readFloat());
+    }
+
+    void resolve(ConstantPool p) { }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInteger.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInteger.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInteger.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInteger.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing an integer constant in the constant pool of a class file
+ */
+public class ConstInteger extends ConstValue {
+    /* The tag value associated with ConstInteger */
+    public static final int MyTag = CONSTANTInteger;
+
+    /* The value */
+    private int intValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag() { return MyTag; }
+
+    /**
+     * return the value associated with the entry
+     */
+    public int value() {
+        return intValue;
+    }
+
+    /**
+     * Return the descriptor string for the constant type.
+     */
+    public String descriptor() {
+        return "I";
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString() {
+        return "CONSTANTInteger(" + indexAsString() + "): " + 
+            "intValue(" + Integer.toString(intValue) + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstInteger)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstInteger other = (ConstInteger)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (this.intValue != other.intValue) {
+            msg.push(String.valueOf("intValue = "
+                                    + other.intValue));
+            msg.push(String.valueOf("intValue = "
+                                    + this.intValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstInteger(int i) {
+        intValue = i;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeInt(intValue);
+    }
+
+    static ConstInteger read(DataInputStream input) throws IOException {
+        return new ConstInteger(input.readInt());
+    }
+
+    void resolve(ConstantPool p) { }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInterfaceMethodRef.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInterfaceMethodRef.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInterfaceMethodRef.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstInterfaceMethodRef.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+
+/**
+ * Class representing a reference to an interface method of some class
+ * in the constant pool of a class file.
+ */
+public class ConstInterfaceMethodRef extends ConstBasicMemberRef {
+    /* The tag value associated with ConstDouble */
+    public static final int MyTag = CONSTANTInterfaceMethodRef;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag () { return MyTag; }
+
+    /**
+     * A printable representation
+     */
+    public String toString () {
+        return "CONSTANTInterfaceMethodRef(" + indexAsString() + "): " + 
+            super.toString();
+    }
+
+    /* package local methods */
+
+    ConstInterfaceMethodRef (ConstClass cname, ConstNameAndType NT) {
+        super(cname, NT);
+    }
+
+    ConstInterfaceMethodRef (int cnameIndex, int NT_index) {
+        super(cnameIndex, NT_index);
+    }
+
+    static ConstInterfaceMethodRef read (DataInputStream input) 
+        throws IOException {
+        int cname = input.readUnsignedShort();
+        int NT = input.readUnsignedShort();
+        return new ConstInterfaceMethodRef (cname, NT);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstLong.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstLong.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstLong.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstLong.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a long constant in the constant pool of a class file
+ */
+public class ConstLong extends ConstValue {
+    /* The tag value associated with ConstLong */
+    public static final int MyTag = CONSTANTLong;
+
+    /* The value */
+    private long longValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag() { return MyTag; }
+
+    /**
+     * return the value associated with the entry
+     */
+    public long value() {
+        return longValue;
+    }
+
+    /**
+     * Return the descriptor string for the constant type.
+     */
+    public String descriptor() {
+        return "J";
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString() {
+        return "CONSTANTLong(" + indexAsString() + "): " + 
+            "longValue(" + Long.toString(longValue) + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstLong)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstLong other = (ConstLong)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (this.longValue != other.longValue) {
+            msg.push(String.valueOf("longValue = "
+                                    + other.longValue));
+            msg.push(String.valueOf("longValue = "
+                                    + this.longValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstLong(long i) {
+        longValue = i;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeLong(longValue);
+    }
+
+    static ConstLong read(DataInputStream input) throws IOException {
+        return new ConstLong(input.readLong());
+    }
+
+    void resolve(ConstantPool p) { }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstMethodRef.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstMethodRef.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstMethodRef.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstMethodRef.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+
+/**
+ * Class representing a reference to a method of some class in the
+ * constant pool of a class file
+ */
+public class ConstMethodRef extends ConstBasicMemberRef {
+    /* The tag value associated with ConstMethodRef */
+    public static final int MyTag = CONSTANTMethodRef;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag () { return MyTag; }
+
+    /**
+     * A printable representation
+     */
+    public String toString () {
+        return "CONSTANTMethodRef(" + indexAsString() + "): " + 
+            super.toString();
+    }
+
+    /* package local methods */
+
+    ConstMethodRef (ConstClass cname, ConstNameAndType NT) {
+        super(cname, NT);
+    }
+
+    ConstMethodRef (int cnameIndex, int NT_index) {
+        super(cnameIndex, NT_index);
+    }
+
+    static ConstMethodRef read (DataInputStream input) throws IOException {
+        int cname = input.readUnsignedShort();
+        int NT = input.readUnsignedShort();
+        return new ConstMethodRef (cname, NT);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstNameAndType.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstNameAndType.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstNameAndType.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstNameAndType.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a name and an associated type in the constant pool
+ * of a class file
+ */
+public class ConstNameAndType extends ConstBasic {
+    /* The tag value associated with ConstDouble */
+    public static final int MyTag = CONSTANTNameAndType;
+
+    /* The name of interest */
+    private ConstUtf8 theName;
+
+    /* The index of the name to be resolved
+     *   - used during class file reading */
+    private int theNameIndex;
+
+    /* The type signature associated with the name */
+    private ConstUtf8 typeSignature;
+
+    /* The index of the signature to be resolved
+     *   - used during class file reading */
+    private int typeSignatureIndex;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag () { return MyTag; }
+
+    /**
+     * Return the name
+     */
+    public ConstUtf8 name() {
+        return theName;
+    }
+
+    /**
+     * Return the type signature associated with the name
+     */
+    public ConstUtf8 signature() {
+        return typeSignature;
+    }
+
+    /**
+     * Modify the signature
+     */
+    public void changeSignature(ConstUtf8 newSig) {
+        typeSignature = newSig;
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString () {
+        return "CONSTANTNameAndType(" + indexAsString() + "): " + 
+            "name(" + theName.toString() + ") " +
+            " type(" + typeSignature.toString() + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstNameAndType)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstNameAndType other = (ConstNameAndType)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.theName.isEqual(msg, other.theName)) {
+            msg.push(String.valueOf("theName = "
+                                    + other.theName));
+            msg.push(String.valueOf("theName = "
+                                    + this.theName));
+            return false;
+        }
+        if (!this.typeSignature.isEqual(msg, other.typeSignature)) {
+            msg.push(String.valueOf("typeSignature = "
+                                    + other.typeSignature));
+            msg.push(String.valueOf("typeSignature = "
+                                    + this.typeSignature));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstNameAndType (ConstUtf8 n, ConstUtf8 sig) {
+        theName = n; typeSignature = sig;
+    }
+
+    ConstNameAndType (int n, int sig) {
+        theNameIndex = n; typeSignatureIndex = sig;
+    }
+
+    void formatData (DataOutputStream b) throws IOException {
+        b.writeShort(theName.getIndex());
+        b.writeShort(typeSignature.getIndex());
+    }
+
+    static ConstNameAndType read (DataInputStream input) throws IOException {
+        int cname = input.readUnsignedShort();
+        int sig = input.readUnsignedShort();
+
+        return new ConstNameAndType (cname, sig);
+    }
+
+    void resolve (ConstantPool p) {
+        theName = (ConstUtf8) p.constantAt(theNameIndex);
+        typeSignature = (ConstUtf8) p.constantAt(typeSignatureIndex);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstString.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstString.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstString.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstString.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a class specification in the constant pool
+ *
+ * ConstString strictly speaking is not a ConstantValue in the
+ * Java VM sense.  However, the compiler generates ConstantValue attributes
+ * which refer to ConstString entries.  This occurs for initialized static
+ * final String fields.  I've changed ConstString to be a ConstValue for 
+ * now as a simplification.
+ */
+public class ConstString extends ConstValue {
+    /* The tag associated with ConstClass entries */
+    public static final int MyTag = CONSTANTString;
+
+    /* The name of the class being referred to */
+    private ConstUtf8 stringValue;
+
+    /* The index of name of the class being referred to
+     *  - used while reading from a class file */
+    private int stringValueIndex;
+
+    /* public accessors */
+
+    /**
+     * Return the tag for this constant
+     */
+    public int tag() { return MyTag; }
+
+    /**
+     * Return the utf8 string calue
+     */
+    public ConstUtf8 value() {
+        return stringValue;
+    }
+
+    /**
+     * Return the descriptor string for the constant type.
+     */
+    public String descriptor() {
+        return "Ljava/lang/String;";
+    }
+
+    /**
+     * A printable representation 
+     */
+    public String toString() {
+        return "CONSTANTString(" + indexAsString() + "): " + 
+            "string(" + stringValue.asString() + ")";
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstString)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstString other = (ConstString)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.stringValue.isEqual(msg, other.stringValue)) {
+            msg.push(String.valueOf("stringValue = "
+                                    + other.stringValue));
+            msg.push(String.valueOf("stringValue = "
+                                    + this.stringValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstString(ConstUtf8 s) {
+        stringValue = s;
+    }
+
+    ConstString(int sIndex) {
+        stringValueIndex = sIndex;
+    }
+
+    void formatData(DataOutputStream b) throws IOException {
+        b.writeShort(stringValue.getIndex());
+    }
+    static ConstString read(DataInputStream input) throws IOException {
+        return new ConstString(input.readUnsignedShort());
+    }
+    void resolve(ConstantPool p) {
+        stringValue = (ConstUtf8) p.constantAt(stringValueIndex);
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUnicode.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUnicode.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUnicode.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUnicode.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a unicode string value in the constant pool
+ *
+ * Note: evidence suggests that this is no longer part of the java VM
+ * spec.
+ */
+public class ConstUnicode extends ConstBasic {
+    /* The tag associated with ConstClass entries */
+    public static final int MyTag = CONSTANTUnicode;
+ 
+    /* The unicode string of interest */
+    private String stringValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag () { return MyTag; }
+
+    /**
+     * return the value associated with the entry
+     */
+    public String asString() {
+        return stringValue;
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString () {
+        return "CONSTANTUnicode(" + indexAsString() + "): " + stringValue;
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstUnicode)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstUnicode other = (ConstUnicode)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.stringValue.equals(other.stringValue)) {
+            msg.push(String.valueOf("stringValue = "
+                                    + other.stringValue));
+            msg.push(String.valueOf("stringValue = "
+                                    + this.stringValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstUnicode (String s) {
+        stringValue = s;
+    }
+
+    void formatData (DataOutputStream b) throws IOException {
+        b.writeBytes(stringValue);
+    }
+
+    static ConstUnicode read (DataInputStream input) throws IOException {
+        int count = input.readShort(); // Is this chars or bytes?
+        StringBuffer b = new StringBuffer();
+        for (int i=0; i < count; i++) { 
+            b.append(input.readChar());
+        }
+        return new ConstUnicode (b.toString());
+    }
+
+    void resolve (ConstantPool p) {
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUtf8.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUtf8.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUtf8.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstUtf8.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * Class representing a utf8 string value in the constant pool
+ */
+public class ConstUtf8 extends ConstBasic {
+    /* The tag associated with ConstClass entries */
+    public static final int MyTag = CONSTANTUtf8;
+ 
+    /* The unicode string of interest */
+    private String stringValue;
+
+    /* public accessors */
+
+    /**
+     * The tag of this constant entry
+     */
+    public int tag () { return MyTag; }
+
+    /**
+     * return the value associated with the entry
+     */
+    public String asString () {
+        return stringValue;
+    }
+
+    /**
+     * A printable representation
+     */
+    public String toString () {
+        return "CONSTANTUtf8(" + indexAsString() + "): " + asString();
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstUtf8)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstUtf8 other = (ConstUtf8)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.stringValue.equals(other.stringValue)) {
+            msg.push(String.valueOf("stringValue = "
+                                    + other.stringValue));
+            msg.push(String.valueOf("stringValue = "
+                                    + this.stringValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    ConstUtf8 (String s) {
+        stringValue = s;
+    }
+
+    void formatData (DataOutputStream b) throws IOException {
+        b.writeUTF(stringValue);
+    }
+
+    static ConstUtf8 read (DataInputStream input) throws IOException {
+        return new ConstUtf8 (input.readUTF());
+    }
+
+    void resolve (ConstantPool p) {
+    }
+}
+
+

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstValue.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstValue.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstValue.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstValue.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+
+/**
+ * An abstract class serving as a common type for constants which
+ * can be the target of ConstantValue attributes
+ */
+
+public abstract class ConstValue extends ConstBasic {
+  /**
+   * The constructor
+   */
+  ConstValue() { }
+
+  /**
+   * Return the descriptor string for the constant type.
+   */
+  public abstract String descriptor();
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantPool.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantPool.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantPool.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantPool.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,444 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.util.Vector;
+import java.util.Hashtable;
+import java.io.*;
+
+/**
+ *  Constant Pool implementation - this represents the constant pool
+ *  of a class in a class file.
+ */
+public class ConstantPool implements VMConstants {
+
+    /* The actual pool */
+    private Vector pool = new Vector();
+
+    /* uniqifier tables */
+    private boolean hashed = false;
+    private Hashtable utfTable = new Hashtable(11);
+    private Hashtable unicodeTable = new Hashtable(3);
+    private Hashtable stringTable = new Hashtable(11);
+    private Hashtable classTable = new Hashtable(11);
+    private Hashtable intTable = new Hashtable(3);
+    private Hashtable floatTable = new Hashtable(3);
+    private Hashtable longTable = new Hashtable(3);
+    private Hashtable doubleTable = new Hashtable(3);
+
+    private Vector methodRefTable = new Vector();
+    private Vector fieldRefTable = new Vector();
+    private Vector ifaceMethodRefTable = new Vector();
+    private Vector nameAndTypeTable = new Vector();
+
+    /* public accessors */
+
+    /**
+     * Return the number of pool entries.
+     */
+    public int nEntries() {
+        return pool.size();
+    }
+
+    /**
+     * Return the constant in the pool at the specified entry index
+     */
+    public ConstBasic constantAt (int index) {
+        return (ConstBasic) pool.elementAt(index);
+    }
+
+    /**
+     * Find or create a class constant in the pool
+     */
+    public ConstClass addClass (String className) {
+        hashConstants();
+        ConstClass c = (ConstClass) classTable.get(className);
+        if (c == null) {
+            c = new ConstClass(addUtf8(className));
+            internConstant(c);
+        }
+        return c;
+    }
+  
+    /**
+     * Find or create a field constant in the pool
+     */
+    public ConstFieldRef addFieldRef (String className, String fieldName,
+                                      String type) {
+        hashConstants();
+        ConstFieldRef f = (ConstFieldRef)
+            searchTable(fieldRefTable, className, fieldName, type);
+
+        if (f == null) {
+            f = new ConstFieldRef (addClass(className),
+                                   addNameAndType(fieldName, type));
+            internConstant(f);
+        }
+        return f;
+    }
+
+    /**
+     * Find or create a method constant in the pool
+     */
+    public ConstMethodRef addMethodRef (String className, String methodName,
+                                        String type) {
+        hashConstants();
+        ConstMethodRef m = (ConstMethodRef)
+            searchTable(methodRefTable, className, methodName, type);
+        if (m == null) {
+            m = new ConstMethodRef (addClass(className),
+                                    addNameAndType(methodName, type));
+            internConstant(m);
+        }
+        return m;
+    }
+
+    /**
+     * Find or create an interface method constant in the pool
+     */
+    public ConstInterfaceMethodRef addInterfaceMethodRef (String className,
+                                                          String methodName, 
String type) {
+        hashConstants();
+        ConstInterfaceMethodRef m = (ConstInterfaceMethodRef)
+            searchTable(ifaceMethodRefTable, className, methodName, type);
+        if (m == null) {
+            m = new ConstInterfaceMethodRef (addClass(className),
+                                             addNameAndType(methodName, type));
+            internConstant(m);
+        }
+        return m;
+    }
+
+    /**
+     * Find or create a string constant in the pool
+     */
+    public ConstString addString (String s) {
+        hashConstants();
+        ConstString cs = (ConstString) stringTable.get(s);
+        if (cs == null) {
+            cs = new ConstString(addUtf8(s));
+            internConstant(cs);
+        }
+        return cs;
+    }
+  
+    /**
+     * Find or create an integer constant in the pool
+     */
+    public ConstInteger addInteger (int i) {
+        hashConstants();
+        Integer io = new Integer(i);
+        ConstInteger ci = (ConstInteger) intTable.get(io);
+        if (ci == null) {
+            ci = new ConstInteger(i);
+            internConstant(ci);
+        }
+        return ci;
+    }
+  
+    /**
+     * Find or create a float constant in the pool
+     */
+    public ConstFloat addFloat (float f) {
+        hashConstants();
+        Float fo = new Float(f);
+        ConstFloat cf = (ConstFloat) floatTable.get(fo);
+        if (cf == null) {
+            cf = new ConstFloat(f);
+            internConstant(cf);
+        }
+        return cf;
+    }
+  
+    /**
+     * Find or create a long constant in the pool
+     */
+    public ConstLong addLong (long l) {
+        hashConstants();
+        Long lo = new Long(l);
+        ConstLong cl = (ConstLong) longTable.get(lo);
+        if (cl == null) {
+            cl = new ConstLong(l);
+            internConstant(cl);
+            internConstant(null);
+        }
+        return cl;
+    }
+  
+    /**
+     * Find or create a double constant in the pool
+     */
+    public ConstDouble addDouble (double d) {
+        hashConstants();
+        Double dobj = new Double(d);
+        ConstDouble cd = (ConstDouble) doubleTable.get(dobj);
+        if (cd == null) {
+            cd = new ConstDouble(d);
+            internConstant(cd);
+            internConstant(null);
+        }
+        return cd;
+    }
+  
+    /**
+     * Find or create a name/type constant in the pool
+     */
+    public ConstNameAndType addNameAndType (String name, String type) {
+        hashConstants();
+        for (int i=0; i<nameAndTypeTable.size(); i++) {
+            ConstNameAndType nt = (ConstNameAndType) 
nameAndTypeTable.elementAt(i);
+            if (nt.name().asString().equals(name) &&
+                nt.signature().asString().equals(type))
+                return nt;
+        }
+
+        ConstNameAndType nt =
+            new ConstNameAndType(addUtf8(name), addUtf8(type));
+        internConstant(nt);
+        return nt;
+    }
+
+    /**
+     * Find or create a utf8 constant in the pool
+     */
+    public ConstUtf8 addUtf8 (String s) {
+        hashConstants();
+        ConstUtf8 u = (ConstUtf8) utfTable.get(s);
+        if (u == null) {
+            u = new ConstUtf8(s);
+            internConstant(u);
+        }
+        return u;
+    }
+
+    /**
+     * Find or create a unicode constant in the pool
+     * Obsolete?
+     */
+    public ConstUnicode addUnicode (String s) {
+        hashConstants();
+        ConstUnicode u = (ConstUnicode) unicodeTable.get(s);
+        if (u == null) {
+            u = new ConstUnicode(s);
+            internConstant(u);
+        }
+        return u;
+    }
+
+    /* package local methods */
+
+    ConstantPool() {
+        pool.addElement(null);
+    }
+
+    ConstantPool(DataInputStream input) throws IOException {
+        pool.addElement(null);
+        int nconstants = input.readUnsignedShort()-1;
+        while (nconstants > 0)
+            nconstants -= readConstant(input);
+
+        resolvePool();
+    }
+
+    //@olsen: added 'indent' parameter
+    void print(PrintStream out, int indent) {
+        for (int i=0; i<pool.size(); i++) {
+            ConstBasic c = constantAt(i);
+            if (c != null) {
+                ClassPrint.spaces(out, indent);
+                out.print(i);
+                out.print(": ");
+                out.println(c.toString());
+            }
+        }
+    }
+
+    //@olsen: added 'out' and 'indent' parameters
+    void summarize(PrintStream out, int indent) {
+        int stringSize = 0;
+        int nStrings = 0;
+        for (int i=0; i<pool.size(); i++) {
+            ConstBasic c = constantAt(i);
+            if (c != null && c.tag() == CONSTANTUtf8) {
+                ConstUtf8 utf8 = (ConstUtf8) c;
+                stringSize += utf8.asString().length();
+                nStrings++;
+            }
+        }
+        ClassPrint.spaces(out, indent);
+        out.println("" + nStrings + " constant pool strings totalling " + 
+                    stringSize + " bytes");
+    }
+
+    void write (DataOutputStream buff) throws IOException {
+        buff.writeShort(pool.size());
+        for (int i=1; i<pool.size(); i++) {
+            ConstBasic cb = (ConstBasic) pool.elementAt(i);
+            if (cb != null) {
+                buff.writeByte((byte) cb.tag());
+                cb.formatData(buff);
+            }
+        }
+    }
+
+    /* private methods */
+
+    private void resolvePool() {
+        /* resolve indexes to object references */
+        for (int i=0; i<pool.size(); i++) {
+            ConstBasic c = constantAt(i);
+            if (c != null) {
+                c.setIndex(i);
+                c.resolve(this);
+            }
+        }
+    }
+
+    private void hashConstants() {
+        if (hashed)
+            return;
+
+        /* Enter objects into the hash tables */
+        for (int j=0; j<pool.size(); j++) {
+            ConstBasic c = constantAt(j);
+            if (c != null) {
+                recordConstant(c);
+            }
+        }
+
+        hashed = true;
+    }
+
+    /* returns the number of slots used */
+    private int readConstant(DataInputStream input) throws IOException {
+        ConstBasic basic;
+        byte b = input.readByte();
+        int slots = 1;
+        switch (b) {
+        case CONSTANTUtf8:
+            basic = ConstUtf8.read(input);
+            break;
+        case CONSTANTUnicode:
+            basic = ConstUnicode.read(input);
+            break;
+        case CONSTANTInteger:
+            basic = ConstInteger.read(input);
+            break;
+        case CONSTANTFloat:
+            basic = ConstFloat.read(input);
+            break;
+        case CONSTANTLong:
+            basic = ConstLong.read(input);
+            slots = 2;
+            break;
+        case CONSTANTDouble:
+            basic = ConstDouble.read(input);
+            slots = 2;
+            break;
+        case CONSTANTClass:
+            basic = ConstClass.read(input);
+            break;
+        case CONSTANTString:
+            basic = ConstString.read(input);
+            break;
+        case CONSTANTFieldRef:
+            basic = ConstFieldRef.read(input);
+            break;
+        case CONSTANTMethodRef:
+            basic = ConstMethodRef.read(input);
+            break;
+        case CONSTANTInterfaceMethodRef:
+            basic = ConstInterfaceMethodRef.read(input);
+            break;
+        case CONSTANTNameAndType:
+            basic = ConstNameAndType.read(input);
+            break;
+        default:
+            throw new ClassFormatError("Don't know this constant type: " +
+                                       Integer.toString(b));
+        }
+
+        pool.addElement(basic);
+        if (slots > 1)
+            pool.addElement(null);   
+        return slots;
+    }
+
+    private void internConstant (ConstBasic c) {
+        if (c != null) {
+            c.setIndex(pool.size());
+            recordConstant(c);
+        }
+        pool.addElement(c);
+    }
+
+    private void recordConstant (ConstBasic c) {
+        if (c != null) {
+            switch (c.tag()) {
+            case CONSTANTUtf8:
+                utfTable.put(((ConstUtf8)c).asString(), c);
+                break;
+            case CONSTANTUnicode:
+                unicodeTable.put(((ConstUnicode)c).asString(), c);
+                break;
+            case CONSTANTInteger:
+                intTable.put(new Integer(((ConstInteger)c).value()), c);
+                break;
+            case CONSTANTFloat:
+                floatTable.put(new Float(((ConstFloat)c).value()), c);
+                break;
+            case CONSTANTLong:
+                longTable.put(new Long(((ConstLong)c).value()), c);
+                break;
+            case CONSTANTDouble:
+                doubleTable.put(new Double(((ConstDouble)c).value()), c);
+                break;
+            case CONSTANTClass:
+                classTable.put(((ConstClass)c).asString(), c);
+                break;
+            case CONSTANTString:
+                stringTable.put(((ConstString)c).value().asString(), c);
+                break;
+            case CONSTANTFieldRef:
+                fieldRefTable.addElement(c);
+                break;
+            case CONSTANTMethodRef:
+                methodRefTable.addElement(c);
+                break;
+            case CONSTANTInterfaceMethodRef:
+                ifaceMethodRefTable.addElement(c);
+                break;
+            case CONSTANTNameAndType:
+                nameAndTypeTable.addElement(c);
+                break;
+            }
+        }
+    }
+
+    private ConstBasicMemberRef searchTable(Vector table, String cname,
+                                            String mname, String sig) {
+        for (int i=0; i<table.size(); i++) {
+            ConstBasicMemberRef memRef = (ConstBasicMemberRef) 
table.elementAt(i);
+            if (memRef.className().asString().equals(cname) &&
+                memRef.nameAndType().name().asString().equals(mname) &&
+                memRef.nameAndType().signature().asString().equals(sig))
+                return memRef;
+        }
+        return null;
+    }
+}

Added: 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantValueAttribute.java
URL: 
http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantValueAttribute.java?view=auto&rev=158176
==============================================================================
--- 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantValueAttribute.java
 (added)
+++ 
incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/classfile/ConstantValueAttribute.java
 Fri Mar 18 17:02:29 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+
+package org.apache.jdo.impl.enhancer.classfile;
+
+import java.io.*;
+import java.util.Stack;
+
+/**
+ * ConstantValueAttribute represents a constant value attribute 
+ * in a class file.  These attributes are used as initialization
+ * values for static fields.
+ */
+public class ConstantValueAttribute extends ClassAttribute {
+    /* The expected name of this attribute */
+    public static final String expectedAttrName = "ConstantValue";
+
+    /* The value */
+    private ConstValue constantValue;
+
+    /* public accessors */
+
+    public ConstValue value() {
+        return constantValue;
+    }
+
+    /** 
+     * Construct a constant value attribute
+     */
+    public ConstantValueAttribute(ConstUtf8 attrName, ConstValue value) {
+        super(attrName);
+        constantValue = value;
+    }
+
+    /**
+     * Compares this instance with another for structural equality.
+     */
+    //@olsen: added method
+    public boolean isEqual(Stack msg, Object obj) {
+        if (!(obj instanceof ConstantValueAttribute)) {
+            msg.push("obj/obj.getClass() = "
+                     + (obj == null ? null : obj.getClass()));
+            msg.push("this.getClass() = "
+                     + this.getClass());
+            return false;
+        }
+        ConstantValueAttribute other = (ConstantValueAttribute)obj;
+
+        if (!super.isEqual(msg, other)) {
+            return false;
+        }
+
+        if (!this.constantValue.isEqual(msg, other.constantValue)) {
+            msg.push(String.valueOf("constantValue = "
+                                    + other.constantValue));
+            msg.push(String.valueOf("constantValue = "
+                                    + this.constantValue));
+            return false;
+        }
+        return true;
+    }
+
+    /* package local methods */
+
+    static ConstantValueAttribute read(ConstUtf8 attrName,
+                                       DataInputStream data, ConstantPool pool)
+        throws IOException {
+        int index = 0;
+        index = data.readUnsignedShort();
+
+        return new ConstantValueAttribute(attrName,
+                                          (ConstValue) pool.constantAt(index));
+    }
+
+    void write(DataOutputStream out) throws IOException {
+        out.writeShort(attrName().getIndex());
+        out.writeInt(2);
+        out.writeShort(constantValue.getIndex());
+    }
+
+    void print(PrintStream out, int indent) {
+        ClassPrint.spaces(out, indent);
+        out.println("ConstantValue: " + constantValue.toString());
+    }
+}
+


Reply via email to