You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2005/08/19 14:41:32 UTC
svn commit: r233473 - in /webservices/jaxme/branches/MAVEN/projects: api/
jm/ js/ js/src/main/java/org/apache/ws/jaxme/js/pattern/
js/src/test/java/org/apache/ws/jaxme/js/junit/ xs/
Author: jochen
Date: Fri Aug 19 05:41:20 2005
New Revision: 233473
URL: http://svn.apache.org/viewcvs?rev=233473&view=rev
Log:
Fixed the ChainGenerator's dependency on the class path
Removed:
webservices/jaxme/branches/MAVEN/projects/js/src/test/java/org/apache/ws/jaxme/js/junit/VersionTest.java
Modified:
webservices/jaxme/branches/MAVEN/projects/api/ (props changed)
webservices/jaxme/branches/MAVEN/projects/jm/ (props changed)
webservices/jaxme/branches/MAVEN/projects/jm/maven.xml
webservices/jaxme/branches/MAVEN/projects/js/ (props changed)
webservices/jaxme/branches/MAVEN/projects/js/maven.xml
webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/Ant.java
webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/ChainGenerator.java
webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/InterfaceDescription.java
webservices/jaxme/branches/MAVEN/projects/xs/ (props changed)
Propchange: webservices/jaxme/branches/MAVEN/projects/api/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 19 05:41:20 2005
@@ -0,0 +1,2 @@
+
+target
Propchange: webservices/jaxme/branches/MAVEN/projects/jm/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 19 05:41:20 2005
@@ -0,0 +1,2 @@
+
+target
Modified: webservices/jaxme/branches/MAVEN/projects/jm/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/jm/maven.xml?rev=233473&r1=233472&r2=233473&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/jm/maven.xml (original)
+++ webservices/jaxme/branches/MAVEN/projects/jm/maven.xml Fri Aug 19 05:41:20 2005
@@ -33,7 +33,7 @@
<ant:taskdef name="chainGenerator" classname="org.apache.ws.jaxme.js.pattern.Ant$AntChainGenerator"
classpathref="jm.class.path"/>
- <ant:chainGenerator destDir="${build.jm.src}">
+ <ant:chainGenerator destDir="${build.jm.src}" srcDir="src/main/java">
<ant:chain
controllerInterfaceName="org.apache.ws.jaxme.generator.sg.AttributeSG"
chainInterfaceName="org.apache.ws.jaxme.generator.sg.AttributeSGChain"
Propchange: webservices/jaxme/branches/MAVEN/projects/js/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 19 05:41:20 2005
@@ -0,0 +1,2 @@
+
+target
Modified: webservices/jaxme/branches/MAVEN/projects/js/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/js/maven.xml?rev=233473&r1=233472&r2=233473&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/js/maven.xml (original)
+++ webservices/jaxme/branches/MAVEN/projects/js/maven.xml Fri Aug 19 05:41:20 2005
@@ -60,25 +60,6 @@
<ant:serverClasses dir="${pom.build.unitTestSourceDirectory}" includes="**/XmlRpcClientTestRemoteClass.java"/>
</ant:xmlRpcGenerator>
- <ant:sql
- src="${pom.build.unitTestSourceDirectory}/org/apache/ws/jaxme/js/junit/create.sql"
- driver="${jdbc.driver}"
- url="${jdbc.url}"
- userid="${jdbc.user}"
- password="${jdbc.password}"
- classpathref="js.test.path"
- caching="false"/>
-
- <ant:versionGenerator driver="${jdbc.driver}"
- url="${jdbc.url}"
- user="${jdbc.user}"
- password="${jdbc.password}"
- tables="MAIN SUB SUBSUB"
- verColumn="VER"
- targetClass="org.apache.ws.jaxme.js.junit.MAINCloner"
- generatingLogging="true"
- destDir="${JS.build.test}"/>
-
<ant:path id="generated.test.src"
location="${JS.build.test}"/>
Modified: webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/Ant.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/Ant.java?rev=233473&r1=233472&r2=233473&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/Ant.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/Ant.java Fri Aug 19 05:41:20 2005
@@ -227,9 +227,12 @@
/** Adds a new interface being implemented.
*/
public InterfaceDescription createImplementedInterface() {
- InterfaceDescription result = new InterfaceDescription();
- implementedInterfaces.add(result);
- return result;
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ cl = ClassLoader.getSystemClassLoader();
+ InterfaceDescription result = new InterfaceDescription(cl);
+ implementedInterfaces.add(result);
+ return result;
}
public void finish() {
super.finish();
@@ -294,37 +297,50 @@
/** Ant task for the {@link org.apache.ws.jaxme.js.pattern.ChainGenerator}.
*/
public static class AntChainGenerator extends ReallyBasicAntTask {
- private List chains = new ArrayList();
- /** Creates a new, nested element with another chain being
- * generated.
- */
- public ChainGenerator createChain() {
- ChainGenerator chain = new ChainGenerator();
- chains.add(chain);
- return chain;
- }
- public void finish() {
- if (chains.size() == 0) {
- throw new BuildException("At least one nested 'chain' element must be given.",
- getLocation());
- }
- }
- public void doExecute() {
- JavaSourceFactory pFactory = new JavaSourceFactory();
- for (Iterator iter = chains.iterator(); iter.hasNext(); ) {
- ChainGenerator chain = (ChainGenerator) iter.next();
- try {
- chain.generate(pFactory);
- } catch (Exception e) {
- throw new BuildException(e, getLocation());
- }
- }
- try {
- pFactory.write(getDestDir());
- } catch (IOException e) {
- throw new BuildException(e, getLocation());
- }
- }
+ private final List chains = new ArrayList();
+ private File srcDir;
+ /** Creates a new, nested element with another chain being
+ * generated.
+ */
+ public ChainGenerator createChain() {
+ ChainGenerator chain = new ChainGenerator();
+ chains.add(chain);
+ return chain;
+ }
+ public void setSrcDir(File pSrcDir) {
+ srcDir = pSrcDir;
+ }
+ public void finish() {
+ if (chains.size() == 0) {
+ throw new BuildException("At least one nested 'chain' element must be given.",
+ getLocation());
+ }
+ }
+ public void doExecute() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ cl = ClassLoader.getSystemClassLoader();
+ }
+ if (srcDir != null) {
+ Path path = (Path) getProject().createDataType("path");
+ path.createPathElement().setLocation(srcDir);
+ cl = new AntClassLoader(getProject(), path);
+ }
+ JavaSourceFactory pFactory = new JavaSourceFactory();
+ for (Iterator iter = chains.iterator(); iter.hasNext(); ) {
+ ChainGenerator chain = (ChainGenerator) iter.next();
+ try {
+ chain.generate(pFactory, cl);
+ } catch (Exception e) {
+ throw new BuildException(e, getLocation());
+ }
+ }
+ try {
+ pFactory.write(getDestDir());
+ } catch (IOException e) {
+ throw new BuildException(e, getLocation());
+ }
+ }
}
/** Ant task for the {@link org.apache.ws.jaxme.js.pattern.VersionGenerator}
Modified: webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/ChainGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/ChainGenerator.java?rev=233473&r1=233472&r2=233473&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/ChainGenerator.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/ChainGenerator.java Fri Aug 19 05:41:20 2005
@@ -12,11 +12,10 @@
* 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.ws.jaxme.js.pattern;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -51,339 +50,322 @@
* @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
*/
public class ChainGenerator {
+ private ClassLoader classLoader;
private String controllerInterfaceName;
- private JavaSource controllerInterface;
- private JavaQName chainInterface, proxyClass, implClass;
-
- /** <p>Sets the controller interface name.</p>
- */
- public void setControllerInterfaceName(String pInterfaceName) throws ClassNotFoundException {
- controllerInterfaceName = pInterfaceName;
- }
-
- /** Returns the controller interface.
- */
- public JavaSource getControllerInterface() {
- return controllerInterface;
- }
-
- private JavaSource loadSource(ClassLoader pClassLoader,
- String pName,
- JavaSourceFactory pFactory)
- throws RecognitionException, TokenStreamException, IOException {
- URL url = pClassLoader.getResource(pName.replace('.', '/') + ".java");
- if (url == null) {
- return null;
- } else {
- return new SourceReflector(url).getJavaSource(pFactory);
- }
- }
-
- private void loadSources(ClassLoader pClassLoader, JavaQName pQName,
- JavaSourceFactory pFactory,
- List pSources, Set pNames)
- throws RecognitionException, TokenStreamException, IOException {
- if (pNames.contains(pQName)) {
- return;
- }
- pNames.add(pQName);
- JavaSource js = loadSource(Thread.currentThread().getContextClassLoader(),
- pQName.toString(), pFactory);
- if (js == null) {
- return;
- }
- pSources.add(js);
- JavaQName[] superInterfaces = js.getExtends();
- for (int i = 0; i < superInterfaces.length; i++) {
- loadSources(pClassLoader, superInterfaces[i],
- pFactory, pSources, pNames);
- }
- }
-
- private JavaSource[] loadSources(ClassLoader pClassLoader, String pName)
- throws RecognitionException, TokenStreamException, IOException {
- JavaSourceFactory jsf = new JavaSourceFactory();
- List sources = new ArrayList();
- Set names = new HashSet();
- loadSources(pClassLoader, JavaQNameImpl.getInstance(pName),
- jsf, sources, names);
- if (sources.isEmpty()) {
- return null;
- } else {
- return (JavaSource[]) sources.toArray(new JavaSource[sources.size()]);
- }
- }
-
- /** <p>Initializes the controller interface.</p>
- * @throws ClassNotFoundException
- * @throws IOException
- * @throws TokenStreamException
- * @throws RecognitionException
- */
- protected JavaSource[] initControllerInterface()
- throws ClassNotFoundException, RecognitionException, TokenStreamException, IOException {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- JavaSource[] result;
- try {
- if (cl == null) {
- throw new ClassNotFoundException(controllerInterfaceName);
- }
- CompiledClassReflector r = new CompiledClassReflector(controllerInterfaceName, cl);
- result = new JavaSource[]{r.getJavaSource(new JavaSourceFactory())};
- } catch (ClassNotFoundException e) {
- result = loadSources(Thread.currentThread().getContextClassLoader(),
- controllerInterfaceName);
- if (result == null) {
- throw e;
- }
- }
- if (!result[0].isInterface()) {
- throw new ClassCastException("The controller must be an interface");
- }
- return result;
- }
-
- /** <p>Sets the interface name being generated for the chain objects.</p>
- */
- public void setChainInterfaceName(String pInterfaceName) {
- JavaQName qName = JavaQNameImpl.getInstance(pInterfaceName);
- setChainInterface(qName);
- }
-
- /** <p>Sets the interface being generated for the chain objects.</p>
- */
- public void setChainInterface(JavaQName pInterface) {
- chainInterface = pInterface;
- }
-
- /** <p>Returns the interface being generated for the chain objects.</p>
- */
- public JavaQName getChainInterface() {
- return chainInterface;
- }
-
- /** <p>Sets the class name being generated for the chain objects.</p>
- */
- public void setProxyClassName(String pClassName) {
- JavaQName qName = JavaQNameImpl.getInstance(pClassName);
- setProxyClass(qName);
- }
-
- /** <p>Sets the class being generated for the chain objects.</p>
- */
- public void setProxyClass(JavaQName pClassName) {
- proxyClass = pClassName;
- }
-
- /** <p>Returns the class being generated for the chain objects. Defaults
- * to <code>getChainInterface() + "Impl"</code>.</p>
- */
- public JavaQName getProxyClass() {
- if (proxyClass == null) {
- JavaQName chainClass = getChainInterface();
- if (chainClass == null) {
- return null;
- } else {
- return JavaQNameImpl.getInstance(chainClass.getPackageName(),
- chainClass.getClassName() + "Impl");
- }
- } else {
- return proxyClass;
- }
- }
-
- /** <p>Sets the name of the chain implementation class.</p>
- */
- public void setImplementationClassName(String pClassName) {
- setImplementationClass(JavaQNameImpl.getInstance(pClassName));
- }
-
- /** <p>Sets the chain implementation class.</p>
- */
- public void setImplementationClass(JavaQName pClassName) {
- implClass = pClassName;
- }
-
- /** <p>Returns the chain implementation classes name. Defaults to
- * <code>getControllerInterface() + "Impl"</code>.</p>
- */
- public JavaQName getImplementationClass() {
- if (implClass == null) {
- if (controllerInterface == null) {
- return null;
- } else {
- JavaQName controllerClass = controllerInterface.getQName();
- return JavaQNameImpl.getInstance(controllerClass.getPackageName(),
- controllerClass.getClassName() + "Impl");
- }
- } else {
- return implClass;
- }
- }
-
- /** Validates the input data.
- */
- public void finish() {
- if (controllerInterface == null) {
- throw new NullPointerException("A controller interface must be given.");
- }
- if (chainInterface == null) {
- throw new NullPointerException("A chain interface must be given.");
- }
- }
-
- private class ProxyInterfaceGenerator extends ProxyGenerator {
- public JavaMethod getInterfaceMethod(JavaSource pSource, JavaMethod pMethod) {
- JavaMethod jm = pSource.newJavaMethod(pMethod);
- Parameter[] parameters = jm.getParams();
- JavaQName controllerInterfaceQName = getControllerInterface().getQName();
- jm.clearParams();
- jm.addParam(controllerInterfaceQName, "pController");
- for (int i = 0; i < parameters.length; i++) {
- jm.addParam(parameters[i]);
- }
- return jm;
- }
- public JavaSource generate(JavaSourceFactory pInterfaceFactory,
- JavaQName pTargetClass,
- InterfaceDescription[] pDescription) throws Exception {
- JavaSource result = super.generate(pInterfaceFactory, pTargetClass,
- pDescription);
- result.clearImplements();
- return result;
- }
- }
-
- private class ProxyImplementationGenerator extends ProxyGenerator {
- protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
- return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
- }
- protected JavaConstructor getConstructor(JavaSource pJs,
- InterfaceDescription[] pInterfaces) {
- JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PROTECTED);
- jcon.addParam(getChainInterface(), "o");
- jcon.addIf("o == null");
- jcon.addThrowNew(NullPointerException.class,
- JavaSource.getQuoted("The supplied object must not be null."));
- jcon.addEndIf();
- jcon.addLine("backingObject = o;");
- return jcon;
- }
-
- public JavaMethod getInterfaceMethod(JavaSource pSource, JavaMethod pMethod) {
- JavaMethod jm = pSource.newJavaMethod(pMethod);
- Parameter[] parameters = jm.getParams();
- JavaQName controllerInterfaceQName = getControllerInterface().getQName();
- jm.clearParams();
- jm.addParam(controllerInterfaceQName, "pController");
- for (int i = 0; i < parameters.length; i++) {
- jm.addParam(parameters[i]);
- }
- List callParameters = new ArrayList();
- callParameters.add("pController");
- for (int i = 0; i < parameters.length; i++) {
- Parameter parameter = parameters[i];
- callParameters.add(", ");
- callParameters.add(parameter.getName());
- }
- jm.addLine((JavaQNameImpl.VOID.equals(pMethod.getType()) ? "" : "return "),
- "backingObject.",
- pMethod.getName(), "(", callParameters, ");");
- return jm;
- }
- public JavaSource generate(JavaSourceFactory pImplementationFactory,
- JavaQName pTargetClass,
- InterfaceDescription[] pDescription) throws Exception {
- JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
- result.clearImplements();
- result.addImplements(getChainInterface());
- return result;
- }
- }
-
- private class ControllerImplementationGenerator extends ProxyGenerator {
- protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
- return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
- }
- protected JavaConstructor getConstructor(JavaSource pJs,
- InterfaceDescription[] pInterfaces) {
- JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PUBLIC);
- jcon.addParam(getChainInterface(), "o");
- jcon.addIf("o == null");
- jcon.addThrowNew(NullPointerException.class,
- JavaSource.getQuoted("The supplied object must not be null."));
- jcon.addEndIf();
- jcon.addLine("backingObject = o;");
- return jcon;
- }
- public JavaMethod getInterfaceMethod(JavaSource pSource,
- JavaMethod pMethod) {
- JavaMethod jm = pSource.newJavaMethod(pMethod);
- Parameter[] parameters = jm.getParams();
- List callParameters = new ArrayList();
- callParameters.add("this");
- for (int i = 0; i < parameters.length; i++) {
- Parameter parameter = parameters[i];
- callParameters.add(", ");
- callParameters.add(parameter.getName());
- }
- jm.addLine((JavaQNameImpl.VOID.equals(pMethod.getType()) ? "" : "return "),
- "backingObject.",
- pMethod.getName(), "(", callParameters, ");");
- return jm;
- }
- protected JavaMethod getGetHeadOfChainMethod(JavaSource pSource) {
- JavaMethod jm = pSource.newJavaMethod("getHeadOfChain",
- getChainInterface(),
- JavaSource.PUBLIC);
- jm.addLine("return backingObject;");
- return jm;
- }
- public JavaSource generate(JavaSourceFactory pImplementationFactory,
- JavaQName pTargetClass,
- InterfaceDescription[] pDescription) throws Exception {
- JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
- getGetHeadOfChainMethod(result);
- return result;
- }
- }
-
- /** Performs the actual work by generating classes using
- * the given <code>pFactory</code>.
- */
- public JavaSource[] generate(JavaSourceFactory pFactory) throws Exception {
-
- JavaSource[] sources = initControllerInterface();
- controllerInterface = sources[0];
- InterfaceDescription[] interfaces = new InterfaceDescription[sources.length];
- for (int i = 0; i < interfaces.length; i++) {
- InterfaceDescription controllerDescription = new InterfaceDescription();
- controllerDescription.setInterface(sources[i].getQName().toString());
- controllerDescription.setMandatory(true);
- interfaces[i] = controllerDescription;
- }
-
- ProxyGenerator proxyInterfaceGenerator = new ProxyInterfaceGenerator();
- JavaSource proxyInterface = proxyInterfaceGenerator.generate(pFactory, getChainInterface(), interfaces);
- proxyInterface.setType(JavaSource.INTERFACE);
-
- ProxyGenerator proxyImpGenerator = new ProxyImplementationGenerator();
- JavaSource proxyImplementation = proxyImpGenerator.generate(pFactory, getProxyClass(), interfaces);
-
- ProxyGenerator controllerImplementationGenerator = new ControllerImplementationGenerator();
- JavaSource controllerImplementation = controllerImplementationGenerator.generate(pFactory, getImplementationClass(), interfaces);
-
- return new JavaSource[]{controllerImplementation, proxyInterface, proxyImplementation};
- }
-
- public static void main(String[] args) throws Exception {
- ChainGenerator cg = new ChainGenerator();
- cg.setChainInterfaceName("org.apache.ws.jaxme.generator.sg.ComplexTypeSGChain");
- cg.setControllerInterfaceName("org.apache.ws.jaxme.generator.sg.ComplexTypeSG");
- cg.setImplementationClassName("org.apache.ws.jaxme.generator.sg.ComplexTypeSGImpl");
- cg.setProxyClassName("org.apache.ws.jaxme.generator.sg.ComplexTypeSGChainImpl");
- JavaSourceFactory f = new JavaSourceFactory();
- cg.generate(f);
- f.write(new File("/tmp/qName"));
- }
+ private JavaSource controllerInterface;
+ private JavaQName chainInterface, proxyClass, implClass;
+
+ /** <p>Sets the controller interface name.</p>
+ */
+ public void setControllerInterfaceName(String pInterfaceName) throws ClassNotFoundException {
+ controllerInterfaceName = pInterfaceName;
+ }
+
+ /** Returns the controller interface.
+ */
+ public JavaSource getControllerInterface() {
+ return controllerInterface;
+ }
+
+ private JavaSource loadSource(String pName,
+ JavaSourceFactory pFactory)
+ throws RecognitionException, TokenStreamException, IOException {
+ URL url = classLoader.getResource(pName.replace('.', '/') + ".java");
+ if (url == null) {
+ return null;
+ } else {
+ return new SourceReflector(url).getJavaSource(pFactory);
+ }
+ }
+
+ private void loadSources(JavaQName pQName,
+ JavaSourceFactory pFactory,
+ List pSources, Set pNames)
+ throws RecognitionException, TokenStreamException, IOException {
+ if (pNames.contains(pQName)) {
+ return;
+ }
+ pNames.add(pQName);
+ JavaSource js = loadSource(pQName.toString(), pFactory);
+ if (js == null) {
+ return;
+ }
+ pSources.add(js);
+ JavaQName[] superInterfaces = js.getExtends();
+ for (int i = 0; i < superInterfaces.length; i++) {
+ loadSources(superInterfaces[i],
+ pFactory, pSources, pNames);
+ }
+ }
+
+ private JavaSource[] loadSources(String pName)
+ throws RecognitionException, TokenStreamException, IOException {
+ JavaSourceFactory jsf = new JavaSourceFactory();
+ List sources = new ArrayList();
+ Set names = new HashSet();
+ loadSources(JavaQNameImpl.getInstance(pName),
+ jsf, sources, names);
+ if (sources.isEmpty()) {
+ return null;
+ } else {
+ return (JavaSource[]) sources.toArray(new JavaSource[sources.size()]);
+ }
+ }
+
+ /** <p>Initializes the controller interface.</p>
+ * @throws ClassNotFoundException
+ * @throws IOException
+ * @throws TokenStreamException
+ * @throws RecognitionException
+ */
+ protected JavaSource[] initControllerInterface()
+ throws ClassNotFoundException, RecognitionException, TokenStreamException, IOException {
+ JavaSource[] result;
+ try {
+ CompiledClassReflector r = new CompiledClassReflector(controllerInterfaceName, classLoader);
+ result = new JavaSource[]{r.getJavaSource(new JavaSourceFactory())};
+ } catch (ClassNotFoundException e) {
+ result = loadSources(controllerInterfaceName);
+ if (result == null) {
+ throw e;
+ }
+ }
+ if (!result[0].isInterface()) {
+ throw new ClassCastException("The controller must be an interface");
+ }
+ return result;
+ }
+
+ /** <p>Sets the interface name being generated for the chain objects.</p>
+ */
+ public void setChainInterfaceName(String pInterfaceName) {
+ JavaQName qName = JavaQNameImpl.getInstance(pInterfaceName);
+ setChainInterface(qName);
+ }
+
+ /** <p>Sets the interface being generated for the chain objects.</p>
+ */
+ public void setChainInterface(JavaQName pInterface) {
+ chainInterface = pInterface;
+ }
+
+ /** <p>Returns the interface being generated for the chain objects.</p>
+ */
+ public JavaQName getChainInterface() {
+ return chainInterface;
+ }
+
+ /** <p>Sets the class name being generated for the chain objects.</p>
+ */
+ public void setProxyClassName(String pClassName) {
+ JavaQName qName = JavaQNameImpl.getInstance(pClassName);
+ setProxyClass(qName);
+ }
+
+ /** <p>Sets the class being generated for the chain objects.</p>
+ */
+ public void setProxyClass(JavaQName pClassName) {
+ proxyClass = pClassName;
+ }
+
+ /** <p>Returns the class being generated for the chain objects. Defaults
+ * to <code>getChainInterface() + "Impl"</code>.</p>
+ */
+ public JavaQName getProxyClass() {
+ if (proxyClass == null) {
+ JavaQName chainClass = getChainInterface();
+ if (chainClass == null) {
+ return null;
+ } else {
+ return JavaQNameImpl.getInstance(chainClass.getPackageName(),
+ chainClass.getClassName() + "Impl");
+ }
+ } else {
+ return proxyClass;
+ }
+ }
+
+ /** <p>Sets the name of the chain implementation class.</p>
+ */
+ public void setImplementationClassName(String pClassName) {
+ setImplementationClass(JavaQNameImpl.getInstance(pClassName));
+ }
+
+ /** <p>Sets the chain implementation class.</p>
+ */
+ public void setImplementationClass(JavaQName pClassName) {
+ implClass = pClassName;
+ }
+
+ /** <p>Returns the chain implementation classes name. Defaults to
+ * <code>getControllerInterface() + "Impl"</code>.</p>
+ */
+ public JavaQName getImplementationClass() {
+ if (implClass == null) {
+ if (controllerInterface == null) {
+ return null;
+ } else {
+ JavaQName controllerClass = controllerInterface.getQName();
+ return JavaQNameImpl.getInstance(controllerClass.getPackageName(),
+ controllerClass.getClassName() + "Impl");
+ }
+ } else {
+ return implClass;
+ }
+ }
+
+ /** Validates the input data.
+ */
+ public void finish() {
+ if (controllerInterface == null) {
+ throw new NullPointerException("A controller interface must be given.");
+ }
+ if (chainInterface == null) {
+ throw new NullPointerException("A chain interface must be given.");
+ }
+ }
+
+ private class ProxyInterfaceGenerator extends ProxyGenerator {
+ public JavaMethod getInterfaceMethod(JavaSource pSource, JavaMethod pMethod) {
+ JavaMethod jm = pSource.newJavaMethod(pMethod);
+ Parameter[] parameters = jm.getParams();
+ JavaQName controllerInterfaceQName = getControllerInterface().getQName();
+ jm.clearParams();
+ jm.addParam(controllerInterfaceQName, "pController");
+ for (int i = 0; i < parameters.length; i++) {
+ jm.addParam(parameters[i]);
+ }
+ return jm;
+ }
+ public JavaSource generate(JavaSourceFactory pInterfaceFactory,
+ JavaQName pTargetClass,
+ InterfaceDescription[] pDescription) throws Exception {
+ JavaSource result = super.generate(pInterfaceFactory, pTargetClass,
+ pDescription);
+ result.clearImplements();
+ return result;
+ }
+ }
+
+ private class ProxyImplementationGenerator extends ProxyGenerator {
+ protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
+ return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
+ }
+ protected JavaConstructor getConstructor(JavaSource pJs,
+ InterfaceDescription[] pInterfaces) {
+ JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PROTECTED);
+ jcon.addParam(getChainInterface(), "o");
+ jcon.addIf("o == null");
+ jcon.addThrowNew(NullPointerException.class,
+ JavaSource.getQuoted("The supplied object must not be null."));
+ jcon.addEndIf();
+ jcon.addLine("backingObject = o;");
+ return jcon;
+ }
+
+ public JavaMethod getInterfaceMethod(JavaSource pSource, JavaMethod pMethod) {
+ JavaMethod jm = pSource.newJavaMethod(pMethod);
+ Parameter[] parameters = jm.getParams();
+ JavaQName controllerInterfaceQName = getControllerInterface().getQName();
+ jm.clearParams();
+ jm.addParam(controllerInterfaceQName, "pController");
+ for (int i = 0; i < parameters.length; i++) {
+ jm.addParam(parameters[i]);
+ }
+ List callParameters = new ArrayList();
+ callParameters.add("pController");
+ for (int i = 0; i < parameters.length; i++) {
+ Parameter parameter = parameters[i];
+ callParameters.add(", ");
+ callParameters.add(parameter.getName());
+ }
+ jm.addLine((JavaQNameImpl.VOID.equals(pMethod.getType()) ? "" : "return "),
+ "backingObject.",
+ pMethod.getName(), "(", callParameters, ");");
+ return jm;
+ }
+ public JavaSource generate(JavaSourceFactory pImplementationFactory,
+ JavaQName pTargetClass,
+ InterfaceDescription[] pDescription) throws Exception {
+ JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
+ result.clearImplements();
+ result.addImplements(getChainInterface());
+ return result;
+ }
+ }
+
+ private class ControllerImplementationGenerator extends ProxyGenerator {
+ protected JavaField getBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces) {
+ return pJs.newJavaField("backingObject", getChainInterface(), JavaSource.PRIVATE);
+ }
+ protected JavaConstructor getConstructor(JavaSource pJs,
+ InterfaceDescription[] pInterfaces) {
+ JavaConstructor jcon = pJs.newJavaConstructor(JavaSource.PUBLIC);
+ jcon.addParam(getChainInterface(), "o");
+ jcon.addIf("o == null");
+ jcon.addThrowNew(NullPointerException.class,
+ JavaSource.getQuoted("The supplied object must not be null."));
+ jcon.addEndIf();
+ jcon.addLine("backingObject = o;");
+ return jcon;
+ }
+ public JavaMethod getInterfaceMethod(JavaSource pSource,
+ JavaMethod pMethod) {
+ JavaMethod jm = pSource.newJavaMethod(pMethod);
+ Parameter[] parameters = jm.getParams();
+ List callParameters = new ArrayList();
+ callParameters.add("this");
+ for (int i = 0; i < parameters.length; i++) {
+ Parameter parameter = parameters[i];
+ callParameters.add(", ");
+ callParameters.add(parameter.getName());
+ }
+ jm.addLine((JavaQNameImpl.VOID.equals(pMethod.getType()) ? "" : "return "),
+ "backingObject.",
+ pMethod.getName(), "(", callParameters, ");");
+ return jm;
+ }
+ protected JavaMethod getGetHeadOfChainMethod(JavaSource pSource) {
+ JavaMethod jm = pSource.newJavaMethod("getHeadOfChain",
+ getChainInterface(),
+ JavaSource.PUBLIC);
+ jm.addLine("return backingObject;");
+ return jm;
+ }
+ public JavaSource generate(JavaSourceFactory pImplementationFactory,
+ JavaQName pTargetClass,
+ InterfaceDescription[] pDescription) throws Exception {
+ JavaSource result = super.generate(pImplementationFactory, pTargetClass, pDescription);
+ getGetHeadOfChainMethod(result);
+ return result;
+ }
+ }
+
+ /** Performs the actual work by generating classes using
+ * the given <code>pFactory</code>.
+ */
+ public JavaSource[] generate(JavaSourceFactory pFactory, ClassLoader pClassLoader) throws Exception {
+ classLoader = pClassLoader;
+ JavaSource[] sources = initControllerInterface();
+ controllerInterface = sources[0];
+ InterfaceDescription[] interfaces = new InterfaceDescription[sources.length];
+ for (int i = 0; i < interfaces.length; i++) {
+ InterfaceDescription controllerDescription = new InterfaceDescription(classLoader);
+ controllerDescription.setInterface(sources[i].getQName().toString());
+ controllerDescription.setMandatory(true);
+ interfaces[i] = controllerDescription;
+ }
+
+ ProxyGenerator proxyInterfaceGenerator = new ProxyInterfaceGenerator();
+ JavaSource proxyInterface = proxyInterfaceGenerator.generate(pFactory, getChainInterface(), interfaces);
+ proxyInterface.setType(JavaSource.INTERFACE);
+
+ ProxyGenerator proxyImpGenerator = new ProxyImplementationGenerator();
+ JavaSource proxyImplementation = proxyImpGenerator.generate(pFactory, getProxyClass(), interfaces);
+
+ ProxyGenerator controllerImplementationGenerator = new ControllerImplementationGenerator();
+ JavaSource controllerImplementation = controllerImplementationGenerator.generate(pFactory, getImplementationClass(), interfaces);
+
+ return new JavaSource[]{controllerImplementation, proxyInterface, proxyImplementation};
+ }
}
Modified: webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/InterfaceDescription.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/InterfaceDescription.java?rev=233473&r1=233472&r2=233473&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/InterfaceDescription.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/js/src/main/java/org/apache/ws/jaxme/js/pattern/InterfaceDescription.java Fri Aug 19 05:41:20 2005
@@ -22,128 +22,114 @@
* </ol
*/
public class InterfaceDescription {
- private boolean isMandatory = true;
- private String interfaceName;
- private String type;
- private JavaSource javaSource;
+ private final ClassLoader classLoader;
+ private boolean isMandatory = true;
+ private String interfaceName;
+ private String type;
+ private JavaSource javaSource;
- private ClassLoader[] getClassLoaders() {
- return new ClassLoader[]{
- Thread.currentThread().getContextClassLoader(),
- getClass().getClassLoader(),
- ClassLoader.getSystemClassLoader()
- };
- }
-
- /** Sets the name of the interface being implemented.
- */
- public void setInterface(String pName) {
- interfaceName = pName;
- }
-
- /** Returns the name of the interface being implemented.
- */
- public String getInterface() {
- return interfaceName;
- }
+ /** Creates a new instance, which uses the given class loader.
+ */
+ public InterfaceDescription(ClassLoader pClassLoader) {
+ classLoader = pClassLoader;
+ }
+
+ /** Sets the name of the interface being implemented.
+ */
+ public void setInterface(String pName) {
+ interfaceName = pName;
+ }
- /** Sets, how to gather information about the interface.
- * Supported values are "Reflection" (Java reflection),
- * or "Source" ({@link org.apache.ws.jaxme.js.util.JavaParser}).
- * The default is null, in which case "Reflection" and "Source"
- * are tried, in that order.
- */
- public void setType(String pType) {
- if (pType == null
- || "Reflection".equalsIgnoreCase(pType)
- || "Source".equalsIgnoreCase(pType)) {
- type = pType;
- } else {
- throw new IllegalArgumentException("Invalid type: " + pType +
- ", expected 'Reflection', 'Source', or null.");
- }
- }
+ /** Returns the name of the interface being implemented.
+ */
+ public String getInterface() {
+ return interfaceName;
+ }
- /** Returns, how to gather information about the interface.
- * Supported values are "Reflection" (Java reflection),
- * or "Source" ({@link org.apache.ws.jaxme.js.util.JavaParser}).
- * The default is null, in which case "Reflection" and "Source"
- * are tried, in that order.
- */
- public String getType() {
- return type;
- }
+ /** Sets, how to gather information about the interface.
+ * Supported values are "Reflection" (Java reflection),
+ * or "Source" ({@link org.apache.ws.jaxme.js.util.JavaParser}).
+ * The default is null, in which case "Reflection" and "Source"
+ * are tried, in that order.
+ */
+ public void setType(String pType) {
+ if (pType == null
+ || "Reflection".equalsIgnoreCase(pType)
+ || "Source".equalsIgnoreCase(pType)) {
+ type = pType;
+ } else {
+ throw new IllegalArgumentException("Invalid type: " + pType +
+ ", expected 'Reflection', 'Source', or null.");
+ }
+ }
- /** Sets whether this interface is mandatory. By default interfaces
- * are mandatory and the backing objects must implement this interface.
- * If an interface isn't mandatory, then a Proxy instance can be created
- * even for objects which don't implement the interface. However, in that
- * case it may happen that a ClassCastException is thrown while invoking
- * a method declared by the interface.
- */
- public void setMandatory(boolean pMandatory) { isMandatory = pMandatory; }
-
- /** Returns whether this interface is mandatory. By default interfaces
- * are mandatory and the backing objects must implement this interface.
- * If an interface isn't mandatory, then a Proxy instance can be created
- * even for objects which don't implement the interface. However, in that
- * case it may happen that a ClassCastException is thrown while invoking
- * a method declared by the interface.
- */
- public boolean isMandatory() { return isMandatory; }
-
- /** Returns an instance of {@link JavaSource}, matching
- * the interface {@link #getInterface()}.
- */
- public JavaSource getJavaSource() throws Exception {
- if (javaSource == null) {
- javaSource = initJavaSource();
- }
- return javaSource;
- }
-
- /** Initializes the object, after all parameters are set.
- */
- private JavaSource initJavaSource() throws Exception {
- Exception ex = null;
- String mode = getType();
- if (mode == null || "Reflection".equals(mode)) {
- try {
- ClassLoader[] cls = getClassLoaders();
- for (int i = 0; i < cls.length; i++) {
- if (cls[i] == null) {
- continue;
- }
-
- Class c = cls[i].loadClass(getInterface());
- if (c != null) {
- return new CompiledClassReflector(c).getJavaSource(new JavaSourceFactory());
- }
- }
- } catch (Exception e) {
- if (ex == null) {
- ex = e;
- }
- }
- }
- if (mode == null || "Source".equals(mode)) {
- ClassLoader[] cls = getClassLoaders();
- for (int i = 0; i < cls.length; i++) {
- if (cls[i] == null) {
- continue;
- }
- URL url = cls[i].getResource(getInterface().replace('.', '/') + ".java");
- if (url != null) {
- SourceReflector reflector = new SourceReflector(url);
- return reflector.getJavaSource(new JavaSourceFactory());
- }
- }
- }
- if (ex == null) {
- throw new IllegalStateException("Failed to locate Java class "
- + getInterface());
- } else {
- throw ex;
- }
- }
+ /** Returns, how to gather information about the interface.
+ * Supported values are "Reflection" (Java reflection),
+ * or "Source" ({@link org.apache.ws.jaxme.js.util.JavaParser}).
+ * The default is null, in which case "Reflection" and "Source"
+ * are tried, in that order.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /** Sets whether this interface is mandatory. By default interfaces
+ * are mandatory and the backing objects must implement this interface.
+ * If an interface isn't mandatory, then a Proxy instance can be created
+ * even for objects which don't implement the interface. However, in that
+ * case it may happen that a ClassCastException is thrown while invoking
+ * a method declared by the interface.
+ */
+ public void setMandatory(boolean pMandatory) { isMandatory = pMandatory; }
+
+ /** Returns whether this interface is mandatory. By default interfaces
+ * are mandatory and the backing objects must implement this interface.
+ * If an interface isn't mandatory, then a Proxy instance can be created
+ * even for objects which don't implement the interface. However, in that
+ * case it may happen that a ClassCastException is thrown while invoking
+ * a method declared by the interface.
+ */
+ public boolean isMandatory() { return isMandatory; }
+
+ /** Returns an instance of {@link JavaSource}, matching
+ * the interface {@link #getInterface()}.
+ */
+ public JavaSource getJavaSource() throws Exception {
+ if (javaSource == null) {
+ javaSource = initJavaSource();
+ }
+ return javaSource;
+ }
+
+ /** Initializes the object, after all parameters are set.
+ */
+ private JavaSource initJavaSource() throws Exception {
+ Exception ex = null;
+ String mode = getType();
+ if (mode == null || "Reflection".equals(mode)) {
+ try {
+ Class c = classLoader.loadClass(getInterface());
+ if (c != null) {
+ return new CompiledClassReflector(c).getJavaSource(new JavaSourceFactory());
+ }
+ } catch (Exception e) {
+ if (ex == null) {
+ ex = e;
+ }
+ }
+ }
+ if (mode == null || "Source".equals(mode)) {
+ URL url = classLoader.getResource(getInterface().replace('.', '/') + ".java");
+ if (url != null) {
+ SourceReflector reflector = new SourceReflector(url);
+ return reflector.getJavaSource(new JavaSourceFactory());
+ }
+ }
+ if (ex == null) {
+ throw new IllegalStateException("Failed to locate Java class "
+ + getInterface());
+ } else {
+ throw ex;
+ }
+ }
}
Propchange: webservices/jaxme/branches/MAVEN/projects/xs/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 19 05:41:20 2005
@@ -0,0 +1,2 @@
+
+target
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org