You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2004/04/15 22:49:17 UTC

cvs commit: xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema StscComplexTypeResolver.java

pcal        2004/04/15 13:49:17

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompilerTask.java Java2Schema.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        DefaultTylarLoader.java ExplodedTylarImpl.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/schema
                        StscComplexTypeResolver.java
  Log:
  fix NPE in StscComplexTypeResolver, fix j2s to generate multiple schemas correctly
  
  Revision  Changes    Path
  1.12      +2 -2      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompilerTask.java
  
  Index: BindingCompilerTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompilerTask.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BindingCompilerTask.java	8 Apr 2004 20:01:00 -0000	1.11
  +++ BindingCompilerTask.java	15 Apr 2004 20:49:17 -0000	1.12
  @@ -139,8 +139,8 @@
         (file, SchemaDocument.type, options);
     }
   
  -  protected static SchemaTypeSystem createSchemaTypeSystem(SchemaDocument[] xsds)
  -    throws IOException, XmlException
  +  public static SchemaTypeSystem createSchemaTypeSystem(SchemaDocument[] xsds)
  +    throws XmlException
     {
       SchemaTypeLoader soapencLoader = org.apache.xmlbeans.impl.schema.SoapEncSchemaTypeSystem.get();
       SchemaTypeLoader xsdLoader = XmlBeans.getBuiltinTypeSystem();
  
  
  
  1.49      +61 -29    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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- Java2Schema.java	8 Apr 2004 20:01:01 -0000	1.48
  +++ Java2Schema.java	15 Apr 2004 20:49:17 -0000	1.49
  @@ -17,11 +17,11 @@
   
   import org.apache.xmlbeans.impl.binding.bts.*;
   import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
  +import org.apache.xmlbeans.impl.binding.tylar.TylarConstants;
  +import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
   import org.apache.xmlbeans.impl.jam.*;
   import org.apache.xmlbeans.impl.common.XMLChar;
  -import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.SchemaTypeSystem;
  -import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlException;
   import org.w3.x2001.xmlSchema.*;
   import javax.xml.namespace.QName;
  @@ -29,6 +29,7 @@
   import java.util.List;
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.Collection;
   import java.io.IOException;
   import java.io.StringWriter;
   
  @@ -76,12 +77,17 @@
     // =========================================================================
     // 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
  +  // the bindings that we're building up
  +  private BindingFile mBindingFile;
  +
  +  // the full loader: bindingFile + baseLoader
  +  private BindingLoader mLoader;
  +
  +  // maps a targetnamespace (string) to a schemadocument that we are creating
  +  private Map mTns2Schemadoc = new HashMap();
  +
  +  // the input classes
  +  private JClass[] mClasses;
   
     // =========================================================================
     // Constructors
  @@ -104,13 +110,6 @@
       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)) {
  @@ -118,28 +117,60 @@
         }
       }
       //
  +    SchemaDocument[] xsds = null;
       try {
         writer.writeBindingFile(mBindingFile);
         //REVIEW maybe we should just include the schema and let super class write it out?
  -      writer.writeSchema(mSchemaDocument,"schema-0.xsd");
  +      xsds = getGeneratedSchemaDocuments();
  +      for(int i=0; i<xsds.length; i++) {
  +        writer.writeSchema(xsds[i],"schema-"+i+".xsd");
  +      }
       } catch(IOException ioe) {
         logError(ioe);
       }
  -    try {
  -      SchemaTypeSystem sts = XmlBeans.compileXsd
  -        (new XmlObject[] {mSchemaDocument},XmlBeans.getBuiltinTypeSystem(),null);
  -      writer.writeSchemaTypeSystem(sts);
  -    } catch(IOException ioe) {
  -      //logError(ioe); ignore for now
  -    } catch(XmlException xe) {
  -      //logError(xe);  ignore for now
  +    SchemaTypeSystem sts = null;
  +    {
  +      try {
  +        sts = Schema2JavaTask.createSchemaTypeSystem(xsds);
  +        if (sts == null) {
  +          throw new IllegalStateException("createSchemaTypeSystem returned null");
  +        }
  +      } catch(XmlException xe) {
  +        ExplodedTylarImpl.showXsbError(xe,null,"write",TylarConstants.SHOW_XSB_ERRORS || isVerbose());
  +      }
  +      if (sts != null) {
  +        try {
  +          writer.writeSchemaTypeSystem(sts);
  +        } catch(IOException ioe) {
  +          ExplodedTylarImpl.showXsbError(ioe,null,"compile",TylarConstants.SHOW_XSB_ERRORS || isVerbose());
  +        }
  +      }
       }
  -
     }
   
     // ========================================================================
     // Private methods
   
  +  private SchemaDocument.Schema findOrCreateSchema(String tns) {
  +    if (tns == null) throw new IllegalArgumentException();
  +    tns = tns.trim();
  +    SchemaDocument doc = (SchemaDocument)mTns2Schemadoc.get(tns);
  +    if (doc == null) {
  +      doc = SchemaDocument.Factory.newInstance();
  +      doc.addNewSchema().setTargetNamespace(tns);
  +      mTns2Schemadoc.put(tns,doc);
  +    }
  +    return doc.getSchema();
  +  }
  +
  +  private SchemaDocument[] getGeneratedSchemaDocuments() {
  +    Collection list = mTns2Schemadoc.values();
  +    SchemaDocument[] out = new SchemaDocument[list.size()];
  +    list.toArray(out);
  +    return out;
  +  }
  +
  +
     /**
      * Returns a bts BindingType for the given JClass.  If such a type
      * has not yet been registered with the loader, it will be created.
  @@ -164,7 +195,8 @@
      */
     private BindingType createBindingTypeFor(JClass clazz) {
       // create the schema type
  -    TopLevelComplexType xsType = mSchema.addNewComplexType();
  +    SchemaDocument.Schema schema = findOrCreateSchema(getTargetNamespace(clazz));
  +    TopLevelComplexType xsType = schema.addNewComplexType();
       String tns = getTargetNamespace(clazz);
       String xsdName = getAnnotation(clazz,TAG_CT_TYPENAME,clazz.getSimpleName());
       QName qname = new QName(tns,xsdName);
  @@ -174,11 +206,11 @@
       // we have to remember whether we created an ExtensionType because that
       // is where the sequence of properties have to go - note that this
       // gets passed into the SchemaPropertyFacade created below.  It's
  -    // unforuntante that the SchemaDocument model does not allow us to deal
  +    // unfortunate that the SchemaDocument model does not allow us to deal
       // with this kind of thing in a more elegant and polymorphic way.
       ExtensionType extType = null;
       if (superclass != null && !superclass.isObjectType() &&
  -            !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();
  @@ -214,7 +246,7 @@
       // 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();
  +      TopLevelElement root = schema.addNewElement();
         root.setName(makeNcNameSafe(anns[i].getValue
                                     (JAnnotation.SINGLE_VALUE_NAME).asString()));
         root.setType(qname);
  
  
  
  1.12      +1 -7      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java
  
  Index: DefaultTylarLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultTylarLoader.java	15 Apr 2004 01:50:06 -0000	1.11
  +++ DefaultTylarLoader.java	15 Apr 2004 20:49:17 -0000	1.12
  @@ -212,13 +212,7 @@
             if (sts == null) throw new IllegalStateException("null returned by SchemaTypeSystemImpl.forName()");
             if (VERBOSE) System.out.println("successfully loaded schema type system");
           } catch(Exception e) {
  -          System.out.println
  -            ("[XBEANS] Notice: an unexpected error occurred while trying to read\n " +
  -             "a binary version of your schemas from "+source+".\n"+
  -             "Your bindings were still loaded, but you may have suffered some " +
  -             "performance degradation if your schemas are very large or " +
  -             "complicated.\n"+e.getMessage());
  -          if (SHOW_XSB_ERRORS) e.printStackTrace();
  +          ExplodedTylarImpl.showXsbError(e,source,"read",TylarConstants.SHOW_XSB_ERRORS);
           }
         }
       }
  
  
  
  1.14      +22 -13    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java
  
  Index: ExplodedTylarImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ExplodedTylarImpl.java	15 Apr 2004 01:50:06 -0000	1.13
  +++ ExplodedTylarImpl.java	15 Apr 2004 20:49:17 -0000	1.14
  @@ -131,13 +131,7 @@
           if (VERBOSE) System.out.println
             ("[XBEANS] loaded schema type system '"+stsName+"'");
         } catch(Exception e) {
  -        System.out.println
  -          ("[XBEANS] Notice: an unexpected error occurred while trying to read\n " +
  -           "a binary version of your schemas from "+dir+".\n"+
  -           "Your bindings were still loaded, but you may have suffered some " +
  -           "performance degradation if your schemas are very large or " +
  -           "complicated.\n"+e.getMessage());
  -        if (SHOW_XSB_ERRORS) e.printStackTrace();
  +        showXsbError(e,dir.toURI(),"read",TylarConstants.SHOW_XSB_ERRORS);
         }
       }
   
  @@ -192,12 +186,7 @@
                                            mRootDir,
                                            null,null,null);
       } catch(Exception e) {
  -      System.out.println
  -        ("[XBEANS] Notice: an unexpected error occurred while trying to save\n " +
  -         "a binary version of your schemas.  Your bindings are still\n "+
  -         "ok, but you may suffer some performance degradation if your schemas\n "+
  -         "are very large or complicated.\n"+e.getMessage());
  -      if (VERBOSE) e.printStackTrace();
  +      showXsbError(e,mRootDir.toURI(),"write",TylarConstants.SHOW_XSB_ERRORS);
       }
     }
   
  @@ -207,6 +196,26 @@
   
     public void close() throws IOException {
       if (mJoust != null) mJoust.close();
  +  }
  +
  +
  +  // ========================================================================
  +  // Public static methods
  +
  +  public static void showXsbError(Throwable e,
  +                                  URI where,
  +                                  String readOrWrite,
  +                                  boolean showTrace)
  +  {
  +    System.out.println
  +      ("[XBEANS] Notice: an unexpected error occurred while trying to\n "+
  +       readOrWrite+" a binary version of your schemas"+
  +       ((where == null) ? "." : " at\n"+where+"\n")+
  +       "\nYour bindings are ok, but you may suffer some performance\n" +
  +       "degradation if your schemas are very large or complicated.\n"+
  +       "(exception is "+e.getClass()+", message is '"+e.getMessage()+"'");
  +    if (showTrace) e.printStackTrace();
  +    System.out.flush();
     }
   
     // ========================================================================
  
  
  
  1.3       +1 -1      xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
  
  Index: StscComplexTypeResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StscComplexTypeResolver.java	12 Feb 2004 20:06:21 -0000	1.2
  +++ StscComplexTypeResolver.java	15 Apr 2004 20:49:17 -0000	1.3
  @@ -522,7 +522,7 @@
           
           // apply rule #2 near http://www.w3.org/TR/xmlschema-1/#c-mve: empty ext model -> mixed taken from base
           if (extensionModel == null && !mixed)
  -            mixed = (baseType.getContentType() == SchemaType.MIXED_CONTENT);
  +            mixed = (baseType != null && baseType.getContentType() == SchemaType.MIXED_CONTENT);
           
           // apply Derivation Valid (Extension) rule 1.4.2.2
           if (baseType != null && (baseType.getContentType() != SchemaType.EMPTY_CONTENT) &&
  
  
  

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