xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daver...@apache.org
Subject cvs commit: xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool SchemaCodeGenerator.java
Date Sat, 10 Apr 2004 02:50:01 GMT
daveremy    2004/04/09 19:50:01

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Schema2Java.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/schema
                        SchemaTypeSystemImpl.java
               v2/src/xmlcomp/org/apache/xmlbeans/impl/tool
                        SchemaCodeGenerator.java
  Log:
  SchemaTypeSystem saver that does not depend on Java being generated.
  Contributed by Radu Preotiuc
  
  Revision  Changes    Path
  1.24      +3 -3      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java
  
  Index: Schema2Java.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Schema2Java.java	8 Apr 2004 20:01:01 -0000	1.23
  +++ Schema2Java.java	10 Apr 2004 02:50:01 -0000	1.24
  @@ -70,10 +70,10 @@
     // Constants
   
     private static String[] PRIMITIVE_TYPES =
  -  {"int", "boolean", "float", "long", "double", "short", "char"};
  +  {"int", "boolean", "float", "long", "double", "short", "byte", "char"};
     private static String[] BOXED_TYPES =
     {"java.lang.Integer", "java.lang.Boolean", "java.lang.Float",
  -   "java.lang.Long", "java.lang.Double", "java.lang.Short",
  +   "java.lang.Long", "java.lang.Double", "java.lang.Short", "java.lang.Byte",
      "java.lang.Character"};
     private static String WILDCARD_ELEMENT_MAPPING = "javax.xml.soap.SOAPElement";
     private static String WILDCARD_ATTRIBUTE_MAPPING = "javax.xml.soap.SOAPElement";
  @@ -1890,7 +1890,7 @@
         mJoust.writeStatement("int val = 0;");
         mJoust.writeStatement("for (int i = 0; i < " + instanceVarName + ".length; i++)
" +
           "{ val *= 19; val += " +
  -        enumHelper.getHashCode(instanceVarName).getMemento().toString() +
  +        enumHelper.getHashCode(instanceVarName + "[i]").getMemento().toString() +
           "; }");
         mJoust.writeStatement("return val");
       }
  
  
  
  1.7       +5 -2      xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
  
  Index: SchemaTypeSystemImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SchemaTypeSystemImpl.java	25 Feb 2004 18:56:50 -0000	1.6
  +++ SchemaTypeSystemImpl.java	10 Apr 2004 02:50:01 -0000	1.7
  @@ -1954,8 +1954,11 @@
                           impl.setContainerFieldIndex((short)2, readShort());
                           break;
                   }
  -                impl.setFullJavaName(readString());
  -                impl.setFullJavaImplName(readString());
  +                // TODO (radup) find the right solution here
  +                String jn = readString();
  +                impl.setFullJavaName(jn == null ? "" : jn);
  +                jn = readString();
  +                impl.setFullJavaImplName(jn == null? "" : jn);
   
                   impl.setAnonymousTypeRefs(readTypeRefArray());
   
  
  
  
  1.7       +55 -12    xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
  
  Index: SchemaCodeGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SchemaCodeGenerator.java	18 Mar 2004 23:28:00 -0000	1.6
  +++ SchemaCodeGenerator.java	10 Apr 2004 02:50:01 -0000	1.7
  @@ -17,6 +17,7 @@
   
   import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.SchemaTypeSystem;
  +import org.apache.xmlbeans.impl.common.IOUtil;
   import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
   import org.apache.xmlbeans.impl.schema.SchemaTypeCodePrinter;
   import org.apache.xmlbeans.SchemaCodePrinter;
  @@ -51,8 +52,6 @@
   
           boolean failure = false;
   
  -        saver.saveToDirectory(classesdir);
  -
           // Schema files already copyed when they where parsed
   //        if ((sourcesToCopyMap != null) && (sourcesToCopyMap.size() > 0))
   //        {
  @@ -102,16 +101,9 @@
               String filename = SchemaTypeCodePrinter.indexClassForSystem(saver).replace('.',
File.separatorChar) + ".java";
               File sourcefile = new File(sourcedir, filename);
               sourcefile.getParentFile().mkdirs();
  -            
  -            Writer writer =
  -                repackager == null
  -                    ? (Writer) new FileWriter( sourcefile )
  -                    : (Writer) new RepackagingWriter( sourcefile, repackager );
  -                            
  -            SchemaTypeCodePrinter.printLoader(writer, saver, opts);
  -            
  -            writer.close();
  -            
  +
  +            saveTypeSystem(saver, classesdir, sourcefile, repackager, opts);
  +
               sourcefiles.add(sourcefile);
           }
           catch (IOException e)
  @@ -126,6 +118,57 @@
               return false;
   
           return true;
  +    }
  +
  +    /**
  +     * Saves a SchemaTypeSystem to the specified directory.
  +     *
  +     * @param system the <code>SchemaTypeSystem</code> to save
  +     * @param classesDir the destination directory for xsb's
  +     * @param sourceFile if present, the TypeSystemHolder source will be
  +     *                   generated in this file for subsequent compilation,
  +     *                   if null then the source will be generated in a temp
  +     *                   directory and then compiled to the destination dir
  +     * @param repackager the repackager to use when generating the holder class
  +     * @param options options. Can be null
  +     */
  +    public static void saveTypeSystem(SchemaTypeSystem system, File classesDir,
  +        File sourceFile, Repackager repackager, XmlOptions options)
  +        throws IOException
  +    {
  +        system.saveToDirectory(classesDir);
  +        options = XmlOptions.maskNull(options);
  +
  +        // Now generate the holder class
  +        File source = sourceFile;
  +        File tempDir = null;
  +        if (source == null)
  +        {
  +            String filename = SchemaTypeCodePrinter.indexClassForSystem(system).replace('.',
  +                File.separatorChar) + ".java";
  +            tempDir = createTempDir();
  +            File sourcedir = IOUtil.createDir(tempDir, "src");
  +            source = new File(sourcedir, filename);
  +            source.getParentFile().mkdirs();
  +        }
  +
  +        Writer writer =
  +            repackager == null
  +                ? (Writer) new FileWriter( source )
  +                : (Writer) new RepackagingWriter( source, repackager );
  +
  +        SchemaTypeCodePrinter.printLoader(writer, system, options);
  +
  +        writer.close();
  +
  +        if (tempDir != null)
  +        {
  +            // now compile the generated file to classesDir
  +            List srcFiles = new ArrayList(1);
  +            srcFiles.add(source);
  +            CodeGenUtil.externalCompile(srcFiles, classesDir, null, false);
  +            tryHardToDelete(tempDir);
  +        }
       }
   
       private static boolean genTypes(SchemaTypeSystem saver, List sourcefiles, File sourcedir,
Repackager repackager, boolean verbose, XmlOptions opts)
  
  
  

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