xml-xmlbeans-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar BaseTylarImpl.java Tylar.java
Date Sat, 20 Mar 2004 21:51:34 GMT
pcal        2004/03/20 13:51:34

  Modified:    v2/jam/src/org/apache/xmlbeans/impl/jam
                        JamServiceParams.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/annotation
                        AnnotationProxy.java DefaultAnnotationProxy.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements
                        AnnotatedElementImpl.java AnnotationValueImpl.java
                        PropertyImpl.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/bts
                        JavaTypeName.java MethodName.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompiler.java Both2Bind.java
                        Java2Schema.java Java2SchemaTask.java
                        TypeMatcherContext.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/logger
                        BindingLogger.java Message.java MessageImpl.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        BaseTylarImpl.java Tylar.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Java2Schema_new.java
  Log:
  add annotation for issetters, move java2schema onto new jam
  
  Revision  Changes    Path
  1.8       +0 -2      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamServiceParams.java
  
  Index: JamServiceParams.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamServiceParams.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JamServiceParams.java	20 Mar 2004 20:10:45 -0000	1.7
  +++ JamServiceParams.java	20 Mar 2004 21:51:34 -0000	1.8
  @@ -345,6 +345,4 @@
      */
     public void setVerbose(boolean v);
   
  -
  -
   }
  
  
  
  1.6       +3 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/AnnotationProxy.java
  
  Index: AnnotationProxy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/AnnotationProxy.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AnnotationProxy.java	20 Mar 2004 20:10:45 -0000	1.5
  +++ AnnotationProxy.java	20 Mar 2004 21:51:34 -0000	1.6
  @@ -100,8 +100,11 @@
     //docme
     public JAnnotationValue getValue(String named) {
       if (named == null) throw new IllegalArgumentException("null name");
  +    //FIXME this impl is very gross
  +    named = named.trim();
       JAnnotationValue[] values = getValues();
       for(int i=0; i<values.length; i++) {
  +      
         if (named.equals(values[i].getName())) return values[i];
       }
       return null;
  
  
  
  1.4       +2 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/DefaultAnnotationProxy.java
  
  Index: DefaultAnnotationProxy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/annotation/DefaultAnnotationProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultAnnotationProxy.java	10 Mar 2004 19:43:48 -0000	1.3
  +++ DefaultAnnotationProxy.java	20 Mar 2004 21:51:34 -0000	1.4
  @@ -60,6 +60,8 @@
      * find a bunch of setters that we don't have.</p>
      */
     public void setValue(String name, Object value) {
  +    if (name == null) throw new IllegalArgumentException("null name");
  +    name = name.trim();
       mValues.add(new AnnotationValueImpl((ElementContext)getLogger(),//yikes, nasty.  FIXME
                                           name,value));
     }
  
  
  
  1.11      +6 -1      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotatedElementImpl.java
  
  Index: AnnotatedElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotatedElementImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AnnotatedElementImpl.java	20 Mar 2004 20:10:45 -0000	1.10
  +++ AnnotatedElementImpl.java	20 Mar 2004 21:51:34 -0000	1.11
  @@ -118,6 +118,7 @@
   
     public MAnnotation getMutableAnnotation(String named) {
       if (mName2Annotation == null) return null;
  +    named = named.trim();
       return (MAnnotation)mName2Annotation.get(named);
     }
   
  @@ -127,6 +128,8 @@
     }
   
     public MAnnotation addAnnotationForTag(String tagName) {
  +    if (tagName == null) throw new IllegalArgumentException("null tagname");
  +    tagName = tagName.trim();
       {
         // looks like we need to maintain a full list no matter what
         AnnotationProxy proxy = getContext().createProxyForTag(tagName);
  @@ -146,6 +149,8 @@
     }
   
     public MAnnotation addAnnotationForTag(String tagName, String tagContents) {
  +    if (tagName == null) throw new IllegalArgumentException("null tagname");
  +    tagName = tagName.trim();
       {
         // looks like we need to maintain a full list no matter what
         AnnotationProxy proxy = getContext().createProxyForTag(tagName);
  @@ -173,7 +178,7 @@
       if (jsr175annotationInstance == null) {
         throw new IllegalArgumentException("null instance");
       }
  -    String typename = getAnnotationTypeFor(jsr175annotationInstance);
  +    String typename = getAnnotationTypeFor(jsr175annotationInstance); //FIXME this isn't working right
       MAnnotation ann = getMutableAnnotation(typename);
       if (ann != null) {
         ann.setAnnotationInstance(jsr175annotationInstance);
  
  
  
  1.2       +4 -4      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java
  
  Index: AnnotationValueImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnnotationValueImpl.java	10 Mar 2004 11:42:08 -0000	1.1
  +++ AnnotationValueImpl.java	20 Mar 2004 21:51:34 -0000	1.2
  @@ -37,13 +37,13 @@
     // Constructors
   
     public AnnotationValueImpl(ElementContext ctx,
  -                              String simpleName,
  -                              Object value) {
  +                             String name,
  +                             Object value) {
       if (ctx == null) throw new IllegalArgumentException("null ctx");
  -    if (simpleName == null) throw new IllegalArgumentException("null name");
  +    if (name == null) throw new IllegalArgumentException("null name");
       if (value == null) throw new IllegalArgumentException("null value");
       mContext = ctx;
  -    mName = simpleName;
  +    mName = name;
       mValue = value;
     }
   
  
  
  
  1.4       +5 -7      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java
  
  Index: PropertyImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertyImpl.java	20 Mar 2004 20:10:45 -0000	1.3
  +++ PropertyImpl.java	20 Mar 2004 21:51:34 -0000	1.4
  @@ -23,10 +23,6 @@
   import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
   import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
   
  -import java.util.HashMap;
  -import java.util.Map;
  -import java.lang.reflect.Method;
  -
   /**
    * <p>Implementation of JProperty.</p>
    *
  @@ -141,11 +137,13 @@
      * this property's getter and/or setters.
      */
     public JAnnotation getAnnotation(String named) {
  -    return null;//FIXME
  +    JAnnotation out = (mGetter != null) ? mGetter.getAnnotation(named) : null;
  +    if (out != null) return out;
  +    return (mSetter != null) ? mSetter.getAnnotation(named) : null;
     }
   
     public JComment getComment() {
  -    //FIXME
  +    //REVIEW do we want to somehow merge the comments?
       if (mGetter != null)  return mGetter.getComment();
       if (mSetter != null)  return mSetter.getComment();
       return null;
  @@ -153,7 +151,7 @@
   
     public JSourcePosition getSourcePosition() {
       return mGetter != null ?
  -            mGetter.getSourcePosition() : mSetter.getSourcePosition();
  +      mGetter.getSourcePosition() : mSetter.getSourcePosition();
     }
   
     public void accept(JVisitor visitor) {
  
  
  
  1.11      +78 -62    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JavaTypeName.java
  
  Index: JavaTypeName.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JavaTypeName.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JavaTypeName.java	13 Mar 2004 00:33:21 -0000	1.10
  +++ JavaTypeName.java	20 Mar 2004 21:51:34 -0000	1.11
  @@ -12,19 +12,12 @@
    *   See the License for the specific language governing permissions and
    *  limitations under the License.
    */
  -
   package org.apache.xmlbeans.impl.binding.bts;
   
  -import org.apache.xmlbeans.impl.jam_old.JClass;
  -import org.apache.xmlbeans.impl.jam_old.JServiceFactory;
  -import org.apache.xmlbeans.impl.jam_old.JService;
  -import org.apache.xmlbeans.impl.jam_old.JClassLoader;
  -import org.apache.xmlbeans.impl.jam_old.JServiceParams;
  -import org.apache.xmlbeans.impl.jam_old.internal.PrimitiveJClass;
  +import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlRuntimeException;
   
  -import java.io.StringWriter;
   import java.io.IOException;
   import java.lang.reflect.Array;
   
  @@ -74,26 +67,6 @@
       return new JavaTypeName(className);
     }
   
  -    /**
  -     * Builds a JavaTypeName for a a java type name
  -     * (in the format returned by Class.getName())
  -     */
  -    public static JavaTypeName forClassName(String type)
  -    {
  -        final JServiceFactory jserv_factory = JServiceFactory.getInstance();
  -        final JServiceParams params = jserv_factory.createServiceParams();
  -        final JService service;
  -        try {
  -            service = jserv_factory.createService(params);
  -        }
  -        catch (IOException e) {
  -            throw new XmlRuntimeException(e);
  -        }
  -        final JClassLoader jcl = service.getClassLoader();
  -        final JClass jc = jcl.loadClass(type);
  -        return forJClass(jc);
  -    }
  -
   
     /**
      * Builds a JavaTypeName for the array containing items with
  @@ -107,16 +80,14 @@
       return forString(itemType.toString() + arrayBrackets);
     }
   
  -
  -
     /**
  -   * Builds a JavaTypeName for the given JClass
  +   * Builds a JavaTypeName for the given JClass.
      */
     public static JavaTypeName forJClass(JClass jClass) {
  -    if (jClass.isArray()) {
  -      return forArray(forJClass(jClass.getArrayComponentType()), jClass.getArrayDimensions());
  +    if (jClass.isArrayType()) {
  +      return forArray(forJClass(jClass.getArrayComponentType()),
  +                      jClass.getArrayDimensions());
       }
  -
       JClass[] interfaces = jClass.getInterfaces();
       for (int i = 0; i < interfaces.length; i++) {
         if (interfaces[i].getQualifiedName().equals(XMLOBJECT_CLASSNAME))
  @@ -126,6 +97,9 @@
       return forString(jClass.getQualifiedName());
     }
   
  +
  +
  +
     // ========================================================================
     // Constructors
   
  @@ -159,16 +133,12 @@
     /**
      * True for classnames that are XmlObjects.
      */
  -  public boolean isXmlObject() {
  -    return isXmlObject;
  -  }
  +  public boolean isXmlObject() { return isXmlObject; }
   
     /**
      * Returns the array depth, 0 for non-arrays, 1 for [], 2 for [][], etc.
      */
  -  public int getArrayDepth() {
  -    return arrayString.length() / 2;
  -  }
  +  public int getArrayDepth() { return arrayString.length() / 2; }
   
     /**
      * Returns the array item type (peeling off "n" array indexes)
  @@ -220,20 +190,57 @@
       return className.substring(index + 1);
     }
   
  +
  +  // ========================================================================
  +  // Object implementation
  +
  +  /**
  +   * Returns the fully-qualified class name.
  +   */
  +  public String toString() {
  +    if (isXmlObject)
  +      return "x=" + className + arrayString;
  +    return className + arrayString;
  +  }
  +
  +  public boolean equals(Object o) {
  +    if (this == o) return true;
  +    if (!(o instanceof JavaTypeName)) return false;
  +
  +    final JavaTypeName javaName = (JavaTypeName) o;
  +
  +    if (isXmlObject != javaName.isXmlObject) return false;
  +    if (!className.equals(javaName.className)) return false;
  +    if (!arrayString.equals(javaName.arrayString)) return false;
  +
  +    return true;
  +  }
  +
  +  public int hashCode() {
  +    return className.hashCode() + arrayString.length() + (isXmlObject ? 1 : 0);
  +  }
  +
  +
  +  // ========================================================================
  +  // Deprecated methods
  +
     /**
      * Loads the class represented by this JavaTypeName in the given
      * ClassLoader.  This is really horrible - the impedance mismatch
      * in the naming here is very really painful.  Need to do something better.
      */
  +  /**
  +   * @deprecated
  +   */
     public Class loadClassIn(ClassLoader loader) throws ClassNotFoundException {
       int d = getArrayDepth();
       if (d == 0) {
         String s = toString();
  -      Class out = PrimitiveJClass.getPrimitiveClass(s);
  +      Class out = org.apache.xmlbeans.impl.jam_old.internal.PrimitiveJClass.getPrimitiveClass(s);
         if (out != null) return out;
         return loader.loadClass(s);
       } else {
  -      Class clazz = PrimitiveJClass.getPrimitiveClass(className);
  +      Class clazz = org.apache.xmlbeans.impl.jam_old.internal.PrimitiveJClass.getPrimitiveClass(className);
         if (clazz == null) clazz = loader.loadClass(className);
         int[] dimensions = new int[d];
         return Array.newInstance(clazz, dimensions).getClass();
  @@ -258,33 +265,42 @@
       }
     }
   
  -  // ========================================================================
  -  // Object implementation
  -
     /**
  -   * Returns the fully-qualified class name.
  +   * @deprecated
      */
  -  public String toString() {
  -    if (isXmlObject)
  -      return "x=" + className + arrayString;
  -    return className + arrayString;
  +  public static JavaTypeName forClassName(String type)
  +  {
  +    final org.apache.xmlbeans.impl.jam_old.JServiceFactory jserv_factory =
  +      org.apache.xmlbeans.impl.jam_old.JServiceFactory.getInstance();
  +    final org.apache.xmlbeans.impl.jam_old.JServiceParams params = jserv_factory.createServiceParams();
  +    final org.apache.xmlbeans.impl.jam_old.JService service;
  +    try {
  +      service = jserv_factory.createService(params);
  +    }
  +    catch (IOException e) {
  +      throw new XmlRuntimeException(e);
  +    }
  +    final  org.apache.xmlbeans.impl.jam_old.JClassLoader jcl = service.getClassLoader();
  +    final  org.apache.xmlbeans.impl.jam_old.JClass jc = jcl.loadClass(type);
  +    return forJClass(jc);
     }
   
  -  public boolean equals(Object o) {
  -    if (this == o) return true;
  -    if (!(o instanceof JavaTypeName)) return false;
  -
  -    final JavaTypeName javaName = (JavaTypeName) o;
  +  /**
  +   * @deprecated
  +   */
  +  public static JavaTypeName forJClass(org.apache.xmlbeans.impl.jam_old.JClass jClass) {
  +    if (jClass.isArray()) {
  +      return forArray(forJClass(jClass.getArrayComponentType()), jClass.getArrayDimensions());
  +    }
   
  -    if (isXmlObject != javaName.isXmlObject) return false;
  -    if (!className.equals(javaName.className)) return false;
  -    if (!arrayString.equals(javaName.arrayString)) return false;
  +    org.apache.xmlbeans.impl.jam_old.JClass[] interfaces = jClass.getInterfaces();
  +    for (int i = 0; i < interfaces.length; i++) {
  +      if (interfaces[i].getQualifiedName().equals(XMLOBJECT_CLASSNAME))
  +        return forString("x=" + jClass.getQualifiedName());
  +    }
   
  -    return true;
  +    return forString(jClass.getQualifiedName());
     }
   
  -  public int hashCode() {
  -    return className.hashCode() + arrayString.length() + (isXmlObject ? 1 : 0);
  -  }
   
   }
  
  
  
  1.6       +19 -2     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/MethodName.java
  
  Index: MethodName.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/MethodName.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MethodName.java	11 Mar 2004 21:26:46 -0000	1.5
  +++ MethodName.java	20 Mar 2004 21:51:34 -0000	1.6
  @@ -15,8 +15,8 @@
   
   package org.apache.xmlbeans.impl.binding.bts;
   
  -import org.apache.xmlbeans.impl.jam_old.JMethod;
  -import org.apache.xmlbeans.impl.jam_old.JParameter;
  +import org.apache.xmlbeans.impl.jam.JMethod;
  +import org.apache.xmlbeans.impl.jam.JParameter;
   import org.apache.xml.xmlbeans.bindingConfig.JavaMethodName;
   
   import java.lang.reflect.Method;
  @@ -210,4 +210,21 @@
        }
      }
      */
  +
  +  /**
  +   * @deprecated
  +   */
  +  public static MethodName create(org.apache.xmlbeans.impl.jam_old.JMethod m) {
  +    org.apache.xmlbeans.impl.jam_old.JParameter[] params = m.getParameters();
  +    if (params == null || params.length == 0) {
  +      return new MethodName(m.getSimpleName());
  +    } else {
  +      JavaTypeName[] types = new JavaTypeName[params.length];
  +      for (int i = 0; i < types.length; i++) {
  +        types[i] = JavaTypeName.forJClass(params[i].getType());
  +      }
  +      return new MethodName(m.getSimpleName(), types);
  +    }
  +  }
  +  
   }
  
  
  
  1.16      +5 -6      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java
  
  Index: BindingCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BindingCompiler.java	13 Mar 2004 00:33:22 -0000	1.15
  +++ BindingCompiler.java	20 Mar 2004 21:51:34 -0000	1.16
  @@ -20,8 +20,8 @@
   import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.CompositeBindingLoader;
   import org.apache.xmlbeans.impl.binding.logger.BindingLogger;
  -import org.apache.xmlbeans.impl.jam_old.JClassLoader;
  -import org.apache.xmlbeans.impl.jam_old.JFactory;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
  +import org.apache.xmlbeans.impl.jam.JamServiceFactory;
   import org.apache.xmlbeans.*;
   
   import java.io.File;
  @@ -243,14 +243,13 @@
      * @throws IllegalStateException if this method is called before
      * the abstract bind() method is called.
      */
  -  public JClassLoader getBaseJavaTypeLoader()
  +  public JamClassLoader getBaseJavaTypeLoader()
     {
       assertCompilationStarted(true);
       if (mBaseTylar == null) {
  -      return JFactory.getInstance().
  -                createClassLoader(ClassLoader.getSystemClassLoader(),null,null);
  +      return JamServiceFactory.getInstance().createSystemJamClassLoader();
       } else {
  -      return mBaseTylar.getJClassLoader();
  +      return mBaseTylar.getJamClassLoader();
       }
     }
   
  
  
  
  1.10      +10 -7     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java
  
  Index: Both2Bind.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Both2Bind.java	13 Mar 2004 00:33:22 -0000	1.9
  +++ Both2Bind.java	20 Mar 2004 21:51:34 -0000	1.10
  @@ -303,7 +303,7 @@
           scratchFromXmlName.put(scratch.getXmlName(), scratch);
         else {
           skip = true;
  -        logError("Both " + scratch.getJavaName() + " and " +
  +        _logError("Both " + scratch.getJavaName() + " and " +
                   ((Scratch) scratchFromXmlName.get(scratch.getXmlName())).getJavaName() +
                   " match Schema " + scratch.getXmlName(),
                   scratch.getJClass(),scratch.getSchemaType());
  @@ -314,7 +314,7 @@
             scratchFromJavaName.put(scratch.getJavaName(), scratch);
           else {
             skip = true;
  -          logError("Both " + scratch.getXmlName() + " and " +
  +          _logError("Both " + scratch.getXmlName() + " and " +
                     ((Scratch) scratchFromJavaName.get(scratch.getJavaName())).getXmlName()+
                     " match Java " + scratch.getJavaName(),
                     scratch.getJClass(),
  @@ -354,7 +354,10 @@
      * Computes a BindingType for a scratch.
      */
     private void createBindingType(Scratch scratch, boolean shouldDefault) {
  -    assert(scratch.getBindingType() == null);
  +    if (scratch == null) throw new IllegalArgumentException("null scratch");
  +    if (scratch.getBindingType() != null) {
  +      throw new IllegalArgumentException("non-null scratch binding type");
  +    }
   
       BindingTypeName btName = BindingTypeName.forPair(scratch.getJavaName(), scratch.getXmlName());
   
  @@ -524,7 +527,7 @@
     private void resolveStructure(Scratch scratch) {
   
       if (scratch.getSchemaType().isSimpleType() || scratch.getSchemaType() == XmlObject.type) {
  -      logError("Java class " + scratch.getJavaName() +
  +      _logError("Java class " + scratch.getJavaName() +
                 " does not match Schema type " +
                 scratch.getXmlName(),
                 scratch.getJClass(),
  @@ -562,7 +565,7 @@
         JavaTypeName collection = null;
         if (multiple) {
           if (!jPropType.isArray()) {
  -          logError("Property " + jProp + " in " + scratch.getJClass() +
  +          _logError("Property " + jProp + " in " + scratch.getJClass() +
                     " is an array, but " + sProp.getName() + " in " +
                     scratch.getSchemaType() + " is a singleton.",
                     jProp,sProp);
  @@ -611,12 +614,12 @@
           }
         }
         if (scratch.getOnBehalfOf() == null) {
  -        logError("Java class " + scratch.getJavaName() +
  +        _logError("Java class " + scratch.getJavaName() +
                   " does not match schema type " +
                   scratch.getXmlName() + " (" + reason + ")",
                   scratch.getJClass(),scratch.getSchemaType());
         } else {
  -        logError("Java class " + scratch.getJavaName() +
  +        _logError("Java class " + scratch.getJavaName() +
                   " does not match schema type " +
                   scratch.getXmlName() + " (" + reason + ")",
                   scratch.getOnBehalfOf().getJProperty(),
  
  
  
  1.44      +15 -15    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
  
  Index: Java2Schema.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- Java2Schema.java	17 Mar 2004 02:25:54 -0000	1.43
  +++ Java2Schema.java	20 Mar 2004 21:51:34 -0000	1.44
  @@ -25,6 +25,7 @@
   import javax.xml.namespace.QName;
   import java.util.ArrayList;
   import java.util.List;
  +import java.util.Properties;
   import java.io.IOException;
   import java.io.StringWriter;
   
  @@ -59,12 +60,12 @@
     public static final String TAG_EL_NILLABLE      = TAG_EL+".nillable";
     public static final String TAG_EL_EXCLUDE       = TAG_EL+".exclude";
     public static final String TAG_EL_ASTYPE        = TAG_EL+".astype";
  -  public static final String TAG_EL_CHECKER       = TAG_EL+".isSetMethod";
   
     public static final String TAG_AT               = "xsdgen:attribute";
     public static final String TAG_AT_NAME          = TAG_AT+".name";
     public static final String TAG_AT_CHECKER       = TAG_AT+".isSetMethod";
   
  +
     // this is the character that replaces invalid characters when creating new
     // xml names.
     private static final char SAFE_CHAR = '_';
  @@ -177,7 +178,7 @@
       // deal with inheritance - see if it extends anything
       JClass superclass = clazz.getSuperclass();
       if (superclass != null && !superclass.isObject() &&
  -            !getAnnotation(clazz,TAG_CT_IGNORESUPER,false)) {
  +      !getAnnotation(clazz,TAG_CT_IGNORESUPER,false)) {
         // FIXME we're ignoring interfaces at the moment
         BindingType superBindingType = getBindingTypeFor(superclass);
         ComplexContentDocument.ComplexContent ccd = xsType.addNewComplexContent();
  @@ -191,15 +192,15 @@
       mBindingFile.addBindingType(bindType,true,true);
       if (clazz.isPrimitive()) {
         // it's good to have registerd the dummy type, but don't go further
  -      logError("Unexpected simple type",clazz);
  +      logError("Unexpected simple type: "+clazz.getQualifiedName());
         return bindType;
       }
       String rootName = getAnnotation(clazz,TAG_CT_ROOT,null);
       if (rootName != null) {
         QName rootQName = new QName(tns, rootName);
         BindingTypeName docBtName =
  -              BindingTypeName.forPair(getJavaName(clazz),
  -                                      XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, rootQName));
  +        BindingTypeName.forPair(getJavaName(clazz),
  +                                XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, rootQName));
         SimpleDocumentBinding sdb = new SimpleDocumentBinding(docBtName);
         sdb.setTypeOfElement(btname.getXmlName());
         mBindingFile.addBindingType(sdb,true,true);
  @@ -234,11 +235,11 @@
     private void bindProperties(JProperty[] props, SchemaPropertyFacade facade) {
       for(int i=0; i<props.length; i++) {
         if (getAnnotation(props[i],TAG_EL_EXCLUDE,false)) {
  -        logVerbose("Marked excluded, skipping",props[i]);
  +        logVerbose("Marked excluded, skipping property "+props[i].getQualifiedName());
           continue;
         }
         if (props[i].getGetter() == null || props[i].getSetter() == null) {
  -        logVerbose("Does not have both getter and setter, skipping",props[i]);
  +        logVerbose("Does not have both getter and setter, skipping "+props[i].getQualifiedName());
           continue; // REVIEW this might have to change someday
         }
         { // determine the property name to use and set it
  @@ -249,7 +250,7 @@
           } else {
             facade.newElementProperty(props[i]);
             facade.setSchemaName(getAnnotation
  -                         (props[i],TAG_EL_NAME,props[i].getSimpleName()));
  +                               (props[i],TAG_EL_NAME,props[i].getSimpleName()));
           }
         }
         { // determine the property type to use and set it
  @@ -267,7 +268,7 @@
             propType = props[i].getType().forName(annotatedType);
             if (propType.isUnresolved()) {
               logError("Could not find class named '"+
  -                    propType.getQualifiedName()+"'",props[i]);
  +                    propType.getQualifiedName()+"'");
             } else {
               facade.setType(propType);
             }
  @@ -330,10 +331,10 @@
       getBindingTypeFor(clazz);  //ensure that we've bound it
       JavaTypeName jtn = JavaTypeName.forString(clazz.getQualifiedName());
       BindingTypeName btn = mLoader.lookupTypeFor(jtn);
  -    logVerbose("BindingTypeName is "+btn,clazz);
  +    logVerbose("BindingTypeName is "+btn);
       BindingType bt = mLoader.getBindingType(btn);
       if (bt != null) return bt.getName().getXmlName().getQName();
  -    logError("could not get qname",clazz);
  +    logError("could not get qname");
       return new QName("ERROR",clazz.getQualifiedName());
     }
   
  @@ -537,7 +538,7 @@
         if (mXsElement != null) {
           if (propType.isArray()) {
             if (propType.getArrayDimensions() != 1) {
  -            logError("Multidimensional arrays NYI",mSrcContext); //FIXME
  +            logError("Multidimensional arrays NYI"); //FIXME
             }
             JClass componentType = propType.getArrayComponentType();
             mXsElement.setMaxOccurs("unbounded");
  @@ -552,8 +553,7 @@
           }
         } else if (mXsAttribute != null) {
           if (propType.isArray()) {
  -          logError("Array properties cannot be mapped to xml attributes",
  -                  mSrcContext);
  +          logError("Array properties cannot be mapped to xml attributes");
           } else {
             mXsAttribute.setType(getQnameFor(propType));
             mBtsProp.setBindingType(getBindingTypeFor(propType));
  @@ -571,7 +571,7 @@
           mXsElement.setNillable(b);
           mBtsProp.setNillable(b);
         } else if (mXsAttribute != null) {
  -        logError("Attributes cannot be nillable:",mSrcContext);
  +        logError("Attributes cannot be nillable:");
         } else {
           throw new IllegalStateException();
         }
  
  
  
  1.20      +41 -13    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java
  
  Index: Java2SchemaTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Java2SchemaTask.java	11 Mar 2004 21:26:46 -0000	1.19
  +++ Java2SchemaTask.java	20 Mar 2004 21:51:34 -0000	1.20
  @@ -18,9 +18,10 @@
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  -import org.apache.xmlbeans.impl.jam_old.JClass;
  -import org.apache.xmlbeans.impl.jam_old.JFactory;
  -import org.apache.xmlbeans.impl.jam_old.JFileSet;
  +import org.apache.xmlbeans.impl.jam.JamServiceFactory;
  +import org.apache.xmlbeans.impl.jam.JamServiceParams;
  +import org.apache.xmlbeans.impl.jam.JamService;
  +import org.apache.xmlbeans.impl.jam.internal.DirectoryScanner;
   
   import java.io.File;
   import java.io.IOException;
  @@ -114,25 +115,52 @@
         //is passed to us
         throw new BuildException("The 'includes' attribute must be set.");
       }
  -    JFactory jf = JFactory.getInstance();
  +    JamServiceFactory jf = JamServiceFactory.getInstance();
  +    JamServiceParams params = jf.createServiceParams();
  +    //
  +    // process the included sources
  +    //
       String[] list = mSrcDir.list();
       if (list.length == 0) throw new BuildException("srcDir attribute required");
       if (list.length > 1) throw new BuildException("multiple srcDirs NYI");
  -    JFileSet fs = jf.createFileSet(new File(list[0]));
  +    File[] sourceRoots = path2files(mSrcDir);
       StringTokenizer st = new StringTokenizer(mIncludes,",");
  -    while(st.hasMoreTokens()) fs.include(st.nextToken().trim());
  -    String classpathString = null;
  +    while(st.hasMoreTokens()) {
  +      params.includeSourcePattern(sourceRoots,st.nextToken().trim());
  +    }
  +//params.setVerbose(DirectoryScanner.class);    
  +    //
  +    // add the sourcepath and classpath, if specified
  +    //
  +    if (mSourcepath != null) {
  +      File[] files = path2files(mSourcepath);
  +      for(int i=0; i<files.length; i++) params.addSourcepath(files[i]);
  +    }
       if (mClasspath != null) {
  -      //this will be removed after jam_old factory is refactored
  -      fs.setClasspath(classpathString = mClasspath.toString());
  +      File[] files = path2files(mClasspath);
  +      for(int i=0; i<files.length; i++) params.addClasspath(files[i]);
       }
  -    final JClass[] classes;
  +    //
  +    // create service, get classes, return compiler
  +    //
  +    JamService service;
       try {
  -      classes = jf.loadSources(fs,null,null,null,null,classpathString);
  +      service = jf.createService(params);
       } catch(IOException ioe) {
  -      ioe.printStackTrace();
         throw new BuildException(ioe);
       }
  -    return new Java2Schema(classes);
  +    return new Java2Schema_new(service.getAllClasses());
  +  }
  +
  +  // ========================================================================
  +  // Private methods
  +
  +  private File[] path2files(Path path) {
  +    String[] list = path.list();
  +    File[] out = new File[list.length];
  +    for(int i=0; i<out.length; i++) {
  +      out[i] = new File(list[i]).getAbsoluteFile();
  +    }
  +    return out;
     }
   }
  
  
  
  1.5       +2 -2      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcherContext.java
  
  Index: TypeMatcherContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcherContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TypeMatcherContext.java	11 Mar 2004 21:26:46 -0000	1.4
  +++ TypeMatcherContext.java	20 Mar 2004 21:51:34 -0000	1.5
  @@ -17,7 +17,7 @@
   
   import org.apache.xmlbeans.impl.binding.logger.BindingLogger;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.impl.jam_old.JClassLoader;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
   import org.apache.xmlbeans.SchemaTypeSystem;
   
   /**
  @@ -49,5 +49,5 @@
      * Normally, this will simply be the loader backed by the system
      * classloader.
      */
  -  public JClassLoader getBaseJavaTypeLoader();
  +  public JamClassLoader getBaseJavaTypeLoader();
   }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema_new.java
  
  Index: Java2Schema_new.java
  ===================================================================
  /*   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.binding.compile;
  
  import org.apache.xmlbeans.impl.binding.bts.*;
  import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
  import org.apache.xmlbeans.impl.jam.*;
  import org.apache.xmlbeans.impl.common.XMLChar;
  import org.w3.x2001.xmlSchema.*;
  import javax.xml.namespace.QName;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import java.util.HashMap;
  import java.io.IOException;
  import java.io.StringWriter;
  
  
  /**
   * Takes a set of Java source inputs and generates a set of XML schemas to
   * which those input should be bound, as well as a binding configuration file
   * which describes to the runtime subsystem how the un/marshalling should
   * be performed.
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class Java2Schema_new extends BindingCompiler {
  
    // =========================================================================
    // Constants
  
    private static final String JAVA_URI_SCHEME      = "java:";
    private static final String JAVA_NAMESPACE_URI   = "language_builtins";
    private static final String JAVA_PACKAGE_PREFIX  = "java.";
  
    public static final String TAG_CT               = "xsdgen:complexType";
    public static final String TAG_CT_EXCLUDE       = TAG_CT+".exclude";
    public static final String TAG_CT_TYPENAME      = TAG_CT+".typeName";
    public static final String TAG_CT_TARGETNS      = TAG_CT+".targetNamespace";
    public static final String TAG_CT_ROOT          = TAG_CT+".rootElement";
    public static final String TAG_CT_IGNORESUPER   = TAG_CT+".ignoreSuper";
  
    private static final String TAG_EL               = "xsdgen:element";
  
    public static final String TAG_EL_NAME          = TAG_EL+".name";
    public static final String TAG_EL_NILLABLE      = TAG_EL+".nillable";
    public static final String TAG_EL_EXCLUDE       = TAG_EL+".exclude";
    public static final String TAG_EL_ASTYPE        = TAG_EL+".astype";
  
    public static final String TAG_AT               = "xsdgen:attribute";
    public static final String TAG_AT_NAME          = TAG_AT+".name";
  
    public static final String TAG_ISSETTER         = "xsdgen:isSetMethodFor";
  
    // this is the character that replaces invalid characters when creating new
    // xml names.
    private static final char SAFE_CHAR = '_';
  
    // =========================================================================
    // Variables
  
    private BindingFile mBindingFile;  // the file we're creating
    private BindingLoader mLoader; // the full loader: bindingFile + baseLoader
    private SchemaDocument mSchemaDocument; // schema doc we're generating
    //private Map mTns2Schema = new HashMap();
    private SchemaDocument.Schema mSchema;
    private JClass[] mClasses; // the input classes
  
    // =========================================================================
    // Constructors
  
    public Java2Schema_new(JClass[] classesToBind) {
      if (classesToBind == null) {
        throw new IllegalArgumentException("null classes");
      }
      mClasses = classesToBind;
    }
  
    // ========================================================================
    // BindingCompiler implementation
  
    /**
     * Does the binding work on the inputs passed to the constructor and writes
     * out the tylar.
     */
    protected void internalBind(TylarWriter writer) {
      mBindingFile = new BindingFile();
      mLoader = CompositeBindingLoader.forPath
              (new BindingLoader[] {mBindingFile, super.getBaseBindingLoader()});
      mSchemaDocument = SchemaDocument.Factory.newInstance();
      mSchema = mSchemaDocument.addNewSchema();
      if (mClasses.length > 0) {
        //FIXME how should we determine the targetnamespace for the schema?
        //here we just derive it from the first class in the list
        mSchema.setTargetNamespace(getTargetNamespace(mClasses[0]));
      }
      //This does the binding
      for(int i=0; i<mClasses.length; i++) {
        if (!getAnnotation(mClasses[i],TAG_CT_EXCLUDE,false)) {
          getBindingTypeFor(mClasses[i]);
        }
      }
      //
      try {
        writer.writeBindingFile(mBindingFile);
        writer.writeSchema(mSchemaDocument,"schema-0.xsd");
      } catch(IOException ioe) {
        logError(ioe);
      }
    }
  
    // ========================================================================
    // Private methods
  
    /**
     * Returns a bts BindingType for the given JClass.  If such a type
     * has not yet been registered with the loader, it will be created.
     *
     * @param clazz Java type for which to return a binding.
     */
    private BindingType getBindingTypeFor(JClass clazz) {
      BindingTypeName btn = mLoader.lookupTypeFor(getJavaName(clazz));
      if (btn != null) {
        BindingType out = mLoader.getBindingType(btn);
        if (out != null) return out;
      }
      return createBindingTypeFor(clazz);
    }
  
    /**
     * Creates a bts BindingType for the given JClass and registers t with the
     * loader.  Note that this method assumes that a BindingType does not
     * already exist for the given JClass.
     *
     * @param clazz Java type for which to generate a binding.
     */
    private BindingType createBindingTypeFor(JClass clazz) {
      // create the schema type
      TopLevelComplexType xsType = mSchema.addNewComplexType();
      String tns = getTargetNamespace(clazz);
      String xsdName = getAnnotation(clazz,TAG_CT_TYPENAME,clazz.getSimpleName());
      QName qname = new QName(tns,xsdName);
      xsType.setName(xsdName);
      // deal with inheritance - see if it extends anything
      JClass superclass = clazz.getSuperclass();
      if (superclass != null && !superclass.isObjectType() &&
              !getAnnotation(clazz,TAG_CT_IGNORESUPER,false)) {
        // FIXME we're ignoring interfaces at the moment
        BindingType superBindingType = getBindingTypeFor(superclass);
        ComplexContentDocument.ComplexContent ccd = xsType.addNewComplexContent();
        ExtensionType et = ccd.addNewExtension();
        et.setBase(superBindingType.getName().getXmlName().getQName());
      }
      // create a binding type
      BindingTypeName btname = BindingTypeName.forPair(getJavaName(clazz),
                                                       XmlTypeName.forTypeNamed(qname));
      ByNameBean bindType = new ByNameBean(btname);
      mBindingFile.addBindingType(bindType,true,true);
      if (clazz.isPrimitiveType()) {
        // it's good to have registerd the dummy type, but don't go further
        logError("Unexpected simple type",clazz);
        return bindType;
      }
      String rootName = getAnnotation(clazz,TAG_CT_ROOT,null);
      if (rootName != null) {
        QName rootQName = new QName(tns, rootName);
        BindingTypeName docBtName =
                BindingTypeName.forPair(getJavaName(clazz),
                                        XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, rootQName));
        SimpleDocumentBinding sdb = new SimpleDocumentBinding(docBtName);
        sdb.setTypeOfElement(btname.getXmlName());
        mBindingFile.addBindingType(sdb,true,true);
      }
      // run through the class' properties to populate the binding and xsdtypes
      SchemaPropertyFacade facade = new SchemaPropertyFacade(xsType,bindType,tns);
      Map props2issetters = new HashMap();
      getIsSetters(clazz,props2issetters);
      bindProperties(clazz.getDeclaredProperties(),props2issetters,facade);
      facade.finish();
      // check to see if they want to create a root elements from this type
      JAnnotation[] anns = getNamedTags(clazz.getAllJavadocTags(),TAG_CT_ROOT);
      for(int i=0; i<anns.length; i++) {
        TopLevelElement root = mSchema.addNewElement();
        root.setName(makeNcNameSafe(anns[i].getValue
                                    (JAnnotation.SINGLE_VALUE_NAME).asString()));
        root.setType(qname);
        // FIXME still not entirely clear to me what we should do about
        // the binding file here
      }
      return bindType;
    }
  
    private void getIsSetters(JClass clazz, Map outPropname2jmethod) {
      JMethod[] methods = clazz.getDeclaredMethods();
      for(int i=0; i<methods.length; i++) {
        JAnnotation ann = methods[i].getAnnotation(TAG_ISSETTER);
        if (ann != null) {
          if (!methods[i].getReturnType().getQualifiedName().equals("boolean")) {
            logWarning("Method "+methods[i].getQualifiedName()+" is marked "+
                       TAG_ISSETTER+"\nbut it does not return boolean."+
                       "Ignoring.");
            continue;
          }
          if (methods[i].getParameters().length > 0) {
            logWarning("Method "+methods[i].getQualifiedName()+" is marked "+
                       TAG_ISSETTER+"\nbut takes arguments.  Ignoring.");
            continue;
          }
          JAnnotationValue propNameVal = ann.getValue(JAnnotation.SINGLE_VALUE_NAME);
          if (propNameVal == null) {
            logWarning("Method "+methods[i].getQualifiedName()+" is marked "+
                       TAG_ISSETTER+"\nbut but no property name is given.  Ignoring");
            continue;
          }
          outPropname2jmethod.put(propNameVal.asString(),methods[i]);
        }
      }
    }
  
    /**
     * Runs through a set of JProperties to creates schema and bts elements
     * to represent those properties.  Note that the details of manipulating the
     * schema and bts are encapsulated within the supplied SchemaPropertyFacade;
     * this method is only responsible for inspecting the properties and their
     * annotations and setting the correct attributes on the facade.
     *
     * @param props Array of JProperty objects to potentially be bound.
     * @param facade Allows us to create and manipulate properties,
     * hides the dirty work
     */
    private void bindProperties(JProperty[] props,
                                Map props2issetters,
                                SchemaPropertyFacade facade) {
      for(int i=0; i<props.length; i++) {
        if (getAnnotation(props[i],TAG_EL_EXCLUDE,false)) {
          logVerbose("Marked excluded, skipping",props[i]);
          continue;
        }
        if (props[i].getGetter() == null || props[i].getSetter() == null) {
          logVerbose("Does not have both getter and setter, skipping",props[i]);
          continue; // REVIEW this might have to change someday
        }
        String propName;
        { // determine the property name to use and set it
          propName = getAnnotation(props[i],TAG_AT_NAME,null);
          if (propName != null) {
            facade.newAttributeProperty(props[i]);
            facade.setSchemaName(propName);
          } else {
            facade.newElementProperty(props[i]);
            facade.setSchemaName(getAnnotation
                           (props[i],TAG_EL_NAME,props[i].getSimpleName()));
          }
        }
        { // determine the property type to use and set it
          JClass propType = null;
          String annotatedType = getAnnotation(props[i],TAG_EL_ASTYPE,null);
          if (annotatedType == null) {
            facade.setType(propType = props[i].getType());
          } else {
            if (props[i].getType().isArrayType()) {
              //THIS IS A QUICK GROSS HACK THAT SHOULD BE REMOVED.
              //IF SOMEONE WANTS TO AS TYPE AN ARRAY PROPERTY, THEY NEED
              //TO ASTYPE IT TO THE ARRAY TYPE THEMSELVES
              annotatedType = "[L"+annotatedType+";";
            }
            propType = props[i].getType().forName(annotatedType);
            if (propType.isUnresolvedType()) {
              logError("Could not find class named '"+
                      propType.getQualifiedName()+"'",props[i]);
            } else {
              facade.setType(propType);
            }
          }
        }
        { // set the getters and setters
          facade.setGetter(props[i].getGetter());
          facade.setSetter(props[i].getSetter());
        }
        {
          JMethod issetter = (JMethod)props2issetters.get(propName);
          if (issetter != null) facade.setIssetter(issetter);
        }
        { // determine if the property is nillable
          JAnnotation a = props[i].getAnnotation(TAG_EL_NILLABLE);
          if (a != null) {
            // if the tag is there but empty, set it to true.  is that weird?
            JAnnotationValue val = a.getValue(JAnnotation.SINGLE_VALUE_NAME);
            if (val.asString().trim().length() == 0) {
              facade.setNillable(true);
            } else {
              facade.setNillable(val.asBoolean());
            }
          }
        }
      }
    }
  
  
    /**
     * Returns a JavaTypeName for the given JClass.  Might want to pool these.
     */
    private JavaTypeName getJavaName(JClass jc) {
      return JavaTypeName.forString(jc.getQualifiedName());
    }
  
    /**
     * Returns the string value of a named annotation, or the provided default
     * if the annotation is not present.
     * REVIEW seems like having this functionality in jam_old would be nice
     */
    private String getAnnotation(JAnnotatedElement elem,
                                 String annName,
                                 String dflt) {
      //System.out.print("checking for "+annName+" on "+elem.getQualifiedName());
      JAnnotation ann = elem.getAnnotation(annName);
      if (ann == null) {
        //System.out.println("...no annotation");
        return dflt;
      }
      JAnnotationValue val = ann.getValue(JAnnotation.SINGLE_VALUE_NAME);
      if (val == null) {
        //System.out.println("...no value!!!");
        return dflt;
      }
      //System.out.println("\n\n\n...value of "+annName+" is "+val.asString()+"!!!!!!!!!");
      return val.asString();
    }
  
    /**
     * Returns the boolean value of a named annotation, or the provided default
     * if the annotation is not present.
     * REVIEW seems like having this functionality in jam_old would be nice
     */
    private boolean getAnnotation(JAnnotatedElement elem,
                                  String annName,
                                  boolean dflt) {
      //System.out.print("checking for "+annName+" on "+elem.getQualifiedName());
      JAnnotation ann = elem.getAnnotation(annName);
      if (ann == null) {
        //System.out.println("...no annotation");
        return dflt;
      }
      JAnnotationValue val = ann.getValue(JAnnotation.SINGLE_VALUE_NAME);
      if (val == null || val.asString().length() == 0) {
        //System.out.println("\n\n\n...no value, returning true!!!");
        //this is a little bit gross.  the logic here is that if the tag is
        //present but empty, it actually is a true value.  E.g., an empty
        //@exclude tag means "yes, do exclude."
        return true;
      }
      //System.out.println("\n\n\n...value of "+annName+" is "+val.asBoolean()+"!!!!!!!!!");
      return val.asBoolean();
    }
  
    /**
     * Returns a QName for the type bound to the given JClass.
     */
    private QName getQnameFor(JClass clazz) {
      getBindingTypeFor(clazz);  //ensure that we've bound it
      JavaTypeName jtn = JavaTypeName.forString(clazz.getQualifiedName());
      BindingTypeName btn = mLoader.lookupTypeFor(jtn);
      logVerbose("BindingTypeName is "+btn,clazz);
      BindingType bt = mLoader.getBindingType(btn);
      if (bt != null) return bt.getName().getXmlName().getQName();
      logError("could not get qname",clazz);
      return new QName("ERROR",clazz.getQualifiedName());
    }
  
    /**
     * Returns a target namespace that should be used for the given class.
     * This takes annotations into consideration.
     */
    private String getTargetNamespace(JClass clazz) {
      String val = getAnnotation(clazz,TAG_CT_TARGETNS,null);
      if (val != null) return val;
      // Ok, they didn't specify it in the markup, so we have to
      // synthesize it from the classname.
      String pkg_name;
      if (clazz.isPrimitiveType()) {
        pkg_name = JAVA_NAMESPACE_URI;
      } else {
        JPackage pkg = clazz.getContainingPackage();
        pkg_name = (pkg == null) ? "" : pkg.getQualifiedName();
        if (pkg_name.startsWith(JAVA_PACKAGE_PREFIX)) {
          pkg_name = JAVA_NAMESPACE_URI+"."+
                  pkg_name.substring(JAVA_PACKAGE_PREFIX.length());
        }
      }
      return JAVA_URI_SCHEME + pkg_name;
    }
  
  
  
    /**
     * Checks the given XML name to ensure that it is a valid XMLName according
     * to the XML 1.0 Recommendation.  If it is not, the name is mangled so
     * as to make it a valid name.  This should be called before setting the
     * name on every schema fragment we create.
     */
    private static String makeNcNameSafe(String name) {
      // it's probably pretty rare that a name isn't valid, so let's just do
      // an optimistic check first without writing out a new string.
      if (name == null || XMLChar.isValidNCName(name) || name.length() == 0) {
        return name;
      }
      // ok, we have to mangle it
      StringWriter out = new StringWriter();
      char ch = name.charAt(0);
      if(!XMLChar.isNCNameStart(ch)) {
        out.write(SAFE_CHAR);
      } else {
        out.write(ch);
      }
      for (int i=1; i < name.length(); i++ ) {
        ch = name.charAt(i);
         if (!XMLChar.isNCName(ch)) {
           out.write(ch);
         }
      }
      return out.toString();
    }
  
    /*
  
    private static boolean isXmlObj(JClass clazz) {
      try {
        JClass xmlObj = clazz.forName("org.apache.xmlbeans.XmlObject");
        return xmlObj.isAssignableFrom(clazz);
      } catch(Exception e) {
        e.printStackTrace(); //FIXME
        return false;
      }
    }
    */
  
  
  
    /**
     * Inner class which encapsulates the creation of schema properties and
     * property bindings and presents them as a unified interface, a kind of
     * 'virtual property.'  This is used by the bindProperties() method, and
     * allows that function to concentrate on inspecting the java types and
     * annotations. This class hides all of the dirty work associated with
     * constructing and initializing a BTS property and either an XSD element
     * or attribute.
     *
     * Note that in some sense, this class behaves as both a factory and a kind
     * of cursor.  It is capable of creating a new virtual property
     * on a given BTS/XSD type pair, and any operations on the facade will
     * apply to that property until the next property is created
     * (via newAttributeProperty or newElementProperty).
     */
    class SchemaPropertyFacade {
  
      // =======================================================================
      // Variables
  
      private TopLevelComplexType mXsType;
      private String mXsTargetNamespace;
      private LocalElement mXsElement = null; // exactly one of these two is
      private Attribute mXsAttribute = null;  // remains null
      private Group mXsSequence = null;
      private List mXsAttributeList = null;
      private ByNameBean mBtsType;
      private QNameProperty mBtsProp = null;
      private JElement mSrcContext = null;
  
      // =======================================================================
      // Constructors
  
      public SchemaPropertyFacade(TopLevelComplexType xsType,
                                  ByNameBean bt,
                                  String tns) {
        if (xsType == null) throw new IllegalArgumentException("null xsType");
        if (bt == null) throw new IllegalArgumentException("null bt");
        if (tns == null) throw new IllegalArgumentException("null tns");
        mXsType = xsType;
        mBtsType = bt;
        mXsTargetNamespace = tns;
      }
  
      // =======================================================================
      // Public methods
  
      /**
       * Creates a new element property and sets this facade represent it.
       * Note that either this method or newAttributeProperty must be called prior
       * to doing any work with the facade.  Also note that you need to
       * completely finish working with each property before moving onto
       * the next via newElementProperty or newAttributeProperty.
       * *
       * @param srcContext A JAM element that represents the java source
       * artifact that is being bound to the property.  This is used
       * only for error reporting purposes.
       */
      public void newElementProperty(JElement srcContext) {
        newBtsProperty();
        mSrcContext = srcContext;
        if (mXsSequence == null) mXsSequence = mXsType.addNewSequence();
        mXsElement = mXsSequence.addNewElement();
        mXsAttribute = null;
      }
  
      /**
       * Creates a new attribute property and sets this facade represent it.
       * Note that either this method or newElementProperty must be called prior
       * to doing any work with the facade.  Also note that you need to
       * completely finish working with each property before moving onto
       * the next via newElementProperty or newAttributeProperty.
       *
       * @param srcContext A JAM element that represents the java source
       * artifact that is being bound to the property.  This is used
       * only for error reporting purposes.
       */
      public void newAttributeProperty(JElement srcContext) {
        newBtsProperty();
        mBtsProp.setAttribute(true);
        mSrcContext = srcContext;
        mXsElement = null;
        if (mXsAttributeList == null) mXsAttributeList = new ArrayList();
        mXsAttributeList.add(mXsAttribute = Attribute.Factory.newInstance());
      }
  
      /**
       * Sets the name of this property (element or attribute) in the
       * generated schema.
       */
      public void setSchemaName(String name) {
        name = makeNcNameSafe(name);
        if (mXsElement != null) {
          mXsElement.setName(name);
        } else if (mXsAttribute != null) {
          mXsAttribute.setName(name);
        } else {
          throw new IllegalStateException();
        }
        mBtsProp.setQName(new QName(mXsTargetNamespace,name));
      }
  
      /**
       * Sets the name of the java getter for this property.
       */
      public void setGetter(JMethod g) {
        mBtsProp.setGetterName(MethodName.create(g));
      }
  
      /**
       * Sets the name of the java setter for this property.
       */
      public void setSetter(JMethod s) {
        mBtsProp.setSetterName(MethodName.create(s));
      }
  
      /**
       * Sets the name of the java setter for this property.
       */
      public void setIssetter(JMethod s) {
        mBtsProp.setIssetterName(MethodName.create(s));
      }
  
      /**
       * Sets the type of the property.  Currently handles arrays
       * correctly but not collections.
       */
      public void setType(JClass propType) {
        if (mXsElement != null) {
          if (propType.isArrayType()) {
            if (propType.getArrayDimensions() != 1) {
              logError("Multidimensional arrays NYI",mSrcContext); //FIXME
            }
            JClass componentType = propType.getArrayComponentType();
            mXsElement.setMaxOccurs("unbounded");
            mXsElement.setType(getQnameFor(componentType));
            mBtsProp.setMultiple(true);
            mBtsProp.setCollectionClass //FIXME
                    (JavaTypeName.forString(componentType.getQualifiedName()+"[]"));
            mBtsProp.setBindingType(getBindingTypeFor(componentType));
          } else {
            mXsElement.setType(getQnameFor(propType));
            mBtsProp.setBindingType(getBindingTypeFor(propType));
          }
        } else if (mXsAttribute != null) {
          if (propType.isArrayType()) {
            logError("Array properties cannot be mapped to xml attributes",
                    mSrcContext);
          } else {
            mXsAttribute.setType(getQnameFor(propType));
            mBtsProp.setBindingType(getBindingTypeFor(propType));
          }
        } else {
          throw new IllegalStateException();
        }
      }
  
      /**
       * Sets whether the property should be bound as nillable.
       */
      public void setNillable(boolean b) {
        if (mXsElement != null) {
          mXsElement.setNillable(b);
          mBtsProp.setNillable(b);
        } else if (mXsAttribute != null) {
          logError("Attributes cannot be nillable:",mSrcContext);
        } else {
          throw new IllegalStateException();
        }
      }
  
      /**
       * This method should always be called when finished building up
       * a type.  It is a hack around an xbeans bug in which the sequences and
       * attributes are output in the order in which they were added (the
       * schema for schemas says the attributes always have to go last).
       */
      public void finish() {
        addBtsProperty();
        if (mXsAttributeList != null) {
          Attribute[] array = new Attribute[mXsAttributeList.size()];
          mXsAttributeList.toArray(array);
          mXsType.setAttributeArray(array);
        }
      }
  
      // =======================================================================
      // Private methods
  
      /**
       * Adds the current bts property to the bts type.  This has to be called
       * for every property.  We do this last because ByNameBean won't
       * let us add more than one prop for same name (name is always blank
       * initially).
       */
      private void addBtsProperty() {
        if (mBtsProp != null) mBtsType.addProperty(mBtsProp);
      }
  
      /**
       * Initialize a new QName property in the bts type
       */
      private void newBtsProperty() {
        if (mBtsProp != null) addBtsProperty(); //if not 1st one, add old one
        mBtsProp = new QNameProperty();
      }
    }
  
  
    //this is temporary, will go away when we have our 175 story straight
    private static JAnnotation[] getNamedTags(JAnnotation[] tags,
                                              String named)
    {
      if (tags == null || tags.length == 0) return new JAnnotation[0];
      List list = new ArrayList();
      for(int i=0; i<tags.length; i++) {
        if (tags[i].getSimpleName().equals(named)) list.add(tags[i]);
      }
      JAnnotation[] out = new JAnnotation[list.size()];
      list.toArray(out);
      return out;
    }
  
  
  
  }
  
  
  
  1.5       +58 -1     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/BindingLogger.java
  
  Index: BindingLogger.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/BindingLogger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BindingLogger.java	11 Mar 2004 21:26:47 -0000	1.4
  +++ BindingLogger.java	20 Mar 2004 21:51:34 -0000	1.5
  @@ -17,7 +17,7 @@
   
   import org.apache.xmlbeans.SchemaProperty;
   import org.apache.xmlbeans.SchemaType;
  -import org.apache.xmlbeans.impl.jam_old.JElement;
  +import org.apache.xmlbeans.impl.jam.JElement;
   
   import java.util.logging.Level;
   
  @@ -251,6 +251,63 @@
         mSink.log(new MessageImpl
                 (Level.FINEST, msg, null, javaCtx, xsdCtx, null));
       }
  +  }
  +
  +
  +  // ========================================================================
  +  // Deprecated methods
  +
  +  /**
  +   * @deprecated
  +   */
  +  public boolean _logError(Throwable error, org.apache.xmlbeans.impl.jam_old.JElement javaContext) {
  +    mAnyErrorsFound = true;
  +    mSink.log(new MessageImpl
  +            (Level.SEVERE, null, error, null, null, null));
  +    return mIgnoreErrors;
  +  }
  +
  +  /**
  +   * @deprecated
  +   */
  +  public boolean _logError(Throwable t, org.apache.xmlbeans.impl.jam_old.JElement jCtx, SchemaType xsdCtx) {
  +    mAnyErrorsFound = true;
  +    mSink.log(new MessageImpl
  +            (Level.SEVERE, null, t, null, xsdCtx, null));
  +    return mIgnoreErrors;
  +  }
  +
  +  /**
  +   * @deprecated
  +   */
  +  public boolean _logError(String msg, org.apache.xmlbeans.impl.jam_old.JElement javaContext) {
  +    mAnyErrorsFound = true;
  +    mSink.log(new MessageImpl
  +            (Level.SEVERE, msg, null, null, null, null));
  +    return mIgnoreErrors;
  +  }
  +
  +  /**
  +   * @deprecated
  +   */
  +  public boolean _logError(String msg, org.apache.xmlbeans.impl.jam_old.JElement javaCtx, SchemaType xsdCtx) {
  +    mAnyErrorsFound = true;
  +    mSink.log(new MessageImpl
  +            (Level.SEVERE, msg, null, null, xsdCtx, null));
  +    return mIgnoreErrors;
  +  }
  +
  +  /**
  +   * Logs a message that fatal error that occurred while performing binding
  +   * on the given schema construct.
  +   *
  +   * @return true if processing should attempt to continue.
  +   */
  +  public boolean _logError(String msg, org.apache.xmlbeans.impl.jam_old.JElement jCtx, SchemaProperty xCtx) {
  +    mAnyErrorsFound = true;
  +    mSink.log(new MessageImpl
  +            (Level.SEVERE, msg, null, null, null, xCtx));
  +    return mIgnoreErrors;
     }
   
   }
  
  
  
  1.4       +1 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/Message.java
  
  Index: Message.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/Message.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Message.java	11 Mar 2004 21:26:47 -0000	1.3
  +++ Message.java	20 Mar 2004 21:51:34 -0000	1.4
  @@ -17,7 +17,7 @@
   
   import org.apache.xmlbeans.SchemaProperty;
   import org.apache.xmlbeans.SchemaType;
  -import org.apache.xmlbeans.impl.jam_old.JElement;
  +import org.apache.xmlbeans.impl.jam.JElement;
   
   import java.util.logging.Level;
   
  
  
  
  1.4       +2 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/MessageImpl.java
  
  Index: MessageImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/MessageImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MessageImpl.java	11 Mar 2004 21:26:47 -0000	1.3
  +++ MessageImpl.java	20 Mar 2004 21:51:34 -0000	1.4
  @@ -17,7 +17,7 @@
   
   import org.apache.xmlbeans.SchemaProperty;
   import org.apache.xmlbeans.SchemaType;
  -import org.apache.xmlbeans.impl.jam_old.JElement;
  +import org.apache.xmlbeans.impl.jam.JElement;
   
   import java.io.PrintWriter;
   import java.io.StringWriter;
  @@ -56,6 +56,7 @@
       mSchemaTypeContext = schemaTypeContext;
       mSchemaPropertyContext = schemaPropertyContext;
     }
  +
   
     // ========================================================================
     // Message implementation
  
  
  
  1.6       +5 -5      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/BaseTylarImpl.java
  
  Index: BaseTylarImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/BaseTylarImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseTylarImpl.java	13 Mar 2004 00:33:22 -0000	1.5
  +++ BaseTylarImpl.java	20 Mar 2004 21:51:34 -0000	1.6
  @@ -19,14 +19,14 @@
   import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.CompositeBindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  -import org.apache.xmlbeans.impl.jam_old.JClassLoader;
  -import org.apache.xmlbeans.impl.jam_old.JFactory;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
  +import org.apache.xmlbeans.impl.jam.JamServiceFactory;
   import org.apache.xmlbeans.*;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   import java.net.URI;
   
   /**
  - * Base class for simplifying implementation of the Tylar interface.
  + * <p>Base class for simplifying implementation of the Tylar interface.</p>
    *
    * @author Patrick Calahan <pcal@bea.com>
    */
  @@ -70,11 +70,11 @@
       }
     }
   
  -  public JClassLoader getJClassLoader()
  +  public JamClassLoader getJamClassLoader()
     {
       // REVIEW should consider caching this result
       // create a classloader chain that runs throw all of the base tylars
       ClassLoader cl = createClassLoader(ClassLoader.getSystemClassLoader());
  -    return JFactory.getInstance().createClassLoader(cl,null,null);
  +    return JamServiceFactory.getInstance().createJamClassLoader(cl);
     }
   }
  
  
  
  1.7       +2 -2      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java
  
  Index: Tylar.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Tylar.java	11 Mar 2004 21:26:47 -0000	1.6
  +++ Tylar.java	20 Mar 2004 21:51:34 -0000	1.7
  @@ -18,7 +18,7 @@
   import java.net.URI;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.impl.jam_old.JClassLoader;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
   import org.apache.xmlbeans.SchemaTypeSystem;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   
  @@ -76,7 +76,7 @@
      * Returns a JClassLoader which can be used to load descriptions of the
      * java types contained in this tylar.
      */
  -  public JClassLoader getJClassLoader();
  +  public JamClassLoader getJamClassLoader();
   
     /**
      * Returns a new ClassLoader that can load any class files contained in
  
  
  

---------------------------------------------------------------------
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