xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/jam/test build.xml
Date Mon, 10 May 2004 22:54:03 GMT
pcal        2004/05/10 15:54:02

  Modified:    v2/jam/src/org/apache/xmlbeans/impl/jam/internal
                        JamClassLoaderImpl.java JamServiceImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements
                        ClassImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect
                        ReflectClassBuilder.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/provider
                        JamClassBuilder.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/xml
                        JamXmlReader.java
               v2/jam/test build.xml
  Log:
  catch/swallow for jdk bug in Class.getFields()
  add lazy population to ClassImpl
  
  Revision  Changes    Path
  1.12      +20 -22    xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamClassLoaderImpl.java
  
  Index: JamClassLoaderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamClassLoaderImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JamClassLoaderImpl.java	12 Apr 2004 22:01:27 -0000	1.11
  +++ JamClassLoaderImpl.java	10 May 2004 22:54:02 -0000	1.12
  @@ -91,28 +91,7 @@
         return out;
       }
       cachePut(out);
  -    ((ClassImpl)out).setState(ClassImpl.POPULATING);
  -    mBuilder.populate(out);
  -    if (mInitializer == null) {
  -      ((ClassImpl)out).setState(ClassImpl.LOADED);
  -    } else {
  -      ((ClassImpl)out).setState(ClassImpl.INITIALIZING);
  -      // see comments below about this.  we need to document this more openly,
  -      // since it affects people writing initializers.
  -      if (mAlreadyInitializing) {
  -        // we already are running initializers, so we have to do it later
  -        mInitializeStack.push(out);
  -      } else {
  -        out.accept(mInitializer);
  -        ((ClassImpl)out).setState(ClassImpl.LOADED);
  -        while(!mInitializeStack.isEmpty()) {
  -          ClassImpl initme = (ClassImpl)mInitializeStack.pop();
  -          initme.accept(mInitializer);
  -          ((ClassImpl)out).setState(ClassImpl.LOADED);
  -        }
  -        mAlreadyInitializing = false;
  -      }
  -    }
  +    ((ClassImpl)out).setState(ClassImpl.UNPOPULATED);
       return out;
     }
   
  @@ -159,6 +138,25 @@
   
     // ========================================================================
     // Public methods?
  +
  +  //should only be called by ClassImpl
  +  public void initialize(ClassImpl out) {
  +    if (mInitializer != null) {
  +      // see comments below about this.  we need to document this more openly,
  +      // since it affects people writing initializers.
  +      if (mAlreadyInitializing) {
  +        // we already are running initializers, so we have to do this one later
  +        mInitializeStack.push(out);
  +      } else {
  +        out.accept(mInitializer);
  +        while(!mInitializeStack.isEmpty()) {
  +          ClassImpl initme = (ClassImpl)mInitializeStack.pop();
  +          initme.accept(mInitializer);
  +        }
  +        mAlreadyInitializing = false;
  +      }
  +    }
  +  }
   
     /**
      * Returns an unmodifiable collection containing the JClasses which
  
  
  
  1.5       +1 -12     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceImpl.java
  
  Index: JamServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JamServiceImpl.java	26 Mar 2004 00:15:39 -0000	1.4
  +++ JamServiceImpl.java	10 May 2004 22:54:02 -0000	1.5
  @@ -70,18 +70,7 @@
     }
   
     // ========================================================================
  -  // Public methods - somexday we need to clean up the way this is exposed.
  -  // at the moment, we just cast down to this elements class to get at
  -  // these methods
  -
  -  public MClass addNewClass(String packageName,
  -                            String className,
  -                            String[] importSpecs)
  -  {
  -    ClassImpl out = new ClassImpl(packageName,className,mContext,importSpecs);
  -    ((JamClassLoaderImpl)getClassLoader()).addToCache(out);//FIXME yuck, please sort this
out
  -    return out;
  -  }
  +  // Hackish methods
   
     // this is a back door for jamxmlutils, which can't know the class names
     // until after it's parsed the xml file (which can't be done without
  
  
  
  1.13      +111 -15   xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java
  
  Index: ClassImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ClassImpl.java	15 Apr 2004 01:50:06 -0000	1.12
  +++ ClassImpl.java	10 May 2004 22:54:02 -0000	1.13
  @@ -16,6 +16,7 @@
   package org.apache.xmlbeans.impl.jam.internal.elements;
   
   import org.apache.xmlbeans.impl.jam.*;
  +import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
   import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
   import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
   import org.apache.xmlbeans.impl.jam.mutable.*;
  @@ -23,6 +24,7 @@
   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.internal.JamClassLoaderImpl;
   
   import java.lang.reflect.Modifier;
   import java.util.ArrayList;
  @@ -40,12 +42,11 @@
     // ========================================================================
     // Constants
   
  -  public static final int NEW = 0;
  -  public static final int BUILDING = 1;
  -  public static final int POPULATING = 2;
  -  public static final int INITIALIZING = 3;
  -  public static final int LOADED = 4;
  -  //public static final int UNRESOLVED = 4;
  +  public static final int NEW = 1;
  +  public static final int UNPOPULATED = 2;
  +  public static final int POPULATING = 3;
  +  public static final int INITIALIZING = 4;
  +  public static final int LOADED = 5;
   
     // ========================================================================
     // Variables
  @@ -69,6 +70,8 @@
   
     private String[] mImports = null;
   
  +  private JamClassBuilder 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;
  @@ -79,11 +82,13 @@
     public ClassImpl(String packageName,
                      String simpleName,
                      ElementContext ctx,
  -                   String[] importSpecs) {
  +                   String[] importSpecs,
  +                   JamClassBuilder populator) {
       super(ctx);
       super.setSimpleName(simpleName);
       mPackageName = packageName.trim();
       mImports = importSpecs;
  +    mPopulator = populator;
     }
   
     // ========================================================================
  @@ -94,6 +99,7 @@
     }
   
     public JClass getSuperclass() {
  +    ensurePopulated();
       if (mSuperClassRef == null) {
         return null;
       } else {
  @@ -102,6 +108,7 @@
     }
   
     public JClass[] getInterfaces() {
  +    ensurePopulated();
       if (mInterfaceRefs == null || mInterfaceRefs.size() == 0) {
         return new JClass[0];
       } else {
  @@ -114,6 +121,7 @@
     }
   
     public JField[] getFields() {
  +    ensurePopulated();
       List list = new ArrayList();
       addFieldsRecursively(this, list);
       JField[] out = new JField[list.size()];
  @@ -122,10 +130,12 @@
     }
   
     public JField[] getDeclaredFields() {
  +    ensurePopulated();
       return getMutableFields();
     }
   
     public JMethod[] getMethods() {
  +    ensurePopulated();
       List list = new ArrayList();
       addMethodsRecursively(this, list);
       JMethod[] out = new JMethod[list.size()];
  @@ -134,6 +144,7 @@
     }
   
     public JProperty[] getProperties() {
  +    ensurePopulated();
       if (mProperties == null) return new JProperty[0];
       JProperty[] out = new JProperty[mProperties.size()];
       mProperties.toArray(out);
  @@ -141,21 +152,42 @@
     }
   
     public JProperty[] getDeclaredProperties() {
  +    ensurePopulated();
       if (mDeclaredProperties == null) return new JProperty[0];
       JProperty[] out = new JProperty[mDeclaredProperties.size()];
       mDeclaredProperties.toArray(out);
       return out;
     }
   
  -  public JMethod[] getDeclaredMethods() { return getMutableMethods(); }
  +  public JMethod[] getDeclaredMethods() {
  +    ensurePopulated();
  +    return getMutableMethods();
  +  }
   
  -  public JConstructor[] getConstructors() { return getMutableConstructors(); }
  +  public JConstructor[] getConstructors() {
  +    ensurePopulated();
  +    return getMutableConstructors();
  +  }
  +
  +  public boolean isInterface() {
  +    ensurePopulated();
  +    return mIsInterface;
  +  }
   
  -  public boolean isInterface() { return mIsInterface; }
  +  public boolean isAnnotationType() {
  +    ensurePopulated();
  +    return mIsAnnotationType;
  +  }
   
  -  public boolean isAnnotationType() { return mIsAnnotationType; }
  +  public boolean isEnumType() {
  +    ensurePopulated();
  +    return mIsEnum;
  +  }
   
  -  public boolean isEnumType() { return mIsEnum; }
  +  public int getModifiers() {
  +    ensurePopulated();
  +    return super.getModifiers();
  +  }
   
     public boolean isFinal() { return Modifier.isFinal(getModifiers()); }
   
  @@ -164,6 +196,7 @@
     public boolean isAbstract() { return Modifier.isAbstract(getModifiers()); }
   
     public boolean isAssignableFrom(JClass arg) {
  +    ensurePopulated();
       if (isPrimitiveType() || arg.isPrimitiveType()) {
         return getQualifiedName().equals(arg.getQualifiedName());
       }
  @@ -171,6 +204,7 @@
     }
   
     public JClass[] getClasses() {
  +    ensurePopulated();
       return new JClass[0];//FIXME
     }
   
  @@ -183,10 +217,12 @@
     }
   
     public JPackage[] getImportedPackages() {
  +    ensurePopulated();
       return new JPackage[0];//FIXME
     }
   
     public JClass[] getImportedClasses() {
  +    ensurePopulated();
   //    if (true) throw new IllegalStateException();
       String[] imports = getImportSpecs();
       if (imports == null) return new JClass[0];
  @@ -222,8 +258,58 @@
     public int getArrayDimensions() { return 0; }
   
     // ========================================================================
  +  // AnnotatedElementImpl implementation - just to add ensureLoaded()
  +
  +  public JAnnotation[] getAnnotations() {
  +    ensurePopulated();
  +    return super.getAnnotations();
  +  }
  +
  +  public JAnnotation getAnnotation(Class proxyClass) {
  +    ensurePopulated();
  +    return super.getAnnotation(proxyClass);
  +  }
  +
  +  public JAnnotation getAnnotation(String named) {
  +    ensurePopulated();
  +    return super.getAnnotation(named);
  +  }
  +
  +  public JAnnotationValue getAnnotationValue(String valueId) {
  +    ensurePopulated();
  +    return super.getAnnotationValue(valueId);
  +  }
  +
  +
  +  public Object getAnnotationProxy(Class proxyClass) {
  +    ensurePopulated();
  +    return super.getAnnotationProxy(proxyClass);
  +  }
  +
  +  public JComment getComment() {
  +    ensurePopulated();
  +    return super.getComment();
  +  }
  +
  +  public JAnnotation[] getAllJavadocTags() {
  +    ensurePopulated();
  +    return super.getAllJavadocTags();
  +  }
  +
  +  // ========================================================================
  +  // Element implementation - just to add ensureLoaded()
  +
  +  public JSourcePosition getSourcePosition() {
  +    ensurePopulated();
  +    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;
  @@ -397,6 +483,7 @@
     }
   
     public String[] getImportSpecs() {
  +    ensurePopulated();
       if (mImports == null) return new String[0];
       return mImports;
     }
  @@ -406,9 +493,7 @@
   
     public void setState(int state) { mState = state; }
   
  -
  -
  -
  +  public void setPopulator(JamClassBuilder builder) { mPopulator = builder; }
   
     // ========================================================================
     // Public static utility methods
  @@ -487,6 +572,17 @@
       }
       clazz = clazz.getSuperclass();
       if (clazz != null) addMethodsRecursively(clazz, out);
  +  }
  +
  +  private void ensurePopulated() {
  +    if (mState == UNPOPULATED) {
  +      if (mPopulator == null) throw new IllegalStateException("null populator");
  +      setState(POPULATING);
  +      mPopulator.populate(this);
  +      setState(INITIALIZING);
  +      ((JamClassLoaderImpl)getClassLoader()).initialize(this);
  +      setState(ClassImpl.LOADED);
  +    }
     }
   
   }
  
  
  
  1.10      +9 -2      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java
  
  Index: ReflectClassBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ReflectClassBuilder.java	7 Apr 2004 04:18:09 -0000	1.9
  +++ ReflectClassBuilder.java	10 May 2004 22:54:02 -0000	1.10
  @@ -125,8 +125,15 @@
       Class[] ints = src.getInterfaces();
       for(int i=0; i<ints.length; i++) dest.addInterface(ints[i].getName());
       // add the fields
  -    Field[] fields = src.getFields();
  -    for(int i=0; i<fields.length; i++) populate(dest.addNewField(),fields[i]);
  +    Field[] fields = null;
  +    try {
  +      fields = src.getFields();
  +    } catch(Exception ignore) {
  +      //FIXME there seems to be some JDK bugs here, workaround for now 180996
  +    }
  +    if (fields != null) {
  +      for(int i=0; i<fields.length; i++) populate(dest.addNewField(),fields[i]);
  +    }
       // add the methods
       Method[] methods = src.getDeclaredMethods();
       for(int i=0; i<methods.length; i++) populate(dest.addNewMethod(),methods[i]);
  
  
  
  1.8       +17 -9     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamClassBuilder.java
  
  Index: JamClassBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamClassBuilder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JamClassBuilder.java	2 Apr 2004 02:41:07 -0000	1.7
  +++ JamClassBuilder.java	10 May 2004 22:54:02 -0000	1.8
  @@ -50,8 +50,7 @@
     /**
      * <p>When a JamClassBuilder decides that it is going to be able
      * to respond to a build() request, it must call this method to get an
  -   * initial instance of MClass.  It should then initialize the MClass
  -   * as appropriate and then return it.</p>
  +   * initial instance of MClass to return.</p>
      *
      * @param packageName qualified name of the package that contains the
      * class to create
  @@ -69,8 +68,7 @@
       if (packageName == null) throw new IllegalArgumentException("null pkg");
       if (className == null) throw new IllegalArgumentException("null class");
       className = className.replace('.','$');
  -    ClassImpl out = new ClassImpl(packageName,className,mContext,importSpecs);
  -    out.setState(ClassImpl.BUILDING);
  +    ClassImpl out = new ClassImpl(packageName,className,mContext,importSpecs,this);
       return out;
     }
   
  @@ -85,12 +83,14 @@
     /**
      * <p>This is called by JAM when it attempts to load a class.  If the
      * builder has access to an artifact (typically a java source or classfile)
  -   * that represents the given type, it should call createClass() to get
  -   * a new instance of MClass, populate that instance, and then return it.
  -   * It should not perform any caching - if an MClass is going to be returned,
  -   * it should be a new instance.</p>
  +   * that represents the given type, it should call createClassToBuild() to get
  +   * a new instance of MClass and then return it.  It should not populate
  +   * the class in any way (e.g. add methods and fields to it) - this must
  +   * be done later when the JamClassLoader calls populate().  Nor should
  +   * any caching be performed - if an MClass is going to be returned,
  +   * it should be a new instance returned by createClassToBuild()</p>
      *
  -   * <p>If not artififact is available, the builder should just return null,
  +   * <p>If no artififact is available, the builder should just return null,
      * signalling that other JamClassBuilders should attempt to build the
      * class.</p>
      *
  @@ -100,5 +100,13 @@
      */ 
     public abstract MClass build(String packageName, String className);
   
  +  /**
  +   * <p>Called by JAM to 'fill out' an instance of a given MClass with
  +   * things like methods and fields.  The implementing builder is responsible
  +   * for inspecting the source artificat (typically a source or class file)
  +   * to call the appropriate createX methods on the given MClass.</p>
  +   *
  +   * @param c
  +   */
     public abstract void populate(MClass c);
   }
  
  
  
  1.4       +2 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/xml/JamXmlReader.java
  
  Index: JamXmlReader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/xml/JamXmlReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JamXmlReader.java	3 Apr 2004 01:21:29 -0000	1.3
  +++ JamXmlReader.java	10 May 2004 22:54:02 -0000	1.4
  @@ -16,6 +16,7 @@
   
   import org.apache.xmlbeans.impl.jam.internal.CachedClassBuilder;
   import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
  +import org.apache.xmlbeans.impl.jam.internal.elements.ClassImpl;
   import org.apache.xmlbeans.impl.jam.mutable.MClass;
   import org.apache.xmlbeans.impl.jam.mutable.MField;
   import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
  @@ -117,6 +118,7 @@
       while(METHOD.equals(getElementName())) readMethod(clazz);
       readAnnotatedElement(clazz);
       assertEnd(CLASS);
  +    ((ClassImpl)clazz).setState(ClassImpl.LOADED);
       nextElement();
     }
   
  
  
  
  1.11      +8 -0      xml-xmlbeans/v2/jam/test/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/test/build.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- build.xml	3 Apr 2004 01:21:29 -0000	1.10
  +++ build.xml	10 May 2004 22:54:02 -0000	1.11
  @@ -1,3 +1,9 @@
  +<!-- NOTE: if you get errors about not being able to load the junit
  +     task, try copying ../external/lib/junit.jar into your ant/lib 
  +     directory.  This seems to be an ant or JDK 1.5 bug, not sure which.
  +-->
  +
  +
   <project name='jam.tests' basedir='.' default='clean_all_test'>
   
   <!-- Build file to build and run JAM tests -->
  @@ -13,6 +19,7 @@
     <property name='jsr173ri_jar' value='../../build/lib/jsr173_ri.jar'/>
     <property name='tidy_jar' value='../external/lib/tidy.jar'/>
   
  +
     <path id='classpath' >
   
    <!-- use build/classes instead of xbean.jar for develpment convenience -->
  @@ -27,6 +34,7 @@
       <pathelement location='${jsr173ri_jar}' />
   
     </path>
  +
   
     <property name='classpath-value' refid='classpath'/>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message