You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/06/28 23:11:38 UTC

cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations TopLevelElementTarget.java ElementTarget.java TypeTarget.java

pcal        2004/06/28 14:11:38

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Java2Schema.java Java2SchemaTask.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal
                        Java2SchemaAnnotationHelper.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations
                        ElementTarget.java TypeTarget.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations
                        TopLevelElementTarget.java
  Log:
  j2s: annotation fixes
  
  Revision  Changes    Path
  1.55      +35 -14    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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Java2Schema.java	24 Jun 2004 21:39:30 -0000	1.54
  +++ Java2Schema.java	28 Jun 2004 21:11:38 -0000	1.55
  @@ -38,6 +38,7 @@
   import java.util.Arrays;
   import java.io.IOException;
   import java.io.StringWriter;
  +import java.math.BigInteger;
   
   
   /**
  @@ -64,6 +65,7 @@
     private static final String TAG_EL               = "xsdgen:element";
   
     public static final String TAG_EL_NAME          = TAG_EL+".name";
  +  public static final String TAG_EL_REQUIRED      = TAG_EL+".required";
     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";
  @@ -107,6 +109,13 @@
       if (classesToBind == null) {
         throw new IllegalArgumentException("null classes");
       }
  +    /*
  +    for(int i=0; i<classesToBind.length; i++) {
  +      if (classesToBind[i].isUnresolvedType()) {
  +        throw new IllegalArgumentException(classesToBind[i].getQualifiedName()+
  +                                           " is unresolved.");
  +      }
  +    } */
       mClasses = classesToBind;
     }
   
  @@ -432,6 +441,19 @@
             }
           }
         }
  +      { // determine if the property is required
  +        JAnnotation a = props[i].getAnnotation(TAG_EL_REQUIRED);
  +        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 == null || val.asString().trim().length() == 0) {
  +            facade.setRequired(true);
  +          } else {
  +            facade.setRequired(val.asBoolean());
  +          }
  +        }
  +      }
  +
       }
     }
   
  @@ -488,20 +510,6 @@
       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
  @@ -681,6 +689,19 @@
           mBtsProp.setNillable(b);
         } else if (mXsAttribute != null) {
           logError("Attributes cannot be nillable:",mSrcContext);
  +      } else {
  +        throw new IllegalStateException();
  +      }
  +    }
  +
  +    /**
  +     * Sets whether the property should be bound as nillable.
  +     */
  +    public void setRequired(boolean b) {
  +      if (mXsElement != null) {
  +        mXsElement.setMinOccurs(BigInteger.valueOf(b ? 1 : 0));
  +      } else if (mXsAttribute != null) {
  +        mXsAttribute.setUse(b ? Attribute.Use.REQUIRED : Attribute.Use.OPTIONAL);
         } else {
           throw new IllegalStateException();
         }
  
  
  
  1.23      +16 -1     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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Java2SchemaTask.java	8 Apr 2004 20:01:01 -0000	1.22
  +++ Java2SchemaTask.java	28 Jun 2004 21:11:38 -0000	1.23
  @@ -41,6 +41,7 @@
     private Path mClasspath = null;
     private String mIncludes = null;
     private Path mSrcDir = null;
  +  private boolean mOrderPropertiesBySource = false;
   
     // =========================================================================
     // Task attributes
  @@ -99,6 +100,18 @@
       mIncludes = includes;
     }
   
  +  /**
  +   * <p>Sets whether elements within generated schema types should be ordered
  +   * according to the source order of their corresponding java properties.
  +   * The default is false, meaning that they will instead be ordered
  +   * alphabetically.</p>
  +   *
  +   * @param b
  +   */
  +  public void setOrderPropertiesBySource(boolean b) {
  +    mOrderPropertiesBySource = b;
  +  }
  +
     public void setCompileSources(boolean ignoredRightNow) {}
   
     public void setCopySources(boolean ignoredRightNow) {}
  @@ -148,7 +161,9 @@
       } catch(IOException ioe) {
         throw new BuildException(ioe);
       }
  -    return new Java2Schema(service.getAllClasses());
  +    Java2Schema out = new Java2Schema(service.getAllClasses());
  +    out.setOrderPropertiesBySource(mOrderPropertiesBySource);
  +    return out;
     }
   
     // ========================================================================
  
  
  
  1.2       +2 -2      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/Java2SchemaAnnotationHelper.java
  
  Index: Java2SchemaAnnotationHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/Java2SchemaAnnotationHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Java2SchemaAnnotationHelper.java	24 Jun 2004 05:30:01 -0000	1.1
  +++ Java2SchemaAnnotationHelper.java	28 Jun 2004 21:11:38 -0000	1.2
  @@ -21,7 +21,7 @@
   import org.apache.xmlbeans.impl.jam.JAnnotationValue;
   import org.apache.xmlbeans.impl.binding.compile.internal.annotations.ClassBindingInfo;
   import org.apache.xmlbeans.impl.binding.compile.internal.annotations.TypeTarget;
  -import org.apache.xmlbeans.impl.binding.compile.internal.annotations.ElementTarget;
  +import org.apache.xmlbeans.impl.binding.compile.internal.annotations.TopLevelElementTarget;
   import org.apache.xmlbeans.impl.binding.compile.Java2Schema;
   
   import javax.xml.namespace.QName;
  @@ -73,7 +73,7 @@
         if (info != null) {
           TypeTarget tt = info.getDefaultTargetType();
           if (tt != null) {
  -          ElementTarget[] e = tt.getTopLevelElements();
  +          TopLevelElementTarget[] e = tt.getTopLevelElements();
             if (e != null && e.length > 0) {
               if (list == null) list = new ArrayList();
               for(int i=0; i<e.length; i++) {
  
  
  
  1.2       +19 -0     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations/ElementTarget.java
  
  Index: ElementTarget.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations/ElementTarget.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElementTarget.java	24 Jun 2004 05:30:01 -0000	1.1
  +++ ElementTarget.java	28 Jun 2004 21:11:38 -0000	1.2
  @@ -22,11 +22,30 @@
   public class ElementTarget extends NamedTarget {
   
     // ========================================================================
  +  // Variables
  +
  +  private boolean mRequired;
  +  private boolean mAttribute;
  +  private boolean mNillable;
  +  private boolean mExclude;
  +
  +  // ========================================================================
     // Constructors
   
     public ElementTarget(QName qn) { super(qn); }
   
     public ElementTarget(String ns, String local) { super(ns,local); }
  +
  +  // ========================================================================
  +  // Public methods
  +
  +  public boolean isRequired() { return mRequired; }
  +
  +  public boolean isAttribute() { return mAttribute; }
  +
  +  public boolean isNillable() { return mNillable; }
  +
  +  public boolean isExclude() { return mExclude; }
   
   
   }
  
  
  
  1.2       +3 -3      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations/TypeTarget.java
  
  Index: TypeTarget.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations/TypeTarget.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeTarget.java	24 Jun 2004 05:30:01 -0000	1.1
  +++ TypeTarget.java	28 Jun 2004 21:11:38 -0000	1.2
  @@ -47,9 +47,9 @@
     // ========================================================================
     // Accessors
   
  -  public ElementTarget[] getTopLevelElements() {
  +  public TopLevelElementTarget[] getTopLevelElements() {
       if (mTargetElements == null) return null;
  -    ElementTarget[] out = new ElementTarget[mTargetElements.size()];
  +    TopLevelElementTarget[] out = new TopLevelElementTarget[mTargetElements.size()];
       mTargetElements.toArray(out);
       return out;
     }
  @@ -61,7 +61,7 @@
   
     public void addNewTopLevelElement(QName qn) {
       if (mTargetElements == null) mTargetElements = new ArrayList();
  -    mTargetElements.add(new ElementTarget(qn));
  +    mTargetElements.add(new TopLevelElementTarget(qn));
     }
   
     public void setIgnoreJavaInheritance(boolean b) { mIgnoreInheritance = b; }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/internal/annotations/TopLevelElementTarget.java
  
  Index: TopLevelElementTarget.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.internal.annotations;
  
  import javax.xml.namespace.QName;
  
  /**
   * @author Patrick Calahan &lt;email: pcal-at-bea-dot-com&gt;
   */
  public class TopLevelElementTarget extends NamedTarget {
  
    // ========================================================================
    // Constructors
  
    public TopLevelElementTarget(QName qn) { super(qn); }
  
    public TopLevelElementTarget(String ns, String local) { super(ns,local); }
  
  }
  
  
  

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