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/05/12 20:44:54 UTC

cvs commit: xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config ExtensionHolder.java InterfaceExtension.java PrePostExtension.java SchemaConfig.java

cezar       2004/05/12 11:44:54

  Modified:    v2       build.xml
               v2/src/marshal/org/apache/xmlbeans/impl/richParser
                        XMLStreamReaderExtImpl.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/schema
                        SchemaTypeSystemCompiler.java
                        SchemaTypeSystemImpl.java
               v2/src/xmlcomp/org/apache/xmlbeans/impl/tool
                        SchemaCompiler.java
               v2/src/xmlconfig/org/apache/xmlbeans/impl/config
                        ExtensionHolder.java InterfaceExtension.java
                        PrePostExtension.java SchemaConfig.java
  Log:
  - JAM enabled extensions: i.e. only extension sources needed when compiling a schema with interface/prePostExtensions.
  - Fixed location for unmarshaling.
  
  DRT: passes
  
  Revision  Changes    Path
  1.60      +10 -5     xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- build.xml	11 May 2004 20:25:11 -0000	1.59
  +++ build.xml	12 May 2004 18:44:53 -0000	1.60
  @@ -197,7 +197,7 @@
   
     <!-- extensions test -->
     <target name="extensionsTest" depends="extensions.compile">
  -    <echo message="JUnit output being sent to build/test/output/drt-product.txt"/>
  +    <echo message="JUnit output being sent to build/test/output/drt-extensions.txt"/>
       <junit fork="yes" printsummary="yes" haltonfailure="yes" showoutput="yes">
         <jvmarg value="-ea"/>
         <classpath>
  @@ -207,7 +207,8 @@
           <pathelement location="build/lib/jsr173_ri.jar"/>
           <pathelement location="build/private/lib/extensions.jar"/>
           <pathelement location="build/test/extensionsuse"/>
  -      </classpath>
  +        <pathelement path='${java.class.path}'/>
  +	  </classpath>
         <formatter type="plain"/>
         <test name="drtcases.ExtensionsTest" outfile="build/test/output/drt-extensions"/>
       </junit>
  @@ -220,7 +221,7 @@
           <pathelement location="build/ar/xbean.jar"/>
           <pathelement location="build/lib/jsr173_api.jar"/>
           <pathelement location="build/lib/jsr173_ri.jar"/>
  -      </classpath>
  +	  </classpath>
       </javac>
   
       <java classname="${schema_compiler}" fork="true" failonerror="true">
  @@ -230,6 +231,7 @@
           <pathelement location="build/lib/jsr173_api.jar"/>
           <pathelement location="build/lib/jsr173_ri.jar"/>
           <pathelement location="build/test/extensions"/>
  +        <pathelement path='${java.class.path}'/>
         </classpath>
         <arg line="-out build/private/lib/extensions.jar test/src/extensions"/>
       </java>
  @@ -246,8 +248,8 @@
         </classpath>
       </javac>
     </target>
  -  <!-- extensions test -->
   
  +  <!-- eric test -->
     <target name="eric" depends="erictest.jar"/>
   
     <target name="default" depends="deploy, builddrt"/>
  @@ -766,7 +768,9 @@
   
     <!-- typeimpl target ============================================== -->
   
  -  <target name="typeimpl.classes" depends="dirs, xmlstore.classes, newstore2.classes, repackage.classes, xmlpublic.classes, typestore.classes, xsdschema.classes, configschema.classes, toolschema.classes, jsr173_api.jar">
  +  <target name="typeimpl.classes" depends="dirs,  xmlstore.classes, newstore2.classes,
  +      repackage.classes, xmlpublic.classes, typestore.classes, xsdschema.classes,
  +      configschema.classes, toolschema.classes, jsr173_api.jar, jam">
       <mkdir dir="build/classes/typeimpl"/>
       <javac destdir="build/classes/typeimpl" source="1.4" debug="on">
         <classpath>
  @@ -780,6 +784,7 @@
           <pathelement location="build/classes/xmlconfig"/>
           <pathelement location="build/classes/configschema"/>
           <pathelement location="build/classes/xsdschema"/>
  +        <pathelement location="build/classes/jam"/>
           <pathelement location="build/lib/jsr173_api.jar"/>
         </classpath>
   
  
  
  
  1.9       +1 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/richParser/XMLStreamReaderExtImpl.java
  
  Index: XMLStreamReaderExtImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/richParser/XMLStreamReaderExtImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XMLStreamReaderExtImpl.java	17 Apr 2004 00:06:23 -0000	1.8
  +++ XMLStreamReaderExtImpl.java	12 May 2004 18:44:53 -0000	1.9
  @@ -834,6 +834,7 @@
                       break loop;
   
                   case XMLStreamReader.END_ELEMENT:
  +                    _location.set(_xmlSteam.getLocation());
                       depth--;
                       if (depth<0)
                           break loop;
  
  
  
  1.5       +29 -4     xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
  
  Index: SchemaTypeSystemCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaTypeSystemCompiler.java	12 Feb 2004 20:06:21 -0000	1.4
  +++ SchemaTypeSystemCompiler.java	12 May 2004 18:44:53 -0000	1.5
  @@ -42,6 +42,7 @@
           private String name;
           private Schema[] schemas;
           private Config[] configs;
  +        private File[] javaFiles;
           private SchemaTypeLoader linkTo;
           private XmlOptions options;
           private Collection errorListener;
  @@ -49,6 +50,7 @@
           private URI baseURI;
           private Map sourcesToCopyMap;
           private File schemasDir;
  +        private File[] classpath;
   
           public String getName()
           {
  @@ -80,6 +82,16 @@
               this.configs = configs;
           }
   
  +        public File[] getJavaFiles()
  +        {
  +            return javaFiles;
  +        }
  +
  +        public void setJavaFiles(File[] javaFiles)
  +        {
  +            this.javaFiles = javaFiles;
  +        }
  +
           public SchemaTypeLoader getLinkTo()
           {
               return linkTo;
  @@ -149,16 +161,29 @@
           {
               this.schemasDir = schemasDir;
           }
  +
  +        public File[] getClasspath()
  +        {
  +            return classpath;
  +        }
  +
  +        public void setClasspath(File[] classpath)
  +        {
  +            this.classpath = classpath;
  +        }
       }
   
       public static SchemaTypeSystem compile(Parameters params)
       {
  -        return compileImpl(params.getName(), params.getSchemas(), params.getConfigs(), params.getLinkTo(), params.getOptions(), params.getErrorListener(), params.isJavaize(), params.getBaseURI(), params.getSourcesToCopyMap(), params.getSchemasDir());
  +        return compileImpl(params.getName(), params.getSchemas(), params.getConfigs(),
  +            params.getJavaFiles(), params.getLinkTo(), params.getOptions(),
  +            params.getErrorListener(), params.isJavaize(), params.getBaseURI(),
  +            params.getSourcesToCopyMap(), params.getSchemasDir(), params.getClasspath());
       }
       
       /* package!!! */ static SchemaTypeSystemImpl compileImpl( String name, Schema[] schemas,
  -         Config[] configs, SchemaTypeLoader linkTo, XmlOptions options, Collection outsideErrors,
  -         boolean javaize, URI baseURI, Map sourcesToCopyMap, File schemasDir)
  +         Config[] configs, File[] javaFiles, SchemaTypeLoader linkTo, XmlOptions options, Collection outsideErrors,
  +         boolean javaize, URI baseURI, Map sourcesToCopyMap, File schemasDir, File[] classpath)
       {
           if (linkTo == null)
               throw new IllegalArgumentException("Must supply linkTo");
  @@ -171,7 +196,7 @@
           try
           {
               state.setErrorListener(errorWatcher);
  -            state.setSchemaConfig(SchemaConfig.forConfigDocuments(configs));
  +            state.setSchemaConfig(SchemaConfig.forConfigDocuments(configs, javaFiles, classpath));
               state.setOptions(options);
               state.setGivenTypeSystemName(name);
               state.setSchemasDir(schemasDir);
  
  
  
  1.8       +2 -1      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SchemaTypeSystemImpl.java	10 Apr 2004 02:50:01 -0000	1.7
  +++ SchemaTypeSystemImpl.java	12 May 2004 18:44:53 -0000	1.8
  @@ -188,7 +188,8 @@
           SchemaTypeSystemImpl stsi =
               SchemaTypeSystemCompiler.compileImpl(
                   null, (Schema[])schemas.toArray(EMPTY_SCHEMA_ARRAY),
  -                (Config[])configs.toArray(EMPTY_CONFIG_ARRAY), linkTo, options, errorWatcher, false, null, null, null);
  +                (Config[])configs.toArray(EMPTY_CONFIG_ARRAY), null, 
  +                linkTo, options, errorWatcher, false, null, null, null, null);
   
           if (errorWatcher.hasError())
           {
  
  
  
  1.9       +8 -6      xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
  
  Index: SchemaCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SchemaCompiler.java	18 Mar 2004 23:28:00 -0000	1.8
  +++ SchemaCompiler.java	12 May 2004 18:44:53 -0000	1.9
  @@ -613,11 +613,11 @@
       }
   
       private static SchemaTypeSystem loadTypeSystem(
  -        String name, File[] xsdFiles,
  -        File[] wsdlFiles, File[] configFiles, ResourceLoader cpResourceLoader,
  +        String name, File[] xsdFiles, File[] wsdlFiles, File[] configFiles,
  +        File[] javaFiles, ResourceLoader cpResourceLoader,
           boolean download, boolean noUpa, boolean noPvr, boolean noAnn,
           Set mdefNamespaces, File baseDir, Map sourcesToCopyMap,
  -        Collection outerErrorListener, File schemasDir, EntityResolver entResolver)
  +        Collection outerErrorListener, File schemasDir, EntityResolver entResolver, File[] classpath)
       {
           XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
   
  @@ -778,6 +778,7 @@
           params.setName(name);
           params.setSchemas(sdocs);
           params.setConfigs(cdocs);
  +        params.setJavaFiles(javaFiles);
           params.setLinkTo(linkTo);
           params.setOptions(opts);
           params.setErrorListener(errorListener);
  @@ -785,6 +786,7 @@
           params.setBaseURI(baseURI);
           params.setSourcesToCopyMap(sourcesToCopyMap);
           params.setSchemasDir(schemasDir);
  +        params.setClasspath(classpath);
           return SchemaTypeSystemCompiler.compile(params);
       }
   
  @@ -842,9 +844,9 @@
   
           // build the in-memory type system
           XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
  -        SchemaTypeSystem system = loadTypeSystem(name, xsdFiles, wsdlFiles, configFiles, cpResourceLoader,
  -            download, noUpa, noPvr, noAnn, mdefNamespaces, baseDir, sourcesToCopyMap, errorListener,
  -            schemasDir, cmdLineEntRes);
  +        SchemaTypeSystem system = loadTypeSystem(name, xsdFiles, wsdlFiles, configFiles,
  +            javaFiles, cpResourceLoader, download, noUpa, noPvr, noAnn, mdefNamespaces,
  +            baseDir, sourcesToCopyMap, errorListener, schemasDir, cmdLineEntRes, classpath);
           if (errorListener.hasError())
               result = false;
           long finish = System.currentTimeMillis();
  
  
  
  1.2       +34 -18    xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/ExtensionHolder.java
  
  Index: ExtensionHolder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/ExtensionHolder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExtensionHolder.java	5 May 2004 00:45:38 -0000	1.1
  +++ ExtensionHolder.java	12 May 2004 18:44:53 -0000	1.2
  @@ -18,12 +18,15 @@
    */
   package org.apache.xmlbeans.impl.config;
   
  +import org.apache.xmlbeans.impl.jam.JMethod;
  +import org.apache.xmlbeans.impl.jam.JParameter;
  +import org.apache.xmlbeans.impl.jam.JClass;
  +
   import java.util.List;
   import java.util.ArrayList;
   import java.util.Map;
   import java.util.HashMap;
   import java.util.Set;
  -import java.lang.reflect.Method;
   
   /**
    * This class reprezents all the extensions for all xbean sets.
  @@ -61,15 +64,20 @@
       private static class MethodSignature
       {
           private String _intfName;  // Stored only for error output, does not influence the equals or hashCode
  -        private Method _method;
  +        private JMethod _method;
  +        private final int NOTINITIALIZED = -1;
  +        private int _hashCode = NOTINITIALIZED;
  +        private String _signature;
   
  -        MethodSignature(String intfName, Method method)
  +        MethodSignature(String intfName, JMethod method)
           {
               if (intfName==null || method==null)
                   throw new IllegalArgumentException("Interface: " + intfName + " method: " + method);
   
               _intfName = intfName;
               _method = method;
  +            _hashCode = NOTINITIALIZED;
  +            _signature = null;
           }
   
           String getInterfaceName()
  @@ -79,14 +87,18 @@
   
           String getSignature()
           {
  +            if (_signature==null)
  +                return _signature;
  +
               String sig = "";
  -            Class[] paramTypes = _method.getParameterTypes();
  +            JParameter[] paramTypes = _method.getParameters();
               for (int i = 0; i < paramTypes.length; i++)
               {
  -                Class paramType = paramTypes[i];
  -                sig += ( i==0 ? "" : " ," ) + paramType.getName();
  +                JClass paramType = paramTypes[i].getType();
  +                sig += ( i==0 ? "" : " ," ) + paramType.getQualifiedName();
               }
  -            return _method.getName() + "(" + sig + ")";
  +            _signature = _method.getSimpleName() + "(" + sig + ")";
  +            return _signature;
           }
   
           public boolean equals(Object o)
  @@ -96,18 +108,18 @@
   
               MethodSignature ms = (MethodSignature)o;
   
  -            if (!ms._method.getName().equals(_method.getName()) )
  +            if (!ms._method.getSimpleName().equals(_method.getSimpleName()) )
                   return false;
   
  -            Class[] paramTypes = _method.getParameterTypes();
  -            Class[] msParamTypes = _method.getParameterTypes();
  +            JParameter[] params = _method.getParameters();
  +            JParameter[] msParams = _method.getParameters();
   
  -            if (msParamTypes.length != paramTypes.length )
  +            if (msParams.length != params.length )
                   return false;
   
  -            for (int i = 0; i < paramTypes.length; i++)
  +            for (int i = 0; i < params.length; i++)
               {
  -                if (msParamTypes[i] != paramTypes[i])
  +                if (!msParams[i].getType().equals(params[i].getType()))
                       return false;
               }
   
  @@ -116,17 +128,21 @@
   
           public int hashCode()
           {
  -            int hash = _method.getName().hashCode();
  +            if (_hashCode!=NOTINITIALIZED)
  +                return _hashCode;
   
  -            Class[] paramTypes = _method.getParameterTypes();
  +            int hash = _method.getSimpleName().hashCode();
   
  -            for (int i = 0; i < paramTypes.length; i++)
  +            JParameter[] params = _method.getParameters();
  +
  +            for (int i = 0; i < params.length; i++)
               {
                   hash *= 19;
  -                hash += paramTypes[i].hashCode();
  +                hash += params[i].getType().hashCode();
               }
   
  -            return hash;
  +            _hashCode = hash;
  +            return _hashCode;
           }
       }
   
  
  
  
  1.2       +120 -90   xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/InterfaceExtension.java
  
  Index: InterfaceExtension.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/InterfaceExtension.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InterfaceExtension.java	5 May 2004 00:45:38 -0000	1.1
  +++ InterfaceExtension.java	12 May 2004 18:44:53 -0000	1.2
  @@ -20,25 +20,26 @@
   
   import org.apache.xml.xmlbeans.x2004.x02.xbean.config.Extensionconfig;
   import org.apache.xmlbeans.XmlObject;
  -
  -import java.lang.reflect.Method;
  -import java.lang.reflect.Modifier;
  +import org.apache.xmlbeans.impl.jam.JMethod;
  +import org.apache.xmlbeans.impl.jam.JClass;
  +import org.apache.xmlbeans.impl.jam.JParameter;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
   
   public class InterfaceExtension
   {
       private NameSet _xbeanSet;
  -    private Class _interface;
  -    private Class _delegateToClass;
  +    private JClass _interface;
  +    private JClass _delegateToClass;
       private String _delegateToClassName;
  -    private Method[] _interfaceMethods;
  -    private Method[] _delegateToMethods;
  +    private JMethod[] _interfaceMethods;
  +    private JMethod[] _delegateToMethods;
   
  -    static InterfaceExtension newInstance(NameSet xbeanSet, Extensionconfig.Interface intfXO)
  +    static InterfaceExtension newInstance(JamClassLoader loader, NameSet xbeanSet, Extensionconfig.Interface intfXO)
       {
           InterfaceExtension result = new InterfaceExtension();
   
           result._xbeanSet = xbeanSet;
  -        result._interface = validateInterface(intfXO.getName(), intfXO);
  +        result._interface = validateInterface(loader, intfXO.getName(), intfXO);
   
           if (result._interface == null)
           {
  @@ -47,7 +48,7 @@
           }
   
           result._delegateToClassName = intfXO.getStaticHandler();
  -        result._delegateToClass = validateClass(result._delegateToClassName, intfXO);
  +        result._delegateToClass = validateClass(loader, result._delegateToClassName, intfXO);
   
           if ( result._delegateToClass==null ) // no HandlerClass
           {
  @@ -61,41 +62,43 @@
           return result;
       }
   
  -    private static Class validateInterface(String intfStr, XmlObject loc)
  +    private static JClass validateInterface(JamClassLoader loader, String intfStr, XmlObject loc)
       {
  -        return validateJava(intfStr, true, loc);
  +        return validateJava(loader, intfStr, true, loc);
       }
   
  -    static Class validateClass(String clsStr, XmlObject loc)
  +    static JClass validateClass(JamClassLoader loader, String clsStr, XmlObject loc)
       {
  -        return validateJava(clsStr, false, loc);
  +        return validateJava(loader, clsStr, false, loc);
       }
   
  -    static Class validateJava(String clsStr, boolean isInterface, XmlObject loc)
  +    static JClass validateJava(JamClassLoader loader, String clsStr, boolean isInterface, XmlObject loc)
       {
  -        final String ent = isInterface ? "Interface" : "Class";
  -        try
  -        {
  -            Class cls = Class.forName(clsStr);
  -            if ( (isInterface && !cls.isInterface()) ||
  -                    (!isInterface && cls.isInterface()))
  -            {
  -                SchemaConfig.error("'" + clsStr + "' must be " +
  -                    (isInterface ? "an interface" : "a class") + ".", loc);
  -            }
  +        if (loader==null)
  +            return null;
   
  -            if (!Modifier.isPublic(cls.getModifiers()))
  -            {
  -                SchemaConfig.error(ent + " '" + clsStr + "' is not public.", loc);
  -            }
  +        final String ent = isInterface ? "Interface" : "Class";
  +        JClass cls = loader.loadClass(clsStr);
   
  -            return cls;
  -        }
  -        catch (ClassNotFoundException e)
  +        if (cls==null)
           {
               SchemaConfig.error(ent + " '" + clsStr + "' not found.", loc);
               return null;
           }
  +
  +        if ( (isInterface && !cls.isInterface()) ||
  +                (!isInterface && cls.isInterface()))
  +        {
  +            SchemaConfig.error("'" + clsStr + "' must be " +
  +                (isInterface ? "an interface" : "a class") + ".", loc);
  +        }
  +
  +        if (!cls.isPublic())
  +        {
  +            SchemaConfig.error(ent + " '" + clsStr + "' is not public.", loc);
  +        }
  +
  +        return cls;
       }
   
       private boolean validateMethods(XmlObject loc)
  @@ -104,7 +107,7 @@
           boolean valid = true;
   
           _interfaceMethods = _interface.getMethods();
  -        _delegateToMethods = new Method[_interfaceMethods.length];
  +        _delegateToMethods = new JMethod[_interfaceMethods.length];
   
           for (int i = 0; i < _interfaceMethods.length; i++)
           {
  @@ -114,64 +117,56 @@
           return valid;
       }
   
  -    private boolean validateMethod(int index, Method method, XmlObject loc)
  +    private boolean validateMethod(int index, JMethod method, XmlObject loc)
       {
  -        String methodName = method.getName();
  -        Class[] paramTypes = method.getParameterTypes();
  -        Class returnType = method.getReturnType();
  +        String methodName = method.getSimpleName();
  +        JParameter[] params = method.getParameters();
  +        JClass returnType = method.getReturnType();
   
  -        Class[] delegateParams = new Class[paramTypes.length+1];
  -        delegateParams[0] = XmlObject.class;
  +        JClass[] delegateParams = new JClass[params.length+1];
  +        delegateParams[0] = returnType.forName("org.apache.xmlbeans.XmlObject");
           for (int i = 1; i < delegateParams.length; i++)
           {
  -            delegateParams[i] = paramTypes[i-1];
  +            delegateParams[i] = params[i-1].getType();
           }
   
  -        Method handlerMethod = null;
  -        try
  +        JMethod handlerMethod = null;
  +        handlerMethod = getMethod(_delegateToClass, methodName, delegateParams);
  +        if (handlerMethod==null)
           {
  -            handlerMethod = _delegateToClass.getMethod(methodName, delegateParams);
  -
  -            // check for throws exceptions
  -            Class[] intfExceptions = method.getExceptionTypes();
  -            Class[] delegateExceptions = handlerMethod.getExceptionTypes();
  -            if ( delegateExceptions.length!=intfExceptions.length )
  -            {
  -                SchemaConfig.error("Handler method '" + _delegateToClass.getName() + "." + methodName + "(" + listTypes(delegateParams) +
  -                    ")' must declare the same exceptions as the interface method '" + _interface.getName() + "." + methodName + "(" + listTypes(paramTypes), loc);
  -                return false;
  -            }
  -
  -            for (int i = 0; i < delegateExceptions.length; i++)
  -            {
  -                if ( delegateExceptions[i]!=intfExceptions[i] )
  -                {
  -                    SchemaConfig.error("Handler method '" + _delegateToClass.getName() + "." + methodName + "(" + listTypes(delegateParams) +
  -                        ")' must declare the same exceptions as the interface method '" + _interface.getName() + "." + methodName + "(" + listTypes(paramTypes), loc);
  -                    return false;
  -                }
  -            }
  +            SchemaConfig.error("Handler class '" + _delegateToClass.getQualifiedName() + "' does not contain method " + methodName + "(" + listTypes(delegateParams) + ")", loc);
  +            return false;
           }
  -        catch (NoSuchMethodException e)
  +
  +        // check for throws exceptions
  +        JClass[] intfExceptions = method.getExceptionTypes();
  +        JClass[] delegateExceptions = handlerMethod.getExceptionTypes();
  +        if ( delegateExceptions.length!=intfExceptions.length )
           {
  -            SchemaConfig.error("Handler class '" + _delegateToClass.getName() + "' does not contain method " + methodName + "(" + listTypes(delegateParams) + ")", loc);
  +            SchemaConfig.error("Handler method '" + _delegateToClass.getQualifiedName() + "." + methodName + "(" + listTypes(delegateParams) +
  +                ")' must declare the same exceptions as the interface method '" + _interface.getQualifiedName() + "." + methodName + "(" + listTypes(params), loc);
               return false;
           }
  -        catch (SecurityException e)
  +
  +        for (int i = 0; i < delegateExceptions.length; i++)
           {
  -            SchemaConfig.error("Security violation for class '" + _interface.getName() + "' accesing method " + methodName + "(" + listTypes(delegateParams) + ")", loc);
  -            return false;
  +            if ( delegateExceptions[i]!=intfExceptions[i] )
  +            {
  +                SchemaConfig.error("Handler method '" + _delegateToClass.getQualifiedName() + "." + methodName + "(" + listTypes(delegateParams) +
  +                    ")' must declare the same exceptions as the interface method '" + _interface.getQualifiedName() + "." + methodName + "(" + listTypes(params), loc);
  +                return false;
  +            }
           }
   
  -        if (!Modifier.isPublic(handlerMethod.getModifiers()) || !Modifier.isStatic(handlerMethod.getModifiers()))
  +        if (!handlerMethod.isPublic() || !handlerMethod.isStatic())
           {
  -            SchemaConfig.error("Method '" + _delegateToClass.getName() + "." + methodName + "(" + listTypes(delegateParams) + ")' must be declared public and static.", loc);
  +            SchemaConfig.error("Method '" + _delegateToClass.getQualifiedName() + "." + methodName + "(" + listTypes(delegateParams) + ")' must be declared public and static.", loc);
               return false;
           }
   
           if (!returnType.equals(handlerMethod.getReturnType()))
           {
  -            SchemaConfig.error("Return type for method '" + handlerMethod.getReturnType() + " " + _delegateToClass.getName() +
  +            SchemaConfig.error("Return type for method '" + handlerMethod.getReturnType() + " " + _delegateToClass.getQualifiedName() +
                       "." + methodName + "(" + listTypes(delegateParams) + ")' does not match the return type of the interface method :'" + returnType + "'.", loc);
               return false;
           }
  @@ -181,12 +176,47 @@
           return true;
       }
   
  -    private static String listTypes(Class[] types)
  +    static JMethod getMethod(JClass cls, String name, JClass[] paramTypes)
  +    {
  +        JMethod[] methods = cls.getMethods();
  +        for (int i = 0; i < methods.length; i++)
  +        {
  +            JMethod method = methods[i];
  +            if (!name.equals(method.getSimpleName()))
  +                continue;
  +
  +            JParameter[] mParams = method.getParameters();
  +            for (int j = 0; j < mParams.length; j++)
  +            {
  +                JParameter mParam = mParams[j];
  +                if (!mParam.getType().equals(paramTypes[j]))
  +                    continue;
  +            }
  +
  +            return method;
  +        }
  +        return null;
  +    }
  +
  +    private static String listTypes(JClass[] types)
       {
           StringBuffer result = new StringBuffer();
           for (int i = 0; i < types.length; i++)
           {
  -            Class type = types[i];
  +            JClass type = types[i];
  +            if (i>0)
  +                result.append(", ");
  +            result.append(emitType(type));
  +        }
  +        return result.toString();
  +    }
  +
  +    private static String listTypes(JParameter[] params)
  +    {
  +        StringBuffer result = new StringBuffer();
  +        for (int i = 0; i < params.length; i++)
  +        {
  +            JClass type = params[i].getType();
               if (i>0)
                   result.append(", ");
               result.append(emitType(type));
  @@ -194,12 +224,12 @@
           return result.toString();
       }
   
  -    public static String emitType(Class cls)
  +    public static String emitType(JClass cls)
       {
  -        if (cls.isArray())
  -            return emitType(cls.getComponentType()) + "[]";
  +        if (cls.isArrayType())
  +            return emitType(cls.getArrayComponentType()) + "[]";
           else
  -            return cls.getName().replace('$', '.');
  +            return cls.getQualifiedName().replace('$', '.');
       }
   
       /* public getters */
  @@ -210,7 +240,7 @@
   
       public String getInterfaceName()
       {
  -        return _interface.getName();
  +        return _interface.getSimpleName();
       }
   
       public String getInterfaceNameForJavaSource()
  @@ -234,10 +264,10 @@
   
       public String getInterfaceMethodName(int methodIndex)
       {
  -        return _interfaceMethods[methodIndex].getName();
  +        return _interfaceMethods[methodIndex].getSimpleName();
       }
   
  -    public Method getInterfaceMethod(int methodIndex)
  +    public JMethod getInterfaceMethod(int methodIndex)
       {
           return _interfaceMethods[methodIndex];
       }
  @@ -245,36 +275,36 @@
       public String getInterfaceMethodDecl(int methodIndex)
       {
           StringBuffer sb = new StringBuffer();
  -        Method m = _interfaceMethods[methodIndex];
  -        Class[] paramTypes = m.getParameterTypes();
  +        JMethod m = _interfaceMethods[methodIndex];
  +        JParameter[] params = m.getParameters();
   
  -        for (int i = 0; i < paramTypes.length; i++)
  +        for (int i = 0; i < params.length; i++)
           {
  -            Class paramType = paramTypes[i];
  +            JClass paramType = params[i].getType();
               sb.append( i==0 ? "" : ", " );
               sb.append( emitType(paramType) + " p" + i);
           }
   
           StringBuffer exceptions = new StringBuffer();
  -        Class[] excClasses = m.getExceptionTypes();
  +        JClass[] excClasses = m.getExceptionTypes();
   
           for (int i=0; i<excClasses.length; i++)
               exceptions.append((i==0 ? " throws " : ", ") + emitType(excClasses[i]));
   
  -        return "public " + emitType(m.getReturnType()) + " " + m.getName() + "(" + sb.toString() + ")" + exceptions.toString();
  +        return "public " + emitType(m.getReturnType()) + " " + m.getSimpleName() + "(" + sb.toString() + ")" + exceptions.toString();
       }
   
       public String getInterfaceMethodImpl(int methodIndex)
       {
  -	// use the methods from the interface for gen the call to the handler
  +	    // use the methods from the interface for gen the call to the handler
           StringBuffer sb = new StringBuffer();
   
  -        if (!void.class.equals(_interfaceMethods[methodIndex].getReturnType()))
  +        if (!_interfaceMethods[methodIndex].getReturnType().forName("void").equals(_interfaceMethods[methodIndex].getReturnType()))
               sb.append("return ");
   
  -        sb.append(_delegateToClassName + "." + _delegateToMethods[methodIndex].getName() + "(this");
  +        sb.append(_delegateToClassName + "." + _delegateToMethods[methodIndex].getSimpleName() + "(this");
   
  -        int paramCount = _interfaceMethods[methodIndex].getParameterTypes().length;
  +        int paramCount = _interfaceMethods[methodIndex].getParameters().length;
           for (int i=0; i<paramCount; i++)
           {
               sb.append(", p" + i);
  
  
  
  1.2       +55 -40    xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/PrePostExtension.java
  
  Index: PrePostExtension.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/PrePostExtension.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrePostExtension.java	5 May 2004 00:45:38 -0000	1.1
  +++ PrePostExtension.java	12 May 2004 18:44:53 -0000	1.2
  @@ -19,10 +19,11 @@
   package org.apache.xmlbeans.impl.config;
   
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
  +import org.apache.xmlbeans.impl.jam.JClass;
  +import org.apache.xmlbeans.impl.jam.JMethod;
   import org.apache.xml.xmlbeans.x2004.x02.xbean.config.Extensionconfig;
   
  -import javax.xml.namespace.QName;
  -import java.lang.reflect.Method;
   
   public class PrePostExtension
   {
  @@ -30,16 +31,30 @@
       public static int OPERATION_INSERT = 2;
       public static int OPERATION_REMOVE = 3;
   
  -    private static final Class[] PARAMTYPES_PREPOST = new Class[]{int.class, XmlObject.class, QName.class, boolean.class, int.class};
  -    private static final String SIGNATURE = "(int, org.apache.xmlbeans.XmlObject, javax.xml.namespace.QName, boolean, int)";
  +    private static JClass[] PARAMTYPES_PREPOST = null; //new JClass[]{int.class, XmlObject.class, QName.class, boolean.class, int.class};
  +    private static final String[] PARAMTYPES_STRING = new String[] {"int", "org.apache.xmlbeans.XmlObject",
  +        "javax.xml.namespace.QName", "boolean", "int"};
  +    private static final String SIGNATURE;
  +    static
  +    {
  +        String sig = "(";
  +        for (int i = 0; i < PARAMTYPES_STRING.length; i++)
  +        {
  +            String t = PARAMTYPES_STRING[i];
  +            if (i!=0)
  +                sig += ", ";
  +            sig += t;
  +        }
  +        SIGNATURE = sig + ")";
  +    }
   
       private NameSet _xbeanSet;
  -    private Class _delegateToClass;
  +    private JClass _delegateToClass;
       private String _delegateToClassName;
  -    private Method _preSet;
  -    private Method _postSet;
  +    private JMethod _preSet;
  +    private JMethod _postSet;
   
  -    static PrePostExtension newInstance(NameSet xbeanSet, Extensionconfig.PrePostSet prePostXO)
  +    static PrePostExtension newInstance(JamClassLoader jamLoader, NameSet xbeanSet, Extensionconfig.PrePostSet prePostXO)
       {
           if (prePostXO==null)
               return null;
  @@ -48,7 +63,7 @@
   
           result._xbeanSet = xbeanSet;
           result._delegateToClassName = prePostXO.getStaticHandler();
  -        result._delegateToClass = InterfaceExtension.validateClass(result._delegateToClassName, prePostXO);
  +        result._delegateToClass = InterfaceExtension.validateClass(jamLoader, result._delegateToClassName, prePostXO);
   
           if ( result._delegateToClass==null ) // no HandlerClass
           {
  @@ -56,61 +71,61 @@
               return result;
           }
   
  -        if (!result.lookAfterPreAndPost(prePostXO))
  +        if (!result.lookAfterPreAndPost(jamLoader, prePostXO))
               return null;
   
           return result;
       }
   
  -    private boolean lookAfterPreAndPost(XmlObject loc)
  +    private boolean lookAfterPreAndPost(JamClassLoader jamLoader, XmlObject loc)
       {
           assert _delegateToClass!=null : "Delegate to class handler expected.";
           boolean valid = true;
   
  -        try
  -        {
  -            _preSet = _delegateToClass.getMethod("preSet", PARAMTYPES_PREPOST);
  +        initParamPrePost(jamLoader);
   
  -            if (!_preSet.getReturnType().equals(boolean.class))
  -            {
  -		// just emit an warning and don't remember as a preSet
  -                SchemaConfig.warning("Method '" + _delegateToClass.getName() +
  -                    ".preSet" + SIGNATURE + "' " +
  -                    "should return boolean to be considered for a preSet handler.", loc);
  -                _preSet = null;
  -            }
  -        }
  -        catch (NoSuchMethodException e)
  +        _preSet = InterfaceExtension.getMethod(_delegateToClass, "preSet", PARAMTYPES_PREPOST);
  +        if (_preSet==null)
           {} // not available is ok, _preSet will be null
  -        catch (SecurityException e)
  -        {
  -            SchemaConfig.error("Security violation for class '" + _delegateToClass.getName() +
  -                "' accesing method preSet" + SIGNATURE , loc);
  -            valid = false;
  -        }
   
  -        try
  +        if (_preSet!=null && !_preSet.getReturnType().equals(jamLoader.loadClass("boolean")))
           {
  -            _postSet = _delegateToClass.getMethod("postSet", PARAMTYPES_PREPOST);
  +            // just emit an warning and don't remember as a preSet
  +            SchemaConfig.warning("Method '" + _delegateToClass.getSimpleName() +
  +                ".preSet" + SIGNATURE + "' " +
  +                "should return boolean to be considered for a preSet handler.", loc);
  +            _preSet = null;
           }
  -        catch (NoSuchMethodException e)
  +
  +        _postSet = InterfaceExtension.getMethod(_delegateToClass, "postSet", PARAMTYPES_PREPOST);
  +        if (_postSet==null)
           {} // not available is ok, _postSet will be null
  -        catch (SecurityException e)
  -        {
  -            SchemaConfig.error("Security violation for class '" + _delegateToClass.getName() +
  -                "' accesing method postSet" + SIGNATURE, loc);
  -            valid = false;
  -        }
   
           if (_preSet==null && _postSet==null)
           {
  -            SchemaConfig.error("prePostSet handler specified '" + _delegateToClass.getName() +
  +            SchemaConfig.error("prePostSet handler specified '" + _delegateToClass.getSimpleName() +
                   "' but no preSet" + SIGNATURE + " or " +
                   "postSet" + SIGNATURE + " methods found.", loc);
               valid = false;
           }
   
           return valid;
  +    }
  +
  +    private void initParamPrePost(JamClassLoader jamLoader)
  +    {
  +        if (PARAMTYPES_PREPOST==null)
  +        {
  +            PARAMTYPES_PREPOST = new JClass[PARAMTYPES_STRING.length];
  +            for (int i = 0; i < PARAMTYPES_PREPOST.length; i++)
  +            {
  +                PARAMTYPES_PREPOST[i] = jamLoader.loadClass(PARAMTYPES_STRING[i]);
  +                if (PARAMTYPES_PREPOST[i]==null)
  +                {
  +                    throw new IllegalStateException("JAM should have access to the following types " + SIGNATURE);
  +                }
  +            }
  +        }
       }
   
       // public methods
  
  
  
  1.5       +63 -8     xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/SchemaConfig.java
  
  Index: SchemaConfig.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlconfig/org/apache/xmlbeans/impl/config/SchemaConfig.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaConfig.java	5 May 2004 00:45:38 -0000	1.4
  +++ SchemaConfig.java	12 May 2004 18:44:53 -0000	1.5
  @@ -18,11 +18,12 @@
   import javax.xml.namespace.QName;
   
   import java.util.Map;
  -import java.util.HashMap;
   import java.util.Collections;
   import java.util.LinkedHashMap;
   import java.util.List;
   import java.util.Iterator;
  +import java.io.File;
  +import java.io.IOException;
   
   import org.apache.xml.xmlbeans.x2004.x02.xbean.config.ConfigDocument.Config;
   import org.apache.xml.xmlbeans.x2004.x02.xbean.config.Nsconfig;
  @@ -31,6 +32,12 @@
   import org.apache.xmlbeans.XmlError;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.impl.schema.StscState;
  +import org.apache.xmlbeans.impl.jam.JamServiceFactory;
  +import org.apache.xmlbeans.impl.jam.JamServiceParams;
  +import org.apache.xmlbeans.impl.jam.JamService;
  +import org.apache.xmlbeans.impl.jam.JClass;
  +import org.apache.xmlbeans.impl.jam.JMethod;
  +import org.apache.xmlbeans.impl.jam.JamClassLoader;
   
   public class SchemaConfig
   {
  @@ -49,13 +56,15 @@
           _extensionHolder = null;
       }
       
  -    public static SchemaConfig forConfigDocuments(Config[] configs)
  +    public static SchemaConfig forConfigDocuments(Config[] configs, File[] javaFiles, File[] classpath)
       {
  -        return new SchemaConfig(configs);
  +        return new SchemaConfig(configs, javaFiles, classpath);
       }
       
  -    private SchemaConfig(Config[] configs)
  +    private SchemaConfig(Config[] configs, File[] javaFiles, File[] classpath)
       {
  +        JamClassLoader jamLoader = getJamLoader(javaFiles, classpath);
  +
           _packageMap = new LinkedHashMap();
           _prefixMap = new LinkedHashMap();
           _suffixMap = new LinkedHashMap();
  @@ -82,7 +91,7 @@
               Extensionconfig[] ext = config.getExtensionArray();
               for (int j = 0; j < ext.length; j++)
               {
  -                recordExtensionSetting(ext[j]);
  +                recordExtensionSetting(jamLoader, ext[j]);
               }
           }
           _extensionHolder.secondPhaseValidation();
  @@ -109,7 +118,7 @@
           }
       }
   
  -    private void recordExtensionSetting(Extensionconfig ext)
  +    private void recordExtensionSetting(JamClassLoader jamLoader, Extensionconfig ext)
       {
           NameSet xbeanSet = null;
           Object key = ext.getFor();
  @@ -135,10 +144,10 @@
   
           for (int i = 0; i < intfXO.length; i++)
           {
  -            _extensionHolder.addInterfaceExtension(InterfaceExtension.newInstance(xbeanSet, intfXO[i]));
  +            _extensionHolder.addInterfaceExtension(InterfaceExtension.newInstance(jamLoader, xbeanSet, intfXO[i]));
           }
   
  -        _extensionHolder.addPrePostExtension(PrePostExtension.newInstance(xbeanSet, ext.getPrePostSet()));
  +        _extensionHolder.addPrePostExtension(PrePostExtension.newInstance(jamLoader, xbeanSet, ext.getPrePostSet()));
       }
   
       private String lookup(Map map, String uri)
  @@ -191,5 +200,51 @@
       public ExtensionHolder getExtensionHolder()
       {
           return _extensionHolder;
  +    }
  +
  +    private JamClassLoader getJamLoader(File[] javaFiles, File[] classpath)
  +    {
  +        JamServiceFactory jf = JamServiceFactory.getInstance();
  +        JamServiceParams params = jf.createServiceParams();
  +
  +        // process the included sources
  +        if (javaFiles!=null)
  +            for (int i = 0; i < javaFiles.length; i++)
  +                params.includeSourceFile(javaFiles[i]);
  +
  +        //params.setVerbose(DirectoryScanner.class);
  +
  +        // add the sourcepath and classpath, if specified
  +        params.addClassLoader(this.getClass().getClassLoader());
  +        if (classpath != null)
  +            for (int i = 0; i < classpath.length; i++)
  +                params.addClasspath(classpath[i]);
  +
  +        // create service, get classes, return compiler
  +        JamService service;
  +        try
  +        {
  +            service = jf.createService(params);
  +        }
  +        catch (IOException ioe)
  +        {
  +            error("Error when accessing .java files.", null);
  +            return null;
  +        }
  +
  +//        JClass[] cls = service.getAllClasses();
  +//        for (int i = 0; i < cls.length; i++)
  +//        {
  +//            JClass cl = cls[i];
  +//            System.out.println("CL: " + cl + " " + cl.getQualifiedName());
  +//            JMethod[] methods = cl.getMethods();
  +//            for (int j = 0; j < methods.length; j++)
  +//            {
  +//                JMethod method = methods[j];
  +//                System.out.println("    " + method.getQualifiedName());
  +//            }
  +//        }
  +
  +        return service.getClassLoader();
       }
   }
  
  
  

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