Author: jason.greene(a)jboss.com
Date: 2007-01-26 16:21:43 -0500 (Fri, 26 Jan 2007)
New Revision: 2144
Added:
trunk/build/etc/wsgen.sh
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/WSGenerate.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/ant/
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/ant/WSGenerate.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/ProviderLocator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/WebServiceGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/BytecodeWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/ChainedWritableWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/NullPrintStream.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorProviderImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WritableWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/spi/
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/spi/WebServiceGeneratorProvider.java
Removed:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/SourceWrapperGenerator.java
Modified:
trunk/build/ant-import/build-release.xml
trunk/build/ant-import/build-thirdparty.xml
trunk/build/version.properties
trunk/jbossws-core/.classpath
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/utils/IOUtils.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsse/WSSecurityConfigFactory.java
Log:
Implement JAX-WS WebServiceGenerator API and SPI
Provide a full implementation
Added feature rich ant task and command line tool
Extend the JAXWSWebServiceMetaDataBuilder to support a tooling mode
Modified: trunk/build/ant-import/build-release.xml
===================================================================
--- trunk/build/ant-import/build-release.xml 2007-01-26 20:49:22 UTC (rev 2143)
+++ trunk/build/ant-import/build-release.xml 2007-01-26 21:21:43 UTC (rev 2144)
@@ -152,6 +152,7 @@
<fileset dir="${etc.dir}">
<include name="wstools.bat"/>
<include name="wstools.sh"/>
+ <include name="wsgen.sh"/>
</fileset>
</copy>
Modified: trunk/build/ant-import/build-thirdparty.xml
===================================================================
--- trunk/build/ant-import/build-thirdparty.xml 2007-01-26 20:49:22 UTC (rev 2143)
+++ trunk/build/ant-import/build-thirdparty.xml 2007-01-26 21:21:43 UTC (rev 2144)
@@ -72,6 +72,7 @@
<get
src="${jboss.repository}/xmlunit-xmlunit/${xmlunit}/lib/xmlunit1.0.jar"
dest="${thirdparty.dir}/xmlunit1.0.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/wscommons-policy/${wscommons-policy}/lib/policy.jar"
dest="${thirdparty.dir}/policy.jar" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/woodstox/${woodstox}/lib/wstx.jar"
dest="${thirdparty.dir}/wstx.jar" usetimestamp="true"
verbose="true"/>
+ <get src="${jboss.repository}/gnu-getopt/${gnu-getopt}/lib/getopt.jar"
dest="${thirdparty.dir}/getopt.jar" usetimestamp="true"
verbose="true"/>
<unzip dest="${thirdparty.dir}"
src="${thirdparty.dir}/ejb3.deployer.zip"/>
</target>
@@ -97,6 +98,7 @@
<pathelement location="${thirdparty.dir}/stax-api.jar"/>
<pathelement location="${thirdparty.dir}/wsdl4j.jar"/>
<pathelement location="${thirdparty.dir}/wstx.jar"/>
+ <pathelement location="${thirdparty.dir}/getopt.jar"/>
<pathelement location="${thirdparty.dir}/xmlsec.jar"/>
<pathelement location="${thirdparty.dir}/xercesImpl.jar"/>
<pathelement location="${thirdparty.dir}/xalan.jar"/>
Added: trunk/build/etc/wsgen.sh
===================================================================
--- trunk/build/etc/wsgen.sh (rev 0)
+++ trunk/build/etc/wsgen.sh 2007-01-26 21:21:43 UTC (rev 2144)
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+# $Id: wstools.sh 1683 2006-12-21 12:40:22Z thomas.diesler(a)jboss.com $
+
+DIRNAME=`dirname $0`
+PROGNAME=`basename $0`
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+case "`uname`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$JBOSS_HOME" ] &&
+ JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Setup JBOSS_HOME
+if [ "x$JBOSS_HOME" = "x" ]; then
+ # get the full path (without any relative bits)
+ JBOSS_HOME=`cd $DIRNAME/..; pwd`
+fi
+export JBOSS_HOME
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+#JPDA options. Uncomment and modify as appropriate to enable remote debugging .
+#JAVA_OPTS="-classic -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n $JAVA_OPTS"
+
+# Setup JBoss sepecific properties
+JAVA_OPTS="$JAVA_OPTS"
+
+# Setup the java endorsed dirs
+JBOSS_ENDORSED_DIRS="$JBOSS_HOME/lib/endorsed"
+
+# Setup the wstools classpath
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jboss-xml-binding.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/activation.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/getopt.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/javassist.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jaxb-api.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jaxb-impl.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jbossall-client.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jbossretro-rt.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jboss-backport-concurrent.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jbossws14-client.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/jbossws-client.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/log4j.jar"
+WSGEN_CLASSPATH="$WSGEN_CLASSPATH:$JBOSS_HOME/client/mail.jar"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ WSGEN_CLASSPATH=`cygpath --path --windows "$WSGEN_CLASSPATH"`
+ JBOSS_ENDORSED_DIRS=`cygpath --path --windows "$JBOSS_ENDORSED_DIRS"`
+fi
+
+# Display our environment
+# echo
"========================================================================="
+# echo ""
+# echo " WSTools Environment"
+# echo ""
+# echo " JBOSS_HOME: $JBOSS_HOME"
+# echo ""
+# echo " JAVA: $JAVA"
+# echo ""
+# echo " JAVA_OPTS: $JAVA_OPTS"
+# echo ""
+# echo " CLASSPATH: $WSGEN_CLASSPATH"
+# echo ""
+# echo
"========================================================================="
+# echo ""
+
+# Execute the JVM
+"$JAVA" $JAVA_OPTS \
+ -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
+ -classpath "$WSGEN_CLASSPATH" \
+ org.jboss.ws.tools.jaxws.WSGenerate "$@"
Modified: trunk/build/version.properties
===================================================================
--- trunk/build/version.properties 2007-01-26 20:49:22 UTC (rev 2143)
+++ trunk/build/version.properties 2007-01-26 21:21:43 UTC (rev 2144)
@@ -29,6 +29,7 @@
apache-tomcat=5.5.20
apache-xalan=j_2.7.0
apache-xerces=2.7.1
+gnu-getopt=1.0.10
hibernate=3.2.1.GA
jboss-backport-concurrent=2.1.0.GA
jboss-common-core=2.0.4.Alpha
Modified: trunk/jbossws-core/.classpath
===================================================================
--- trunk/jbossws-core/.classpath 2007-01-26 20:49:22 UTC (rev 2143)
+++ trunk/jbossws-core/.classpath 2007-01-26 21:21:43 UTC (rev 2144)
@@ -16,7 +16,7 @@
<classpathentry kind="lib"
path="/build/thirdparty/jboss-logging-spi.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/jboss-remoting.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/jboss-xml-binding.jar"
sourcepath="/build/thirdparty/jboss-xml-binding-src.zip"/>
- <classpathentry kind="lib" path="/build/thirdparty/wsdl4j.jar"
sourcepath="/build/thirdparty/wsdl4j-1_5_2.zip"/>
+ <classpathentry kind="lib"
path="/build/thirdparty/wsdl4j.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/xmlsec.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/ejb3.deployer/jboss-annotations-ejb3.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/ejb3.deployer/jboss-ejb3x.jar"/>
@@ -30,5 +30,6 @@
<classpathentry kind="lib"
path="/build/thirdparty/mail.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/jbosssx-client.jar"
sourcepath="/build/thirdparty/jbosssx-src.zip"/>
<classpathentry kind="lib"
path="/build/thirdparty/wstx.jar"/>
+ <classpathentry kind="lib"
path="/build/thirdparty/getopt.jar"/>
<classpathentry kind="output" path="output-eclipse"/>
</classpath>
Copied:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWrapperGenerator.java
(from rev 2041,
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WrapperGenerator.java)
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWrapperGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/AbstractWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,98 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.core.jaxws;
+
+import java.beans.Introspector;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+
+/**
+ * Base class for JAX-WS wrapper generation.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ * @version $Revision$
+ */
+public abstract class AbstractWrapperGenerator implements WrapperGenerator
+{
+ private static Set<String> excludedGetters;
+ protected ClassLoader loader;
+
+ public AbstractWrapperGenerator(ClassLoader loader)
+ {
+ this.loader = loader;
+ }
+
+ public void reset(ClassLoader loader)
+ {
+ this.loader = loader;
+ }
+
+ static
+ {
+ excludedGetters = new HashSet<String>(4);
+ excludedGetters.add("getCause");
+ excludedGetters.add("getClass");
+ excludedGetters.add("getLocalizedMessage");
+ excludedGetters.add("getStackTrace");
+ }
+
+ protected SortedMap<String, Class<?>>
getExceptionProperties(Class<?> exception)
+ {
+ if (! Exception.class.isAssignableFrom(exception))
+ throw new IllegalArgumentException("Not an exception");
+
+ TreeMap<String, Class<?>> sortedGetters = new TreeMap<String,
Class<?>>();
+
+ for (Method method : exception.getMethods())
+ {
+ if (java.lang.reflect.Modifier.isStatic(method.getModifiers()))
+ continue;
+
+ Class<?> returnType = method.getReturnType();
+ if (returnType == void.class)
+ continue;
+
+ String name = method.getName();
+ if (excludedGetters.contains(name))
+ continue;
+
+ int offset;
+ if (name.startsWith("get"))
+ offset = 3;
+ else if (name.startsWith("is"))
+ offset = 2;
+ else
+ continue;
+
+ name = Introspector.decapitalize(name.substring(offset));
+ sortedGetters.put(name, returnType);
+ }
+
+ return sortedGetters;
+ }
+}
\ No newline at end of file
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/DynamicWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -53,19 +53,32 @@
import org.jboss.ws.metadata.umdm.TypesMetaData;
import org.jboss.ws.metadata.umdm.WrappedParameter;
-public class DynamicWrapperGenerator extends WrapperGenerator
+public class DynamicWrapperGenerator extends AbstractWrapperGenerator
{
private static Logger log = Logger.getLogger(DynamicWrapperGenerator.class);
- private ClassPool pool;
+ protected ClassPool pool;
+ protected boolean prune = true;
public DynamicWrapperGenerator(ClassLoader loader)
{
super(loader);
+ init(loader);
+ }
+
+ private void init(ClassLoader loader)
+ {
pool = new ClassPool(true);
pool.appendClassPath(new LoaderClassPath(loader));
}
-
+
+ @Override
+ public void reset(ClassLoader loader)
+ {
+ super.reset(loader);
+ init(loader);
+ }
+
/**
* Generates a wrapper type and assigns it to the passed ParameterMetaData
* object. This routine requires the pmd to contain completed wrappedTypes
@@ -101,6 +114,7 @@
{
addProperty(clazz, parameter.getType(), parameter.getName(),
parameter.getVariable(), parameter.getTypeArguments());
}
+ clazz.stopPruning(!prune);
pool.toClass(clazz, loader);
JavaUtils.clearBlacklists(loader);
}
Deleted: trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WrapperGenerator.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/WrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -1,99 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.ws.core.jaxws;
-
-import java.beans.Introspector;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.jboss.ws.metadata.umdm.FaultMetaData;
-import org.jboss.ws.metadata.umdm.ParameterMetaData;
-
-
-/**
- * Base class for JAX-WS wrapper generation.
- *
- * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
- * @version $Revision$
- */
-public abstract class WrapperGenerator
-{
- private static Set<String> excludedGetters;
- protected ClassLoader loader;
-
- public WrapperGenerator(ClassLoader loader)
- {
- this.loader = loader;
- }
-
- static
- {
- excludedGetters = new HashSet<String>(4);
- excludedGetters.add("getCause");
- excludedGetters.add("getClass");
- excludedGetters.add("getLocalizedMessage");
- excludedGetters.add("getStackTrace");
- }
-
- protected SortedMap<String, Class<?>>
getExceptionProperties(Class<?> exception)
- {
- if (! Exception.class.isAssignableFrom(exception))
- throw new IllegalArgumentException("Not an exception");
-
- TreeMap<String, Class<?>> sortedGetters = new TreeMap<String,
Class<?>>();
-
- for (Method method : exception.getMethods())
- {
- if (java.lang.reflect.Modifier.isStatic(method.getModifiers()))
- continue;
-
- Class<?> returnType = method.getReturnType();
- if (returnType == void.class)
- continue;
-
- String name = method.getName();
- if (excludedGetters.contains(name))
- continue;
-
- int offset;
- if (name.startsWith("get"))
- offset = 3;
- else if (name.startsWith("is"))
- offset = 2;
- else
- continue;
-
- name = Introspector.decapitalize(name.substring(offset));
- sortedGetters.put(name, returnType);
- }
-
- return sortedGetters;
- }
-
-
-
- public abstract void generate(ParameterMetaData pmd);
- public abstract void generate(FaultMetaData fmd);
-}
\ No newline at end of file
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/attachment/SwapableMemoryDataSource.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -111,17 +111,7 @@
if (rbaos != null && rbaos.size() > maxMemorySize)
{
- File tmpdir = null;
- try
- {
- tmpdir = IOUtils.createTempDirectory();
- }
- catch (Throwable e)
- {
- // Ignore if the server config cannot be found
- // this would be the case if we are on the client side
- }
-
+ File tmpdir = IOUtils.createTempDirectory();
swapFile = File.createTempFile(SWAP_PREFIX, SWAP_SUFFIX, tmpdir);
swapFile.deleteOnExit();
os = new FileOutputStream(swapFile);
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/utils/IOUtils.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/utils/IOUtils.java 2007-01-26
20:49:22 UTC (rev 2143)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/utils/IOUtils.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -111,10 +111,21 @@
public static File createTempDirectory() throws IOException
{
- ServerConfigFactory factory = ServerConfigFactory.getInstance();
- ServerConfig config = factory.getServerConfig();
- File tmpdir = new File(config.getServerTempDir().getCanonicalPath() +
"/jbossws");
- tmpdir.mkdirs();
+ File tmpdir = null;
+
+ try
+ {
+ ServerConfigFactory factory = ServerConfigFactory.getInstance();
+ ServerConfig config = factory.getServerConfig();
+
+ tmpdir = new File(config.getServerTempDir().getCanonicalPath() +
"/jbossws");
+ tmpdir.mkdirs();
+ }
+ catch (Throwable t)
+ {
+ // Use the Java temp directory if there is no server config (the client)
+ }
+
return tmpdir;
}
}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -60,6 +60,7 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.jaxrpc.Use;
+import org.jboss.ws.core.jaxws.AbstractWrapperGenerator;
import org.jboss.ws.core.jaxws.DynamicWrapperGenerator;
import org.jboss.ws.core.jaxws.WrapperGenerator;
import org.jboss.ws.core.utils.HolderUtils;
@@ -784,9 +785,18 @@
throw new WSException("No exposable methods found");
}
+ protected void initWrapperGenerator(ClassLoader loader)
+ {
+ // Use the dynamic generator by default. Otherwise reset the last
+ if (wrapperGenerator == null)
+ wrapperGenerator = new DynamicWrapperGenerator(loader);
+ else
+ wrapperGenerator.reset(loader);
+ }
+
protected void resetMetaDataBuilder(ClassLoader loader)
{
- wrapperGenerator = new DynamicWrapperGenerator(loader);
+ initWrapperGenerator(loader);
javaTypes.clear();
typeRefs.clear();
jaxbCtx = null;
@@ -876,4 +886,12 @@
}
}
}
+
+ /**
+ * Set the wrapper generator for this builder.
+ */
+ public void setWrapperGenerator(WrapperGenerator wrapperGenerator)
+ {
+ this.wrapperGenerator = wrapperGenerator;
+ }
}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -23,12 +23,27 @@
// $Id$
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Writer;
+import java.net.URL;
+
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPMessageHandlers;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.server.UnifiedDeploymentInfo;
import org.jboss.ws.core.utils.IOUtils;
import org.jboss.ws.metadata.builder.MetaDataBuilder;
-import org.jboss.ws.metadata.umdm.*;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
+import org.jboss.ws.metadata.umdm.UnifiedMetaData;
import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
import org.jboss.ws.metadata.wsdl.WSDLUtils;
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
@@ -40,15 +55,6 @@
import org.jboss.ws.tools.wsdl.WSDLWriter;
import org.jboss.ws.tools.wsdl.WSDLWriterResolver;
-import javax.jws.*;
-import javax.jws.soap.SOAPMessageHandlers;
-import javax.management.ObjectName;
-import javax.xml.namespace.QName;
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.net.URL;
-
/**
* An abstract annotation meta data builder.
*
@@ -61,6 +67,11 @@
@SuppressWarnings("deprecation")
public class JAXWSWebServiceMetaDataBuilder extends JAXWSServerMetaDataBuilder
{
+ private boolean generateWsdl = true;
+ private boolean toolMode = false;
+ private File wsdlDirectory = null;
+ private PrintStream messageStream = null;
+
private static class EndpointResult
{
private Class<?> epClass;
@@ -68,8 +79,12 @@
private ServiceMetaData serviceMetaData;
private URL wsdlLocation;
}
+
+ public void setGenerateWsdl(boolean generateWsdl)
+ {
+ this.generateWsdl = generateWsdl;
+ }
-
public ServerEndpointMetaData buildWebServiceMetaData(UnifiedMetaData wsMetaData,
UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName)
{
try
@@ -110,9 +125,20 @@
createJAXBContext(sepMetaData);
populateXmlTypes(sepMetaData);
- // Process or generate WSDL
- processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData);
+ // The server must always generate WSDL
+ if (generateWsdl || !toolMode)
+ processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData);
+ // No need to process endpoint items if we are in tool mode
+ if (toolMode)
+ return sepMetaData;
+
+ // Sanity check: read the generated WSDL and initialize the schema model
+ // Note, this should no longer be needed, look into removing it
+ WSDLDefinitions wsdlDefinitions = serviceMetaData.getWsdlDefinitions();
+ JBossXSModel schemaModel =
WSDLUtils.getSchemaModel(wsdlDefinitions.getWsdlTypes());
+ serviceMetaData.getTypesMetaData().setSchemaModel(schemaModel);
+
// process config
processEndpointConfig(udi, sepClass, linkName, sepMetaData);
@@ -128,22 +154,14 @@
else if (seiClass.isAnnotationPresent(HandlerChain.class))
processHandlerChain(sepMetaData, seiClass);
- // Sanity check: read the generated WSDL and initialize the schema model
- WSDLDefinitions wsdlDefinitions = serviceMetaData.getWsdlDefinitions();
- JBossXSModel schemaModel =
WSDLUtils.getSchemaModel(wsdlDefinitions.getWsdlTypes());
- serviceMetaData.getTypesMetaData().setSchemaModel(schemaModel);
-
// Init the endpoint address
MetaDataBuilder.initEndpointAddress(udi, sepMetaData, linkName);
- // replace the SOAP address
- MetaDataBuilder.replaceAddressLocation(sepMetaData);
-
// Process an optional @SOAPMessageHandlers annotation
if (sepClass.isAnnotationPresent(SOAPMessageHandlers.class) ||
seiClass.isAnnotationPresent(SOAPMessageHandlers.class))
log.warn("@SOAPMessageHandlers is deprecated as of JAX-WS 2.0 with no
replacement.");
- // process endpoint meta data extensions
+ MetaDataBuilder.replaceAddressLocation(sepMetaData);
processEndpointMetaDataExtensions(sepMetaData, wsdlDefinitions);
// init service endpoint id
@@ -253,25 +271,45 @@
// Ensure that types are only in the interface qname
wsdlDefinitions.getWsdlTypes().setNamespace(epMetaData.getPortTypeName().getNamespaceURI());
- final File tmpdir = IOUtils.createTempDirectory();
- File wsdlTmpFile = File.createTempFile(serviceName, ".wsdl",
tmpdir);
- wsdlTmpFile.deleteOnExit();
+ final File dir, wsdlFile;
+
+ if (wsdlDirectory != null)
+ {
+ dir = wsdlDirectory;
+ wsdlFile = new File(dir, serviceName + ".wsdl");
+ }
+ else
+ {
+ dir = IOUtils.createTempDirectory();
+ wsdlFile = File.createTempFile(serviceName, ".wsdl", dir);
+ wsdlFile.deleteOnExit();
+ }
- Writer writer = IOUtils.getCharsetFileWriter(wsdlTmpFile,
Constants.DEFAULT_XML_CHARSET);
+ message(wsdlFile.getName());
+ Writer writer = IOUtils.getCharsetFileWriter(wsdlFile,
Constants.DEFAULT_XML_CHARSET);
new WSDLWriter(wsdlDefinitions).write(writer, Constants.DEFAULT_XML_CHARSET,
new WSDLWriterResolver() {
public WSDLWriterResolver resolve(String suggestedFile) throws
IOException
{
- File newTmpFile = File.createTempFile(suggestedFile, ".wsdl",
tmpdir);
- newTmpFile.deleteOnExit();
- actualFile = newTmpFile.getName();
+ File file;
+ if (wsdlDirectory != null)
+ {
+ file = new File(dir, suggestedFile + ".wsdl");
+ }
+ else
+ {
+ file = File.createTempFile(suggestedFile, ".wsdl", dir);
+ file.deleteOnExit();
+ }
+ actualFile = file.getName();
+ message(actualFile);
charset = Constants.DEFAULT_XML_CHARSET;
- writer = IOUtils.getCharsetFileWriter(newTmpFile,
Constants.DEFAULT_XML_CHARSET);
+ writer = IOUtils.getCharsetFileWriter(file,
Constants.DEFAULT_XML_CHARSET);
return this;
}
});
writer.close();
- serviceMetaData.setWsdlLocation(wsdlTmpFile.toURL());
+ serviceMetaData.setWsdlLocation(wsdlFile.toURL());
}
catch (RuntimeException rte)
{
@@ -283,4 +321,25 @@
}
}
}
+
+ private void message(String msg)
+ {
+ if (messageStream != null)
+ messageStream.println(msg);
+ }
+
+ public void setToolMode(boolean toolMode)
+ {
+ this.toolMode = toolMode;
+ }
+
+ public void setWsdlDirectory(File wsdlDirectory)
+ {
+ this.wsdlDirectory = wsdlDirectory;
+ }
+
+ public void setMessageStream(PrintStream messageStream)
+ {
+ this.messageStream = messageStream;
+ }
}
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java 2007-01-26
20:49:22 UTC (rev 2143)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsdl/WSDLUtils.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -71,6 +71,7 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.ParameterWrapping;
import org.jboss.ws.core.utils.HolderUtils;
+import org.jboss.ws.core.utils.JavaUtils;
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
import org.jboss.xb.binding.Util;
@@ -706,7 +707,7 @@
public String getTypeNamespace(Class javaType)
{
- return getTypeNamespace(javaType.getPackage().getName());
+ return getTypeNamespace(JavaUtils.getPackageName(javaType));
}
/**
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsse/WSSecurityConfigFactory.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsse/WSSecurityConfigFactory.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/wsse/WSSecurityConfigFactory.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -85,9 +85,12 @@
{
UnifiedVirtualFile child = vfsRoot.findChild(resource);
URL url = child.toURL();
- InputStream inputStream = url.openStream();
- inputStream.close();
-
+ if (url != null)
+ {
+ InputStream inputStream = url.openStream();
+ inputStream.close();
+ }
+
return url;
}
catch (Exception e)
Deleted: trunk/jbossws-core/src/main/java/org/jboss/ws/tools/SourceWrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/SourceWrapperGenerator.java 2007-01-26
20:49:22 UTC (rev 2143)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/SourceWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -1,165 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ws.tools;
-
-import java.util.List;
-import java.util.SortedMap;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.namespace.QName;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.WSException;
-import org.jboss.ws.core.jaxws.WrapperGenerator;
-import org.jboss.ws.core.utils.JavaUtils;
-import org.jboss.ws.metadata.umdm.FaultMetaData;
-import org.jboss.ws.metadata.umdm.OperationMetaData;
-import org.jboss.ws.metadata.umdm.ParameterMetaData;
-import org.jboss.ws.metadata.umdm.WrappedParameter;
-
-import com.sun.codemodel.JAnnotationArrayMember;
-import com.sun.codemodel.JAnnotationUse;
-import com.sun.codemodel.JCodeModel;
-import com.sun.codemodel.JDefinedClass;
-import com.sun.codemodel.JExpr;
-import com.sun.codemodel.JFieldVar;
-import com.sun.codemodel.JMethod;
-import com.sun.codemodel.JMod;
-
-/**
- * Generates source for wrapper beans
- *
- * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
- * @version $Revision$
- */
-public class SourceWrapperGenerator extends WrapperGenerator
-{
-
- private static Logger log = Logger.getLogger(SourceWrapperGenerator.class);
- private JCodeModel codeModel = new JCodeModel();
-
- public SourceWrapperGenerator(ClassLoader loader)
- {
- super(loader);
- }
-
- public void generate(ParameterMetaData pmd)
- {
- List<WrappedParameter> wrappedParameters = pmd.getWrappedParameters();
- OperationMetaData operationMetaData = pmd.getOperationMetaData();
-
- if (operationMetaData.isDocumentWrapped() == false)
- throw new WSException("Operation is not document/literal (wrapped)");
-
- if (wrappedParameters == null)
- throw new WSException("Cannot generate a type when their is no type
information");
-
- String wrapperName = pmd.getJavaTypeName();
- if (log.isDebugEnabled())
- log.debug("Generating wrapper: " + wrapperName);
-
- try
- {
-
- JDefinedClass clazz = codeModel._class(wrapperName);
- addClassAnnotations(clazz, pmd.getXmlName(), pmd.getXmlType(), null);
- for (WrappedParameter wrapped : wrappedParameters)
- {
- addProperty(clazz, wrapped.getType(), wrapped.getName(),
wrapped.getVariable());
- }
- }
- catch (Exception e)
- {
- throw new WSException("Could not generate wrapper type: " +
wrapperName, e);
- }
- }
- public void generate(FaultMetaData fmd)
- {
- String faultBeanName = fmd.getFaultBeanName();
- Class exception = fmd.getJavaType();
-
- try
- {
- SortedMap<String, Class<?>> properties =
getExceptionProperties(exception);
- String[] propertyOrder = properties.keySet().toArray(new String[0]);
-
- JDefinedClass clazz = codeModel._class(faultBeanName);
- addClassAnnotations(clazz, fmd.getXmlName(), fmd.getXmlType(), propertyOrder);
-
- for (String property : propertyOrder)
- addProperty(clazz, properties.get(property).getName(), new QName(property),
property);
- }
- catch (Exception e)
- {
- throw new WSException("Could not generate wrapper type: " +
faultBeanName, e);
- }
- }
-
- private static String getterPrefix(Class type)
- {
- return Boolean.TYPE == type || Boolean.class == type ? "is" :
"get";
- }
-
- private void addProperty(JDefinedClass clazz, String typeName, QName name, String
variable)
- throws ClassNotFoundException
- {
- Class type = JavaUtils.loadJavaType(typeName, loader);
- JFieldVar field = clazz.field(JMod.PRIVATE, type, variable);
- JAnnotationUse annotation = field.annotate(XmlElement.class);
- if (name.getNamespaceURI() != null)
- annotation.param("namespace", name.getNamespaceURI());
- annotation.param("name", name.getLocalPart());
-
- // Add acessor methods
- JMethod method = clazz.method(JMod.PUBLIC, type, getterPrefix(type) +
JavaUtils.capitalize(variable));
- method.body()._return(JExpr._this().ref(variable));
-
- method = clazz.method(JMod.PUBLIC, type, "set" +
JavaUtils.capitalize(variable));
- method.body().assign(JExpr._this().ref(variable), method.param(type, variable));
- }
-
- private static void addClassAnnotations(JDefinedClass clazz, QName xmlName, QName
xmlType, String[] propertyOrder)
- {
- JAnnotationUse annotation = clazz.annotate(XmlRootElement.class);
- if (xmlName.getNamespaceURI() != null && xmlName.getNamespaceURI().length()
> 0)
- annotation.param("namespace", xmlName.getNamespaceURI());
- annotation.param("name", xmlName.getLocalPart());
-
- annotation = clazz.annotate(XmlType.class);
- if (xmlType.getNamespaceURI() != null & xmlType.getNamespaceURI().length() >
0)
- annotation.param("namespace", xmlType.getNamespaceURI());
- annotation.param("name", xmlType.getLocalPart());
- if (propertyOrder != null)
- {
- JAnnotationArrayMember paramArray =
annotation.paramArray("propOrder");
- for (String property : propertyOrder)
- paramArray.param(property);
- }
-
- annotation = clazz.annotate(XmlAccessorType.class);
- annotation.param("value", XmlAccessType.FIELD);
- }
-}
\ No newline at end of file
Added: trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/WSGenerate.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/WSGenerate.java
(rev 0)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/WSGenerate.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws;
+
+import gnu.getopt.Getopt;
+import gnu.getopt.LongOpt;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+
+/**
+ * WSGenerate is a command line tool that generates portable JAX-WS artifacts
+ * for a service endpoint implementation.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ */
+public class WSGenerate
+{
+ private boolean generateSource = false;
+ private boolean generateWsdl = false;
+ private boolean quiet = false;
+ private boolean showTraces = false;
+ private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private File outputDir = new File("output");
+ private File resourceDir = null;
+ private File sourceDir = null;
+
+ public static String PROGRAM_NAME = System.getProperty("program.name",
"wsgen");
+
+ public static void main(String[] args)
+ {
+ WSGenerate generate = new WSGenerate();
+ String endpoint = generate.parseArguments(args);
+ System.exit(generate.generate(endpoint));
+ }
+
+ private String parseArguments(String[] args)
+ {
+ String shortOpts = "hwko:r:s:cqt";
+ LongOpt[] longOpts =
+ {
+ new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
+ new LongOpt("wsdl", LongOpt.NO_ARGUMENT, null, 'w'),
+ new LongOpt("keep", LongOpt.NO_ARGUMENT, null, 'k'),
+ new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o'),
+ new LongOpt("resource", LongOpt.REQUIRED_ARGUMENT, null,
'r'),
+ new LongOpt("source", LongOpt.REQUIRED_ARGUMENT, null, 's'),
+ new LongOpt("classpath", LongOpt.REQUIRED_ARGUMENT, null,
'c'),
+ new LongOpt("quiet", LongOpt.NO_ARGUMENT, null, 'q'),
+ new LongOpt("show-traces", LongOpt.NO_ARGUMENT, null, 't'),
+ };
+
+ Getopt getopt = new Getopt(PROGRAM_NAME, args, shortOpts, longOpts);
+ int c;
+ while ((c = getopt.getopt()) != -1)
+ {
+ switch (c)
+ {
+ case 'k':
+ generateSource = true;
+ break;
+ case 's':
+ sourceDir = new File(getopt.getOptarg());
+ break;
+ case 'r':
+ resourceDir = new File(getopt.getOptarg());
+ break;
+ case 'w':
+ generateWsdl = true;
+ break;
+ case 't':
+ showTraces = true;
+ break;
+ case 'o':
+ outputDir = new File(getopt.getOptarg());
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 'c':
+ processClassPath(getopt.getOptarg());
+ break;
+ case 'h':
+ printHelp();
+ System.exit(0);
+ case '?':
+ System.exit(1);
+ }
+ }
+
+ int endpointPos = getopt.getOptind();
+ if (endpointPos >= args.length)
+ {
+ System.err.println("Error: endpoint implementation was not
specified!");
+ printHelp();
+ System.exit(1);
+ }
+
+ return args[endpointPos];
+ }
+
+
+ private int generate(String endpoint)
+ {
+ if (!JavaUtils.isLoaded(endpoint, loader))
+ {
+ System.err.println("Error: Could not load class [" + endpoint +
"]. Did you specify a valid --classpath?");
+ return 1;
+ }
+
+ WebServiceGenerator gen = WebServiceGenerator.newInstance(loader);
+ gen.setGenerateWsdl(generateWsdl);
+ gen.setGenerateSource(generateSource);
+ gen.setOutputDirectory(outputDir);
+ if (resourceDir != null)
+ gen.setResourceDirectory(resourceDir);
+ if (sourceDir != null)
+ gen.setSourceDirectory(sourceDir);
+
+ if (! quiet)
+ gen.setMessageStream(System.out);
+
+ try
+ {
+ gen.generate(endpoint);
+ return 0;
+ }
+ catch (Throwable t)
+ {
+ System.err.println("Error: Could not generate. (use --show-traces to see
full traces)");
+ if (!showTraces)
+ {
+ String message = t.getMessage();
+ if (message == null)
+ message = t.getClass().getSimpleName();
+ System.err.println("Error: " + message);
+ }
+ else
+ {
+ t.printStackTrace(System.err);
+ }
+
+ }
+
+ return 1;
+ }
+
+ private void processClassPath(String classPath)
+ {
+ String[] entries = classPath.split(File.pathSeparator);
+ List<URL> urls= new ArrayList<URL>(entries.length);
+ for (String entry : entries)
+ {
+ try
+ {
+ urls.add(new File(entry).toURL());
+ }
+ catch (MalformedURLException e)
+ {
+ System.err.println("Error: a classpath entry was malformed: " +
entry);
+ }
+ }
+ loader = new URLClassLoader(urls.toArray(new URL[0]), loader);
+ }
+
+ private static void printHelp()
+ {
+ PrintStream out = System.out;
+ out.println("WSGenerate generates portable JAX-WS artifacts for an endpoint
implementation.\n");
+ out.println("usage: " + PROGRAM_NAME + " [options] <endpoint
class name>\n");
+ out.println("options: ");
+ out.println(" -h, --help Show this help message");
+ out.println(" -k, --keep Keep/Generate Java
source");
+ out.println(" -w, --wsdl Enable WSDL file
generation");
+ out.println(" -c. --classpath The classpath that contains the
endpoint");
+ out.println(" -o, --output=<directory> The directory to put
generated artifacts");
+ out.println(" -r, --resource=<directory> The directory to put
resource artifacts");
+ out.println(" -s, --source=<directory> The directory to put Java
source");
+ out.println(" -q, --quiet Be somewhat more quiet");
+ out.println(" -t, --show-traces Show full exception stack
traces");
+ out.flush();
+ }
+}
Added: trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/ant/WSGenerate.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/ant/WSGenerate.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/ant/WSGenerate.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,217 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.tools.jaxws.ant;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.ExecuteJava;
+import org.apache.tools.ant.taskdefs.LogOutputStream;
+import org.apache.tools.ant.types.CommandlineJava;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+
+/**
+ * Ant task which invokes WebServiceGenerate.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ */
+public class WSGenerate extends Task
+{
+ private Path classpath = new Path(getProject());
+ private String sei = null;
+ private File destdir = null;
+ private File resourcedestdir = null;
+ private File sourcedestdir = null;
+ private boolean keep = false;
+ private boolean genwsdl = false;
+ private boolean verbose = false;
+ private boolean fork = false;
+
+ public void setClasspath(Path classpath)
+ {
+ this.classpath = classpath;
+ }
+
+ public void setClasspathRef(Reference ref)
+ {
+ createClasspath().setRefid(ref);
+ }
+
+ public Path createClasspath()
+ {
+ return classpath;
+ }
+
+ public void setDestdir(File destdir)
+ {
+ this.destdir = destdir;
+ }
+
+ public void setKeep(boolean keep)
+ {
+ this.keep = keep;
+ }
+
+ public void setSei(String sei)
+ {
+ this.sei = sei;
+ }
+
+ public void setEndpoint(String endpoint)
+ {
+ this.sei = endpoint;
+ }
+
+ public void setFork(boolean fork)
+ {
+ this.fork = fork;
+ }
+
+ public void setResourcedestdir(File resourcedestdir)
+ {
+ this.resourcedestdir = resourcedestdir;
+ }
+
+ public void setSourcedestdir(File sourcedestdir)
+ {
+ this.sourcedestdir = sourcedestdir;
+ }
+
+ public void setVerbose(boolean verbose)
+ {
+ this.verbose = verbose;
+ }
+
+ public void setGenwsdl(boolean genwsdl)
+ {
+ this.genwsdl = genwsdl;
+ }
+
+ private ClassLoader getClasspathLoader(ClassLoader parent)
+ {
+ return new AntClassLoader(parent, getProject(), classpath, false);
+ }
+
+ public void executeNonForked()
+ {
+ ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
+ ClassLoader antLoader = this.getClass().getClassLoader();
+ Thread.currentThread().setContextClassLoader(antLoader);
+ try
+ {
+ WebServiceGenerator gen = WebServiceGenerator.newInstance();
+ gen.setClassLoader(getClasspathLoader(antLoader));
+ if (verbose)
+ gen.setMessageStream(new PrintStream(new LogOutputStream(this,
Project.MSG_INFO)));
+ gen.setGenerateSource(keep);
+ gen.setGenerateWsdl(genwsdl);
+ if (destdir != null)
+ gen.setOutputDirectory(destdir);
+ if (resourcedestdir != null)
+ gen.setResourceDirectory(resourcedestdir);
+ if (sourcedestdir != null)
+ gen.setSourceDirectory(sourcedestdir);
+ if (verbose)
+ log("Generating from endpoint: " + sei, Project.MSG_INFO);
+
+ gen.generate(sei);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(prevCL);
+ }
+ }
+
+ public void execute() throws BuildException
+ {
+ if (fork)
+ executeForked();
+ else
+ executeNonForked();
+ }
+
+ private Path getTaskClassPath()
+ {
+ // Why is everything in the Ant API a big hack???
+ ClassLoader cl = this.getClass().getClassLoader();
+ if (cl instanceof AntClassLoader)
+ {
+ return new Path(getProject(), ((AntClassLoader)cl).getClasspath());
+ }
+
+ return new Path(getProject());
+ }
+
+ private void executeForked() throws BuildException
+ {
+ CommandlineJava command = new CommandlineJava();
+ command.setClassname(org.jboss.ws.tools.jaxws.WSGenerate.class.getName());
+
+ Path path = command.createClasspath(getProject());
+ path.append(getTaskClassPath());
+ path.append(classpath);
+
+ if (keep)
+ command.createArgument().setValue("-k");
+
+ if (genwsdl)
+ command.createArgument().setValue("-w");
+
+ if (destdir != null)
+ {
+ command.createArgument().setValue("-o");
+ command.createArgument().setFile(destdir);
+ }
+ if (resourcedestdir != null)
+ {
+ command.createArgument().setValue("-r");
+ command.createArgument().setFile(resourcedestdir);
+ }
+ if (sourcedestdir != null)
+ {
+ command.createArgument().setValue("-s");
+ command.createArgument().setFile(sourcedestdir);
+ }
+
+ if (!verbose)
+ command.createArgument().setValue("-q");
+
+ // Always dump traces
+ command.createArgument().setValue("-t");
+ command.createArgument().setValue(sei);
+
+ if (verbose)
+ log("Command invoked: " + command.getJavaCommand().toString());
+
+ ExecuteJava execute = new ExecuteJava();
+ execute.setClasspath(path);
+ execute.setJavaCommand(command.getJavaCommand());
+ if (execute.fork(this) != 0)
+ throw new BuildException("Could not invoke wsgen", getLocation());
+ }
+}
\ No newline at end of file
Added: trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/ProviderLocator.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/ProviderLocator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/ProviderLocator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.tools.jaxws.api;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Locates a provider.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ *
+ */
+class ProviderLocator
+{
+ static <T> T locate(Class<T> providerType, String providerProperty, String
defaultProvider, ClassLoader loader)
+ {
+ String provider = null;
+
+ try
+ {
+
+ PrivilegedAction action = new PropertyAccessAction(providerProperty);
+ provider = (String)AccessController.doPrivileged(action);
+ if (provider == null)
+ provider = defaultProvider;
+
+ Class<?> clazz = loader.loadClass(provider);
+ return (T) clazz.newInstance();
+ }
+ catch (Throwable t)
+ {
+ if (provider == null)
+ throw new IllegalStateException("Failure reading system property: "
+ providerProperty);
+
+ throw new IllegalStateException("Could not load provider:" +
provider);
+ }
+
+ }
+
+ private static class PropertyAccessAction implements PrivilegedAction
+ {
+ private String name;
+
+ PropertyAccessAction(String name)
+ {
+ this.name = name;
+ }
+
+ public Object run()
+ {
+ return System.getProperty(name);
+ }
+ }
+
+}
\ No newline at end of file
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/WebServiceGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/WebServiceGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/api/WebServiceGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,151 @@
+package org.jboss.ws.tools.jaxws.api;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import org.jboss.ws.WSException;
+import org.jboss.ws.tools.TestMe;
+import org.jboss.ws.tools.jaxws.spi.WebServiceGeneratorProvider;
+
+
+/**
+ * WebServiceGenerator is responsible for generating the required portable
+ * JAX-WS artifacts for a service endpoint implementation. This includes class
+ * files for wrapper types and fault beans. WSDL may be optionally generated as
+ * well using this API.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ *
+ * <p>The following example generates class files, source files and WSDL for an
+ * endpoint:</p>
+ * <pre>
+ * WebServiceGenerator generator = WebServiceGenerator.newInstance();
+ * generator.setGenerateSource(true);
+ * generator.setGenerateWsdl(true);
+ * generator.setOutputDirectory(new File("output"));
+ * generator.setMessageStream(System.out);
+ * generator.generate(TestMe.class);
+ * </pre>
+ *
+ * <p>Thread-Safety:</p>
+ * This class expects to be thread-confined, so it can not be shared between threads.
+ */
+public abstract class WebServiceGenerator
+{
+ private static String DEFAULT_PROVIDER =
"org.jboss.ws.tools.jaxws.impl.WebServiceGeneratorProviderImpl";
+ public static final String PROVIDER_PROPERTY =
"org.jboss.ws.tools.jaxws.webServiceGeneratorProvider";
+
+ protected WebServiceGenerator()
+ {
+
+ }
+
+ /**
+ * Obtain a new instance of a WebServiceGenerator. This will use the current
+ * thread's context class loader to locate the WebServiceGeneratorProvider
+ * implementation.
+ *
+ * @return a new WebServiceGenerator
+ */
+ public static WebServiceGenerator newInstance()
+ {
+ return newInstance(Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Obtain a new instance of a WebServiceGenerator. The specified ClassLoader will be
used to
+ * locate the WebServiceGeneratorProvide implementation
+ *
+ * @param loader the ClassLoader to use
+ * @return a new WebServiceGenerator
+ */
+ public static WebServiceGenerator newInstance(ClassLoader loader)
+ {
+ WebServiceGeneratorProvider provider =
ProviderLocator.locate(WebServiceGeneratorProvider.class, PROVIDER_PROPERTY,
DEFAULT_PROVIDER, loader);
+ return provider.createGenerator(loader);
+ }
+
+ /**
+ * Enables/Disables WSDL generation.
+ *
+ * @param generateWsdl whether or not to generate WSDL
+ */
+ public abstract void setGenerateWsdl(boolean generateWsdl);
+
+ /**
+ * Enables/Disables Java source generation.
+ *
+ * @param generateSource whether or not to generate Java source.
+ */
+ public abstract void setGenerateSource(boolean generateSource);
+
+ /**
+ * Sets the main output directory. If the directory does not exist, it will be
created.
+ *
+ * @param directory the root directory for generated files
+ */
+ public abstract void setOutputDirectory(File directory);
+
+ /**
+ * Sets the resource directory. This directory will contain any generated
+ * WSDL and XSD files. If the directory does not exist, it will be created.
+ * If not specified, the output directory will be used instead.
+ *
+ * @param directory the root directory for generated resource files
+ */
+ public abstract void setResourceDirectory(File directory);
+
+ /**
+ * Sets the source directory. This directory will contain any generated Java source.
+ * If the directory does not exist, it will be created. If not specified,
+ * the output directory will be used instead.
+ *
+ * @param directory the root directory for generated source code
+ */
+ public abstract void setSourceDirectory(File directory);
+
+ /**
+ * Sets the ClassLoader used to discover types. This defaults to the one used
+ * in instantiation.
+ *
+ * @param loader the ClassLoader to use
+ */
+ public abstract void setClassLoader(ClassLoader loader);
+
+ /**
+ * Generates artifacts using the current settings. This method may be invoked
+ * more than once (e.g. multiple endpoints).
+ *
+ * @param endpointClass the name of the endpoint implementation bean
+ * @throws WSException if any error occurs during processing, or the class is not
found
+ */
+ public abstract void generate(String endpointClass);
+
+ /**
+ * Generates artifacts using the current settings. This method may be invoked
+ * more than once (e.g. multiple endpoints).
+ *
+ * @param endpointClass the endpoint implementation bean
+ * @throws WSException if any error occurs during processing
+ */
+ public abstract void generate(Class<?> endpointClass);
+
+ /**
+ * Sets the PrintStream to use for status feedback. The simplest example
+ * would be to use System.out.
+ *
+ * <p>Example output:</p>
+ * <pre>
+ * Generating WSDL:
+ * TestMeService.wsdl
+ * Writing Source:
+ * org/jboss/ws/tools/jaxws/TestMe.java
+ * org/jboss/ws/tools/jaxws/TestMeResponse.java
+ * Writing Classes:
+ * org/jboss/ws/tools/jaxws/TestMe.class
+ * org/jboss/ws/tools/jaxws/TestMeResponse.class
+ * </pre>
+ * @param messageStream the stream to use for status messages:
+ */
+ public abstract void setMessageStream(PrintStream messageStream);
+}
\ No newline at end of file
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/BytecodeWrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/BytecodeWrapperGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/BytecodeWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.CannotCompileException;
+import javassist.NotFoundException;
+
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.jaxws.DynamicWrapperGenerator;
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+
+public class BytecodeWrapperGenerator extends DynamicWrapperGenerator implements
WritableWrapperGenerator
+{
+ private List<String> typeNames = new ArrayList<String>();
+ PrintStream stream;
+
+ public BytecodeWrapperGenerator(ClassLoader loader, PrintStream stream)
+ {
+ super(loader);
+ this.stream = stream;
+ prune = false;
+ }
+
+ @Override
+ public void reset(ClassLoader loader)
+ {
+ super.reset(loader);
+ typeNames.clear();
+ }
+
+ @Override
+ public void generate(FaultMetaData fmd)
+ {
+ super.generate(fmd);
+
+ typeNames.add(fmd.getFaultBeanName());
+ }
+
+ @Override
+ public void generate(ParameterMetaData pmd)
+ {
+ super.generate(pmd);
+
+ typeNames.add(pmd.getJavaTypeName());
+ }
+
+ public void write(File directory) throws IOException
+ {
+ stream.println("Writing Classes:");
+ for (String name : typeNames)
+ {
+ try
+ {
+ stream.println(name.replace('.', '/') + ".class");
+ pool.get(name).writeFile(directory.getAbsolutePath());
+ }
+ catch (CannotCompileException e)
+ {
+ throw new WSException(e);
+ }
+ catch (NotFoundException e)
+ {
+ throw new WSException(e);
+ }
+ }
+ }
+}
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/ChainedWritableWrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/ChainedWritableWrapperGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/ChainedWritableWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.ws.core.jaxws.WrapperGenerator;
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+
+public class ChainedWritableWrapperGenerator implements WrapperGenerator
+{
+ private List<Entry> chain = new ArrayList<Entry>();
+
+ static class Entry
+ {
+ Entry(WritableWrapperGenerator generator, File directory)
+ {
+ this.generator = generator;
+ this.directory = directory;
+ }
+
+ WritableWrapperGenerator generator;
+ File directory;
+ }
+
+ public ChainedWritableWrapperGenerator()
+ {
+ }
+
+ public void reset(ClassLoader loader)
+ {
+ for (Entry entry : chain)
+ entry.generator.reset(loader);
+ }
+
+ public void write() throws IOException
+ {
+ for (Entry entry : chain)
+ entry.generator.write(entry.directory);
+ }
+
+ public void generate(FaultMetaData fmd)
+ {
+ for (Entry entry : chain)
+ entry.generator.generate(fmd);
+ }
+
+ public void generate(ParameterMetaData pmd)
+ {
+ for (Entry entry : chain)
+ entry.generator.generate(pmd);
+ }
+
+ public void add(WritableWrapperGenerator generator, File directory)
+ {
+ chain.add(new Entry(generator, directory));
+ }
+}
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/NullPrintStream.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/NullPrintStream.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/NullPrintStream.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Locale;
+
+class NullPrintStream extends PrintStream
+{
+ NullPrintStream()
+ {
+ // Doesn't actually do anything
+ super(new ByteArrayOutputStream());
+ }
+
+ @Override
+ public PrintStream append(char c)
+ {
+ return this;
+ }
+
+ @Override
+ public PrintStream append(CharSequence csq, int start, int end)
+ {
+ return this;
+ }
+
+ @Override
+ public PrintStream append(CharSequence csq)
+ {
+ return this;
+ }
+
+ @Override
+ public boolean checkError()
+ {
+ return false;
+ }
+
+ @Override
+ public void close()
+ {
+ }
+
+ @Override
+ public void flush()
+ {
+ }
+
+ @Override
+ public PrintStream format(Locale l, String format, Object... args)
+ {
+ return this;
+ }
+
+ @Override
+ public PrintStream format(String format, Object... args)
+ {
+ return this;
+ }
+
+ @Override
+ public void print(boolean b)
+ {
+ }
+
+ @Override
+ public void print(char c)
+ {
+ }
+
+ @Override
+ public void print(char[] s)
+ {
+ }
+
+ @Override
+ public void print(double d)
+ {
+ }
+
+ @Override
+ public void print(float f)
+ {
+ }
+
+ @Override
+ public void print(int i)
+ {
+ }
+
+ @Override
+ public void print(long l)
+ {
+ }
+
+ @Override
+ public void print(Object obj)
+ {
+ }
+
+ @Override
+ public void print(String s)
+ {
+ }
+
+ @Override
+ public PrintStream printf(Locale l, String format, Object... args)
+ {
+ return this;
+ }
+
+ @Override
+ public PrintStream printf(String format, Object... args)
+ {
+ return this;
+ }
+
+ @Override
+ public void println()
+ {
+ }
+
+ @Override
+ public void println(boolean x)
+ {
+ }
+
+ @Override
+ public void println(char x)
+ {
+ }
+
+ @Override
+ public void println(char[] x)
+ {
+ }
+
+ @Override
+ public void println(double x)
+ {
+ }
+
+ @Override
+ public void println(float x)
+ {
+ }
+
+ @Override
+ public void println(int x)
+ {
+ }
+
+ @Override
+ public void println(long x)
+ {
+ }
+
+ @Override
+ public void println(Object x)
+ {
+ }
+
+ @Override
+ public void println(String x)
+ {
+ }
+
+ @Override
+ protected void setError()
+ {
+ }
+
+ @Override
+ public void write(byte[] buf, int off, int len)
+ {
+ }
+
+ @Override
+ public void write(int b)
+ {
+ }
+
+ @Override
+ public void write(byte[] b) throws IOException
+ {
+ }
+}
Copied:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java
(from rev 2041,
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/SourceWrapperGenerator.java)
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/SourceWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,184 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.SortedMap;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.jaxws.AbstractWrapperGenerator;
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.OperationMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.jboss.ws.metadata.umdm.WrappedParameter;
+
+import com.sun.codemodel.JAnnotationArrayMember;
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JCodeModel;
+import com.sun.codemodel.JDefinedClass;
+import com.sun.codemodel.JExpr;
+import com.sun.codemodel.JFieldVar;
+import com.sun.codemodel.JMethod;
+import com.sun.codemodel.JMod;
+
+/**
+ * Generates source for wrapper beans
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ * @version $Revision$
+ */
+public class SourceWrapperGenerator extends AbstractWrapperGenerator implements
WritableWrapperGenerator
+{
+ private static Logger log = Logger.getLogger(SourceWrapperGenerator.class);
+ private PrintStream stream;
+ private JCodeModel codeModel;
+
+
+ public SourceWrapperGenerator(ClassLoader loader, PrintStream stream)
+ {
+ super(loader);
+ this.stream = stream;
+ codeModel = new JCodeModel();
+ }
+
+ @Override
+ public void reset(ClassLoader loader)
+ {
+ super.reset(loader);
+ codeModel = new JCodeModel();
+ }
+
+ public void write(File directory) throws IOException
+ {
+ stream.println("Writing Source:");
+ codeModel.build(directory, stream);
+ }
+
+ public void generate(ParameterMetaData pmd)
+ {
+ List<WrappedParameter> wrappedParameters = pmd.getWrappedParameters();
+ OperationMetaData operationMetaData = pmd.getOperationMetaData();
+
+ if (operationMetaData.isDocumentWrapped() == false)
+ throw new WSException("Operation is not document/literal (wrapped)");
+
+ if (wrappedParameters == null)
+ throw new WSException("Cannot generate a type when their is no type
information");
+
+ String wrapperName = pmd.getJavaTypeName();
+ if (log.isDebugEnabled())
+ log.debug("Generating wrapper: " + wrapperName);
+
+ try
+ {
+
+ JDefinedClass clazz = codeModel._class(wrapperName);
+ addClassAnnotations(clazz, pmd.getXmlName(), pmd.getXmlType(), null);
+ for (WrappedParameter wrapped : wrappedParameters)
+ {
+ addProperty(clazz, wrapped.getType(), wrapped.getName(),
wrapped.getVariable());
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WSException("Could not generate wrapper type: " +
wrapperName, e);
+ }
+ }
+ public void generate(FaultMetaData fmd)
+ {
+ String faultBeanName = fmd.getFaultBeanName();
+ Class exception = fmd.getJavaType();
+
+ try
+ {
+ SortedMap<String, Class<?>> properties =
getExceptionProperties(exception);
+ String[] propertyOrder = properties.keySet().toArray(new String[0]);
+
+ JDefinedClass clazz = codeModel._class(faultBeanName);
+ addClassAnnotations(clazz, fmd.getXmlName(), fmd.getXmlType(), propertyOrder);
+
+ for (String property : propertyOrder)
+ addProperty(clazz, properties.get(property).getName(), new QName(property),
property);
+ }
+ catch (Exception e)
+ {
+ throw new WSException("Could not generate wrapper type: " +
faultBeanName, e);
+ }
+ }
+
+ private static String getterPrefix(Class type)
+ {
+ return Boolean.TYPE == type || Boolean.class == type ? "is" :
"get";
+ }
+
+ private void addProperty(JDefinedClass clazz, String typeName, QName name, String
variable)
+ throws ClassNotFoundException
+ {
+ Class type = JavaUtils.loadJavaType(typeName, loader);
+ JFieldVar field = clazz.field(JMod.PRIVATE, type, variable);
+ JAnnotationUse annotation = field.annotate(XmlElement.class);
+ if (name.getNamespaceURI() != null)
+ annotation.param("namespace", name.getNamespaceURI());
+ annotation.param("name", name.getLocalPart());
+
+ // Add acessor methods
+ JMethod method = clazz.method(JMod.PUBLIC, type, getterPrefix(type) +
JavaUtils.capitalize(variable));
+ method.body()._return(JExpr._this().ref(variable));
+
+ method = clazz.method(JMod.PUBLIC, type, "set" +
JavaUtils.capitalize(variable));
+ method.body().assign(JExpr._this().ref(variable), method.param(type, variable));
+ }
+
+ private static void addClassAnnotations(JDefinedClass clazz, QName xmlName, QName
xmlType, String[] propertyOrder)
+ {
+ JAnnotationUse annotation = clazz.annotate(XmlRootElement.class);
+ if (xmlName.getNamespaceURI() != null && xmlName.getNamespaceURI().length()
> 0)
+ annotation.param("namespace", xmlName.getNamespaceURI());
+ annotation.param("name", xmlName.getLocalPart());
+
+ annotation = clazz.annotate(XmlType.class);
+ if (xmlType.getNamespaceURI() != null & xmlType.getNamespaceURI().length() >
0)
+ annotation.param("namespace", xmlType.getNamespaceURI());
+ annotation.param("name", xmlType.getLocalPart());
+ if (propertyOrder != null)
+ {
+ JAnnotationArrayMember paramArray =
annotation.paramArray("propOrder");
+ for (String property : propertyOrder)
+ paramArray.param(property);
+ }
+
+ annotation = clazz.annotate(XmlAccessorType.class);
+ annotation.param("value", XmlAccessType.FIELD);
+ }
+}
\ No newline at end of file
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,169 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.tools.jaxws.impl;
+
+import static org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType.JAXWS_EJB3;
+import static org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType.JAXWS_JSE;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateless;
+
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.server.UnifiedDeploymentInfo;
+import org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType;
+import org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder;
+import org.jboss.ws.metadata.umdm.ResourceLoaderAdapter;
+import org.jboss.ws.metadata.umdm.UnifiedMetaData;
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+
+/**
+ * The provided implementation of a WebServiceGenerator.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ */
+final class WebServiceGeneratorImpl extends WebServiceGenerator
+{
+ private ClassLoader loader;
+ private boolean generateWsdl = false;
+ private boolean generateSource = false;
+ private File outputDir = new File("output");
+ private File resourceDir = outputDir;
+ private File sourceDir = outputDir;
+ private PrintStream messageStream = new NullPrintStream();
+
+ @Override
+ public void generate(Class<?> endpointClass)
+ {
+ if (!outputDir.exists())
+ if (!outputDir.mkdirs())
+ throw new WSException("Could not create directory: " + outputDir);
+
+ if (generateWsdl && !resourceDir.exists())
+ if (!resourceDir.mkdirs())
+ throw new WSException("Could not create directory: " +
resourceDir);
+
+
+ if (generateSource && !sourceDir.exists())
+ if (!sourceDir.mkdirs())
+ throw new WSException("Could not create directory: " + sourceDir);
+
+ DeploymentType type = (endpointClass.isAnnotationPresent(Stateless.class)) ?
JAXWS_EJB3 : JAXWS_JSE;
+ UnifiedDeploymentInfo udi = new UnifiedDeploymentInfo(type)
+ {
+ @Override
+ public URL getMetaDataFileURL(String resourcePath) throws IOException
+ {
+ return null;
+ }
+ };
+ udi.classLoader = loader;
+
+ UnifiedMetaData umd = new UnifiedMetaData(new ResourceLoaderAdapter(loader));
+ umd.setClassLoader(loader);
+
+ ChainedWritableWrapperGenerator generator = new ChainedWritableWrapperGenerator();
+ if (generateSource)
+ generator.add(new SourceWrapperGenerator(loader, messageStream), sourceDir);
+ generator.add(new BytecodeWrapperGenerator(loader, messageStream), outputDir);
+
+ JAXWSWebServiceMetaDataBuilder builder = new JAXWSWebServiceMetaDataBuilder();
+ builder.setWrapperGenerator(generator);
+ builder.setGenerateWsdl(generateWsdl);
+ builder.setToolMode(true);
+ builder.setWsdlDirectory(resourceDir);
+ builder.setMessageStream(messageStream);
+
+ if (generateWsdl)
+ messageStream.println("Generating WSDL:");
+
+ builder.buildWebServiceMetaData(umd, udi, endpointClass, null);
+ try
+ {
+ generator.write();
+ }
+ catch (IOException io)
+ {
+ throw new WSException("Could not write output files:", io);
+ }
+ }
+
+ @Override
+ public void generate(String endpointClass)
+ {
+ try
+ {
+ generate(loader.loadClass(endpointClass));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new WSException("Class not found: " + endpointClass);
+ }
+ }
+
+ @Override
+ public void setClassLoader(ClassLoader loader)
+ {
+ this.loader = loader;
+ }
+
+ @Override
+ public void setGenerateWsdl(boolean generateWsdl)
+ {
+ this.generateWsdl = generateWsdl;
+ }
+
+ @Override
+ public void setOutputDirectory(File directory)
+ {
+ outputDir = directory;
+ }
+
+ @Override
+ public void setGenerateSource(boolean generateSource)
+ {
+ this.generateSource = generateSource;
+ }
+
+ @Override
+ public void setResourceDirectory(File directory)
+ {
+ resourceDir = directory;
+ }
+
+ @Override
+ public void setSourceDirectory(File directory)
+ {
+ sourceDir = directory;
+ }
+
+ @Override
+ public void setMessageStream(PrintStream messageStream)
+ {
+ this.messageStream = messageStream;
+ }
+}
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorProviderImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorProviderImpl.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorProviderImpl.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+import org.jboss.ws.tools.jaxws.spi.WebServiceGeneratorProvider;
+
+public class WebServiceGeneratorProviderImpl implements WebServiceGeneratorProvider
+{
+ public WebServiceGenerator createGenerator(ClassLoader loader)
+ {
+ WebServiceGeneratorImpl impl = new WebServiceGeneratorImpl();
+ impl.setClassLoader(loader);
+ return impl;
+ }
+}
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WritableWrapperGenerator.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WritableWrapperGenerator.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WritableWrapperGenerator.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.jboss.ws.core.jaxws.WrapperGenerator;
+
+public interface WritableWrapperGenerator extends WrapperGenerator
+{
+ public void write(File directory) throws IOException;
+}
\ No newline at end of file
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/spi/WebServiceGeneratorProvider.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/spi/WebServiceGeneratorProvider.java
(rev 0)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/spi/WebServiceGeneratorProvider.java 2007-01-26
21:21:43 UTC (rev 2144)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.jaxws.spi;
+
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+
+/**
+ * WebServiceGeneratorProvider defines the contract for a WebServiceGenerator provider.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ */
+public interface WebServiceGeneratorProvider
+{
+ /**
+ * Create a new WebServiceGenerator. There are no restrictions on how this
+ * should be performed. The passed ClassLoader is the one used in
+ * {@link WebServiceGenerator#newInstance(ClassLoader)}. This loader
+ * should be made available to the generated WebServiceGenerator.
+ *
+ * @param loader the ClassLoader for type discovery
+ * @return a new WebServiceGenerator
+ */
+ public WebServiceGenerator createGenerator(ClassLoader loader);
+}