You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2004/08/14 04:02:32 UTC

cvs commit: xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool CommandLine.java

cezar       2004/08/13 19:02:32

  Modified:    v2       build.xml
               v2/src/tools/org/apache/xmlbeans/impl/inst2xsd Inst2Xsd.java
                        Inst2XsdOptions.java RussianDollStrategy.java
                        SalamiSliceStrategy.java VenetianBlindStrategy.java
               v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util
                        Element.java TypeSystemHolder.java
               v2/src/xmlcomp/org/apache/xmlbeans/impl/tool
                        CommandLine.java
  Added:       v2/bin   inst2xsd inst2xsd.cmd
  Log:
  Command line for inst2xsd plus some fixes.
  
  checkintests: pass
  
  Revision  Changes    Path
  1.83      +2 -1      xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- build.xml	11 Aug 2004 03:02:41 -0000	1.82
  +++ build.xml	14 Aug 2004 02:02:31 -0000	1.83
  @@ -525,7 +525,7 @@
   
       <target name="tools.classes"
             depends="dirs, common.classes, xmlpublic.classes, typestore.classes, saaj_api.classes, piccolo.classes,
  -          typeimpl.classes">
  +          typeimpl.classes, xmlcomp.classes">
         <mkdir dir="build/classes/tools"/>
         <javac srcdir="src/tools" destdir="build/classes/tools" source="${javac.source}" target="${javac.target}" debug="on">
           <classpath id="tools.compile.path">
  @@ -537,6 +537,7 @@
             <pathelement location="build/classes/saaj_api"/>
             <pathelement location="build/classes/piccolo"/>
             <pathelement location="build/classes/typeimpl"/>
  +          <pathelement location="build/classes/xmlcomp"/>
           </classpath>
         </javac>
   
  
  
  
  1.1                  xml-xmlbeans/v2/bin/inst2xsd
  
  Index: inst2xsd
  ===================================================================
  #!/bin/sh
  
  #Instance to Schema tool
  #Builds xsd files from xml instance files.
  
  cp=
  cp=$cp:$XMLBEANS_HOME/build/ar/xbean.jar:$XMLBEANS_HOME/build/lib/jsr173_api.jar:$XMLBEANS_HOME/build/lib/resolver.jar
  
  case "`uname`" in
      CYGWIN*)
          cp=`cygpath -w -p $cp`
          ;;
  esac
  
  java -classpath $cp org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd $*
  
  
  
  1.1                  xml-xmlbeans/v2/bin/inst2xsd.cmd
  
  Index: inst2xsd.cmd
  ===================================================================
  @rem Instance to Schema tool
  @rem
  @rem Builds xsd files from xml instance files.
  
  @echo off
  
  setlocal
  if "%XMLBEANS_HOME%" EQU "" (set XMLBEANS_HOME=%~dp0..)
  
  set cp=
  set cp=%cp%;%XMLBEANS_HOME%\build\ar\xbean.jar
  set cp=%cp%;%XMLBEANS_HOME%\build\lib\jsr173_api.jar
  set cp=%cp%;%XMLBEANS_HOME%\build\lib\resolver.jar
  
  java -classpath %cp% org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd %*
  
  :done
  
  
  
  1.2       +165 -22   xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java
  
  Index: Inst2Xsd.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Inst2Xsd.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ Inst2Xsd.java	14 Aug 2004 02:02:31 -0000	1.2
  @@ -19,16 +19,19 @@
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlOptions;
  +import org.apache.xmlbeans.XmlError;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   import org.apache.xmlbeans.impl.inst2xsd.util.TypeSystemHolder;
  +import org.apache.xmlbeans.impl.tool.CommandLine;
   
   import java.io.File;
  -import java.io.FileReader;
   import java.io.IOException;
   import java.io.Reader;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.Set;
  +import java.util.HashSet;
   
   /**
    * @author Cezar Andrei (cezar.andrei at bea.com) Date: Jul 16, 2004
  @@ -37,27 +40,169 @@
    *
    * How it works:
    *  - first: pass through all the instances, building a TypeSystemHolder structure
  - *  - second: serialize the TypeSystemHolder structure into   
  + *  - second: serialize the TypeSystemHolder structure into SchemaDocuments
    */
   public class Inst2Xsd
   {
       public static void main(String[] args)
           throws IOException, XmlException
       {
  -        if (args.length != 1)
  +        if (args.length == 0)
           {
  -            System.out.println("Usage: Inst2xsd instance.xml");
  +            printHelp();
  +            System.exit(0);
               return;
           }
   
  -        File instFile = new File(args[0]);
  +        Set opts = new HashSet();
  +        opts.add("design");
  +        opts.add("simple-content-types");
  +        opts.add("enumerations");
  +        opts.add("outDir");
  +        opts.add("outPrefix");
  +
  +        CommandLine cl = new CommandLine(args, opts);
           Inst2XsdOptions inst2XsdOptions = new Inst2XsdOptions();
  -        inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_VENETIAN_BLIND);
  -        SchemaDocument[] schemas = inst2xsd(new Reader[] {new FileReader(instFile)}, inst2XsdOptions);
  +
  +        if (cl.getOpt("license") != null)
  +        {
  +            CommandLine.printLicense();
  +            System.exit(0);
  +            return;
  +        }
  +
  +        if (cl.getOpt("help") != null)
  +        {
  +            printHelp();
  +            System.exit(0);
  +            return;
  +        }
  +
  +        String design = cl.getOpt("design");
  +        if (design==null)
  +        {
  +            // default
  +        }
  +        else if (design.equals("vb"))
  +        {
  +            inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_VENETIAN_BLIND);
  +        }
  +        else if (design.equals("rd"))
  +        {
  +            inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_RUSSIAN_DOLL);
  +        }
  +        else if (design.equals("ss"))
  +        {
  +            inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_SALAMI_SLICE);
  +        }
  +        else
  +        {
  +            printHelp();
  +            System.exit(0);
  +            return;
  +        }
  +
  +        String simpleContent = cl.getOpt("simple-content-types");
  +        if (simpleContent==null)
  +        {
  +            //default
  +        }
  +        else if (simpleContent.equals("smart"))
  +        {
  +            inst2XsdOptions.setSimpleContentTypes(Inst2XsdOptions.SIMPLE_CONTENT_TYPES_SMART);
  +        }
  +        else if (simpleContent.equals("string"))
  +        {
  +            inst2XsdOptions.setSimpleContentTypes(Inst2XsdOptions.SIMPLE_CONTENT_TYPES_STRING);
  +        }
  +        else
  +        {
  +            printHelp();
  +            System.exit(0);
  +            return;
  +        }
  +
  +        String enumerations = cl.getOpt("enumerations");
  +        if (enumerations==null)
  +        {
  +            // default
  +        }
  +        else if (enumerations.equals("never"))
  +        {
  +            inst2XsdOptions.setUseEnumerations(Inst2XsdOptions.ENUMERATION_NEVER);
  +        }
  +        else
  +        {
  +            try
  +            {
  +                int intVal = Integer.parseInt(enumerations);
  +                inst2XsdOptions.setUseEnumerations(intVal);
  +            }
  +            catch (NumberFormatException e)
  +            {
  +                printHelp();
  +                System.exit(0);
  +                return;
  +            }
  +        }
  +
  +        File outDir = new File( cl.getOpt("outDir")==null ? "." : cl.getOpt("outDir"));
  +
  +        String outPrefix = cl.getOpt("outPrefix");
  +        if (outPrefix==null)
  +            outPrefix = "schema";
  +
  +        inst2XsdOptions.setVerbose((cl.getOpt("verbose") != null));
  +        boolean validate = cl.getOpt("validate")!=null;
  +
  +        File[] xmlFiles = cl.filesEndingWith(".xml");
  +        XmlObject[] xmlInstances = new XmlObject[xmlFiles.length];
  +        for (int i = 0; i < xmlFiles.length; i++)
  +        {
  +            xmlInstances[i] = XmlObject.Factory.parse(xmlFiles[i]);
  +        }
  +
  +        SchemaDocument[] schemaDocs = inst2xsd(xmlInstances, inst2XsdOptions);
  +
  +        for (int i = 0; i < schemaDocs.length; i++)
  +        {
  +            SchemaDocument schema = schemaDocs[i];
  +
  +            if (inst2XsdOptions.isVerbose())
  +                System.out.println("----------------------\n\n" + schema);
  +
  +            schema.save(new File(outDir, outPrefix + i + ".xsd"), new XmlOptions().setSavePrettyPrint());
  +        }
  +
  +        if (validate)
  +        {
  +            validateInstances(schemaDocs, xmlInstances);
  +        }
  +    }
  +
  +    private static void printHelp()
  +    {
  +        System.out.println("Generates XMLSchema from instance xml documents.");
  +        System.out.println("Usage: inst2xsd [opts] [instance.xml]*");
  +        System.out.println("Options include:");
  +        System.out.println("    -design [rd|ss|vb] - XMLSchema design type");
  +        System.out.println("             rd  - Russian Doll Design - local elements and local types");
  +        System.out.println("             ss  - Salami Slice Design - global elements and local types");
  +        System.out.println("             vb  - Venetian Blind Design (default) - local elements and global complex types");
  +        System.out.println("    -simple-content-types [smart|string] - Simple content types detection (leaf text). Smart is the default");
  +        System.out.println("    -enumerations [never|NUMBER] - Use enumerations. Default value is " + Inst2XsdOptions.ENUMERATION_NOT_MORE_THAN_DEFAULT + ".");
  +        System.out.println("    -outDir [dir] - Directory for output files. Default is '.'");
  +        System.out.println("    -outPrefix [file_name_prefix] - Prefix for output file names. Default is 'schema'");
  +        System.out.println("    -validate - Validates input instances agaist generated schemas.");
  +        System.out.println("    -verbose - print more informational messages");
  +        System.out.println("    -license - print license information");
  +        System.out.println("    -help - help imformation");
       }
   
       private Inst2Xsd() {}
   
  +    // public entry points
  +
       public static SchemaDocument[] inst2xsd(Reader[] instReaders, Inst2XsdOptions options)
           throws IOException, XmlException
       {
  @@ -98,16 +243,10 @@
           // processDoc the instance
           strategy.processDoc(instances, options, typeSystemHolder);
   
  -        // debug only
  -        //System.out.println("typeSystemHolder.toString(): " + typeSystemHolder);
  -        SchemaDocument[] sDocs = typeSystemHolder.getSchemaDocuments();
  +        if (options.isVerbose())
  +            System.out.println("typeSystemHolder.toString(): " + typeSystemHolder);
   
  -        for (int i = 0; i < sDocs.length; i++)
  -        {
  -            System.out.println("--------------------\n\n" + sDocs[i] );
  -        }
  -        assert validateInstances(sDocs, instances);
  -        // end debug only
  +        SchemaDocument[] sDocs = typeSystemHolder.getSchemaDocuments();
   
           return sDocs;
       }
  @@ -128,12 +267,16 @@
               {
                   e.printStackTrace(System.out);
               }
  -            System.out.println("Schema invalid");
  +            System.out.println("\n-------------------\n\nInvalid schemas.");
               for (Iterator errors = compErrors.iterator(); errors.hasNext(); )
  -                System.out.println(errors.next());
  +            {
  +                XmlError xe = (XmlError)errors.next();
  +                System.out.println(xe.getLine() + ":" + xe.getColumn() + " " + xe.getMessage());
  +            }
               return false;
           }
   
  +        System.out.println("\n-------------------");
           boolean result = true;
   
           for (int i = 0; i < instances.length; i++)
  @@ -163,13 +306,14 @@
                   result = false;
               }
               else if (xobj.validate(new XmlOptions().setErrorListener(errors)))
  -                System.out.println("Instance[" + i + "] valid.");
  +                System.out.println("Instance[" + i + "] valid - " + instances[i].documentProperties().getSourceName());
               else
               {
  -                System.out.println("Instance[" + i + "] NOT valid.");
  +                System.out.println("Instance[" + i + "] NOT valid - " + instances[i].documentProperties().getSourceName());
                   for (Iterator it = errors.iterator(); it.hasNext(); )
                   {
  -                    System.out.println("    " + it.next());
  +                    XmlError xe = (XmlError)it.next();
  +                    System.out.println(xe.getLine() + ":" + xe.getColumn() + " " + xe.getMessage());
                   }
                   result = false;
               }
  @@ -177,5 +321,4 @@
   
           return result;
       }
  -
   }
  
  
  
  1.2       +22 -4     xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/Inst2XsdOptions.java
  
  Index: Inst2XsdOptions.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/Inst2XsdOptions.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Inst2XsdOptions.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ Inst2XsdOptions.java	14 Aug 2004 02:02:31 -0000	1.2
  @@ -19,9 +19,9 @@
   
        Options:
          * Design
  -          o Russian Doll Design
  -          o Salami Slice Design
  -          o Venetian Blind Design
  +          o Russian Doll Design - local elements and local types
  +          o Salami Slice Design - global elements and local types
  +          o Venetian Blind Design - local elements and global complex types
          * Simple content types (leafs)
             o smart (default) - try to find out the right simple shema type
             o always xsd:string
  @@ -36,7 +36,7 @@
       public static final int DESIGN_SALAMI_SLICE   = 2;
       public static final int DESIGN_VENETIAN_BLIND = 3;
   
  -    private int _design = DESIGN_RUSSIAN_DOLL;
  +    private int _design = DESIGN_VENETIAN_BLIND;
   
       // schema type for simple content values
       public static final int SIMPLE_CONTENT_TYPES_SMART  = 1;
  @@ -50,6 +50,8 @@
   
       private int _enumerations = ENUMERATION_NOT_MORE_THAN_DEFAULT;
   
  +    private boolean _verbose = false;
  +
   
       public int getDesign()
       {
  @@ -68,6 +70,8 @@
        */
       public void setDesign(int designType)
       {
  +        if (designType!=DESIGN_RUSSIAN_DOLL && designType!=DESIGN_SALAMI_SLICE && designType!=DESIGN_VENETIAN_BLIND)
  +            throw new IllegalArgumentException("Unknown value for design type.");
           _design = designType;
       }
   
  @@ -83,6 +87,8 @@
   
       public void setUseEnumerations(int useEnumerations)
       {
  +        if (useEnumerations<ENUMERATION_NEVER)
  +            throw new IllegalArgumentException("UseEnumerations must be set to a value bigger than " + ENUMERATION_NEVER);
           _enumerations = useEnumerations;
       }
   
  @@ -93,6 +99,18 @@
   
       public void setSimpleContentTypes(int simpleContentTypes)
       {
  +        if (simpleContentTypes!=SIMPLE_CONTENT_TYPES_SMART && simpleContentTypes!=SIMPLE_CONTENT_TYPES_STRING)
  +            throw new IllegalArgumentException("Unknown value for simpleContentTypes.");
           _simpleContentTypes = simpleContentTypes;
  +    }
  +
  +    public boolean isVerbose()
  +    {
  +        return _verbose;
  +    }
  +
  +    public void setVerbose(boolean verbose)
  +    {
  +        _verbose = verbose;
       }
   }
  
  
  
  1.2       +52 -19    xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
  
  Index: RussianDollStrategy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RussianDollStrategy.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ RussianDollStrategy.java	14 Aug 2004 02:02:31 -0000	1.2
  @@ -35,6 +35,11 @@
   public class RussianDollStrategy
       implements XsdGenStrategy
   {
  +    static final String _xsi         = "http://www.w3.org/2001/XMLSchema-instance";
  +
  +    static final QName _xsiNil          = new QName( _xsi, "nil", "xsi" );
  +    static final QName _xsiType         = new QName( _xsi, "type", "xsi" );
  +
       public void processDoc(XmlObject[] instances, Inst2XsdOptions options, TypeSystemHolder typeSystemHolder)
       {
           for (int i = 0; i < instances.length; i++)
  @@ -56,15 +61,25 @@
               Element withElem = processElement(xc, comment.toString(), options, typeSystemHolder);
               withElem.setGlobal(true);
   
  -            Element intoElem = typeSystemHolder.getGlobalElement(withElem.getName());
  +            addGlobalElement(withElem, typeSystemHolder, options);
  +        }
  +    }
   
  -            if (intoElem==null)
  -                typeSystemHolder.addGlobalElement(withElem);
  -            else
  -            {
  -                combineTypes(intoElem.getType(), withElem.getType(), options);
  -                combineElementComments(intoElem, withElem);
  -            }
  +    protected Element addGlobalElement(Element withElem, TypeSystemHolder typeSystemHolder, Inst2XsdOptions options)
  +    {
  +        assert withElem.isGlobal();
  +        Element intoElem = typeSystemHolder.getGlobalElement(withElem.getName());
  +
  +        if (intoElem==null)
  +        {
  +            typeSystemHolder.addGlobalElement(withElem);
  +            return withElem;
  +        }
  +        else
  +        {
  +            combineTypes(intoElem.getType(), withElem.getType(), options);
  +            combineElementComments(intoElem, withElem);
  +            return intoElem;
           }
       }
   
  @@ -91,7 +106,11 @@
               {
                   case XmlCursor.TokenType.INT_ATTR:
                       // todo check for xsi:type
  -                    attributes.add(processAttribute(xc, options, element.getName().getNamespaceURI(), typeSystemHolder));
  +                    // ignore xsi:type and xsi:nil atributes
  +                    QName attName = xc.getName();
  +                    if (!_xsiNil.equals(attName) && !_xsiType.equals(attName))
  +                        attributes.add(processAttribute(xc, options, element.getName().getNamespaceURI(), typeSystemHolder));
  +
                       break;
   
                   case XmlCursor.TokenType.INT_START:
  @@ -108,7 +127,7 @@
                       break;
   
                   case XmlCursor.TokenType.INT_NAMESPACE:
  -                    // ignore for now,
  +                    // ignore,
                       // each element and attribute will take care to define itself in the right targetNamespace
                       break;
   
  @@ -200,7 +219,7 @@
   
               if (currentElem==null)
               {   // first element in this type
  -                checkIfElementReferenceIsNeeded(child, parentNamespace, typeSystemHolder);
  +                checkIfElementReferenceIsNeeded(child, parentNamespace, typeSystemHolder, options);
                   elemType.addElement(child);
                   elemNamesToElements.put(child.getName(), child);
                   currentElem = child;
  @@ -220,7 +239,7 @@
                   Element sameElem = (Element)elemNamesToElements.get(child.getName());
                   if (sameElem==null)
                   {   // new element name
  -                    checkIfElementReferenceIsNeeded(child, parentNamespace, typeSystemHolder);
  +                    checkIfElementReferenceIsNeeded(child, parentNamespace, typeSystemHolder, options);
                       elemType.addElement(child);
                       elemNamesToElements.put(child.getName(), child);
                   }
  @@ -235,7 +254,8 @@
           }
       }
   
  -    protected void checkIfElementReferenceIsNeeded(Element child, String parentNamespace, TypeSystemHolder typeSystemHolder)
  +    protected void checkIfElementReferenceIsNeeded(Element child, String parentNamespace,
  +        TypeSystemHolder typeSystemHolder, Inst2XsdOptions options)
       {
           if (!child.getName().getNamespaceURI().equals(parentNamespace))
           {
  @@ -244,7 +264,7 @@
               referencedElem.setName(child.getName());
               referencedElem.setType(child.getType());
   
  -            typeSystemHolder.addGlobalElement(referencedElem);
  +            referencedElem = addGlobalElement(referencedElem, typeSystemHolder, options);
   
               child.setRef(referencedElem); // clears child's type
           }
  @@ -451,8 +471,16 @@
           return XmlString.type.getName();
       }
   
  +
       protected void combineTypes(Type into, Type with, Inst2XsdOptions options)
       {
  +        if (into==with)
  +            return;
  +
  +        if (into.isGlobal() && with.isGlobal() && into.getName().equals(with.getName()))
  +            return;
  +
  +
           if (into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT &&
               with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT)
           {
  @@ -465,13 +493,13 @@
               (with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
               with.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT) )
           {
  -            //complex type simple content
  -            into.setContentType(Type.COMPLEX_TYPE_SIMPLE_CONTENT);
  -
               // take the extension name if it's a complex type
               QName intoTypeName = into.isComplexType() ? into.getExtensionType().getName() : into.getName();
               QName withTypeName = with.isComplexType() ? with.getExtensionType().getName() : with.getName();
   
  +            //complex type simple content
  +            into.setContentType(Type.COMPLEX_TYPE_SIMPLE_CONTENT);
  +
               QName moreGeneralTypeName = combineToMoreGeneralSimpleType(intoTypeName, withTypeName);
               if (into.isComplexType())
               {
  @@ -528,7 +556,6 @@
               with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT) : "Invalid arguments";
   
           //simple type simple content
  -
           into.setName(combineToMoreGeneralSimpleType(into.getName(), with.getName()));
   
           // take care of enumeration values
  @@ -646,6 +673,10 @@
               for (int j = 0; j < into.getElements().size(); j++)
               {
                   Element intoElem = (Element)into.getElements().get(j);
  +
  +                if (intoElem==fromElem)
  +                    continue outterLoop;
  +
                   if (intoElem.getName().equals(fromElem.getName()))
                   {
                       combineTypes(intoElem.getType(), fromElem.getType(), options);
  @@ -658,6 +689,8 @@
               }
               // fromElem doesn't exist in into type, will add it right now
               into.addElement(fromElem);
  +            fromElem.setMinOccurs(0);
  +            fromElem.setMaxOccurs(Element.UNBOUNDED);
           }
   
           // for all the elements that are in into and not in from they need to be optional
  @@ -688,7 +721,7 @@
   
       protected void combineElementComments(Element into, Element with)
       {
  -        if (with.getComment()!=null || with.getComment().length()>0)
  +        if (with.getComment()!=null && with.getComment().length()>0)
           {
               if (into.getComment()==null)
                   into.setComment(with.getComment());
  
  
  
  1.2       +3 -2      xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/SalamiSliceStrategy.java
  
  Index: SalamiSliceStrategy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/SalamiSliceStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SalamiSliceStrategy.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ SalamiSliceStrategy.java	14 Aug 2004 02:02:31 -0000	1.2
  @@ -25,7 +25,8 @@
       extends RussianDollStrategy
       implements XsdGenStrategy
   {
  -    protected void checkIfElementReferenceIsNeeded(Element child, String parentNamespace, TypeSystemHolder typeSystemHolder)
  +    protected void checkIfElementReferenceIsNeeded(Element child, String parentNamespace,
  +        TypeSystemHolder typeSystemHolder, Inst2XsdOptions options)
       {
           // always add element references
           Element referencedElem = new Element();
  @@ -33,7 +34,7 @@
           referencedElem.setName(child.getName());
           referencedElem.setType(child.getType());
   
  -        typeSystemHolder.addGlobalElement(referencedElem);
  +        referencedElem = addGlobalElement(referencedElem, typeSystemHolder, options);
   
           child.setRef(referencedElem); // clears child's type
       }
  
  
  
  1.2       +40 -9     xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/VenetianBlindStrategy.java
  
  Index: VenetianBlindStrategy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/VenetianBlindStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VenetianBlindStrategy.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ VenetianBlindStrategy.java	14 Aug 2004 02:02:31 -0000	1.2
  @@ -17,6 +17,7 @@
   import org.apache.xmlbeans.impl.inst2xsd.util.Element;
   import org.apache.xmlbeans.impl.inst2xsd.util.TypeSystemHolder;
   import org.apache.xmlbeans.impl.inst2xsd.util.Type;
  +import org.apache.xmlbeans.impl.inst2xsd.util.Attribute;
   
   import javax.xml.namespace.QName;
   
  @@ -54,7 +55,7 @@
                   }
                   else
                   {
  -                    if (compatibleTypes(elemType, candidate))
  +                    if (compatibleTypes(candidate, elemType))
                       {
                           combineTypes(candidate, elemType, options);
                           elem.setType(candidate);
  @@ -69,18 +70,48 @@
       {
           // when two types look like they are the same ?
   
  -        if (!elemType.isComplexType() && !candidate.isComplexType())
  +        if (elemType==candidate)
               return true;
   
  -        if (elemType.isComplexType() && !candidate.isComplexType())
  -            return false;
  -        if (!elemType.isComplexType() && candidate.isComplexType())
  -            return false;
  +//        if (typeIsReferencedInside(elemType, candidate) || typeIsReferencedInside(candidate, elemType))
  +//            return false;
  +//
  +//        if (!elemType.isComplexType() && !candidate.isComplexType())
  +//            return true;
  +//
  +//        if (elemType.isComplexType() && !candidate.isComplexType())
  +//            return false;
  +//        if (!elemType.isComplexType() && candidate.isComplexType())
  +//            return false;
  +//
  +//        // both complex after this point
  +//
  +//        //todo: be smarter: look at att and elem names and types - compute a difference index
   
  -        // both complex after this point
  +        return true;
  +    }
   
  -        //todo: be smarter: look at att and elem names and types - compute a difference index
  +    private boolean typeIsReferencedInside(Type entity, Type container)
  +    {
  +        for (int i = 0; i < container.getElements().size(); i++)
  +        {
  +            Element element = (Element) container.getElements().get(i);
  +            if (entity==element.getType())
  +                return true;
   
  -        return true;
  +            if (typeIsReferencedInside(entity, element.getType()))
  +                return true;
  +        }
  +
  +        for (int i = 0; i < container.getAttributes().size(); i++)
  +        {
  +            Attribute attribute = (Attribute) container.getAttributes().get(i);
  +            if (entity==attribute.getType())
  +                return true;
  +
  +            if (typeIsReferencedInside(entity, attribute.getType()))
  +                return true;
  +        }
  +        return false;
       }
   }
  
  
  
  1.2       +2 -1      xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/Element.java
  
  Index: Element.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/Element.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Element.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ Element.java	14 Aug 2004 02:02:32 -0000	1.2
  @@ -119,7 +119,8 @@
               ", _minOccurs = " + _minOccurs +
               ", _maxOccurs = " + _maxOccurs +
               ", _comment = " + _comment +
  -            ",\n    _type = " + _type +
  +            ",\n    _type = " + ( _type==null ? "null" :
  +                (_type.isGlobal() ? _type.getName().toString() : _type.toString())) +
               "\n  }";
       }
   }
  
  
  
  1.2       +5 -2      xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/TypeSystemHolder.java
  
  Index: TypeSystemHolder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/TypeSystemHolder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeSystemHolder.java	7 Aug 2004 20:10:15 -0000	1.1
  +++ TypeSystemHolder.java	14 Aug 2004 02:02:32 -0000	1.2
  @@ -300,6 +300,7 @@
               for (int i = 0; i < type.getElements().size(); i++)
               {
                   Element child = (Element) type.getElements().get(i);
  +                assert !child.isGlobal();
                   org.w3.x2001.xmlSchema.LocalElement childLocalElement = explicitGroup.addNewElement();
                   fillUpLocalElement(child, childLocalElement, tns);
               }
  @@ -354,7 +355,9 @@
       public String toString()
       {
           return "TypeSystemHolder{" +
  -            "_globalElements=" + _globalElements +
  -            "}";
  +            "\n\n_globalElements=" + _globalElements +
  +            "\n\n_globalAttributes=" + _globalAttributes +
  +            "\n\n_globalTypes=" + _globalTypes +
  +            "\n}";
       }
   }
  
  
  
  1.3       +2 -2      xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/CommandLine.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommandLine.java	12 Feb 2004 20:06:25 -0000	1.2
  +++ CommandLine.java	14 Aug 2004 02:02:32 -0000	1.3
  @@ -61,11 +61,11 @@
       {
           try
           {
  -            IOUtil.copyCompletely(CommandLine.class.getClassLoader().getResourceAsStream("license.txt"), System.out);
  +            IOUtil.copyCompletely(CommandLine.class.getClassLoader().getResourceAsStream("LICENSE.txt"), System.out);
           }
           catch (Exception e)
           {
  -            System.out.println("License available in this JAR in license.txt");
  +            System.out.println("License available in this JAR in LICENSE.txt");
           }
       }
   
  
  
  

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