poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1857518 [4/7] - in /xmlbeans/branches/xmlbeans-536: ./ src/jam/ src/jam/org/ src/jam/org/apache/ src/jam/org/apache/xmlbeans/ src/jam/org/apache/xmlbeans/impl/ src/jam/org/apache/xmlbeans/impl/jam/ src/jam/org/apache/xmlbeans/impl/jam/anno...
Date Sun, 14 Apr 2019 13:55:07 GMT
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,371 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JAnnotation;
+import org.apache.xmlbeans.impl.jam.JAnnotationValue;
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+
+
+/**
+ * <p>Implementation of JAnnotationValue</p>
+ *
+ * @author Patrick Calahan <codehaus@bea.com>
+ */
+public class AnnotationValueImpl implements JAnnotationValue {
+
+  // ========================================================================
+  // Variables
+
+  private Object mValue = null;
+  private JClassRef mType = null;
+  private String mName;
+  private ElementContext mContext;
+
+  // ========================================================================
+  // Constructors
+
+  public AnnotationValueImpl(ElementContext ctx,
+                             String name,
+                             Object value,
+                             JClass type) {
+    if (ctx == null) throw new IllegalArgumentException("null ctx");
+    if (name == null) throw new IllegalArgumentException("null name");
+    if (value == null) throw new IllegalArgumentException("null value");
+    if (type == null) throw new IllegalArgumentException("null type");
+    if (value.getClass().isArray()) {
+      mValue = ensureArrayWrapped(value);
+    } else {
+      mValue = value;
+    }
+    mContext = ctx;
+    mName = name;
+    mType = QualifiedJClassRef.create(type);
+  }
+
+  // ========================================================================
+  // JAnnotationValue implementation
+
+  public boolean isDefaultValueUsed() {
+    throw new IllegalStateException("NYI");
+    //return mIsDefaultUsed;
+  }
+
+  public String getName() { return mName; }
+
+  public JClass getType() { return mType.getRefClass(); }
+
+
+  public JAnnotation asAnnotation() {
+    if (mValue instanceof JAnnotation) {
+      return (JAnnotation)mValue;
+    } else {
+      return null; //REVIEW or throw?
+    }
+  }
+
+  public JClass asClass() {
+    if (mValue instanceof JClass) {
+      return (JClass)mValue;
+    } else {
+      return null; //REVIEW or throw?
+    }
+  }
+
+  public String asString() {
+    if (mValue == null) return null;
+    return mValue.toString();
+  }
+
+  public int asInt() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).intValue();
+    try {
+      return Integer.parseInt(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public boolean asBoolean() throws IllegalArgumentException {
+    if (mValue == null) return false;
+    return Boolean.valueOf(mValue.toString().trim()).booleanValue();
+  }
+
+  public long asLong() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).longValue();
+    try {
+      return Long.parseLong(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public short asShort() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).shortValue();
+    try {
+      return Short.parseShort(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public double asDouble() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).doubleValue();
+    try {
+      return Double.parseDouble(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public float asFloat() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).floatValue();
+    try {
+      return Float.parseFloat(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public byte asByte() throws NumberFormatException {
+    if (mValue == null) return 0;
+    if (mValue instanceof Number) return ((Number)mValue).byteValue();
+    try {
+      return Byte.parseByte(mValue.toString().trim());
+    } catch (NumberFormatException nfe) {
+      return 0;
+    }
+  }
+
+  public char asChar() throws IllegalArgumentException {
+    //FIXME this is not right
+    if (mValue == null) return 0;
+    if (mValue instanceof Character) return ((Character)mValue).charValue();
+    mValue = mValue.toString();
+    return (((String)mValue).length() == 0) ? 0 : ((String)mValue).charAt(0);
+  }
+
+  public JClass[] asClassArray() {
+    if (mValue instanceof JClass[]) {
+      return (JClass[])mValue;
+    } else {
+      return null;
+    }
+  }
+
+  public JAnnotation[] asAnnotationArray() {
+    if (mValue instanceof JAnnotation[]) {
+      return (JAnnotation[])mValue;
+    } else {
+      return null;
+    }
+  }
+
+  public String[] asStringArray() {
+    if (!mValue.getClass().isArray()) return null;
+    String[] out = new String[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element on "+
+                                   getName());
+        out[i] = "";
+      } else {
+        out[i] = ((Object[])mValue)[i].toString();
+      }
+    }
+    return out;
+  }
+
+  public int[] asIntArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    int[] out = new int[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Integer.parseInt(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public boolean[] asBooleanArray() throws IllegalArgumentException {
+    if (!mValue.getClass().isArray()) return null;
+    boolean[] out = new boolean[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = false;
+      } else {
+        out[i] = Boolean.valueOf(((Object[])mValue)[i].toString()).booleanValue();
+      }
+    }
+    return out;
+  }
+
+  public short[] asShortArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    short[] out = new short[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Short.parseShort(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public long[] asLongArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    long[] out = new long[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Long.parseLong(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public double[] asDoubleArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    double[] out = new double[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Double.parseDouble(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public float[] asFloatArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    float[] out = new float[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Float.parseFloat(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public byte[] asByteArray() throws NumberFormatException {
+    if (!mValue.getClass().isArray()) return null;
+    byte[] out = new byte[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        out[i] = Byte.parseByte(((Object[])mValue)[i].toString());
+      }
+    }
+    return out;
+  }
+
+  public char[] asCharArray() throws IllegalArgumentException {
+    if (!mValue.getClass().isArray()) return null;
+    char[] out = new char[((Object[])mValue).length];
+    for(int i=0; i<out.length; i++) {
+      if (((Object[])mValue)[i] == null) {
+        mContext.getLogger().error("Null annotation value array element "+
+                                   i+" on "+getName());
+        out[i] = 0;
+      } else {
+        //FIXME this is not right
+        out[i] = (((Object[])mValue)[i].toString()).charAt(0);
+      }
+    }
+    return out;
+  }
+
+  // ========================================================================
+  // Private methods
+
+  //ugh, where is autoboxing when you need it?
+  private static final Object[] ensureArrayWrapped(Object o) {
+    if (o instanceof Object[]) return (Object[])o;
+    if (o instanceof int[]) {
+      int dims = ((int[])o).length;
+      Integer[] out = new Integer[dims];
+      for(int i=0; i<dims; i++) out[i] = new Integer(((int[])o)[i]);
+      return out;
+    } else if (o instanceof boolean[]) {
+      int dims = ((boolean[])o).length;
+      Boolean[] out = new Boolean[dims];
+      for(int i=0; i<dims; i++) out[i] = Boolean.valueOf(((boolean[])o)[i]);
+      return out;
+    } else if (o instanceof byte[]) {
+      int dims = ((byte[])o).length;
+      Byte[] out = new Byte[dims];
+      for(int i=0; i<dims; i++) out[i] = new Byte(((byte[])o)[i]);
+      return out;
+    } else if (o instanceof char[]) {
+      int dims = ((char[])o).length;
+      Character[] out = new Character[dims];
+      for(int i=0; i<dims; i++) out[i] = new Character(((char[])o)[i]);
+      return out;
+    } else if (o instanceof float[]) {
+      int dims = ((float[])o).length;
+      Float[] out = new Float[dims];
+      for(int i=0; i<dims; i++) out[i] = new Float(((float[])o)[i]);
+      return out;
+    } else if (o instanceof double[]) {
+      int dims = ((double[])o).length;
+      Double[] out = new Double[dims];
+      for(int i=0; i<dims; i++) out[i] = new Double(((double[])o)[i]);
+      return out;
+    } else if (o instanceof long[]) {
+      int dims = ((long[])o).length;
+      Long[] out = new Long[dims];
+      for(int i=0; i<dims; i++) out[i] = new Long(((long[])o)[i]);
+      return out;
+    } else if (o instanceof short[]) {
+      int dims = ((short[])o).length;
+      Short[] out = new Short[dims];
+      for(int i=0; i<dims; i++) out[i] = new Short(((short[])o)[i]);
+      return out;
+    } else {
+      throw new IllegalStateException("Unknown array type "+o.getClass());
+    }
+   }
+
+  public Object getValue() { return mValue; }
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ArrayClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ArrayClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ArrayClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ArrayClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,178 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JamClassLoader;
+
+import java.io.StringWriter;
+
+
+/**
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public final class ArrayClassImpl extends BuiltinClassImpl {
+
+  // ========================================================================
+  // Variables
+
+  private int mDimensions;
+  private JClass mComponentType;
+
+  // ========================================================================
+  // Factory methods
+
+
+  /**
+   * Creates an array JClass from a field descriptor as described in the JLS.
+   * This is the nasty '[[[Lfoo.bar.Baz;'-style notation.
+   */
+  public static JClass createClassForFD(String arrayFD, JamClassLoader loader)
+  {
+    if (!arrayFD.startsWith("[")) {
+      throw new IllegalArgumentException("must be an array type fd: "+arrayFD);
+    }
+    String componentType;
+    if (arrayFD.endsWith(";")) {
+      // if it's an array of complex types, we need to construct
+      // an ArrayClassImpl wrapper and go back into the context to
+      // get the component type, since a source description for it
+      // might be available
+      int dims = arrayFD.indexOf("L");
+      if (dims != -1 && dims<arrayFD.length()-2) {
+        componentType = arrayFD.substring(dims+1,arrayFD.length()-1);
+        return new ArrayClassImpl(loader.loadClass(componentType),dims);
+      } else {
+        // name is effed
+        throw new IllegalArgumentException("array type field descriptor '"+
+                                           arrayFD+"' is malformed");
+      }
+    } else {
+      int dims = arrayFD.lastIndexOf("[")+1;
+      String compFd = arrayFD.substring(dims,dims+1);
+      JClass primType = loader.loadClass(compFd);
+      if (primType == null) {
+        // if it didn't end with ';', it has to be a valid primitive
+        // type name or it's effed
+        throw new IllegalArgumentException("array type field descriptor '"+
+                                           arrayFD+"' is malformed");
+      }
+      return new ArrayClassImpl(primType,dims);
+    }
+  }
+
+  /**
+   * Returns the normal form for a given array name.  This is a trimmed,
+   * unspaced field descriptor, e.g. '[[[Ljava.lang.String;' for a three
+   * dimensional array of strings.  This method will also normalize
+   * understands declaration-style array names, e.g. 'java.lang.String[][][]'.
+   */
+  public static String normalizeArrayName(String declaration) {
+    //REVIEW should we worry about internal spaces?
+    if (declaration.startsWith("[")) return declaration;
+    if (declaration.endsWith("]")) {
+      int bracket = declaration.indexOf('[');
+      if (bracket != -1) {
+        String typeName = declaration.substring(0,bracket);
+        String fd = PrimitiveClassImpl.getPrimitiveClassForName(typeName);
+        if (fd == null) fd = 'L'+typeName+';';
+        StringWriter out = new StringWriter();
+        do {
+          out.write('[');
+          bracket = declaration.indexOf('[',bracket+1);
+        } while(bracket != -1);
+        out.write(fd);
+        return out.toString();
+      }
+    }
+    throw new IllegalArgumentException("'"+declaration+
+                                       "' does not name an array");
+  }
+
+
+
+  // ========================================================================
+  // Constructors - use factory method
+
+  /**
+   * Constructs a JDClass for the given ClassDoc in the given context.
+   */
+  private ArrayClassImpl(JClass componentType, int dimensions)
+  {
+    super(((ElementImpl)componentType).getContext());
+    if (dimensions < 1) {
+      throw new IllegalArgumentException("dimensions="+dimensions);
+    }
+    if (componentType == null) {
+      throw new IllegalArgumentException("null componentType");
+    }
+    mComponentType = componentType;
+    mDimensions = dimensions;
+  }
+
+  // ========================================================================
+  // JElement implementation
+
+//  public JElement getParent() { return null; }
+
+  public String getSimpleName() {
+    String out = getQualifiedName();
+    int lastDot = out.lastIndexOf('.');
+    return (lastDot == -1) ? out : out.substring(lastDot+1);
+  }
+
+  public String getQualifiedName() {
+    StringWriter out = new StringWriter();
+    out.write(mComponentType.getQualifiedName());
+    for(int i=0; i<mDimensions; i++) out.write("[]");
+    return out.toString();
+  }
+
+  // ========================================================================
+  // JClass implementation
+
+  public boolean isArrayType() { return true; }
+
+  public JClass getArrayComponentType() { return mComponentType; }
+
+  public int getArrayDimensions() { return mDimensions; }
+
+  public JClass getSuperclass() {
+    return getClassLoader().loadClass("java.lang.Object");
+  }
+
+  public boolean isAssignableFrom(JClass c) {
+    return c.isArrayType() &&
+            (c.getArrayDimensions() == mDimensions) &&
+            (mComponentType.isAssignableFrom(c.getArrayComponentType()));
+  }
+
+  public String getFieldDescriptor() {
+    //REVIEW should we cache this result?
+    StringWriter out = new StringWriter();
+    for(int i=0; i<mDimensions; i++) out.write("[");
+    if (mComponentType.isPrimitiveType()) {
+      out.write(mComponentType.getFieldDescriptor());
+    } else {
+      out.write("L");
+      out.write(mComponentType.getQualifiedName());
+      out.write(";");
+    }
+    return out.toString();
+  }
+
+
+
+}

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/BuiltinClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/BuiltinClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/BuiltinClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/BuiltinClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,188 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JConstructor;
+import org.apache.xmlbeans.impl.jam.JField;
+import org.apache.xmlbeans.impl.jam.JMethod;
+import org.apache.xmlbeans.impl.jam.JPackage;
+import org.apache.xmlbeans.impl.jam.JProperty;
+import org.apache.xmlbeans.impl.jam.JSourcePosition;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
+import org.apache.xmlbeans.impl.jam.mutable.MField;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+/**
+ * <p>Base class for types that are 'built in' to the VM.  This includes
+ * void, primitives (but not their wrappers like Integer), and array types.
+ * Note that java.lang.Object is not considered a Builtin.</p>
+ *
+ * <p>Note that while builtin classes cannot be modified, they can
+ * be annotated and commented.</p>
+ *
+ * I think this is going to include generics as well.
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public abstract class BuiltinClassImpl extends AnnotatedElementImpl
+  implements MClass
+{
+
+  // ========================================================================
+  // Constructors
+
+  protected BuiltinClassImpl(ElementContext ctx) {
+    super(ctx);
+  }
+
+  // ========================================================================
+  // JElement implementation
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public String getQualifiedName() { return mSimpleName; }
+
+  public String getFieldDescriptor() { return mSimpleName; }
+
+  // ========================================================================
+  // JMember implementation
+
+  public int getModifiers() { return Object.class.getModifiers(); }
+  public boolean isPublic() { return true; }
+  public boolean isPackagePrivate() { return false; }
+  public boolean isProtected() { return false; }
+  public boolean isPrivate() { return false; }
+  public JSourcePosition getSourcePosition() { return null; }
+  public JClass getContainingClass() { return null; }
+
+  // ========================================================================
+  // JClass implementation
+
+  public JClass forName(String fd) {
+    return getClassLoader().loadClass(fd);
+  }
+
+  public JClass getArrayComponentType() { return null; }
+  public int getArrayDimensions() { return 0; }
+
+  public JClass getSuperclass() { return null; }
+  public JClass[] getInterfaces() { return NO_CLASS; }
+  public JField[] getFields() { return NO_FIELD; }
+  public JField[] getDeclaredFields() { return NO_FIELD; }
+  public JConstructor[] getConstructors() { return NO_CONSTRUCTOR;}
+  public JMethod[] getMethods() { return NO_METHOD; }
+  public JMethod[] getDeclaredMethods() { return NO_METHOD; }
+  public JPackage getContainingPackage() { return null; }
+  public boolean isInterface() { return false; }
+
+  public boolean isArrayType() { return false; }
+  public boolean isAnnotationType() { return false; }
+  public boolean isPrimitiveType() { return false; }
+  public boolean isBuiltinType() { return true; }
+  public boolean isUnresolvedType() { return false; }
+  public boolean isObjectType() { return false; }
+  public boolean isVoidType() { return false; }
+  public boolean isEnumType() { return false; }
+  public Class getPrimitiveClass() { return null; }
+  public boolean isAbstract() { return false; }
+  public boolean isFinal() { return false; }
+  public boolean isStatic() { return false; }
+  public JClass[] getClasses() { return NO_CLASS; }
+  public JProperty[] getProperties() { return NO_PROPERTY; }
+  public JProperty[] getDeclaredProperties() { return NO_PROPERTY; }
+  public JPackage[] getImportedPackages() { return NO_PACKAGE; }
+  public JClass[] getImportedClasses() { return NO_CLASS; }
+
+  // ========================================================================
+  // MClass implementation
+
+  public MField[] getMutableFields() { return NO_FIELD; }
+  public MConstructor[] getMutableConstructors() { return NO_CONSTRUCTOR; }
+  public MMethod[] getMutableMethods() { return NO_METHOD; }
+
+  // can't do any of this stuff
+
+  public void setSimpleName(String s) { nocando(); }
+
+  public void setIsAnnotationType(boolean b) { nocando(); }
+  public void setIsInterface(boolean b) { nocando(); }
+  public void setIsUnresolvedType(boolean b) { nocando(); }
+  public void setIsEnumType(boolean b) { nocando(); }
+  public void setSuperclass(String qualifiedClassName) { nocando(); }
+  public void setSuperclassUnqualified(String unqualifiedClassName) { nocando(); }
+  public void setSuperclass(JClass clazz) { nocando(); }
+  public void addInterface(String className) { nocando(); }
+  public void addInterfaceUnqualified(String unqualifiedClassName) { nocando(); }
+  public void addInterface(JClass interf) { nocando(); }
+  public void removeInterface(String className) { nocando(); }
+  public void removeInterface(JClass interf) { nocando(); }
+  public MConstructor addNewConstructor() { nocando(); return null; }
+  public void removeConstructor(MConstructor constr) { nocando(); }
+  public MField addNewField() { nocando(); return null; }
+  public void removeField(MField field) { nocando(); }
+  public MMethod addNewMethod() { nocando(); return null; }
+  public void removeMethod(MMethod method) { nocando(); }
+  public void setModifiers(int modifiers) { nocando(); }
+  public MClass addNewInnerClass(String named) { nocando(); return null; }
+  public void removeInnerClass(MClass inner) { nocando(); }
+
+  public JProperty addNewProperty(String name, JMethod m, JMethod x) {
+    nocando();
+    return null;
+  }
+  public void removeProperty(JProperty prop) { nocando(); }
+
+  public JProperty addNewDeclaredProperty(String name, JMethod m, JMethod x) {
+    nocando();
+    return null;
+  }
+  public void removeDeclaredProperty(JProperty prop) { nocando(); }
+
+  // ========================================================================
+  // Object implementation
+
+  public boolean equals(Object o) {
+    if (o instanceof JClass) {
+      return ((JClass)o).getFieldDescriptor().equals(getFieldDescriptor());
+    } else {
+      return false;
+    }
+  }
+
+  public int hashCode() { return getFieldDescriptor().hashCode(); }
+
+  // ========================================================================
+  // Protected methods
+
+  protected void reallySetSimpleName(String name) {
+    super.setSimpleName(name);
+  }
+
+  // ========================================================================
+  // Private methods
+
+  private void nocando() {
+    throw new UnsupportedOperationException("Cannot alter builtin types");
+  }
+
+}

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,684 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JAnnotation;
+import org.apache.xmlbeans.impl.jam.JAnnotationValue;
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JComment;
+import org.apache.xmlbeans.impl.jam.JConstructor;
+import org.apache.xmlbeans.impl.jam.JField;
+import org.apache.xmlbeans.impl.jam.JMethod;
+import org.apache.xmlbeans.impl.jam.JPackage;
+import org.apache.xmlbeans.impl.jam.JProperty;
+import org.apache.xmlbeans.impl.jam.JSourcePosition;
+import org.apache.xmlbeans.impl.jam.internal.JamClassLoaderImpl;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRefContext;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
+import org.apache.xmlbeans.impl.jam.mutable.MField;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * <p>Implementation of JClass and MClass.</p>
+ *
+ * @author Patrick Calahan <jdclasspcal@bea.com>
+ */
+public class ClassImpl extends MemberImpl implements MClass,
+  JClassRef, JClassRefContext
+{
+  // ========================================================================
+  // Constants
+
+  public static final int NEW = 1;
+  public static final int UNPOPULATED = 2;
+  public static final int POPULATING = 3;
+  public static final int UNINITIALIZED = 4;
+  public static final int INITIALIZING = 5;
+  public static final int LOADED = 6;
+
+  // ========================================================================
+  // Variables
+
+  private int mState = NEW;
+
+  private boolean mIsAnnotationType = false;
+  private boolean mIsInterface = false;
+  private boolean mIsEnum = false;
+
+  private String mPackageName = null;
+
+  private JClassRef mSuperClassRef = null; // classrefs to the class we extend
+  private ArrayList mInterfaceRefs = null; // refs to interfaces we elements.
+
+  private ArrayList mFields = null;
+  private ArrayList mMethods = null;
+  private ArrayList mConstructors = null;
+  private ArrayList mProperties = null;
+  private ArrayList mDeclaredProperties = null;
+  private ArrayList mInnerClasses = null;
+
+  private String[] mImports = null;
+
+  private JamClassPopulator mPopulator;
+
+  // FIXME implement this - we should only create one UnqualifiedJClassRef
+  // for each unqualified name so as to avoid resolving them over and over.
+  //private Map mName2Uqref = null;
+
+  // ========================================================================
+  // Constructors
+
+  public ClassImpl(String packageName,
+                   String simpleName,
+                   ElementContext ctx,
+                   String[] importSpecs,
+                   JamClassPopulator populator) {
+    super(ctx);
+    super.setSimpleName(simpleName);
+    mPackageName = packageName.trim();
+    mImports = importSpecs;
+    mPopulator = populator;
+    setState(UNPOPULATED);
+  }
+
+  public ClassImpl(String packageName,
+                   String simpleName,
+                   ElementContext ctx,
+                   String[] importSpecs)
+  {
+    super(ctx);
+    super.setSimpleName(simpleName);
+    mPackageName = packageName.trim();
+    mImports = importSpecs;
+    mPopulator = null;
+    setState(UNINITIALIZED);
+  }
+
+  private ClassImpl(String packageName,
+                    String simpleName,
+                    String[] importSpecs,
+                    ClassImpl parent)
+  {
+    super(parent);
+    super.setSimpleName(simpleName);
+    mPackageName = packageName.trim();
+    mImports = importSpecs;
+    mPopulator = null;
+    setState(UNINITIALIZED);
+  }
+
+
+
+  // ========================================================================
+  // JClass implementation
+
+  public JPackage getContainingPackage() {
+    return getClassLoader().getPackage(mPackageName);
+  }
+
+  public JClass getSuperclass() {
+    ensureLoaded();
+    if (mSuperClassRef == null) {
+      return null;
+    } else {
+      return mSuperClassRef.getRefClass();
+    }
+  }
+
+  public JClass[] getInterfaces() {
+    ensureLoaded();
+    if (mInterfaceRefs == null || mInterfaceRefs.size() == 0) {
+      return new JClass[0];
+    } else {
+      JClass[] out = new JClass[mInterfaceRefs.size()];
+      for(int i=0; i<out.length; i++) {
+        out[i] = ((JClassRef)mInterfaceRefs.get(i)).getRefClass();
+      }
+      return out;
+    }
+  }
+
+  public JField[] getFields() {
+    ensureLoaded();
+    List list = new ArrayList();
+    addFieldsRecursively(this, list);
+    JField[] out = new JField[list.size()];
+    list.toArray(out);
+    return out;
+  }
+
+  public JField[] getDeclaredFields() {
+    ensureLoaded();
+    return getMutableFields();
+  }
+
+  public JMethod[] getMethods() {
+    ensureLoaded();
+    List list = new ArrayList();
+    addMethodsRecursively(this, list);
+    JMethod[] out = new JMethod[list.size()];
+    list.toArray(out);
+    return out;
+  }
+
+  public JProperty[] getProperties() {
+    ensureLoaded();
+    if (mProperties == null) return new JProperty[0];
+    JProperty[] out = new JProperty[mProperties.size()];
+    mProperties.toArray(out);
+    return out;
+  }
+
+  public JProperty[] getDeclaredProperties() {
+    ensureLoaded();
+    if (mDeclaredProperties == null) return new JProperty[0];
+    JProperty[] out = new JProperty[mDeclaredProperties.size()];
+    mDeclaredProperties.toArray(out);
+    return out;
+  }
+
+  public JMethod[] getDeclaredMethods() {
+    ensureLoaded();
+    return getMutableMethods();
+  }
+
+  public JConstructor[] getConstructors() {
+    ensureLoaded();
+    return getMutableConstructors();
+  }
+
+  public boolean isInterface() {
+    ensureLoaded();
+    return mIsInterface;
+  }
+
+  public boolean isAnnotationType() {
+    ensureLoaded();
+    return mIsAnnotationType;
+  }
+
+  public boolean isEnumType() {
+    ensureLoaded();
+    return mIsEnum;
+  }
+
+  public int getModifiers() {
+    ensureLoaded();
+    return super.getModifiers();
+  }
+
+
+  public boolean isFinal() { return Modifier.isFinal(getModifiers()); }
+
+  public boolean isStatic() { return Modifier.isStatic(getModifiers()); }
+
+  public boolean isAbstract() { return Modifier.isAbstract(getModifiers()); }
+
+  public boolean isAssignableFrom(JClass arg) {
+    ensureLoaded();
+    if (isPrimitiveType() || arg.isPrimitiveType()) {
+      return getQualifiedName().equals(arg.getQualifiedName());
+    }
+    return isAssignableFromRecursively(arg);
+  }
+
+  public JClass[] getClasses() {
+    ensureLoaded();
+    if (mInnerClasses == null) return new JClass[0];
+    JClass[] out = new JClass[mInnerClasses.size()];
+    mInnerClasses.toArray(out);
+    return out;
+  }
+
+  public String getFieldDescriptor() {
+    return getQualifiedName();
+  }
+
+  public JClass forName(String name) {
+    return getClassLoader().loadClass(name);
+  }
+
+  public JPackage[] getImportedPackages() {
+    ensureLoaded();
+    Set set = new TreeSet();
+    JClass[] importedClasses = getImportedClasses();
+    for(int i=0; i<importedClasses.length; i++) {
+      JPackage c = importedClasses[i].getContainingPackage();
+      if (c != null) set.add(c);
+    }
+    String[] imports = getImportSpecs();
+    if (imports != null) {
+      for(int i=0; i<imports.length; i++) {
+        if (imports[i].endsWith(".*")) {
+          set.add(getClassLoader().
+                  getPackage(imports[i].substring(0,imports[i].length()-2)));
+        }
+      }
+    }
+    JPackage[] array = new JPackage[set.size()];
+    set.toArray(array);
+    return array;
+  }
+
+  public JClass[] getImportedClasses() {
+    ensureLoaded();
+    String[] imports = getImportSpecs();
+    if (imports == null) return new JClass[0];
+    List list = new ArrayList();
+    for(int i=0; i<imports.length; i++) {
+      if (imports[i].endsWith("*")) continue;
+      list.add(getClassLoader().loadClass(imports[i]));
+    }
+    JClass[] out = new JClass[list.size()];
+    list.toArray(out);
+    return out;
+  }
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public void setSimpleName(String name) {
+    throw new UnsupportedOperationException("Class names cannot be changed");
+  }
+
+  public Class getPrimitiveClass()  { return null; }
+  public boolean isPrimitiveType()  { return false; }
+  public boolean isBuiltinType()    { return false; }
+  public boolean isVoidType()       { return false; }
+  public boolean isUnresolvedType() { return false; }
+  public boolean isObjectType() {
+    return getQualifiedName().equals("java.lang.Object");
+  }
+
+  public boolean isArrayType() { return false; }
+  public JClass getArrayComponentType() { return null; }
+  public int getArrayDimensions() { return 0; }
+
+  // ========================================================================
+  // AnnotatedElementImpl implementation - just to add ensureLoaded()
+
+  public JAnnotation[] getAnnotations() {
+    ensureLoaded();
+    return super.getAnnotations();
+  }
+
+  public JAnnotation getAnnotation(Class proxyClass) {
+    ensureLoaded();
+    return super.getAnnotation(proxyClass);
+  }
+
+  public JAnnotation getAnnotation(String named) {
+    ensureLoaded();
+    return super.getAnnotation(named);
+  }
+
+  public JAnnotationValue getAnnotationValue(String valueId) {
+    ensureLoaded();
+    return super.getAnnotationValue(valueId);
+  }
+
+
+  public Object getAnnotationProxy(Class proxyClass) {
+    ensureLoaded();
+    return super.getAnnotationProxy(proxyClass);
+  }
+
+  public JComment getComment() {
+    ensureLoaded();
+    return super.getComment();
+  }
+
+  public JAnnotation[] getAllJavadocTags() {
+    ensureLoaded();
+    return super.getAllJavadocTags();
+  }
+
+  // ========================================================================
+  // Element implementation - just to add ensureLoaded()
+
+  public JSourcePosition getSourcePosition() {
+    ensureLoaded();
+    return super.getSourcePosition();
+  }
+
+
+  // ========================================================================
+  // MClass implementation
+
+  //FIXME should add assertiong here that state is not LOADED
+
+  public void setSuperclass(String qualifiedClassName) {
+    if (qualifiedClassName == null) {
+      mSuperClassRef = null;
+    } else {
+      if (qualifiedClassName.equals(getQualifiedName())) {
+        throw new IllegalArgumentException
+          ("A class cannot be it's own superclass: '"+qualifiedClassName+"'");
+      }
+      mSuperClassRef = QualifiedJClassRef.create(qualifiedClassName, this);
+    }
+  }
+
+  public void setSuperclassUnqualified(String unqualifiedClassName) {
+    mSuperClassRef = UnqualifiedJClassRef.create(unqualifiedClassName,this);
+  }
+
+  public void setSuperclass(JClass clazz) {
+    if (clazz == null) {
+      mSuperClassRef = null;
+    } else {
+      setSuperclass(clazz.getQualifiedName());
+    }
+  }
+
+  public void addInterface(JClass interf) {
+    if (interf == null) throw new IllegalArgumentException("null interf");
+
+    addInterface(interf.getQualifiedName());
+  }
+
+  public void addInterface(String qcName) {
+    if (mInterfaceRefs == null) mInterfaceRefs = new ArrayList();
+    if (qcName.equals(getQualifiedName())) {
+      throw new IllegalArgumentException
+        ("A class cannot implement itself: '"+qcName+"'");
+    }
+    mInterfaceRefs.add(QualifiedJClassRef.create(qcName,this));
+  }
+
+  public void addInterfaceUnqualified(String ucname) {
+    if (mInterfaceRefs == null) mInterfaceRefs = new ArrayList();
+    mInterfaceRefs.add(UnqualifiedJClassRef.create(ucname,this));
+  }
+
+  public void removeInterface(JClass interf) {
+    if (interf == null) throw new IllegalArgumentException("null interf");
+    removeInterface(interf.getQualifiedName());
+  }
+
+  public void removeInterface(String qcname) {
+    //REVIEW this is quite inefficient, but maybe it doesnt matter so much
+    if (qcname == null) throw new IllegalArgumentException("null classname");
+    if (mInterfaceRefs == null) return;
+    for(int i=0; i<mInterfaceRefs.size(); i++) {
+      if (qcname.equals
+              (((JClassRef)mInterfaceRefs.get(i)).getQualifiedName())) {
+        mInterfaceRefs.remove(i);
+      }
+    }
+  }
+
+  public MConstructor addNewConstructor() {
+    if (mConstructors == null) mConstructors = new ArrayList();
+    MConstructor out = new ConstructorImpl(this);
+    mConstructors.add(out);
+    return out;
+  }
+
+  public void removeConstructor(MConstructor constr) {
+    if (mConstructors == null) return;
+    mConstructors.remove(constr);
+  }
+
+  public MConstructor[] getMutableConstructors() {
+    if (mConstructors == null || mConstructors.size() == 0) {
+      return new MConstructor[0];
+    }
+    MConstructor[] out = new MConstructor[mConstructors.size()];
+    mConstructors.toArray(out);
+    return out;
+  }
+
+  public MField addNewField() {
+    if (mFields == null) mFields = new ArrayList();
+    MField out = new FieldImpl(defaultName(mFields.size()),
+                                this,"java.lang.Object");
+    mFields.add(out);
+    return out;
+  }
+
+  public void removeField(MField field) {
+    if (mFields == null) return;
+    mFields.remove(field);
+  }
+
+  public MField[] getMutableFields() {
+    if (mFields == null || mFields.size() == 0) {
+      return new MField[0];
+    }
+    MField[] out = new MField[mFields.size()];
+    mFields.toArray(out);
+    return out;
+  }
+
+  public MMethod addNewMethod() {
+    if (mMethods == null) mMethods = new ArrayList();
+    MMethod out = new MethodImpl(defaultName(mMethods.size()),this);
+    mMethods.add(out);
+    return out;
+  }
+
+  public void removeMethod(MMethod method) {
+    if (mMethods == null) return;
+    mMethods.remove(method);
+  }
+
+  public MMethod[] getMutableMethods() {
+    if (mMethods == null || mMethods.size() == 0) {
+      return new MMethod[0];
+    }
+    MMethod[] out = new MMethod[mMethods.size()];
+    mMethods.toArray(out);
+    return out;
+  }
+
+  public JProperty addNewProperty(String name, JMethod getter, JMethod setter) {
+    if (mProperties == null) mProperties = new ArrayList();
+    String typeName = (getter != null) ?
+      getter.getReturnType().getFieldDescriptor() :
+      setter.getParameters()[0].getType().getFieldDescriptor();
+    JProperty out = new PropertyImpl(name,getter,setter,typeName);
+    mProperties.add(out);
+    return out;
+  }
+
+  public void removeProperty(JProperty p) {
+    if (mProperties != null) mProperties.remove(p);
+  }
+
+  public JProperty addNewDeclaredProperty(String name, JMethod getter, JMethod setter) {
+    if (mDeclaredProperties == null) mDeclaredProperties = new ArrayList();
+    String typeName = (getter != null) ?
+      getter.getReturnType().getFieldDescriptor() :
+      setter.getParameters()[0].getType().getFieldDescriptor();
+    JProperty out = new PropertyImpl(name,getter,setter,typeName);
+    mDeclaredProperties.add(out);
+    return out;
+  }
+
+  public void removeDeclaredProperty(JProperty p) {
+    if (mDeclaredProperties != null) mDeclaredProperties.remove(p);
+  }
+
+  public MClass addNewInnerClass(String name) {
+    // strip off everything but the last bit, no matter what they give us.
+    // we'll prepend our own simplename to make sure the full nesting
+    // is expressed correctly (i.e. with '$').
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot == -1) lastDot = name.lastIndexOf('$');
+    if (lastDot != -1) name = name.substring(lastDot+1);
+    ClassImpl inner = new ClassImpl(mPackageName,
+                                 getSimpleName()+"$"+name,
+                                 getImportSpecs(),
+                                 this);
+    if (mInnerClasses == null) mInnerClasses = new ArrayList();
+    mInnerClasses.add(inner);
+    inner.setState(LOADED); //REVIEW this works, but inner class lifecycle is not well thought-out
+    ((JamClassLoaderImpl)getClassLoader()).addToCache(inner);
+    return inner;
+  }
+
+  public void removeInnerClass(MClass clazz) {
+    if (mInnerClasses == null) return;
+    mInnerClasses.remove(clazz);
+  }
+
+  public void setIsInterface(boolean b) { mIsInterface = b; }
+
+  public void setIsAnnotationType(boolean b) { mIsAnnotationType = b; }
+
+  public void setIsEnumType(boolean b) { mIsEnum = b; }
+
+  public String getQualifiedName() {
+    return ((mPackageName.length() > 0) ? (mPackageName + '.') : "") +
+      mSimpleName;
+  }
+
+  // ========================================================================
+  // JClassRef implementation (to accommodate direct references)
+
+  public JClass getRefClass() { return this; }
+
+  // ========================================================================
+  // JClassRefContext implementation
+
+  public String getPackageName() {
+    return mPackageName;
+  }
+
+  public String[] getImportSpecs() {
+    ensureLoaded();
+    if (mImports == null) return new String[0];
+    return mImports;
+  }
+
+  // ========================================================================
+  // Public methods for internal use only
+
+  public void setState(int state) {
+    mState = state;
+  }
+
+  // ========================================================================
+  // Public static utility methods
+
+  /**
+   * Throws an IllegalArgument exception if the given string is not a valid
+   * class name.  Useful for parameter checking in several places.
+   */
+  public static void validateClassName(String className)
+          throws IllegalArgumentException
+  {
+    if (className == null) {
+      throw new IllegalArgumentException("null class name specified");
+    }
+    if (!Character.isJavaIdentifierStart(className.charAt(0))) {
+      throw new IllegalArgumentException
+              ("Invalid first character in class name: "+className);
+    }
+    for(int i=1; i<className.length(); i++) {
+      char c = className.charAt(i);
+      if (c == '.') {
+        if (className.charAt(i-1) == '.') {
+          throw new IllegalArgumentException
+                  ("'..' not allowed in class name: "+className);
+        }
+        if (i == className.length()-1) {
+          throw new IllegalArgumentException
+                  ("'.' not allowed at end of class name: "+className);
+        }
+      } else {
+        if (!Character.isJavaIdentifierPart(c)) {
+          throw new IllegalArgumentException
+                  ("Illegal character '"+c+"' in class name: "+className);
+        }
+      }
+    }
+  }
+
+  // ========================================================================
+  // Private methods
+
+  private boolean isAssignableFromRecursively(JClass arg) {
+    if (this.getQualifiedName().equals(arg.getQualifiedName())) return true;
+    // check all of arg's implemented interfaces, recursively
+    JClass[] interfaces = arg.getInterfaces();
+    if (interfaces != null) {
+      for (int i=0; i<interfaces.length; i++) {
+        if (isAssignableFromRecursively(interfaces[i])) return true;
+      }
+    }
+    // check arg's superclass, recursively
+    arg = arg.getSuperclass();
+    if (arg != null) {
+      if (isAssignableFromRecursively(arg)) return true;
+    }
+    return false;
+  }
+
+  private void addFieldsRecursively(JClass clazz, Collection out) {
+    JField[] fields = clazz.getDeclaredFields();
+    for (int i = 0; i < fields.length; i++) out.add(fields[i]);
+    JClass[] ints = clazz.getInterfaces();
+    for (int i = 0; i < ints.length; i++) {
+      addFieldsRecursively(ints[i], out);
+    }
+    clazz = clazz.getSuperclass();
+    if (clazz != null) addFieldsRecursively(clazz, out);
+  }
+
+  private void addMethodsRecursively(JClass clazz, Collection out) {
+    JMethod[] methods = clazz.getDeclaredMethods();
+    for (int i = 0; i < methods.length; i++) out.add(methods[i]);
+    JClass[] ints = clazz.getInterfaces();
+    for (int i = 0; i < ints.length; i++) {
+      addMethodsRecursively(ints[i], out);
+    }
+    clazz = clazz.getSuperclass();
+    if (clazz != null) addMethodsRecursively(clazz, out);
+  }
+
+  public void ensureLoaded() {
+    if (mState == LOADED) return;
+    if (mState == UNPOPULATED) {
+      if (mPopulator == null) throw new IllegalStateException("null populator");
+      setState(POPULATING);
+      mPopulator.populate(this);
+      setState(UNINITIALIZED);
+    }
+    if (mState == UNINITIALIZED) {
+      setState(INITIALIZING);
+      ((JamClassLoaderImpl)getClassLoader()).initialize(this);
+    }
+    setState(ClassImpl.LOADED);
+  }
+
+}

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/CommentImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/CommentImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/CommentImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/CommentImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,56 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.mutable.MComment;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+/**
+ * <p>Implementation
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public final class CommentImpl extends ElementImpl implements MComment {
+
+  // ========================================================================
+  // Variables
+
+  private String mText = null;
+
+  // ========================================================================
+  // Constructors
+
+  /*package*/ CommentImpl(ElementImpl parent) { super(parent); }
+
+  // ========================================================================
+  // MComment implementation
+
+  public void setText(String text) { mText = text; }
+
+  public String getText() { return (mText == null) ? "" : mText; }
+
+  // ========================================================================
+  // JElement implementation
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public String getQualifiedName() {
+    return getParent().getQualifiedName()+".{comment}"; //REVIEW
+  }
+
+}

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ConstructorImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ConstructorImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ConstructorImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ConstructorImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,79 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JParameter;
+import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+import java.io.StringWriter;
+import java.lang.reflect.Modifier;
+
+/**
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public final class ConstructorImpl extends InvokableImpl implements MConstructor {
+
+  // ========================================================================
+  // Constructors
+
+  /*package*/ ConstructorImpl(ClassImpl containingClass) {
+    super(containingClass);
+    setSimpleName(containingClass.getSimpleName());
+  }
+
+  // ========================================================================
+  // JElement implementation
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public String getQualifiedName() {
+    StringWriter sbuf = new StringWriter();
+    sbuf.write(Modifier.toString(getModifiers()));
+    sbuf.write(' ');
+    sbuf.write(getSimpleName());
+    sbuf.write('(');
+    {
+    JParameter[] params = getParameters();
+    if (params != null && params.length > 0) {
+      for(int i=0; i<params.length; i++) {
+        sbuf.write(params[i].getType().getQualifiedName());
+        if (i<params.length-1) sbuf.write(',');
+      }
+    }
+    }
+    sbuf.write(')');
+    /* REVIEW the docs on java.lang.reflect.Constructor don't say include
+       the exceptions.  That seems wrong, but we'll go with it for now.
+    {
+      JClass[] thrown = getExceptionTypes();
+      if (thrown != null && thrown.length > 0) {
+        sbuf.write(" throws ");
+        for(int i=0; i<thrown.length; i++) {
+          sbuf.write(thrown[i].getQualifiedName());
+          if (i<thrown.length-1) sbuf.write(',');
+        }
+      }
+    }
+    */
+    return sbuf.toString();
+  }
+
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementContext.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementContext.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementContext.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementContext.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,42 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JamClassLoader;
+import org.apache.xmlbeans.impl.jam.annotation.AnnotationProxy;
+import org.apache.xmlbeans.impl.jam.provider.JamLogger;
+
+/**
+ * <p>Context object required by every ElementImpl.</p>
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public interface ElementContext extends JamLogger /**REMOVE THIS EXTENDS PLEASE*/ {
+
+  public JamLogger getLogger();
+
+  /**
+   * <p>Returns the classloader the elements should use for type resolution.
+   * </p>
+   */
+  public JamClassLoader getClassLoader();
+
+  /**
+   * <p>Creates an empty appropriate proxy for the given 175 annotation
+   * instance.</p>
+   */
+  public AnnotationProxy createAnnotationProxy(String jsr175typename);
+
+}

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ElementImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,180 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JElement;
+import org.apache.xmlbeans.impl.jam.JPackage;
+import org.apache.xmlbeans.impl.jam.JProperty;
+import org.apache.xmlbeans.impl.jam.JSourcePosition;
+import org.apache.xmlbeans.impl.jam.JamClassLoader;
+import org.apache.xmlbeans.impl.jam.internal.JamServiceContextImpl;
+import org.apache.xmlbeans.impl.jam.mutable.MElement;
+import org.apache.xmlbeans.impl.jam.mutable.MSourcePosition;
+import org.apache.xmlbeans.impl.jam.provider.JamLogger;
+
+/**
+ * <p>Implementation of JElement and MElement.</p>
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public abstract class ElementImpl implements Comparable, MElement {
+
+  // ========================================================================
+  // Constants
+
+  // help reduce waste
+  public static final ElementImpl[] NO_NODE = new ElementImpl[0];
+  public static final ClassImpl[] NO_CLASS = new ClassImpl[0];
+  public static final FieldImpl[] NO_FIELD = new FieldImpl[0];
+  public static final ConstructorImpl[] NO_CONSTRUCTOR = new ConstructorImpl[0];
+  public static final MethodImpl[] NO_METHOD = new MethodImpl[0];
+  public static final ParameterImpl[] NO_PARAMETER = new ParameterImpl[0];
+  public static final JPackage[] NO_PACKAGE = new JPackage[0];//FIXME
+  public static final AnnotationImpl[] NO_ANNOTATION = new AnnotationImpl[0];
+
+  public static final CommentImpl[] NO_COMMENT = new CommentImpl[0];
+  public static final JProperty[] NO_PROPERTY = new JProperty[0];//FIXME
+
+  // ========================================================================
+  // Variables
+
+  private ElementContext mContext;
+  protected String mSimpleName;
+  private MSourcePosition mPosition = null;
+  private Object mArtifact = null;
+  private ElementImpl mParent;
+
+  // ========================================================================
+  // Constructors
+
+  protected ElementImpl(ElementImpl parent) {
+    if (parent == null) throw new IllegalArgumentException("null ctx");
+    if (parent == this) {
+      throw new IllegalArgumentException("An element cannot be its own parent");
+    }
+    JElement check = parent.getParent();
+    while(check != null) {
+      if (check == this) throw new IllegalArgumentException("cycle detected");
+      check = check.getParent();
+    };
+    mContext = parent.getContext();
+    mParent = parent;
+  }
+
+  protected ElementImpl(ElementContext ctx) {
+    if (ctx == null) throw new IllegalArgumentException("null ctx");
+    mContext = ctx;
+  }
+
+  // ========================================================================
+  // JElement implementation
+
+  public final JElement getParent() { return mParent; }
+
+  public String getSimpleName() { return mSimpleName; }
+
+  public JSourcePosition getSourcePosition() { return mPosition; }
+
+  public Object getArtifact() { return mArtifact; }
+
+  // ========================================================================
+  // MElement implementation
+
+  public void setSimpleName(String name) {
+    if (name == null) throw new IllegalArgumentException("null name");
+    mSimpleName = name.trim();
+  }
+
+  public MSourcePosition createSourcePosition() {
+    return mPosition = new SourcePositionImpl();
+  }
+
+  public void removeSourcePosition() {
+    mPosition = null;
+  }
+
+  public MSourcePosition getMutableSourcePosition() {
+    return mPosition;
+  }
+
+  public void setArtifact(Object artifact) {
+    if (artifact == null) {
+      //throw new IllegalArgumentException("null artifact");
+      //fixme there are some extensions that are passing null
+      //getLogger().warning(new IllegalArgumentException("null artifact"));
+    }
+    if (mArtifact != null) {
+      throw new IllegalStateException("artifact already set");
+    }
+    mArtifact = artifact;
+  }
+
+  // ========================================================================
+  // Public methods & JClass elements
+
+  public JamClassLoader getClassLoader() {
+    return mContext.getClassLoader();
+  }
+
+  public static String defaultName(int count) {
+    return "unnamed_"+count;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof ElementImpl)) return false;
+    final ElementImpl eElement = (ElementImpl) o;
+    String qn = getQualifiedName();
+    if (qn == null) return false;
+    String oqn = eElement.getQualifiedName();
+    if (oqn == null) return false;
+    return qn.equals(oqn);
+  }
+
+  public int hashCode() {
+    String qn = getQualifiedName();
+    return (qn == null) ? 0 : qn.hashCode();
+  }
+
+  // ========================================================================
+  // Other public methods
+
+  public ElementContext getContext() { return mContext; }
+
+  // ========================================================================
+  // Object implementation
+
+  public String toString() {
+    return getQualifiedName();
+  }
+  
+  // ========================================================================
+  // Protected methods
+
+  protected JamLogger getLogger() {
+    return ((JamServiceContextImpl)mContext).getLogger();
+  }
+
+  // ========================================================================
+  // Comparable implementation
+
+  public int compareTo(Object o) {
+    if (!(o instanceof JElement)) {
+      return -1;
+    }
+    return getQualifiedName().compareTo(((JElement)o).getQualifiedName());
+  }
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/FieldImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/FieldImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/FieldImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/FieldImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,119 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.DirectJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MField;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+import java.io.StringWriter;
+import java.lang.reflect.Modifier;
+
+/**
+ * <p>Implementation of JField and MField.</p>
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public final class FieldImpl extends MemberImpl implements MField {
+
+  // ========================================================================
+  // Variables
+
+  private JClassRef mTypeClassRef;
+
+  // ========================================================================
+  // Constructors
+
+  /*package*/ FieldImpl(String simpleName,
+                         ClassImpl containingClass,
+                         String qualifiedTypeClassName) {
+    super(containingClass);
+    super.setSimpleName(simpleName);
+    mTypeClassRef = QualifiedJClassRef.create
+            (qualifiedTypeClassName,containingClass);
+  }
+
+  // ========================================================================
+  // MField implementation
+
+  public void setType(JClass type) {
+    if (type == null) throw new IllegalArgumentException("null type");
+    mTypeClassRef = DirectJClassRef.create(type);
+  }
+
+  public void setType(String qcname) {
+    if (qcname == null) throw new IllegalArgumentException("null qcname");
+    mTypeClassRef = QualifiedJClassRef.create
+            (qcname,(ClassImpl)getContainingClass());
+  }
+
+  public void setUnqualifiedType(String ucname) {
+    if (ucname == null) throw new IllegalArgumentException("null ucname");
+    mTypeClassRef = UnqualifiedJClassRef.create
+            (ucname,(ClassImpl)getContainingClass());
+  }
+
+  // ========================================================================
+  // JField implementation
+
+  public JClass getType() {
+    if (mTypeClassRef == null) throw new IllegalStateException();
+    return mTypeClassRef.getRefClass();
+  }
+
+  public boolean isFinal() {
+    return Modifier.isFinal(getModifiers());
+  }
+
+  public boolean isStatic() {
+    return Modifier.isStatic(getModifiers());
+  }
+
+  public boolean isVolatile() {
+    return Modifier.isVolatile(getModifiers());
+  }
+
+  public boolean isTransient() {
+    return Modifier.isTransient(getModifiers());
+  }
+
+  // ========================================================================
+  // M/JElement implementation
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public String getQualifiedName() {
+    StringWriter sbuf = new StringWriter();
+    sbuf.write(Modifier.toString(getModifiers()));
+    sbuf.write(' ');
+    sbuf.write(getType().getQualifiedName());
+    sbuf.write(' ');
+    sbuf.write(getContainingClass().getQualifiedName());
+    sbuf.write('.');
+    sbuf.write(getSimpleName());
+    return sbuf.toString();
+  }
+
+
+
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/InvokableImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/InvokableImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/InvokableImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/InvokableImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,160 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JParameter;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.DirectJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
+import org.apache.xmlbeans.impl.jam.mutable.MParameter;
+
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public abstract class InvokableImpl extends MemberImpl implements MInvokable {
+
+  // ========================================================================
+  // Variables
+
+  private List mExceptionClassRefs = null;
+  private List mParameters = null;
+
+  // ========================================================================
+  // Constructors
+
+  protected InvokableImpl(ClassImpl containingClass) {
+    super(containingClass);
+  }
+
+  // ========================================================================
+  // MConstructor implementation
+
+  public void addException(JClass exceptionClass) {
+    if (exceptionClass == null) {
+      throw new IllegalArgumentException("null exception class");
+    }
+    if (mExceptionClassRefs == null) mExceptionClassRefs = new ArrayList();
+    mExceptionClassRefs.add(DirectJClassRef.create(exceptionClass));
+  }
+
+  public void addException(String qcname) {
+    if (qcname == null) throw new IllegalArgumentException("null qcname");
+    if (mExceptionClassRefs == null) mExceptionClassRefs = new ArrayList();
+    mExceptionClassRefs.add(QualifiedJClassRef.
+                            create(qcname,(ClassImpl)getContainingClass()));
+  }
+
+  public void addUnqualifiedException(String ucname) {
+    if (ucname == null) throw new IllegalArgumentException("null qcname");
+    if (mExceptionClassRefs == null) mExceptionClassRefs = new ArrayList();
+    mExceptionClassRefs.add(UnqualifiedJClassRef.
+                            create(ucname,(ClassImpl)getContainingClass()));
+  }
+
+  public void removeException(String exceptionClassName) {
+    if (exceptionClassName == null) {
+      throw new IllegalArgumentException("null classname");
+    }
+    if (mExceptionClassRefs != null) {
+      mExceptionClassRefs.remove(exceptionClassName);
+    }
+  }
+
+  public void removeException(JClass exceptionClass) {
+    removeException(exceptionClass.getQualifiedName());
+  }
+
+  public MParameter addNewParameter() {
+    if (mParameters == null) mParameters = new ArrayList();
+    MParameter param = new ParameterImpl(defaultName(mParameters.size()),
+                                          this,"java.lang.Object");
+    mParameters.add(param);
+    return param;
+  }
+
+  public void removeParameter(MParameter parameter) {
+    if (mParameters != null) mParameters.remove(parameter);
+  }
+
+  public MParameter[] getMutableParameters() {
+    if (mParameters == null || mParameters.size() == 0) {
+    return new MParameter[0];
+    } else {
+      MParameter[] out = new MParameter[mParameters.size()];
+      mParameters.toArray(out);
+      return out;
+    }
+  }
+
+  // ========================================================================
+  // JInvokable implementation
+
+  public JParameter[] getParameters() {
+    return getMutableParameters();
+  }
+
+  public JClass[] getExceptionTypes() {
+    if (mExceptionClassRefs == null || mExceptionClassRefs.size() == 0) {
+      return new JClass[0];
+    }
+    JClass[] out = new JClass[mExceptionClassRefs.size()];
+    for(int i=0; i<out.length; i++) {
+      out[i] = ((JClassRef)mExceptionClassRefs.get(i)).getRefClass();
+    }
+    return out;
+  }
+
+  public String getQualifiedName() {
+    //REVIEW this probably needs more thought
+    StringWriter out = new StringWriter();
+    out.write(getContainingClass().getQualifiedName());
+    out.write('.');
+    out.write(getSimpleName());
+    out.write('(');
+    JParameter[] params = getParameters();
+    for(int i=0; i<params.length; i++) {
+      out.write(params[i].getType().getQualifiedName());
+      if (i<params.length-1) out.write(", ");
+    }
+    out.write(')');
+    return out.toString();
+  }
+
+  // ========================================================================
+  // Other public methods
+
+  //FIXME this is here only so the parser can be lazy - please remove it
+  public void setUnqualifiedThrows(List classnames) {
+    if (classnames == null || classnames.size() == 0) {
+      mExceptionClassRefs= null;
+      return;
+    }
+    mExceptionClassRefs = new ArrayList(classnames.size());
+    for(int i=0; i<classnames.size(); i++) {
+      mExceptionClassRefs.add(UnqualifiedJClassRef.create
+                              ((String)classnames.get(i),
+                               (ClassImpl)getContainingClass()));
+    }
+  }
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MemberImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MemberImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MemberImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MemberImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,76 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JElement;
+import org.apache.xmlbeans.impl.jam.JMember;
+import org.apache.xmlbeans.impl.jam.mutable.MMember;
+
+import java.lang.reflect.Modifier;
+
+/**
+ * <p>Implementation of JMember and EMenber.</p>
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public abstract class MemberImpl extends AnnotatedElementImpl implements MMember {
+
+  // ========================================================================
+  // Variables
+
+  private int mModifiers = 0;
+
+  // ========================================================================
+  // Constructors
+
+  protected MemberImpl(ElementImpl parent) {
+    super(parent);
+  }
+
+  protected MemberImpl(ElementContext ctx) {
+    super(ctx);
+  }
+
+  // ========================================================================
+  // JMember implementation
+
+  public JClass getContainingClass() {
+    JElement p = getParent();
+    //FIXME very gross
+    if (p instanceof JClass) return (JClass)p;
+    if (p instanceof JMember) return ((JMember)p).getContainingClass();
+    return null;
+  }
+
+  public int getModifiers() { return mModifiers; }
+
+  public boolean isPackagePrivate() {
+    return !isPrivate() && !isPublic() && !isProtected();
+  }
+
+  public boolean isPrivate() { return Modifier.isPrivate(getModifiers()); }
+
+  public boolean isProtected() { return Modifier.isProtected(getModifiers()); }
+
+  public boolean isPublic() { return Modifier.isPublic(getModifiers()); }
+
+  // ========================================================================
+  // MMember implementation
+
+  public void setModifiers(int modifiers) { mModifiers = modifiers; }
+
+}
\ No newline at end of file

Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MethodImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MethodImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MethodImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/MethodImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,146 @@
+/*   Copyright 2004 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.xmlbeans.impl.jam.internal.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JParameter;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.DirectJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+import java.io.StringWriter;
+import java.lang.reflect.Modifier;
+
+
+
+/**
+ * <p>Standard implementation of MMethod.  It's probably bad inheritance to
+ * extend ConstructorImpl, but it's convenient and no one should ever care
+ * since this is a private class; there is no inheritance between method and
+ * constructor in the public API.</p>
+ *
+ * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
+ */
+public final class MethodImpl extends InvokableImpl implements MMethod {
+
+  // ========================================================================
+  // Variables
+
+  private JClassRef mReturnTypeRef = null;
+
+  // ========================================================================
+  // Constructors
+
+  /*package*/ MethodImpl(String simpleName, ClassImpl containingClass) {
+    super(containingClass);
+    setSimpleName(simpleName);
+  }
+
+  // ========================================================================
+  // MMethod implementation
+
+  public void setReturnType(String className) {
+    mReturnTypeRef = QualifiedJClassRef.create
+            (className,(ClassImpl)getContainingClass());
+  }
+
+  public void setUnqualifiedReturnType(String unqualifiedTypeName) {
+    mReturnTypeRef = UnqualifiedJClassRef.create
+            (unqualifiedTypeName,(ClassImpl)getContainingClass());
+  }
+
+  public void setReturnType(JClass c) {
+    mReturnTypeRef = DirectJClassRef.create(c);
+  }
+
+  // ========================================================================
+  // JMethod implementation
+
+  public JClass getReturnType() {
+    if (mReturnTypeRef == null) {
+      return getClassLoader().loadClass("void");
+    } else {
+      return mReturnTypeRef.getRefClass();
+    }
+  }
+
+  public boolean isFinal() {
+    return Modifier.isFinal(getModifiers());
+  }
+
+  public boolean isStatic() {
+    return Modifier.isStatic(getModifiers());
+  }
+
+  public boolean isAbstract() {
+    return Modifier.isAbstract(getModifiers());
+  }
+
+  public boolean isNative() {
+    return Modifier.isNative(getModifiers());
+  }
+
+  public boolean isSynchronized() {
+    return Modifier.isSynchronized(getModifiers());
+  }
+
+  // ========================================================================
+  // Element implementation
+
+  public void accept(MVisitor visitor) { visitor.visit(this); }
+
+  public void accept(JVisitor visitor) { visitor.visit(this); }
+
+  public String getQualifiedName() {
+    StringWriter sbuf = new StringWriter();
+    sbuf.write(Modifier.toString(getModifiers()));
+    sbuf.write(' ');
+    JClass returnJClass = getReturnType();
+    if (returnJClass == null){
+      sbuf.write("void ");  // should not happen
+    } else {
+      sbuf.write(returnJClass.getQualifiedName());
+      sbuf.write(' ');
+    }
+    sbuf.write(getSimpleName());
+    sbuf.write('(');
+    {
+    JParameter[] params = getParameters();
+    if (params != null && params.length > 0) {
+      for(int i=0; i<params.length; i++) {
+        sbuf.write(params[i].getType().getQualifiedName());
+        if (i<params.length-1) sbuf.write(',');
+      }
+    }
+    }
+    sbuf.write(')');
+    {
+      JClass[] thrown = getExceptionTypes();
+      if (thrown != null && thrown.length > 0) {
+        sbuf.write(" throws ");
+        for(int i=0; i<thrown.length; i++) {
+          sbuf.write(thrown[i].getQualifiedName());
+          if (i<thrown.length-1) sbuf.write(',');
+        }
+      }
+    }
+    return sbuf.toString();
+  }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message