xmlbeans-commits 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/common/org/apache/xmlbeans/impl/common JarHelper.java
Date Thu, 15 Apr 2004 01:50:06 GMT
pcal        2004/04/14 18:50:06

  Modified:    v2/jam   build.xml
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal
                        JamServiceContextImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements
                        ClassImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc
                        JavadocClassBuilder.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/provider
                        JamServiceFactoryImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/visitor
                        PropertyInitializer.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        DebugTylarWriter.java DefaultTylarLoader.java
                        ExplodedTylarImpl.java TylarConstants.java
                        TylarImpl.java
               v2/src/common/org/apache/xmlbeans/impl/common JarHelper.java
  Log:
  Binding: more work on xsb writing in tylars JAM: weak references for jclasses
  
  Revision  Changes    Path
  1.18      +1 -3      xml-xmlbeans/v2/jam/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/build.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- build.xml	2 Apr 2004 02:41:06 -0000	1.17
  +++ build.xml	15 Apr 2004 01:50:05 -0000	1.18
  @@ -91,9 +91,7 @@
       <copy  todir='${classes_dir}' ><fileset dir='license'/></copy>
       <jar jarfile='${jam_jar}'    basedir='${classes_dir}'/>
       <jar jarfile='${javadoc_zip}' basedir='${javadocbuild_dir}'/>
  -    <jar jarfile='${jamsrc_zip}' basedir='.' 
  -         excludes='${build_dir}/**,src/**,test/**'/>
  -    <jar jarfile='${jamsrc_zip}' basedir='${src_dir}' update='true'/>
  +    <jar jarfile='${jamsrc_zip}' basedir='.'  excludes='${build_dir}/**,test'/>
     </target>
   
     <target name='website' depends='all,javadocs,jars'>
  
  
  
  1.14      +2 -3      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceContextImpl.java
  
  Index: JamServiceContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceContextImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JamServiceContextImpl.java	12 Apr 2004 21:06:57 -0000	1.13
  +++ JamServiceContextImpl.java	15 Apr 2004 01:50:06 -0000	1.14
  @@ -67,7 +67,7 @@
   
   
     private MVisitor mCommentInitializer = null;
  -  private MVisitor mPropertyInitializer = null;
  +  private MVisitor mPropertyInitializer = new PropertyInitializer();
     private List mOtherInitializers = null;
     private List mUnstructuredSourceFiles = null;
     private List mClassLoaders = null;
  @@ -234,8 +234,7 @@
       if (mCommentInitializer != null) initers.add(mCommentInitializer);
       // initers.add((mCommentInitializer != null) ? mCommentInitializer :
       //             new CommentInitializer());
  -    initers.add((mPropertyInitializer != null) ? mPropertyInitializer :
  -                new PropertyInitializer());
  +    if (mPropertyInitializer != null) initers.add(mPropertyInitializer);
       if (mOtherInitializers != null) initers.addAll(mOtherInitializers);
       // now go
       MVisitor[] inits = new MVisitor[initers.size()];
  
  
  
  1.12      +11 -1     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java
  
  Index: ClassImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/ClassImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ClassImpl.java	2 Apr 2004 02:41:06 -0000	1.11
  +++ ClassImpl.java	15 Apr 2004 01:50:06 -0000	1.12
  @@ -187,7 +187,17 @@
     }
   
     public JClass[] getImportedClasses() {
  -    return new JClass[0];//FIXME
  +//    if (true) throw new IllegalStateException();
  +    String[] imports = getImportSpecs();
  +    if (imports == null) return new JClass[0];
  +    List list = new ArrayList();
  +    for(int i=0; i<imports.length; i++) {
  +      if (imports[i].endsWith("*")) continue;
  +      list.add(getClassLoader().loadClass(imports[i]));
  +    }
  +    JClass[] out = new JClass[list.size()];
  +    list.toArray(out);
  +    return out;
     }
   
     public void accept(MVisitor visitor) { visitor.visit(this); }
  
  
  
  1.21      +11 -1     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java
  
  Index: JavadocClassBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JavadocClassBuilder.java	8 Apr 2004 19:44:44 -0000	1.20
  +++ JavadocClassBuilder.java	15 Apr 2004 01:50:06 -0000	1.21
  @@ -175,7 +175,17 @@
         }
         return null;
       }
  -    MClass out = createClassToBuild(packageName, className, null);
  +    String[] importSpecs = null;
  +    {
  +      ClassDoc[] imported = cd.importedClasses();
  +      if (imported != null) {
  +        importSpecs = new String[imported.length];
  +        for(int i=0; i<imported.length; i++) {
  +          importSpecs[i] = imported[i].qualifiedName();
  +        }
  +      }
  +    }
  +    MClass out = createClassToBuild(packageName, className, importSpecs);
       out.setArtifact(cd);
       return out;
     }
  
  
  
  1.9       +1 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamServiceFactoryImpl.java
  
  Index: JamServiceFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/provider/JamServiceFactoryImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JamServiceFactoryImpl.java	26 Mar 2004 00:15:39 -0000	1.8
  +++ JamServiceFactoryImpl.java	15 Apr 2004 01:50:06 -0000	1.9
  @@ -99,6 +99,7 @@
     public JamClassLoader createJamClassLoader(ClassLoader cl) {
       JamServiceParams params = createServiceParams();
       params.setUseSystemClasspath(true); //?
  +    params.setPropertyInitializer(null);
       try {
         JamService service = createService(params);
         return service.getClassLoader();
  
  
  
  1.7       +2 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/visitor/PropertyInitializer.java
  
  Index: PropertyInitializer.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/visitor/PropertyInitializer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PropertyInitializer.java	20 Mar 2004 20:10:45 -0000	1.6
  +++ PropertyInitializer.java	15 Apr 2004 01:50:06 -0000	1.7
  @@ -51,6 +51,8 @@
         if (name.startsWith("get") && name.length() > 3 ||
           name.startsWith("is") && name.length() > 2) {
           JClass typ = methods[i].getReturnType();
  +        //FIXME we just want the name - this forces the whole thing to be resolved
  +        // need to either getReturnTypeRef() or change ClassImpl so that it lazily builds
itself
           if (typ == null) continue; // must have a typ and have
           if (methods[i].getParameters().length > 0) continue; //no params
           if (name.startsWith("get")) {
  
  
  
  1.5       +15 -0     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DebugTylarWriter.java
  
  Index: DebugTylarWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DebugTylarWriter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DebugTylarWriter.java	7 Apr 2004 04:18:10 -0000	1.4
  +++ DebugTylarWriter.java	15 Apr 2004 01:50:06 -0000	1.5
  @@ -26,6 +26,7 @@
   import java.io.IOException;
   import java.io.PrintWriter;
   import java.io.Writer;
  +import java.io.File;
   
   /**
    * Implementation of TylarWriter which simply dumps everything it gets to some
  @@ -114,5 +115,19 @@
     public Writer createWriter(String packageName, String className)
             throws IOException {
       return mOut;
  +  }
  +
  +  // ========================================================================
  +  // main method
  +
  +  public static void main(String[] args) {
  +    try {
  +      TylarLoader loader = DefaultTylarLoader.getInstance();
  +      Tylar tylar = loader.load(new File(args[0]).toURI());
  +      new DebugTylarWriter().write(tylar);
  +    } catch(Exception e) {
  +      e.printStackTrace();
  +    }
  +    System.out.flush();
     }
   }
  
  
  
  1.11      +44 -6     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultTylarLoader.java	25 Feb 2004 18:56:48 -0000	1.10
  +++ DefaultTylarLoader.java	15 Apr 2004 01:50:06 -0000	1.11
  @@ -17,13 +17,17 @@
   
   import java.io.*;
   import java.net.URI;
  +import java.net.URLClassLoader;
  +import java.net.URL;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.jar.JarEntry;
   import java.util.jar.JarInputStream;
   import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
   import org.apache.xmlbeans.XmlException;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  +import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   
   /**
  @@ -32,7 +36,7 @@
    *
    * @author Patrick Calahan <pcal@bea.com>
    */
  -public class DefaultTylarLoader implements TylarLoader {
  +public class DefaultTylarLoader implements TylarLoader, TylarConstants {
   
     // ========================================================================
     // Constants
  @@ -40,18 +44,21 @@
     private static final String FILE_SCHEME = "file";
   
     private static final char[] OTHER_SEPCHARS = {'\\'};
  +
     private static final char SEPCHAR = '/';
   
     private static final boolean VERBOSE = false;
   
     private static final String BINDING_FILE_JARENTRY =
  -          normalizeEntryName(TylarConstants.BINDING_FILE);
  +          normalizeEntryName(TylarConstants.BINDING_FILE).toLowerCase();
   
     private static final String SCHEMA_DIR_JARENTRY =
  -          normalizeEntryName(TylarConstants.SCHEMA_DIR);
  +          normalizeEntryName(TylarConstants.SCHEMA_DIR).toLowerCase();
   
     private static final String SCHEMA_EXT = ".xsd";
   
  +  private static final String STS_PREFIX = "schema"+SEPCHAR+"system"+SEPCHAR;
  +
     // ========================================================================
     // Singleton
   
  @@ -157,9 +164,20 @@
       BindingFile bf = null;
       Collection schemas = null;
       StubbornInputStream stubborn = new StubbornInputStream(jin);
  +    String stsName = null;
       while ((entry = jin.getNextJarEntry()) != null) {
  -      if (entry.isDirectory()) continue;
         String name = normalizeEntryName(entry.getName());
  +      if (name.endsWith(""+SEPCHAR)) {
  +        if (name.startsWith(STS_PREFIX) &&
  +          name.length() > STS_PREFIX.length()) {
  +          // the name of the sts is the name of the only directory under
  +          // schema/system
  +          stsName = STS_PACKAGE+"."+name.substring(STS_PREFIX.length(),name.length()-1);
  +          if (VERBOSE) System.out.println("sts name is "+stsName);
  +        }
  +        continue;
  +      }
  +      name = name.toLowerCase();
         if (name.equals(BINDING_FILE_JARENTRY)) {
           if (VERBOSE) System.out.println("parsing binding file "+name);
           bf = BindingFile.forDoc(BindingConfigDocument.Factory.parse(stubborn));
  @@ -184,7 +202,27 @@
                  "' is not a tylar: it does not contain a binding file");
       }
       jin.close();
  -    return new TylarImpl(source,bf,schemas);
  +    if (VERBOSE) System.out.println("Done reading jar entries");
  +    SchemaTypeSystem sts = null;
  +    if (stsName != null) {
  +      {
  +        try {
  +          URLClassLoader ucl = new URLClassLoader(new URL[] {source.toURL()});
  +          sts = SchemaTypeSystemImpl.forName(stsName,ucl);
  +          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();
  +        }
  +      }
  +    }
  +    return new TylarImpl(source,bf,schemas,sts);
     }
     // ========================================================================
     // Private methods
  @@ -195,7 +233,7 @@
      * leading slashes or anything else that can go wrong.
      */
     private static final String normalizeEntryName(String name) {
  -    name = name.toLowerCase().trim();
  +    name = name.trim();
       for(int i=0; i<OTHER_SEPCHARS.length; i++) {
         name = name.replace(OTHER_SEPCHARS[i],SEPCHAR);
       }
  
  
  
  1.13      +28 -9     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExplodedTylarImpl.java	8 Apr 2004 20:01:01 -0000	1.12
  +++ ExplodedTylarImpl.java	15 Apr 2004 01:50:06 -0000	1.13
  @@ -38,6 +38,8 @@
   import org.apache.xmlbeans.impl.binding.joust.SourceJavaOutputStream;
   import org.apache.xmlbeans.impl.binding.joust.ValidatingJavaOutputStream;
   import org.apache.xmlbeans.impl.common.JarHelper;
  +import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
  +import org.apache.xmlbeans.impl.tool.SchemaCodeGenerator;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   
   /**
  @@ -119,12 +121,24 @@
       parseSchemas(new File(dir, SCHEMA_DIR), schemas);
       SchemaTypeSystem sts = null;
       {
  -      File stsDir = new File(dir, STS_DIR);
  -      if (stsDir.exists()) {
  -        //FIXME i still dont get how to do this.  Where is the TypeSystemHolder?
  -        // sts = SchemaTypeSystemImpl.forName()
  +      //try to read the xsbs.  first we need to figure out the sts name.
  +      try {
  +        File stsDir = new File(dir, "schema"+SEP+"system");
  +        String stsName = stsDir.list()[0];
  +        ClassLoader cl = new URLClassLoader(new URL[]{dir.toURL()});
  +        sts = SchemaTypeSystemImpl.forName(STS_PACKAGE+"."+stsName,cl);
  +        if (sts == null) throw new IllegalStateException("null returned by SchemaTypeSystemImpl.forName()");
  +        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();
         }
  -
       }
   
       return new ExplodedTylarImpl(dir, bf, schemas, sts, joust);
  @@ -174,11 +188,16 @@
       if (sts == null) throw new IllegalArgumentException("null sts");
       mSchemaTypeSystem = sts;
       try {
  -      sts.saveToDirectory(new File(mRootDir, STS_DIR));
  +      SchemaCodeGenerator.saveTypeSystem(sts,
  +                                         mRootDir,
  +                                         null,null,null);
       } catch(Exception e) {
  -      System.out.println("[XBEANS] HAS A PROBLEM WRITING XSBs, IGNORING FOR NOW: "+
  -                         e.getMessage()+"\n YOUR BINDINGS ARE STILL OK");
  -      //e.printStackTrace(System.out);
  +      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();
       }
     }
   
  
  
  
  1.6       +5 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarConstants.java
  
  Index: TylarConstants.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarConstants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TylarConstants.java	7 Apr 2004 04:18:10 -0000	1.5
  +++ TylarConstants.java	15 Apr 2004 01:50:06 -0000	1.6
  @@ -34,6 +34,10 @@
     public static final String SRC_ROOT     = "META-INF"+SEP+"src";
     public static final String BINDING_FILE = "META-INF"+SEP+"binding-file.xml";
     public static final String SCHEMA_DIR   = "META-INF"+SEP+"schemas";
  -  public static final String STS_DIR      = "META-INF"+SEP+"schema_type_system"; 
  +
  +  public static final String STS_PACKAGE  = "schema.system";
  +
  +
  +  public static final boolean SHOW_XSB_ERRORS = false;
   
   }
  
  
  
  1.7       +19 -1     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarImpl.java
  
  Index: TylarImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TylarImpl.java	7 Apr 2004 04:18:10 -0000	1.6
  +++ TylarImpl.java	15 Apr 2004 01:50:06 -0000	1.7
  @@ -48,18 +48,22 @@
   
     public TylarImpl() {}
   
  +
     /**
      * @param sourceUri source uri or null
      * @param bf the binding file
      * @param schemas the schemas
  +   * @param sts schema type system (or null)
      */
     public TylarImpl(URI sourceUri,
                      BindingFile bf,
  -                   Collection schemas)
  +                   Collection schemas,
  +                   SchemaTypeSystem sts)
     {
       mSourceURI = sourceUri;
       mBindingFile = bf;
       mSchemas = schemas;
  +    mSts = sts;
     }
   
     // ========================================================================
  @@ -120,4 +124,18 @@
     }
   
     public void close() {}
  +
  +  // ========================================================================
  +  // Deprecated methods
  +  
  +  /**
  +   * @deprecated
  +   */
  +  public TylarImpl(URI sourceUri,
  +                   BindingFile bf,
  +                   Collection schemas)
  +  {
  +    this(sourceUri,bf,schemas,null);
  +  }
  +
   }
  
  
  
  1.3       +9 -7      xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/JarHelper.java
  
  Index: JarHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/JarHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JarHelper.java	12 Feb 2004 20:06:08 -0000	1.2
  +++ JarHelper.java	15 Apr 2004 01:50:06 -0000	1.3
  @@ -119,6 +119,7 @@
     // ========================================================================
     // Private methods
   
  +  private static final char SEP = '/';
     /**
      * Recursively jars up the given path under the given directory.
      */
  @@ -127,13 +128,14 @@
       if (mVerbose) System.out.println("checking " + dirOrFile2jar);
       if (dirOrFile2jar.isDirectory()) {
         String[] dirList = dirOrFile2jar.list();
  -      String subPath = (path == null)? File.separator :
  -              (path+dirOrFile2jar.getName()+File.separator);
  -      JarEntry je = new JarEntry(subPath);
  -      je.setTime(dirOrFile2jar.lastModified());
  -      jos.putNextEntry(je);
  -      jos.flush();
  -      jos.closeEntry();
  +      String subPath = (path == null)? "" : (path+dirOrFile2jar.getName()+SEP);
  +      if (path != null) {
  +        JarEntry je = new JarEntry(subPath);
  +        je.setTime(dirOrFile2jar.lastModified());
  +        jos.putNextEntry(je);
  +        jos.flush();
  +        jos.closeEntry();
  +      }
         for (int i = 0; i < dirList.length; i++) {
           File f = new File(dirOrFile2jar, dirList[i]);
           jarDir(f,jos,subPath);
  
  
  

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