You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2004/03/01 22:20:06 UTC
cvs commit: xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam GoldenMethod.java ModifierHelper.java ClassesJamTest.java ImplComparisonTest.java JamTestBase.java SourcesJamTest.java
pcal 2004/03/01 13:20:06
Modified: v2/src/jam java.g
v2/src/jam/org/apache/xmlbeans/impl/jam JFactory.java
JFileSet.java package.html
v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser
JavaSourceParser.java
v2/src/jam/org/apache/xmlbeans/impl/jam/provider
JStoreParams.java
v2/src/jeti/org/apache/xmlbeans/impl/jeti ToolContext.java
v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
Foo.java FooImpl.java
v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam
ClassesJamTest.java ImplComparisonTest.java
JamTestBase.java SourcesJamTest.java
Added: v2/src/jam/org/apache/xmlbeans/impl/jam JResult.java
JResultFactory.java JResultParams.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable
EResult.java EResultFactory.java EResultParams.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl
EResultImpl.java EResultParamsImpl.java
v2/src/jam/org/apache/xmlbeans/impl/jam/provider
DefaultJResultFactory.java JResultImpl.java
JResultParamsImpl.java
v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam
GoldenMethod.java ModifierHelper.java
Removed: v2/src/jam/org/apache/xmlbeans/impl/jam JProvider.java
JService.java JServiceFactory.java
JServiceParams.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable
EService.java EServiceFactory.java
EServiceParams.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl
EServiceImpl.java EServiceParamsImpl.java
v2/src/jam/org/apache/xmlbeans/impl/jam/internal
JServiceImpl.java JServiceParamsImpl.java
v2/src/jam/org/apache/xmlbeans/impl/jam/provider
BaseJProvider.java DefaultJProvider.java
Log:
jam: rename JService->JResult, streamline spi, add new test cases
Revision Changes Path
1.4 +6 -6 xml-xmlbeans/v2/src/jam/java.g
Index: java.g
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/java.g,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- java.g 1 Mar 2004 00:10:18 -0000 1.3
+++ java.g 1 Mar 2004 21:20:05 -0000 1.4
@@ -171,7 +171,7 @@
private String mLastJavadoc = null;
private String /*EPackage*/ mPackage;
- private EService mService;
+ private EResult mResult;
private List mErrors = null;
private List mImports = new ArrayList();
private List mClasses = new ArrayList();
@@ -182,12 +182,12 @@
// ========================================================================
// Public methods
- public void init(EService service, EClass clazz) {
- mService = service;
+ public void init(EResult result, EClass clazz) {
+ mResult = result;
}
- public void setService(EService service) {
- mService = service;
+ public void setService(EResult result) {
+ mResult = result;
}
public EClass[] getResults() {
@@ -240,7 +240,7 @@
private EClass newClass(String simpleName) {
//FIXME more to do here
- EClass clazz = mService.addNewClass(mPackage,simpleName/*,mImports*/);
+ EClass clazz = mResult.addNewClass(mPackage,simpleName/*,mImports*/);
mClasses.add(clazz);
return clazz;
}
1.9 +1 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java
Index: JFactory.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JFactory.java 12 Feb 2004 20:06:09 -0000 1.8
+++ JFactory.java 1 Mar 2004 21:20:05 -0000 1.9
@@ -43,7 +43,7 @@
* }
* </pre>
*
- * @deprecated Please us JServiceFactory instead.
+ * @deprecated Please us JResultFactory instead.
*
* @author Patrick Calahan <pc...@bea.com>
*/
1.6 +1 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFileSet.java
Index: JFileSet.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFileSet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JFileSet.java 12 Feb 2004 20:06:09 -0000 1.5
+++ JFileSet.java 1 Mar 2004 21:20:05 -0000 1.6
@@ -22,7 +22,7 @@
* <p>Describes a set of input source files which describe the java types to
* be represented. Instances of JFileSet are created by JFactory.</p>
*
- * @deprecated Please us JServiceFactory instead.
+ * @deprecated Please us JResultFactory instead.
*
* @author Patrick Calahan <pc...@bea.com>
*/
1.2 +169 -0 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/package.html
Index: package.html
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/package.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- package.html 29 Sep 2003 21:29:05 -0000 1.1
+++ package.html 1 Mar 2004 21:20:05 -0000 1.2
@@ -36,4 +36,173 @@
</ul>
+
+<h3>Comparison of Java Type Inspection Technologies</h3>
+
+
+
+<table border='1'>
+ <tr>
+ <td />
+ <td colspan='2' align='center'>JDK 1.4</td>
+ <td colspan='2' align='center'>JDK 1.5</td>
+ </tr>
+ <tr>
+ <td />
+ <td>Javadoc</td>
+ <td>Reflect</td>
+ <td>Javadoc</td>
+ <td>Reflect</td>
+ <td>JavaBeans</td>
+ <td>XDoclet</td>
+ <td>QDox</td>
+ <td>JAM</td>
+ </tr>
+
+ <tr>
+ <td>JSR-175 from sources</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>JSR-175 from classfiles</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Javadoc-style metadata from source</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td>?</td>
+ <td>no</td>
+ <td>no</td>
+ <td>?</td>
+ <td>?</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Line/column number info</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no(1)</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no(1)</td>
+ <td>no(1)</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Retrieve comments from source</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Method parameter names</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no(1)</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no(1)</td>
+ <td>no(1)</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Overlay external metadata</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Full introspection of 175 annotation types<br>
+ (including default values)</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+
+ <tr>
+ <td>Parse invalid source files</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Extensibility/SPI</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ <tr>
+ <td>Supports 'Property' abstraction</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ <td>no</td>
+ <td>no</td>
+ <td bgcolor='#22DD22'>yes</td>
+ </tr>
+
+ </table>
+
+<h4>notes</h4>
+<p>
+ (1) This information is embedded in the .class files when the -g debug
+ flag specified on javac so that it can be displayed in stack
+ traces. However, there still is no API provided for retrieving
+ this information at runtime.<br />
+</p>
+
+
+
</body>
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JResult.java
Index: JResult.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam;
/**
* <p>Encapsulates the a set of java classes which were which met a set of
* criteria described in a JResultParams object. A JResult exposes both a
* particular set of JClasses, as well as a JClassLoader which can be used
* to load related classes.</p>
*
* @author Patrick Calahan <pc...@bea.com>
*/
public interface JResult {
/**
* Returns a JClassLoader which can be used to load JClasses from class-
* and source-file locations specified in the JResultParams with which
* this service was instantiated. Note that it is possible to use this
* mechanism to load JClasses that are not returned by getClasses().
*/
public JClassLoader getClassLoader();
/**
* Returns the names of the classes that were described in the
* JResultParams object used to create this service. Note that this
* list will never change for a given service; though it is possible
* to use the service's JClassLoader to load other types, this method will
* always return the initial set of classes.
*/
public String[] getClassNames();
/**
* Returns an iterator of the JClasses named in the array returned by
* getClassNames().
*/
public JClassIterator getClasses();
/**
* Returns all of the JClasses returned by getClasses() in a single
* array. Use of this method (as opposed to getClasses()) is not advised
* if you expect to be dealing with a very large set of classes, as it makes
* it less likely that JClasses will be garbage collected when no longer
* needed.
*/
public JClass[] getAllClasses();
//public void invalidate(JClass clazz);
//public void invalidateAll();
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JResultFactory.java
Index: JResultFactory.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam;
import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
import org.apache.xmlbeans.impl.jam.provider.DefaultJResultFactory;
import java.io.IOException;
import java.io.File;
import java.io.PrintWriter;
/**
* This is the normal entry point into the JAM subsystem. JResultFactory
* is a singleton factory which can create a new JResultParams and
* JServices. Here is a code sample that demonstrates how to use
* JResultFactory.
*
* <pre>
* JResultFactory factory = JResultFactory.getInstance();
* JResultParams params = factory.createServiceParams();
* params.includeSources(new File("c:/myproject/src","mypackage/*.java"));
* JResult service = factory.createService(params);
* </pre>
*
* @author Patrick Calahan <pc...@bea.com>
*/
public abstract class JResultFactory {
// ========================================================================
// Constants
private static final JResultFactory DEFAULT = new DefaultJResultFactory();
// ========================================================================
// Singleton
/**
* Return the default factory singleton for this VM.
*/
public static JResultFactory getInstance() { return DEFAULT; }
// ========================================================================
// Constructors
protected JResultFactory() {}
// ========================================================================
// Public methods
/**
* Create a new JResultParams instance. The params can be populated
* and then given to the createService method to create a new JResult.
*/
public abstract JResultParams createResultParams();
/**
* Create a new JResult from the given parameters.
*
* @throws IOException if an IO error occurred while creating the service
* @throws IllegalArgumentException if the params is null or not
* an instance returned by createServiceParams().
*/
public abstract JResult createResult(JResultParams params) throws IOException;
// ========================================================================
// main() method
public static void main(String[] args) {
try {
JResultParams sp = getInstance().createResultParams();
for(int i=0; i<args.length; i++) {
sp.includeSourceFiles(new File("."),args[i]);
}
JResult service = getInstance().createResult(sp);
JamPrinter jp = JamPrinter.newInstance();
PrintWriter out = new PrintWriter(System.out);
for(JClassIterator i = service.getClasses(); i.hasNext(); ) {
out.println("-------- ");
jp.print(i.nextClass(),out);
}
out.flush();
} catch(Exception e){
e.printStackTrace();
}
System.out.flush();
System.err.flush();
}
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JResultParams.java
Index: JResultParams.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam;
import java.io.File;
import java.io.PrintWriter;
/**
* Object which specifies parameters for creating a new JResult.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public interface JResultParams {
// ========================================================================
// Public methods
/**
* Specifies a set of java source files to be included in the JResult.
*
* <p>Note that calling this method implicitly includes the 'root' in
* the sourcepath (exactly as if addSourcepath(root) had been called).</p>
*
* @param root Root directory of the source files.
* @param pattern A relative file pattern (as described above under
* 'Include and Exclude Patterns').
* @throws IllegalArgumentException if either argument is null.
*/
public void includeSourceFiles(File root, String pattern);
/**
* Specifies a set of java source files to be excluded in the JResult.
* Note that calling this method implicitly includes the 'root' in
* the sourcepath (as in a call to addSourcepath(root)).
*
* @param root Root directory of the source files.
* @param pattern A relative file pattern (as described above under
* 'Include and Exclude Patterns').
* @throws IllegalArgumentException if either argument is null.
*/
public void excludeSourceFiles(File root, String pattern);
/**
* Specifies a set of java class files to be excluded in the JResult.
* Note that calling this method implicitly includes the 'root' in
* the classpath (as in a call to addClasspath(root)).
*
* @param root Root directory of the source files.
* @param pattern A relative file pattern (as described above under
* 'Include and Exclude Patterns').
* @throws IllegalArgumentException if either argument is null.
*/
public void includeClassFiles(File root, String pattern);
/**
* Specifies a set of java class files to be excluded from the JResult.
* Note that calling this method implicitly includes the 'root' in
* the classpath (as in a call to addClasspath(root)).
*
* @param root Root directory of the source files.
* @param pattern A relative file pattern (as described above under
* 'Include and Exclude Patterns').
* @throws IllegalArgumentException if either argument is null.
*/
public void excludeClassFiles(File root, String pattern);
/**
* <p>Includes a single source File in the JResult. The root parameter
* should identify the source root of the java source file; the sourceFile
* parameter must be under the root subtree.</p>
*
* <p>For example, if a class "foo.bar.MyClass" is stored in a file
* "c:/myproject/src/foo/bar/MyClass.java", that class could be included in
* the service by calling</p>
*
* <pre>
* includeSourceFile(new File("c:/myproject/src"),
* new File("c:/myproject/src/foo/bar/MyClass.java"));
* </pre>
*
* <p>Note that this equivalent to calling</p>
*
* <pre>
* includeSourceFiles(new File("c:/myproject/src"),"foo/bar/MyClass.java");
* </pre>
*
* <p>If you are calling this method and have more than one root directory,
* and do not readily know which is the correct root for a given source
* File, you can use the getRootForFile() utility method to determine the
* correct root to use.</p>
*
* <p>Note that calling this method implicitly includes the 'root' in
* the sourcepath (exactly as if addSourcepath(root) had been called).</p>
*
* @param root source root for the java source file
* @param sourceFile the java source file
* @throws IllegalArgumentException if either argument is null or if
* root is not an ancestor of sourceFile in the file system.
*/
public void includeSourceFile(File root, File sourceFile);
/**
* <p>Excludes a single source File in the JResult in exactly the same
* way theat includeSourceFile() includes a source file.
*/
public void excludeSourceFile(File root, File sourceFile);
/**
* <p>Includes a single class File in the JResult in exactly the same
* way theat includeSourceFile() includes a source file.
*/
public void includeClassFile(File root, File sourceFile);
/**
* <p>Excludes a single class File in the JResult in exactly the same
* way theat includeSourceFile() includes a source file.
*/
public void excludeClassFile(File root, File sourceFile);
/**
* Names a specific class to be included in the JResult. Note that
* this will return an 'unresolved' JClass unless a source or class file
* for the named class is available in the classpath or sourcepath.
*
* @param qualifiedClassname a full-qualified classname
* @throws IllegalArgumentException if the argument is null or not
* a valid classname.
*/
public void includeClass(String qualifiedClassname);
/**
* Names a specific class to be excluded in the JResult. Note that
* this will have no affect if the named class cannot be found in the
* sourcepath or classpath.
*
* @param qualifiedClassname a full-qualified classname
* @throws IllegalArgumentException if the argument is null or not
* a valid classname.
*/
public void excludeClass(String qualifiedClassname);
/**
* Adds an element to the JResult sourcepath. The service's JClassLoader
* will search this path to find a .java file on which to base a JClass
* when requested to load a class that was not included in the service.
*/
public void addSourcepath(File sourcepathElement);
/**
* Adds an element to the JResult classpath. The service's JClassLoader
* will search this path to find a .class file on which to base a JClass
* when requested to load a class that was not included in the service
* and for which no source could be found in the sourcepath.
*
* @param classpathElement element of the classpath
* @throws IllegalArgumentException if the argument is null
*/
public void addClasspath(File classpathElement);
/**
* Sets a loader for external annotations to be used in the service.
*
* @param ann an implementation of JAnnotationLoader
* @throws IllegalArgumentException if the argument is null
*/
public void setAnnotationLoader(JAnnotationLoader ann);
/**
* Sets a PrintWriter to which the JResult implementation should log
* errors and debugging information. If this is never set, all such output
* will be suppressed.
*
* @param out a PrintWriter to write to
* @throws IllegalArgumentException if the argument is null
*/
public void setLogger(PrintWriter out);
/**
* Sets whether the JResult should send verbose output to the logger.
* Has no effect if setLogger() is never called.
*
* @param v whether or not boolean output is enabled.
*/
public void setVerbose(boolean v);
/**
* Sets the parent JClassLoader of the service JClassLoader.
*
* @param loader the parent loaer
* @throws IllegalArgumentException if the argument is null
*/
public void setParentClassLoader(JClassLoader loader);
//public void setBaseClassLoader(ClassLoader cl);
/**
* Adds an element to the tool classpath. This is the classpath that
* will be used by the JResult implementation to find any libraries
* on which it depends. This classpath distinct from the service classpath
* set by addClasspath().
*
* @param classpathElement element of the classpath
* @throws IllegalArgumentException if the argument is null
*/
public void addToolClasspath(File classpathElement);
/**
* Specifies whether the JAM Service should load classes from the system
* classpath. The default for this is true.
*/
public void setUseSystemClasspath(boolean use);
/**
* Sets a JResult implementation-dependent property.
*/
public void setProperty(String name, String value);
/**
* <p>Utility method which, given an array of Files representing a series of
* java source roots, returns the first one in array order which is an
* ancestor of the given sourceFile in the file hierarchy. Returns null if
* the sourceFile is not under any of the given sourceRoots</p>
*
* @param sourceRoots roots to check
* @param sourceFile source file
* @return the sourceRoot that contains the sourceFile, or null if none
* does.
* @throws IllegalArgumentException if either argument is null.
*/
public File getRootForFile(File[] sourceRoots, File sourceFile);
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EResult.java
Index: EResult.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.editable;
import org.apache.xmlbeans.impl.jam.JResult;
import org.apache.xmlbeans.impl.jam.JClass;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public interface EResult extends JResult {
public EClass addNewClass(String packageName, String className);
public EClass addNewClass(JClass copyme);
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EResultFactory.java
Index: EResultFactory.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.editable;
import org.apache.xmlbeans.impl.jam.JResult;
import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
import org.apache.xmlbeans.impl.jam.editable.impl.EResultParamsImpl;
import org.apache.xmlbeans.impl.jam.editable.impl.EResultImpl;
import java.io.IOException;
import java.io.PrintWriter;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class EResultFactory {
// ========================================================================
// Constants
private static final EResultFactory INSTANCE = new EResultFactory();
// ========================================================================
// Singleton
/**
* Return the factory singleton.
*/
public static EResultFactory getInstance() { return INSTANCE; }
private EResultFactory() {}
// ========================================================================
// Public methods
/**
* Create a new JResultParams instance. The params can be populated
* and then given to the createService method to create a new JResult.
*/
public EResultParams createServiceParams() {
return new EResultParamsImpl();
}
/**
* Create a new JResult from the given parameters.
*
* @throws IllegalArgumentException if the params is null or not
* an instance returned by createServiceParams().
*/
public EResult createService(EResultParams params) {
return new EResultImpl((EResultParamsImpl)params);
}
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
out.println("Running EServiceTest");
try {
EResultFactory factory = EResultFactory.getInstance();
EResultParams params = factory.createServiceParams();
EResult service = factory.createService(params);
//
//dumb test code
//
EClass testClass = service.addNewClass("com.bea.pcal","TestClass");
EClass fooClass = service.addNewClass("com.bea.pcal","Foo");
testClass.addNewMethod().setReturnType(fooClass);
testClass.addNewField().setUnqualifiedType("TestClass");
//
JamPrinter.newInstance().print(service.getClasses(),out);
} catch(Exception e) {
e.printStackTrace();
}
out.flush();
System.out.flush();
System.err.flush();
}
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EResultParams.java
Index: EResultParams.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.editable;
import org.apache.xmlbeans.impl.jam.JAnnotationLoader;
import org.apache.xmlbeans.impl.jam.JClassLoader;
import java.io.File;
import java.io.PrintWriter;
/**
* Structure which encapsulates a set of parameters used to create a new
* EResult.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public interface EResultParams {
/**
* Sets a loader for external annotations to be used in the service.
*
* @param ann an implementation of JAnnotationLoader
* @throws IllegalArgumentException if the argument is null
*/
public void setAnnotationLoader(JAnnotationLoader ann);
/**
* Sets a PrintWriter to which the EResult implementation should log
* errors and debugging information. If this is never set, all such output
* will be suppressed.
*
* @param out a PrintWriter to write to
* @throws IllegalArgumentException if the argument is null
*/
public void setLogger(PrintWriter out);
/**
* Sets whether the EResult should send verbose output to the logger.
* Has no effect if setLogger() is never called.
*
* @param v whether or not boolean output is enabled.
*/
public void setVerbose(boolean v);
/**
* Sets the parent JClassLoader of the service's JClassLoader.
*
* @param loader the parent loaer
* @throws IllegalArgumentException if the argument is null
*/
public void setParentClassLoader(JClassLoader loader);
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EResultImpl.java
Index: EResultImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.editable.impl;
import org.apache.xmlbeans.impl.jam.editable.EResult;
import org.apache.xmlbeans.impl.jam.editable.EClass;
import org.apache.xmlbeans.impl.jam.*;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class EResultImpl implements EResult, JClassLoader {
// ========================================================================
// Variables
private Map mClasses = new HashMap();
private JClassLoader mBaseClassLoader;
private JAnnotationLoader mAnnotationLoader = null;
// ========================================================================
// Constructors
public EResultImpl(EResultParamsImpl params) {
mBaseClassLoader = params.getParentClassLoader();
mAnnotationLoader = params.getAnnotationLoader();
}
// ========================================================================
// EResult implementation
public EClass addNewClass(String packageName, String className) {
EClassImpl out = new EClassImpl(packageName,className,this);
mClasses.put(out.getQualifiedName(),out);
return out;
}
public EClass addNewClass(JClass copyme) {
throw new IllegalStateException("NYI");
}
public JClassLoader getClassLoader() {
return this;
}
// ========================================================================
// JResult implementation
public String[] getClassNames() {
String[] out = new String[mClasses.values().size()];
mClasses.keySet().toArray(out);
return out;
}
public JClassIterator getClasses() {
return new JClassIterator(this,getClassNames());
}
public JClass[] getAllClasses() {
JClass[] out = new JClass[mClasses.values().size()];
mClasses.values().toArray(out);
return out;
}
// ========================================================================
// JClassLoader implementation
public JClass loadClass(String classname) {
JClass out = (JClass)mClasses.get(classname);
if (out != null) return out;
return mBaseClassLoader.loadClass(classname);
}
public JPackage getPackage(String qualifiedPackageName) {
return mBaseClassLoader.getPackage(qualifiedPackageName);
}
public JAnnotationLoader getAnnotationLoader() {
return mAnnotationLoader;
}
public JClassLoader getParent() {
return mBaseClassLoader;
}
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EResultParamsImpl.java
Index: EResultParamsImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.editable.impl;
import org.apache.xmlbeans.impl.jam.editable.EResultParams;
import org.apache.xmlbeans.impl.jam.JAnnotationLoader;
import org.apache.xmlbeans.impl.jam.JClassLoader;
import org.apache.xmlbeans.impl.jam.JFactory;
import java.io.PrintWriter;
/**
* FIXME - implement this
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class EResultParamsImpl implements EResultParams {
// ========================================================================
// Variables
private JClassLoader mParentLoader =
JFactory.getInstance().getSystemClassLoader();//FIXME
private JAnnotationLoader mAnnLoader = null;
private boolean mVerbose = false;
// ========================================================================
// Package methods
/*package*/ JClassLoader getParentClassLoader() {
return mParentLoader;
}
/*package*/ boolean isVerbose() {
return mVerbose;
}
/*package*/ JAnnotationLoader getAnnotationLoader() {
return mAnnLoader;
}
// ========================================================================
// EResultParams implementation
public void setAnnotationLoader(JAnnotationLoader ann) {
mAnnLoader = ann;
}
public void setLogger(PrintWriter out) {
}
public void setVerbose(boolean v) {
mVerbose = v;
}
public void setParentClassLoader(JClassLoader loader) {
}
}
1.3 +7 -7 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/JavaSourceParser.java
Index: JavaSourceParser.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/JavaSourceParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaSourceParser.java 25 Feb 2004 18:56:49 -0000 1.2
+++ JavaSourceParser.java 1 Mar 2004 21:20:05 -0000 1.3
@@ -18,9 +18,9 @@
import org.apache.xmlbeans.impl.jam.internal.parser.generated.JavaParser;
import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
import org.apache.xmlbeans.impl.jam.editable.EClass;
-import org.apache.xmlbeans.impl.jam.editable.EService;
-import org.apache.xmlbeans.impl.jam.editable.EServiceFactory;
-import org.apache.xmlbeans.impl.jam.editable.EServiceParams;
+import org.apache.xmlbeans.impl.jam.editable.EResult;
+import org.apache.xmlbeans.impl.jam.editable.EResultFactory;
+import org.apache.xmlbeans.impl.jam.editable.EResultParams;
import java.io.*;
import java.util.ArrayList;
@@ -52,7 +52,7 @@
// ========================================================================
// Public methods
- public EClass[] parse(Reader in, EService service) throws Exception {
+ public EClass[] parse(Reader in, EResult service) throws Exception {
JavaLexer lexer = new JavaLexer(in);
JavaParser parser = new JavaParser(lexer);
parser.setService(service);
@@ -61,9 +61,9 @@
}
public EClass[] parse(Reader in) throws Exception {
- EServiceFactory esf = EServiceFactory.getInstance();
- EServiceParams params = esf.createServiceParams();
- EService defaultService = esf.createService(params);
+ EResultFactory esf = EResultFactory.getInstance();
+ EResultParams params = esf.createServiceParams();
+ EResult defaultService = esf.createService(params);
JavaLexer lexer = new JavaLexer(in);
JavaParser parser = new JavaParser(lexer);
parser.setService(defaultService);
1.2 +3 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JStoreParams.java
Index: JStoreParams.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JStoreParams.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JStoreParams.java 25 Feb 2004 18:56:49 -0000 1.1
+++ JStoreParams.java 1 Mar 2004 21:20:05 -0000 1.2
@@ -63,7 +63,9 @@
/**
* <p>Structure containing information given to a BaseJProvider subclass in
- * order to instantiate a new JStore.</p>
+ * order to instantiate a new JStore. This interface really just provides
+ * an 'inside look' at JResultParams - it's usually going to be implemented
+ * by the same object.</p>
*
* @author Patrick Calahan <pc...@bea.com>
*/
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/DefaultJResultFactory.java
Index: DefaultJResultFactory.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.provider;
import org.apache.xmlbeans.impl.jam.JResultFactory;
import org.apache.xmlbeans.impl.jam.JResultParams;
import org.apache.xmlbeans.impl.jam.JResult;
import org.apache.xmlbeans.impl.jam.JClassLoader;
import org.apache.xmlbeans.impl.jam.internal.RootJClassLoader;
import org.apache.xmlbeans.impl.jam.internal.reflect.RClassLoader;
import org.apache.xmlbeans.impl.jam.internal.javadoc.JDClassLoaderFactory;
import java.io.IOException;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
/**
* <p>Default implementation of JResultFactory. It currently uses javadoc
* for inspecting sources and reflection for inspecting classes.</p>
*
* <p>Note that this class can be used as a base class for custom factories.
* </p>
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class DefaultJResultFactory extends JResultFactory {
// ========================================================================
// Constructors
public DefaultJResultFactory() {}
// ========================================================================
// JResultFactory implementation
public JResultParams createResultParams() {
return new JResultParamsImpl();
}
public JResult createResult(JResultParams jsps) throws IOException {
//assert that they aren't implementing JResultParams themselves or
//getting them from somewhere else
if (!(jsps instanceof JResultParamsImpl)) {
throw new IllegalArgumentException
("JResultParams must be instantiated by this JResultFactory.");
}
//create and return the service
return new JResultImpl(createClassLoader((JResultParamsImpl)jsps),
getSpecifiedClasses((JResultParamsImpl)jsps));
}
// ========================================================================
// Protected methods - override at your own risk
/**
* <p>Returns the set of classes to be included in a JResult to be
* created by the given params. You should not override this
* unless you really know what you're doing.</p>
*/
protected String[] getSpecifiedClasses(JResultParamsImpl params)
throws IOException
{
return params.getAllClassnames();
}
/**
* <p>Creates the main classloader to be used given the input params.
* This is usually a composite of the a source classloader and a
* classfile classloader. Subclasses may override to change the behavior.
* </p>
*/
protected JClassLoader createClassLoader(JResultParamsImpl params)
throws IOException
{
// Build up the clasloader chain. Note that each loader we create is
// used as a parent of the next.
//
// The root classloader deals with Object, void, primitives, arrays...
JClassLoader loader = new RootJClassLoader(params.getAnnotationLoader());
// Usually they will also want the system classloader in there, but this
// is optional
if (params.isUseSystemClasspath()) {
loader = new RClassLoader(ClassLoader.getSystemClassLoader(),loader);
}
// Now create a loader for any classfile loading they specified
JClassLoader classfileLoader = createClassfileLoader(params,loader);
if (classfileLoader != null) loader = classfileLoader;
// Finally check for sources
JClassLoader sourceLoader = createSourceLoader(params,loader);
if (sourceLoader != null) loader = sourceLoader;
//
return loader;
}
/**
* <p>Creates the sourcefile classloader to be used given the input params.
* Returns null if no source files are specified in the params. Subclasses
* may override to change the way in which java sources are loaded.</p>
*/
protected JClassLoader createSourceLoader(JResultParamsImpl params,
JClassLoader parent)
throws IOException
{
//FIXME someday should make the name of the service class to use here
//settable via a system property
File[] files = params.getSourceFiles();
if (files == null || files.length == 0) return null;
String sourcePath = (params.getInputSourcepath() == null) ? null :
params.getInputSourcepath().toString();
String classPath = (params.getInputClasspath() == null) ? null :
params.getInputClasspath().toString();
return JDClassLoaderFactory.getInstance().
create(files,
parent,
params.getAnnotationLoader(),
params.getOut(),
sourcePath,
classPath,
null);//FIXME get javadoc args from param props
}
/**
* <p>Creates the sourcefile classloader to be used given the input params.
* If no class files or classloaders are specified in the params, this
* source files are specified in the params, this just returns null.
* Subclasses may override to change the way in which java classes
* are loaded.</p>
*/
protected JClassLoader createClassfileLoader(JStoreParams jp,
JClassLoader parent)
throws IOException
{
//FIXME someday should make the name of the service class to use here
//settable via a system property
JPath cp = jp.getInputClasspath();
if (cp == null) {
return null;
} else {
URL[] urls = cp.toUrlPath();
return new RClassLoader(new URLClassLoader(urls),parent);
}
}
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JResultImpl.java
Index: JResultImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.provider;
import org.apache.xmlbeans.impl.jam.JResult;
import org.apache.xmlbeans.impl.jam.JClassLoader;
import org.apache.xmlbeans.impl.jam.JClassIterator;
import org.apache.xmlbeans.impl.jam.JClass;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class JResultImpl implements JResult {
// ========================================================================
// Variables
private JClassLoader mClassLoader;
private String[] mClassNames;
// ========================================================================
// Constructors
public JResultImpl(JClassLoader jcl, String[] classes) {
if (jcl == null) throw new IllegalArgumentException("null jcl");
if (classes == null) throw new IllegalArgumentException("null classes");
mClassLoader = jcl;
mClassNames = classes;
}
// ========================================================================
// JResult implementation
public JClassLoader getClassLoader() {
return mClassLoader;
}
public String[] getClassNames() {
return mClassNames;
}
public JClassIterator getClasses() {
return new JClassIterator(getClassLoader(),getClassNames());
}
public JClass[] getAllClasses() {
JClass[] out = new JClass[mClassNames.length];
for(int i=0; i<out.length; i++) {
out[i] = getClassLoader().loadClass(mClassNames[i]);
}
return out;
}
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JResultParamsImpl.java
Index: JResultParamsImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.provider;
import org.apache.xmlbeans.impl.jam.JAnnotationLoader;
import org.apache.xmlbeans.impl.jam.JClassLoader;
import org.apache.xmlbeans.impl.jam.JResultParams;
import org.apache.xmlbeans.impl.jam.internal.DirectoryScanner;
import org.apache.xmlbeans.impl.jam.provider.JStoreParams;
import org.apache.xmlbeans.impl.jam.provider.JPath;
import java.util.*;
import java.io.PrintWriter;
import java.io.File;
import java.io.IOException;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class JResultParamsImpl implements JResultParams, JStoreParams
{
// ========================================================================
// Variables
private Properties mProperties = null;
private Map mSourceRoot2Scanner = null;
private Map mClassRoot2Scanner = null;
private List mClasspath = null;
private List mSourcepath = null;
private List mToolClasspath = null;
private List mIncludeClasses = null;
private List mExcludeClasses = null;
private PrintWriter mOut = null;
private JAnnotationLoader mAnnotationLoader = null;
private boolean mUseSystemClasspath = true;
private boolean mVerbose = false;
private JClassLoader mParentClassloader = null;
// ========================================================================
// Constructors
public JResultParamsImpl() {}
// ========================================================================
// Public methods - used by BaseJProvider
public JAnnotationLoader getAnnotationLoader() {
return mAnnotationLoader;
}
public boolean isUseSystemClasspath() { return mUseSystemClasspath; }
public boolean isVerbose() { return mVerbose; }
/**
* Returns an array containing the qualified names of the classes which
* are in the Service class set.
*/
public String[] getAllClassnames() throws IOException {
Set all = new HashSet();
if (mIncludeClasses != null) all.addAll(mIncludeClasses);
for(Iterator i = getAllDirectoryScanners(); i.hasNext(); ) {
DirectoryScanner ds = (DirectoryScanner)i.next();
String[] files = ds.getIncludedFiles();
for(int j=0; j<files.length; j++) {
all.add(filename2classname(files[j]));
}
}
if (mExcludeClasses != null) all.removeAll(mExcludeClasses);
String[] out = new String[all.size()];
all.toArray(out);
return out;
}
/*
public String[] getSourceClassnames() throws IOException {
if (mSourceRoot2Scanner == null) return new String[0];
Set set = new HashSet();
for(Iterator i = mSourceRoot2Scanner.values().iterator(); i.hasNext(); ) {
DirectoryScanner ds = (DirectoryScanner)i.next();
String[] files = ds.getIncludedFiles();
for(int j=0; j<files.length; j++) {
set.add(filename2classname(files[j]));
}
}
String[] out = new String[set.size()];
set.toArray(out);
return out;
}*/
public File[] getSourceFiles() throws IOException {
if (mSourceRoot2Scanner == null) return new File[0];
Set set = new HashSet();
for(Iterator i = mSourceRoot2Scanner.values().iterator(); i.hasNext(); ) {
DirectoryScanner ds = (DirectoryScanner)i.next();
String[] files = ds.getIncludedFiles();
for(int j=0; j<files.length; j++) {
set.add(new File(ds.getRoot(),files[j]));
}
}
File[] out = new File[set.size()];
set.toArray(out);
return out;
}
// ========================================================================
// JResultFactory implementation
public void includeSourceFiles(File srcRoot, String pattern) {
addSourcepath(srcRoot);
getSourceScanner(srcRoot).include(pattern);
}
public void includeClassFiles(File srcRoot, String pattern) {
addClasspath(srcRoot);
getClassScanner(srcRoot).include(pattern);
}
public void excludeSourceFiles(File srcRoot, String pattern) {
addSourcepath(srcRoot);
getSourceScanner(srcRoot).exclude(pattern);
}
public void excludeClassFiles(File srcRoot, String pattern) {
addClasspath(srcRoot);
getClassScanner(srcRoot).exclude(pattern);
}
public void includeSourceFile(File root, File sourceFile) {
includeSourceFiles(root,source2pattern(root,sourceFile));
}
public void excludeSourceFile(File root, File sourceFile) {
excludeSourceFiles(root,source2pattern(root,sourceFile));
}
public void includeClassFile(File root, File classFile) {
includeClassFiles(root,source2pattern(root,classFile));
}
public void excludeClassFile(File root, File classFile) {
excludeClassFiles(root,source2pattern(root,classFile));
}
public void includeClass(String qualifiedClassname) {
if (mIncludeClasses == null) mIncludeClasses = new ArrayList();
mIncludeClasses.add(qualifiedClassname);
}
public void excludeClass(String qualifiedClassname) {
if (mExcludeClasses == null) mExcludeClasses = new ArrayList();
mExcludeClasses.add(qualifiedClassname);
}
public void addClasspath(File classpathElement) {
if (mClasspath == null) mClasspath = new ArrayList();
mClasspath.add(classpathElement);
}
public void addSourcepath(File sourcepathElement) {
if (mSourcepath == null) mSourcepath = new ArrayList();
mSourcepath.add(sourcepathElement);
}
public void addToolClasspath(File classpathElement) {
if (mToolClasspath == null) mToolClasspath = new ArrayList();
mToolClasspath.add(classpathElement);
}
public void setProperty(String name, String value) {
if (mProperties == null) mProperties = new Properties();
mProperties.setProperty(name,value);
}
public void setLogger(PrintWriter out) { mOut = out; }
public void setVerbose(boolean v) {
mVerbose = v;
}
public void setAnnotationLoader(JAnnotationLoader ann) {
mAnnotationLoader = ann;
}
public void setParentClassLoader(JClassLoader loader) {
mParentClassloader = loader;
}
public void setUseSystemClasspath(boolean use) {
mUseSystemClasspath = use;
}
// ========================================================================
// JStoreParams implementation
public JPath getInputClasspath() {
return createJPath(mClasspath);
}
public JPath getInputSourcepath() {
return createJPath(mSourcepath);
}
public JPath getToolClasspath() {
return createJPath(mToolClasspath);
}
public PrintWriter getOut() {
return null;
}
public Properties getProperties() {
return null;
}
public JClassLoader getParentClassLoader() {
return null;
}
public File getRootForFile(File[] sourceRoots, File sourceFile) {
if (sourceRoots == null) throw new IllegalArgumentException("null roots");
if (sourceFile == null) throw new IllegalArgumentException("null file");
String f = sourceFile.getAbsolutePath();
for(int i=0; i<sourceRoots.length; i++) {
if (f.startsWith(sourceRoots[i].getAbsolutePath())) {//cheesy?
return sourceRoots[i];
}
}
return null;
}
// ========================================================================
// Private methods
/**
* Converts the sourceFile to a pattern expression relative to the
* given root.
*/
private String source2pattern(File root, File sourceFile) {
//REVIEW this is a bit cheesy
String r = root.getAbsolutePath();
String s = sourceFile.getAbsolutePath();
return s.substring(r.length());
}
/**
* Converts the given java source or class filename into a qualified
* classname. The filename is assumed to be relative to the source or
* class root.
*/
private static String filename2classname(String filename) {
int extDot = filename.lastIndexOf('.');
if (extDot != -1) filename = filename.substring(0,extDot);
filename = filename.replace('/','.');
filename = filename.replace('\\','.');
return filename;
}
/**
* Returns all of the directory scanners for all class and source
* roots created in this params object.
*/
private Iterator getAllDirectoryScanners() {
Collection out = new ArrayList();
if (mSourceRoot2Scanner != null) {
out.addAll(mSourceRoot2Scanner.values());
}
if (mClassRoot2Scanner != null) {
out.addAll(mClassRoot2Scanner.values());
}
return out.iterator();
}
/**
* Creates a JPath for the given collection of Files, or returns null
* if the collections is null or empty.
*/
private static JPath createJPath(Collection filelist) {
if (filelist == null || filelist.size() == 0) return null;
File[] files = new File[filelist.size()];
filelist.toArray(files);
return JPath.forFiles(files);
}
/**
* Returns the DirectoryScanner which we have mapped to the given source
* root, creating a new one if necessary.
*/
private DirectoryScanner getSourceScanner(File srcRoot) {
if (mSourceRoot2Scanner == null) mSourceRoot2Scanner = new HashMap();
DirectoryScanner out = (DirectoryScanner)mSourceRoot2Scanner.get(srcRoot);
if (out == null) {
mSourceRoot2Scanner.put(srcRoot,out = new DirectoryScanner(srcRoot));
}
return out;
}
/**
* Returns the DirectoryScanner which we have mapped to the given class
* root, creating a new one if necessary.
*/
private DirectoryScanner getClassScanner(File clsRoot) {
if (mClassRoot2Scanner == null) mClassRoot2Scanner = new HashMap();
DirectoryScanner out = (DirectoryScanner)mClassRoot2Scanner.get(clsRoot);
if (out == null) {
mClassRoot2Scanner.put(clsRoot,out = new DirectoryScanner(clsRoot));
}
return out;
}
}
1.2 +2 -2 xml-xmlbeans/v2/src/jeti/org/apache/xmlbeans/impl/jeti/ToolContext.java
Index: ToolContext.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jeti/org/apache/xmlbeans/impl/jeti/ToolContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ToolContext.java 25 Feb 2004 21:26:25 -0000 1.1
+++ ToolContext.java 1 Mar 2004 21:20:06 -0000 1.2
@@ -14,7 +14,7 @@
*/
package org.apache.xmlbeans.impl.jeti;
-import org.apache.xmlbeans.impl.jam.JServiceFactory;
+import org.apache.xmlbeans.impl.jam.JResultFactory;
import org.apache.xmlbeans.impl.jeti.parameter.ParameterService;
import org.apache.xmlbeans.impl.jeti.output.OutputService;
import org.apache.xmlbeans.impl.jeti.logging.LoggingService;
@@ -49,7 +49,7 @@
* <p>Returns an entry point into the JAM service, which provides a model
* of java type information.</p>
*/
- public JServiceFactory getJavaTypeService();
+ public JResultFactory getJavaTypeService();
/**
* <p>Returns a service which exposes user-specified parameters for
1.2 +1 -0 xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/Foo.java
Index: Foo.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/Foo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Foo.java 18 Feb 2004 01:32:54 -0000 1.1
+++ Foo.java 1 Mar 2004 21:20:06 -0000 1.2
@@ -12,4 +12,5 @@
public int getId();
public void setId(int id);
+
}
1.2 +7 -1 xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java
Index: FooImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FooImpl.java 18 Feb 2004 01:32:54 -0000 1.1
+++ FooImpl.java 1 Mar 2004 21:20:06 -0000 1.2
@@ -5,9 +5,15 @@
*
* @author pcal Nov 25, 2003
*/
-public class FooImpl extends Base implements Foo {
+public abstract class FooImpl extends Base implements Foo {
public int getId() { return -1; }
public void setId(int id) {}
+
+ private final static void setId2(double id) {}
+
+ protected synchronized void setId3(double id, double id2) {}
+
+ protected abstract void setId4(double id, double id2, double id3);
}
1.2 +9 -6 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ClassesJamTest.java
Index: ClassesJamTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ClassesJamTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClassesJamTest.java 18 Feb 2004 02:55:26 -0000 1.1
+++ ClassesJamTest.java 1 Mar 2004 21:20:06 -0000 1.2
@@ -55,8 +55,9 @@
*/
package org.apache.xmlbeans.test.jam;
-import org.apache.xmlbeans.impl.jam.JServiceFactory;
-import org.apache.xmlbeans.impl.jam.JServiceParams;
+import org.apache.xmlbeans.impl.jam.JResultFactory;
+import org.apache.xmlbeans.impl.jam.JResultParams;
+import org.apache.xmlbeans.impl.jam.JResult;
import java.io.IOException;
@@ -77,14 +78,16 @@
// ========================================================================
// JamTestBase implementation
- protected JServiceParams getBasicServiceParams() throws IOException {
- JServiceFactory jsf = JServiceFactory.getInstance();
- JServiceParams params = jsf.createServiceParams();
+ protected JResult getResultToTest() throws IOException {
+ JResultFactory jsf = JResultFactory.getInstance();
+ JResultParams params = jsf.createResultParams();
params.includeClassFiles(getDummyclassesClassDir(),"**/*.class");
- return params;
+ return jsf.createResult(params);
}
protected boolean isAnnotationsAvailable() {
return false;
}
+
+ protected boolean isParameterNamesKnown() { return false; }
}
1.3 +4 -4 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ImplComparisonTest.java
Index: ImplComparisonTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ImplComparisonTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImplComparisonTest.java 25 Feb 2004 23:03:47 -0000 1.2
+++ ImplComparisonTest.java 1 Mar 2004 21:20:06 -0000 1.3
@@ -28,8 +28,8 @@
// ========================================================================
// Variables
- private JService mService1;
- private JService mService2;
+ private JResult mService1;
+ private JResult mService2;
private boolean mCompareAnnotations = false;
private boolean mCompareComments = false;
private PrintWriter mOut = new PrintWriter(System.out);
@@ -39,7 +39,7 @@
// ========================================================================
// Public methods
- public void compare(JService service1, JService service2) {
+ public void compare(JResult service1, JResult service2) {
List list1 = getSortedClassList(service1);
//FIXME should also compare that the same classes are in each service
// List list2 = getSortedClassList(service2);
@@ -118,7 +118,7 @@
return out;
}
- private List getSortedClassList(JService service) {
+ private List getSortedClassList(JResult service) {
JClass[] classes = service.getAllClasses();
Arrays.sort(classes,JElementComparator.getInstance());
return Arrays.asList(classes);
1.3 +66 -19 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java
Index: JamTestBase.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JamTestBase.java 25 Feb 2004 18:56:50 -0000 1.2
+++ JamTestBase.java 1 Mar 2004 21:20:06 -0000 1.3
@@ -60,10 +60,13 @@
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
/**
* <p>Abstract base class for basic jam test cases. These test cases work
- * against an abstract JService - they don't care how the java types
+ * against an abstract JResult - they don't care how the java types
* were loaded. Extending classes are responsible for implementing the
* getService() method which should create the service from sources, or
* classes, or whatever is appropriate.</p>
@@ -75,13 +78,38 @@
// ========================================================================
// Constants
+ //this array must contain the names of all of the test classes under
+ //dummyclasses
+ private static final String[] ALL_CLASSES = {
+ "org.apache.xmlbeans.test.jam.dummyclasses.ejb.IEnv",
+ "org.apache.xmlbeans.test.jam.dummyclasses.ejb.TraderEJB",
+ "org.apache.xmlbeans.test.jam.dummyclasses.ejb.TradeResult",
+ "org.apache.xmlbeans.test.jam.dummyclasses.Base",
+ "org.apache.xmlbeans.test.jam.dummyclasses.Baz",
+ "org.apache.xmlbeans.test.jam.dummyclasses.Foo",
+ "org.apache.xmlbeans.test.jam.dummyclasses.FooImpl"
+ };
+
+
+ // this needs to correspond to the methods on the FooImpl dummyclass
+ private static final String[][] FOOIMPL_METHODS = {
+ {"public", "int", "getId", null},
+ {"public", "void", "setId", "int id"},
+ {"private final static", "void", "setId2", "double id"},
+ {"protected synchronized ", "void", "setId3", "double id, double id2"},
+ {"protected abstract", "void", "setId4", "double id, double id2, double id3"},
+ };
+
+
protected static final String
DUMMY = "org.apache.xmlbeans.test.jam.dummyclasses";
+
+
// ========================================================================
// Variables
- private JService mService = null;
+ private JResult mResult = null;
private JClassLoader mLoader = null;
// ========================================================================
@@ -99,16 +127,20 @@
// Abstract methods
/**
- * Called during setup() to return the parameters which we can use to
- * create a service that contains all of java types under dummyclasses.
+ * Called during setup() to get the JResult object to test against.
*/
- protected abstract JServiceParams getBasicServiceParams() throws Exception;
+ protected abstract JResult getResultToTest() throws Exception;
//kind of a quick hack for now, should remove this and make sure that
//even the classes case make the annotations available using a special
//JStore
protected abstract boolean isAnnotationsAvailable();
+ //kind of a quick hack for now, should remove this and make sure that
+ //even the classes case make the annotations available using a special
+ //JStore
+ protected abstract boolean isParameterNamesKnown();
+
// ========================================================================
// Utility methods
@@ -130,18 +162,38 @@
// TestCase implementation
public void setUp() throws Exception {
- JServiceFactory jsf = JServiceFactory.getInstance();
- mService = jsf.createService(getBasicServiceParams());
- if (mService == null) throw new IllegalArgumentException("null service");
- mLoader = mService.getClassLoader();
- if (mLoader == null) throw new IllegalArgumentException("null loader");
+ mResult = getResultToTest();
+ mLoader = mResult.getClassLoader();
}
// ========================================================================
// Test methods
+ public void testAllClassesAvailable() {
+ JClass[] classes = mResult.getAllClasses();
+ List classNames = new ArrayList(classes.length);
+ for(int i=0; i<classes.length; i++) {
+ classNames.add(classes[i].getQualifiedName());
+ }
+ List expected = Arrays.asList(ALL_CLASSES);
+ assertTrue("result does not contain all expected classes",
+ classNames.containsAll(expected));
+
+ assertTrue("result contains more than expected classes",
+ expected.containsAll(classNames));
+ }
+
+ /**
+ * Verify that FooImpl has the correct methods with the correct
+ * number of parameters and correct return types.
+ */
+ public void testFooImplMethods() {
+ JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
+ GoldenMethod[] methods = GoldenMethod.createArray(FOOIMPL_METHODS);
+ GoldenMethod.doComparison(fooImpl.getDeclaredMethods(),methods,isParameterNamesKnown(),this);
+ }
+
public void testInterfaceIsAssignableFrom()
- throws ClassNotFoundException
{
JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
JClass foo = mLoader.loadClass(DUMMY+".Foo");
@@ -152,7 +204,6 @@
}
public void testClassIsAssignableFrom()
- throws ClassNotFoundException
{
JClass fooImpl = mLoader.loadClass(DUMMY+".FooImpl");
JClass base = mLoader.loadClass(DUMMY+".Base");
@@ -163,7 +214,6 @@
}
public void testClassIsAssignableFromDifferentClassLoaders()
- throws ClassNotFoundException
{
JClass baz = mLoader.loadClass(DUMMY+".Baz");
JClass runnable = mLoader.loadClass("java.lang.Runnable");
@@ -174,7 +224,8 @@
}
- public void testAnnotationsAndInheritance() {
+ public void testAnnotationsAndInheritance()
+ {
JClass ejb = mLoader.loadClass(DUMMY+".ejb.TraderEJB");
JClass ienv = ejb.getInterfaces()[0];
JMethod ejbBuy = ejb.getMethods()[0];
@@ -197,7 +248,6 @@
}
-
// ========================================================================
// Private methods
@@ -214,7 +264,4 @@
assertTrue("'"+j.getQualifiedName()+"' expected to NOT have annotation '"+ann+"'",
a == null);
}
-
-
-
-}
+}
\ No newline at end of file
1.2 +11 -6 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/SourcesJamTest.java
Index: SourcesJamTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/SourcesJamTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SourcesJamTest.java 18 Feb 2004 02:55:26 -0000 1.1
+++ SourcesJamTest.java 1 Mar 2004 21:20:06 -0000 1.2
@@ -55,8 +55,9 @@
*/
package org.apache.xmlbeans.test.jam;
-import org.apache.xmlbeans.impl.jam.JServiceFactory;
-import org.apache.xmlbeans.impl.jam.JServiceParams;
+import org.apache.xmlbeans.impl.jam.JResultFactory;
+import org.apache.xmlbeans.impl.jam.JResultParams;
+import org.apache.xmlbeans.impl.jam.JResult;
import java.io.IOException;
@@ -77,14 +78,18 @@
// ========================================================================
// JamTestBase implementation
- protected JServiceParams getBasicServiceParams() throws IOException {
- JServiceFactory jsf = JServiceFactory.getInstance();
- JServiceParams params = jsf.createServiceParams();
+ protected JResult getResultToTest() throws IOException {
+ JResultFactory jsf = JResultFactory.getInstance();
+ JResultParams params = jsf.createResultParams();
params.includeSourceFiles(getDummyclassesSourceRoot(),"**/*.java");
- return params;
+ return jsf.createResult(params);
}
protected boolean isAnnotationsAvailable() {
+ return true;
+ }
+
+ protected boolean isParameterNamesKnown() {
return true;
}
}
1.1 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/GoldenMethod.java
Index: GoldenMethod.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.test.jam;
import org.apache.xmlbeans.impl.jam.JMethod;
import org.apache.xmlbeans.impl.jam.JParameter;
import java.util.StringTokenizer;
import junit.framework.Assert;
/**
* Independent test structure representing a method. Can be compared
* to a JMethod.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class GoldenMethod {
// ========================================================================
// Factory methods/static utils
public static GoldenMethod[] createArray(String[][] params) {
GoldenMethod[] out = new GoldenMethod[params.length];
for(int i=0; i<out.length; i++) {
out[i] = new GoldenMethod(params[i]);
}
return out;
}
public static void doComparison(JMethod[] result,
GoldenMethod[] expected,
boolean compareParamNames,
Assert a) {
a.assertTrue("different number of methods ["+
result.length+","+expected.length+"]",
result.length == expected.length);
for(int i=0; i<result.length; i++) {
expected[i].compare(result[i],compareParamNames,a);
}
}
// ========================================================================
// Variables
private int mModifers;
private String mReturnType;
private String mName;
private String[] mParamTypes;
private String[] mParamNames;
// ========================================================================
// Constructors
public GoldenMethod(String[] modsTypeNameParams) {
this(modsTypeNameParams[0],
modsTypeNameParams[1],
modsTypeNameParams[2],
modsTypeNameParams[3]);
}
/**
*
* @param modiferString
* @param name
* @param paramString
*/
public GoldenMethod(String modiferString,
String type,
String name,
String paramString) {
mModifers = ModifierHelper.parseModifiers(modiferString);
mReturnType = type;
mName = name;
//parse parameter string
if (paramString == null) {
mParamTypes = new String[0];
mParamNames = new String[0];
} else {
StringTokenizer st = new StringTokenizer(paramString,",");
mParamTypes = new String[st.countTokens()];
mParamNames = new String[st.countTokens()];
int i = 0;
while(st.hasMoreTokens()) {
String token = st.nextToken().trim();
int space = token.indexOf(" ");
mParamNames[i] = token.substring(space).trim();
mParamTypes[i] = token.substring(0,space).trim();
i++;
}
}
}
public void compare(JMethod method, boolean compareParamNames, Assert a) {
a.assertTrue("method names are different",
method.getSimpleName().equals(mName));
a.assertTrue("return types are different",
method.getReturnType().getQualifiedName().equals(mReturnType));
a.assertTrue("modifiers are different on "+method.getSimpleName()+
"["+method.getModifiers()+","+mModifers+"]",
method.getModifiers() == mModifers);
JParameter[] params = method.getParameters();
a.assertTrue("parameter lists are of different lengths",
params.length == mParamTypes.length);
for(int i=0; i<params.length; i++) {
a.assertTrue("parameter type is different on "+method.getSimpleName()+
"["+params[i].getType().getQualifiedName()+","+mParamTypes[i]+"]",
params[i].getType().getQualifiedName().equals(mParamTypes[i]));
if (compareParamNames) {
a.assertTrue("parameter names are different on "+method.getSimpleName(),
params[i].getSimpleName().equals(mParamNames[i]));
}
}
}
}
1.1 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ModifierHelper.java
Index: ModifierHelper.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.test.jam;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Modifier;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class ModifierHelper {
public static int parseModifiers(String modString) {
StringTokenizer st = new StringTokenizer(modString);
int mods = 0;
while(st.hasMoreTokens()) {
int mask = getMaskFor(st.nextToken().trim());
mods = (mods | mask);
}
return mods;
}
public static int getMaskFor(String name) {
Integer i = (Integer)mToken2Mask.get(name);
if (i == null) throw new IllegalArgumentException("unknown modifier '"+
name+"'");
return i.intValue();
}
// ========================================================================
// Static initialization
private static Map mToken2Mask;
private static Object[][] MASKS = {
{"private",new Integer(Modifier.PRIVATE)},
{"protected",new Integer(Modifier.PROTECTED)},
{"public",new Integer(Modifier.PUBLIC)},
{"abstract",new Integer(Modifier.ABSTRACT)},
{"final",new Integer(Modifier.FINAL)},
{"strictfp",new Integer(Modifier.STRICT)},
{"synchronized",new Integer(Modifier.SYNCHRONIZED)},
{"final",new Integer(Modifier.FINAL)},
{"static",new Integer(Modifier.STATIC)},
{"volatile",new Integer(Modifier.VOLATILE)},
{"transient",new Integer(Modifier.TRANSIENT)}
};
static {
mToken2Mask = new HashMap();
for(int i=0; i<MASKS.length; i++) {
mToken2Mask.put(MASKS[i][0],MASKS[i][1]);
}
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org