Author: mmerz
Date: Thu Oct 14 11:20:46 2004
New Revision: 54794

Added:
   
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/ControlProvider.java
   
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/InvalidTypeMappingException.java
Modified:
   incubator/beehive/trunk/wsm/build.xml
   
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AxisHook.java
   
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/DropInDeploymentHandler.java
   incubator/beehive/trunk/wsm/test/webapps/AnnotatedAxis/WEB-INF/web.xml
Log:
Enable controls for WSM projects. *.jws source files can now use control 
annotations.
Note that this creates dependencies on the controls sub-project: wsm-axis now 
requires controls.jar.

Contributors: Jonathan Colwell, Michael Merz



Modified: incubator/beehive/trunk/wsm/build.xml
==============================================================================
--- incubator/beehive/trunk/wsm/build.xml       (original)
+++ incubator/beehive/trunk/wsm/build.xml       Thu Oct 14 11:20:46 2004
@@ -39,8 +39,6 @@
     <property name="ext.lib.dir" value="external"/>
     <property name="wsm.jar" value="${jars.dir}/wsm.jar"/>
     <property name="wsm-axis.jar" value="${jars.dir}/wsm-axis.jar"/>
-    <path id="api.classpath">
-  </path>
     <path id="runtime.classpath">
         <pathelement location="${ant.jar}"/>
         <pathelement location="${tools.jar}"/>
@@ -50,8 +48,6 @@
         <pathelement location="${junit.jar}"/>
         <pathelement location="${log4j.jar}"/>
         <pathelement location="${lib.dir}/xmltypes.jar"/>
-        <path refid="api.classpath"/>
-        <pathelement location="${api.classes}"/>
     </path>
     <fileset id="axis.jars" dir="${ext.lib.dir}">
         <include name="wsdl4j.jar"/>
@@ -64,6 +60,7 @@
     </fileset>
     <path id="axis.classpath">
         <fileset refid="axis.jars"/>
+        <pathelement location="${controls.jar}"/>
         <pathelement location="${os.JAVA_HOME}/lib/tools.jar"/>
         <path refid="runtime.classpath"/>
         <pathelement location="${runtime.classes}"/>
@@ -132,7 +129,7 @@
     </target>
     <target name="api" depends="dirs" if="isJDKOver5">
         <!-- Build the API classes -->
-        <javac destdir="${api.classes}" classpathref="api.classpath" 
debug="on">
+        <javac destdir="${api.classes}" debug="on">
             <src path="${api.dir}"/>
         </javac>
     </target>
@@ -144,6 +141,8 @@
         </javac>
     </target>
     <target name="axis" depends="runtime" if="isJDKOver5">
+        <!-- makes sure controls.jar has been built -->
+        <ant dir="${beehive.dir}/controls" target="build"/>
         <!-- Build the badtiger classes using source=1.4 compile flag -->
         <echo message="BadTiger build"/>
         <javac destdir="${runtime.classes}" classpathref="axis.classpath" 
source="1.4" debug="on">
@@ -163,7 +162,7 @@
     <!-- ==================================================================== 
-->
     <target name="build" depends="classes" if="isJDKOver5">
         <echo message="--------------------------------------------------"/>
-        <echo message="|      WSM build starting                    |"/>
+        <echo message="|      WSM build starting                        |"/>
         <echo message="--------------------------------------------------"/>
         <jar jarfile="${wsm.jar}">
             <fileset dir="${api.classes}"/>
@@ -172,12 +171,12 @@
             </fileset>
         </jar>
         <echo message="--------------------------------------------------"/>
-        <echo message="|      WSM build ending                      |"/>
+        <echo message="|      WSM build ending                          |"/>
         <echo message="--------------------------------------------------"/>
     </target>
     <target name="build_axis" depends="axis" if="isJDKOver5">
         <echo message="--------------------------------------------------"/>
-        <echo message="|      WSM-AXIS build starting                    |"/>
+        <echo message="|      WSM-AXIS build starting                   |"/>
         <echo message="--------------------------------------------------"/>
         <jar jarfile="${wsm-axis.jar}">
             <fileset dir="${runtime.classes}">
@@ -185,7 +184,7 @@
             </fileset>
         </jar>
         <echo message="--------------------------------------------------"/>
-        <echo message="|      WSM-AXIS build ending                      |"/>
+        <echo message="|      WSM-AXIS build ending                     |"/>
         <echo message="--------------------------------------------------"/>
     </target>
     <!-- ==================================================================== 
-->
@@ -238,9 +237,12 @@
         <copy todir="${webapps.dist.dir}/${axis.dir}/WEB-INF/lib">
             <fileset dir="${jars.dir}" includes="**/*.jar"/>
         </copy>
+        <copy file="${controls.jar}" 
todir="${webapps.dist.dir}/${axis.dir}/WEB-INF/lib" />
+        <copy file="${velocity14.jar}" 
todir="${webapps.dist.dir}/${axis.dir}/WEB-INF/lib" />
+        <copy file="${velocitydep14.jar}" 
todir="${webapps.dist.dir}/${axis.dir}/WEB-INF/lib" />
         <copy file="${log4j.jar}" 
todir="${webapps.dist.dir}/${axis.dir}/WEB-INF/lib"/>
         <echo message="--------------------------------------------------"/>
-        <echo message="|       WSM deploy ending                   |"/>
+        <echo message="|       WSM deploy ending                        |"/>
         <echo message="--------------------------------------------------"/>
     </target>
     <!-- ==================================================================== 
-->
@@ -254,11 +256,11 @@
     <!-- ==================================================================== 
-->
     <target name="minprod">
         <echo message="--------------------------------------------------"/>
-        <echo message="|       WSM minprod starting                 |"/>
+        <echo message="|       WSM minprod starting                     |"/>
         <echo message="--------------------------------------------------"/>
         <antcall target="deploy"/>
         <echo message="--------------------------------------------------"/>
-        <echo message="|       WSM minprod completed                |"/>
+        <echo message="|       WSM minprod completed                    |"/>
         <echo message="--------------------------------------------------"/>
     </target>
     <!-- ==================================================================== 
-->
@@ -266,8 +268,7 @@
     <!-- ==================================================================== 
-->
     <target name="docs" if="isJDKOver5">
         <javadoc destdir="${docs.dir}/reference/classref_wsm" maxmemory="256M" 
windowtitle="WSM Documentation" doctitle="Web Services Metadata" version="true" 
author="false" use="true" additionalparam="-breakiterator -noqualifier all 
-notimestamp " useexternalfile="true" classpathref="axis.classpath">
-            <packageset dir="${api.dir}" defaultexcludes="yes">
-        </packageset>
+            <packageset dir="${api.dir}" defaultexcludes="yes" />
             <packageset dir="${runtime.dir}" defaultexcludes="yes">
                 <exclude name="**/axis/badtiger"/>
             </packageset>

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AxisHook.java
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AxisHook.java
   (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AxisHook.java
   Thu Oct 14 11:20:46 2004
@@ -17,6 +17,9 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.io.File;
+import java.io.Serializable;
+import java.rmi.Remote;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -58,7 +61,9 @@
 
     public static ServiceDesc createServiceDesc(WebServiceTYPEMetadata wsm,
                                                 ClassLoader cl)
-        throws ClassNotFoundException, NoSuchMethodException
+        throws ClassNotFoundException,
+               NoSuchMethodException,
+               InvalidTypeMappingException
     {
  
         JavaServiceDesc sd = new JavaServiceDesc();
@@ -192,87 +197,139 @@
         return null;
     }
 
-    private static void configureTypeMapping(ServiceDesc desc, Class type) {
+    private static void configureTypeMapping(ServiceDesc desc, Class type)
+        throws InvalidTypeMappingException {
         
-        if (type.isArray()) {
+        if (Void.TYPE.equals(type)) {
+            // do nothing.
+        }
+        else if (type.isArray()) {
             configureTypeMapping(desc, type.getComponentType());
         }
         else {
-            
+
             TypeMapping tm = desc.getTypeMapping();
             QName q = tm.getTypeQName(type);
             
             if (Collection.class.isAssignableFrom(type)) {
-                // overriding the default Axis conversion of all Collections
-                // to {http://schemas.xmlsoap.org/soap/encoding/}Array
-                // since the namespace prefix is left hanging with literal use
+                /*
+                 * NOTE [EMAIL PROTECTED] 2004-Oct-11 -- 
+                 * overriding the default Axis conversion of all Collections
+                 * to {http://schemas.xmlsoap.org/soap/encoding/}Array
+                 * since the namespace prefix is left hanging with literal use
+                 */
                 q = generateQName(type, desc);
                 tm.register( type, q,
                              new CollectionSerializerFactory(type, q),
                              new VectorDeserializerFactory(type, q));
-            }            
-            else if (isActivationEnabled() &&
-                     (java.awt.Image.class.isAssignableFrom(type) 
-                      || getMultipartClass().isAssignableFrom(type)
-                      || getDataHandlerClass().isAssignableFrom(type))) {
+            }
+            else {
                 
                 if (q == null) {
                     q = generateQName(type, desc);
                 }
 
                 if (! tm.isRegistered(type, q)) {
-                    try {
 
-                        /*
-                         * NOTE [EMAIL PROTECTED] 2004-Oct-08 -- doing 
reflection here
-                         * in case AXIS was built without attachment support.
-                         */
-                        ClassLoader cl = AxisHook.class.getClassLoader();
-                        Class<SerializerFactory> sfClass = 
-                            (Class<SerializerFactory>)
-                            
cl.loadClass("org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory");
-                        Class<DeserializerFactory> dsfClass = 
-                            (Class<DeserializerFactory>)
-                            
cl.loadClass("org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory");
-                        Constructor<SerializerFactory> sfCon = 
-                            sfClass.getConstructor(Class.class,
-                                                   QName.class);
-                        Constructor<DeserializerFactory> dsfCon =
-                            dsfClass.getConstructor(Class.class,
-                                                    QName.class);
+                    /*
+                     * NOTE [EMAIL PROTECTED] 2004-Oct-11 -- these datahandler
+                     * using classes are generally already registered but 
+                     * just in case...
+                     */        
+
+                    if (isActivationEnabled() &&
+                        (java.awt.Image.class.isAssignableFrom(type) 
+                         || getMultipartClass().isAssignableFrom(type)
+                         || getDataHandlerClass().isAssignableFrom(type))) {
+
+                        try {
+                            /*
+                             * NOTE [EMAIL PROTECTED] 2004-Oct-08 -- doing 
+                             * reflection here in case AXIS was built without 
+                             * attachment support.
+                             */
+                            ClassLoader cl = AxisHook.class.getClassLoader();
+                            Class<SerializerFactory> sfClass = 
+                                (Class<SerializerFactory>)
+                                
cl.loadClass("org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory");
+                            Class<DeserializerFactory> dsfClass = 
+                                (Class<DeserializerFactory>)
+                                
cl.loadClass("org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory");
+                            Constructor<SerializerFactory> sfCon = 
+                                sfClass.getConstructor(Class.class,
+                                                       QName.class);
+                            Constructor<DeserializerFactory> dsfCon =
+                                dsfClass.getConstructor(Class.class,
+                                                        QName.class);
                         
-                        SerializerFactory sf = sfCon.newInstance(type, q);
-                        DeserializerFactory dsf = dsfCon.newInstance(type, q);
+                            SerializerFactory sf = sfCon.newInstance(type, q);
+                            DeserializerFactory dsf = dsfCon.newInstance(type, 
q);
 
-                        tm.register(type, q, sf, dsf);
+                            tm.register(type, q, sf, dsf);
 
+                        }
+                        catch (Exception e) {
+                            /*
+                             * FIXME [EMAIL PROTECTED] 2004-Oct-08 -- 
+                             * log this properly
+                             */
+                            e.printStackTrace();
+                        }
                     }
-                    catch (Exception e) {
-                        /*
-                         * FIXME [EMAIL PROTECTED] 2004-Oct-08 -- 
-                         * log this properly
-                         */
-                        e.printStackTrace();
+                    else if (Serializable.class.isAssignableFrom(type)
+                             /*
+                              * NOTE [EMAIL PROTECTED] 2004-Oct-11 --
+                              * java.io.Serializable is required and
+                              * java.rmi.Remote is prohibited
+                              * by the jax-rpc spec 
+                              */
+                             && !Remote.class.isAssignableFrom(type)
+                             /*
+                              * NOTE [EMAIL PROTECTED] 2004-Oct-11 -- 
+                              * restricting against File since even though it
+                              * is technically serializable, it doesn't make
+                              * sense to serialize as a bean.  
+                              * That and it causes an infinite
+                              * loop as it keeps returning itself from the 
+                              * getAbsoluteFile and getCanonicalFile calls
+                              */
+                             && !File.class.isAssignableFrom(type)) {
+                
+                        tm.register( type, q,
+                                     new BeanSerializerFactory(type, q),
+                                     /*
+                                      * NOTE [EMAIL PROTECTED] 2004-Oct-11 -- 
+                                      * should check that the type to 
deserialize
+                                      * has a default contructor but with this 
+                                      * setup there is no way to know if it is
+                                      * used only in serialization.
+                                      */
+                                     new BeanDeserializerFactory(type, q));
+                        Map serProps = BeanDeserializerFactory
+                            .getProperties(type, null);
+                        for (BeanPropertyDescriptor beanProps :
+                                 (Collection<BeanPropertyDescriptor>)serProps
+                                 .values()) {
+                            Class subType = beanProps.getType();
+                            if (!(subType.isPrimitive() 
+                                  || subType.getName().startsWith("java.")
+                                  || subType.getName().startsWith("javax."))) {
+                                
+                                configureTypeMapping(desc, subType);
+                            }
+                        }
                     }
-                }                
-            }
-            else if (q == null) {
-                q = generateQName(type, desc);
-                if (! tm.isRegistered(type, q)) {
-                    tm.register( type, q,
-                                 new BeanSerializerFactory(type, q),
-                                 new BeanDeserializerFactory(type, q));
-                    Map serProps = BeanDeserializerFactory
-                        .getProperties(type, null);
-                    for (BeanPropertyDescriptor beanProps :
-                             (Collection<BeanPropertyDescriptor>)serProps
-                             .values()) {
-                        configureTypeMapping(desc, beanProps.getType());
+                    else {
+                        throw new InvalidTypeMappingException
+                            ("failed to register " + type.getName()
+                             + " as a valid web service datatype,"
+                             + " consider using a custom type mapping");
                     }
                 }
             }
         }
     }
+
 
     private static QName generateQName(Class type, ServiceDesc desc)
     {

Added: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/ControlProvider.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/ControlProvider.java
    Thu Oct 14 11:20:46 2004
@@ -0,0 +1,75 @@
+/*
+ * ControlProvider.java
+ * 
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * 
+ * Original author: Jonathan Colwell
+ */
+package org.apache.beehive.wsm.axis;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.axis.MessageContext;
+import org.apache.axis.providers.java.RPCProvider;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+import org.apache.beehive.controls.runtime.bean.ControlContainerContext;
+
+/*******************************************************************************
+ * 
+ *
+ * @author Jonathan Colwell
+ */
+public class ControlProvider extends RPCProvider
+{
+    protected Object makeNewServiceObject(MessageContext msgContext, String 
clsName)
+        throws Exception
+    {
+        Object obj = super.makeNewServiceObject(msgContext, clsName);
+        initializeControls(obj);
+        return obj;
+    }
+
+    private void initializeControls(Object obj) throws Exception
+    {
+        Class cls = obj.getClass();
+        Field[] fields = cls.getFields();
+
+        // search for fields with @Control annotations
+        for (Field field : fields)
+        {
+            if (null != field.getAnnotation(Control.class))
+            {
+                //attempt to load using client initializer.
+                ControlContainerContext ccc =
+                    ControlContainerContext.getContext();
+                if (null == ccc)
+                {
+                    throw new Exception("no control container context found");
+                }
+                Class clientInitializer =
+                    cls.getClassLoader().loadClass(cls.getName() + 
"ClientInitializer");
+                Method init =
+                    clientInitializer.getMethod("initialize", 
ControlBeanContext.class, cls);
+                init.invoke(null, ccc, obj);
+                break;
+            }
+        }
+    }
+}
\ No newline at end of file

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/DropInDeploymentHandler.java
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/DropInDeploymentHandler.java
    (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/DropInDeploymentHandler.java
    Thu Oct 14 11:20:46 2004
@@ -1,3 +1,5 @@
+package org.apache.beehive.wsm.axis;
+
 /*
  * DropInDeploymentHandler.java
  * 
@@ -18,8 +20,6 @@
  * 
  */
 
-package org.apache.beehive.wsm.axis;
-
 import org.apache.beehive.wsm.jsr181.model.WebServiceTYPEMetadata;
 import org.apache.beehive.wsm.jsr181.model.WebServiceMETHODMetadata;
 import org.apache.beehive.wsm.jsr181.model.WebServicePARAMETERMetadata;
@@ -28,19 +28,24 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FileWriter;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLDecoder;
-import java.util.Map;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
+
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
@@ -81,99 +86,93 @@
  * @author Sam Ruby ([EMAIL PROTECTED])
  *
  */
-public class DropInDeploymentHandler extends BasicHandler {
-
+public class DropInDeploymentHandler extends BasicHandler
+{
     protected static Log log =
         LogFactory.getLog(DropInDeploymentHandler.class.getName());
 
-
     private Map<Class, SOAPService> mSoapServiceMap =
         new HashMap<Class, SOAPService>();
 
-
     public void invoke(MessageContext mc)
         throws AxisFault
     {
         try {
             SOAPService ss =
                 
createSOAPServiceFromAnnotatedClass(compileDroppedInSource(mc));
-            if (ss != null) {
+            if (null != ss)
+            {
                 ss.setEngine(mc.getAxisEngine());
                 ss.init();  
                 mc.setService(ss);
                 // blow away the real path to bypass the regular JWSHandler
                 mc.removeProperty(Constants.MC_REALPATH);
             }
-       
-        } catch (Exception e) {
+        }
+        catch (Exception e)
+        {
             throw AxisFault.makeFault(e);
         }
     }
 
-
-    public void generateWSDL(MessageContext msgContext) throws AxisFault {
-        invoke(msgContext);
-    }
-
-
-    protected SOAPService createSOAPServiceFromAnnotatedSource(File sourceFile)
-        throws Exception
+    public void generateWSDL(MessageContext msgContext) throws AxisFault
     {
-        // FIXME [EMAIL PROTECTED] 2004-Sep-21 -- run APT and set up the 
metadata
-        return null;
+        invoke(msgContext);
     }
 
-    protected SOAPService createSOAPServiceFromAnnotatedClass(Class cls)
+    protected SOAPService createSOAPServiceFromAnnotatedClass(Class clazz)
         throws Exception
     {
+        SOAPService rpc = null;
+        
+        if (null != clazz)
+        {
+            rpc = mSoapServiceMap.get(clazz);
+            if (null == rpc)
+            {
+                WebServiceTYPEMetadata wsm =
+                    WsmReflectionAnnotationProcessor.getObjectModel(clazz);
 
-        if (cls != null) {
-            SOAPService rpc = mSoapServiceMap.get(cls);
-
-            if (rpc == null) {
-
-                WebServiceTYPEMetadata wsm = WsmReflectionAnnotationProcessor
-                    .getObjectModel(cls);
-
-                rpc = createSOAPServiceUsingAnnotations(wsm, cls);
+                rpc = createSOAPServiceUsingAnnotations(wsm, clazz);
             }
-            return rpc;
-        }
-        else {
-            return null;
         }
-    }
-
-    protected SOAPService createSOAPServiceUsingAnnotations
-        (WebServiceTYPEMetadata wsm, Class cls) 
-        throws Exception {
 
+        return rpc;
+    }
 
-        if (wsm != null) {
+    protected SOAPService 
createSOAPServiceUsingAnnotations(WebServiceTYPEMetadata wsm, Class cls)
+        throws Exception
+    {
+        SOAPService rpc = null;
+        
+        if (null != wsm)
+        {
             HandlerHandler hh = new HandlerHandler();
             hh.init(wsm);
-            SOAPService rpc = new SOAPService(hh, new RPCProvider(), hh);
+            rpc = new SOAPService(hh, new ControlProvider(), hh);
             rpc.setName(wsm.getWsName());
             rpc.setOption(RPCProvider.OPTION_CLASSNAME, cls.getName() );
 
             // Take the setting for the scope option from the handler
             // parameter named "scope"
             String scope = (String)getOption(RPCProvider.OPTION_SCOPE);
-            if (scope == null) {
+            if (null == scope)
+            {
                 scope = "Request";
             }
             rpc.setOption(RPCProvider.OPTION_SCOPE, scope);
                 
-            ServiceDesc sd = AxisHook
-                .createServiceDesc(wsm, cls.getClassLoader());
+            ServiceDesc sd = AxisHook.createServiceDesc(wsm, 
cls.getClassLoader());
             rpc.setServiceDescription(sd);
      
             List allowedMethodNames = sd.getAllowedMethods();
             Iterator allowIt = allowedMethodNames.iterator();
             StringBuffer sb = new StringBuffer();
             boolean firstPass = true;
-            while (allowIt.hasNext()) {
-                if (firstPass) {
+            while (allowIt.hasNext())
+            {
+                if (firstPass)
+                {
                     sb.append(' ');
                     firstPass = false;
                 }
@@ -194,55 +193,114 @@
             rpc.setUse(sd.getUse());
                 
             mSoapServiceMap.put(cls, rpc);                
-            return rpc;
-        }
-        else {
-            return null;
         }
+        return rpc;
     }
 
-    protected Class compileDroppedInSource(MessageContext mc)
+    protected void compileWithApt(String defaultClasspath, String outDirPath, 
File clsFile, String jFile)
         throws Exception
     {
-        if (mc != null) {
+        com.sun.tools.apt.Main apt = new com.sun.tools.apt.Main();
+        String[] args = {
+            "-classpath", defaultClasspath, // classpath -- todo necessary?
+            "-d", outDirPath, // output directory
+            jFile // source file
+        };
+        
+        PrintWriter pw = new PrintWriter(new StringWriter());
+        int result = apt.compile(args, pw);
+
+        if (0 != result) // todo evaluate the return code
+        {
+            clsFile.delete();
+            
+            // construct error message
+            Document doc = XMLUtils.newDocument();
+            Element root = doc.createElementNS("", "Errors");
+            StringBuffer message = new StringBuffer("Error compiling ");
+            message.append(jFile);
+            message.append(":\n");
+            message.append(pw.toString());
+            message.append("\n");
+            root.appendChild(doc.createTextNode(message.toString()));
+            
+            // generate fault
+            AxisFault af = new AxisFault(
+                "Server.compileError",
+                Messages.getMessage("badCompile00", jFile),
+                null,
+                new Element[] { root }
+            );
+
+            // log fault
+            log.warn("Error compiling JWS", af);
+
+            // FIXME [EMAIL PROTECTED] 2004-Sep-23 -- 
+            // logging error to System.out since I have no idea
+            // where log.warn is dumping the error.
+            // Additionally, the error only shows up if a method
+            // is invoked, otherwise, the error is not displayed.
+            // af.printStackTrace();
 
-            String realpath = mc.getStrProp(Constants.MC_REALPATH);
-            String extension = (String)getOption("extension");
-            if (extension == null) {
-                extension = ".jws";
+            // throw fault
+            throw af;
+        }
+    }
+    
+    
+    protected Class compileDroppedInSource(MessageContext mc)
+        throws Exception
+    {
+        final String EXTENSION_JWS = ".jws";
+        final String EXTENSION_JAVA = ".java";
+        final String EXTENSION_CLASS = ".class";
+        
+        if (null != mc)
+        {
+            // get extension for jws-files; typically ".jws"
+            String extension = (String) getOption("extension");
+            if (null == extension)
+            {
+                extension = EXTENSION_JWS;
             }
 
-            if ((realpath!=null) && (realpath.endsWith(extension))) {
-                /* Grab the *.jws filename from the context - should have been 
*/
-                /* placed there by another handler (ie. HTTPActionHandler)     
*/
-                
/***************************************************************/
+            String realpath = mc.getStrProp(Constants.MC_REALPATH);
+            if ((null != realpath) && (realpath.endsWith(extension)))
+            {
+                // grab the *.jws filename from context; placed there by 
HTTPActionHandler
                 String srcPath = realpath;
-                String rel = mc.getStrProp(Constants.MC_RELATIVE_PATH);
+                String relPath = mc.getStrProp(Constants.MC_RELATIVE_PATH);
             
-                // Check for file existance, report error with
-                // relative path to avoid giving out directory info.
-                File srcFile = new File( srcPath );
-                if (!srcFile.exists()) {
-                    throw new FileNotFoundException(rel);
+                // check if file exists
+                File srcFile = new File(srcPath);
+                if (! srcFile.exists())
+                {
+                    // report error with relative path to avoid giving out 
directory info
+                    throw new FileNotFoundException(relPath);
                 }
 
-                //clean up the relative path to use as the class destination 
dir
-                if (rel.charAt(0) == '/') {
-                    rel = rel.substring(1);
+                // clean up the relative path to use as the class destination 
dir
+                if ('/' == relPath.charAt(0))
+                {
+                    relPath = relPath.substring(1);
                 }
-            
-                int lastSlash = rel.lastIndexOf('/');
+                /*
+                int lastSlash = relPath.lastIndexOf('/');
                 String dir = null;
             
-                if (lastSlash > 0) {
-                    dir = rel.substring(0, lastSlash);
+                if (0 < lastSlash)
+                {
+                    dir = relPath.substring(0, lastSlash);
+                }
+
+                String relativeOutputPath = relPath.substring(lastSlash + 1);
+                */
+                String relativeOutputPath = relPath;
+                String outDirPath = mc.getStrProp(Constants.MC_JWS_CLASSDIR);
+                if (null == outDirPath)
+                {
+                    outDirPath = "." ;
                 }
-            
-                String relativeOutputPath = rel.substring(lastSlash + 1);
-            
-                String outDirPath = mc
-                    .getStrProp( Constants.MC_JWS_CLASSDIR );
-                if ( outDirPath == null ) outDirPath = "." ;
             
                 // Build matching directory structure under the output
                 // directory.  In other words, if we have:
@@ -250,132 +308,72 @@
                 //
                 // That will be compiled to:
                 //    .../jwsOutputDirectory/jws1/Foo.class
-                if (dir != null) {
+                /*
+                if (null != dir)
+                {
                     outDirPath = outDirPath + File.separator + dir;
                 }
-            
+                */
                 // Confirm output directory exists.  If not, create it IF we're
                 // allowed to.
                 // !!! TODO: add a switch to control this.
                 File outDirectory = new File(outDirPath);
-                if (!outDirectory.exists()) {
+                if (! outDirectory.exists())
+                {
                     outDirectory.mkdirs();
                 }
             
                 String jFile = outDirPath + File.separator 
                     + relativeOutputPath
                     .substring(0, 
relativeOutputPath.length()-extension.length())
-                    + ".java";
+                    + EXTENSION_JAVA;
             
                 String cFile = outDirPath + File.separator 
                     + relativeOutputPath
                     .substring(0, 
relativeOutputPath.length()-extension.length())
-                    + ".class";
+                    + EXTENSION_CLASS;
             
-                File clsFile = new File( cFile );
-            
-                /* Get the class */
-                /*****************/
-                String clsName = null ;
-                //clsName = mc.getStrProp(Constants.MC_RELATIVE_PATH);
-                if ( clsName == null ) clsName = srcFile.getName();
-                if ( clsName != null && clsName.charAt(0) == '/' )
+                File clsFile = new File(cFile);
+
+                // get class name
+                //String clsName = srcFile.getName();
+                String clsName = relativeOutputPath;
+                if ((null != clsName) && ('/' == clsName.charAt(0)))
+                {
                     clsName = clsName.substring(1);
-            
-                clsName = clsName.substring( 0, clsName.length()-4 );
+                }
+                clsName = clsName.substring(0, clsName.length() - 4);
                 clsName = clsName.replace('/', '.');
-            
-                     
-                /* Check to see if we need to recompile */
-                /****************************************/
-                if ( !clsFile.exists() 
-                     || srcFile.lastModified() > clsFile.lastModified() ) {
-                    /* If the class file doesn't exist, or it's older than the 
*/
-                    /* java file then recompile the java file.                 
*/
-                    
/***********************************************************/
+
+                // compile the source file if necessary
+                if ((! clsFile.exists()) || (srcFile.lastModified() > 
clsFile.lastModified()))
+                {
                     File javaFile = new File(jFile);
                     try {
                         srcFile.renameTo(javaFile);
-
-                        /* Now run javac on the *.java file */
-                        /************************************/
-                        Compiler compiler = CompilerFactory.getCompiler();
-                
-                        compiler.setClasspath(ClasspathUtils
-                                              .getDefaultClasspath(mc));
-                        compiler.setDestination(outDirPath);
-                        compiler.addFile(jFile);
-
-                        boolean result = compiler.compile();
-
-                        if ( !result ) {
-                            /* 
-                             * Delete the *class file - sometimes it gets 
created
-                             * even when there are errors - so erase it so it 
-                             * doesn't confuse us.
-                             */
-                            clsFile.delete();
-                    
-                            Document doc = XMLUtils.newDocument();
-                    
-                            Element         root = doc.createElementNS("",
-                                                                       
"Errors");
-                            StringBuffer message = 
-                                new StringBuffer("Error compiling ");
-                            message.append(jFile);
-                            message.append(":\n");
-
-                            List errors = compiler.getErrors();
-                            int count = errors.size();
-                            for (int i = 0; i < count; i++) {
-                                CompilerError error =
-                                    (CompilerError) errors.get(i);
-                                if (i > 0) message.append("\n");
-                                message.append("Line ");
-                                message.append(error.getStartLine());
-                                message.append(", column ");
-                                message.append(error.getStartColumn());
-                                message.append(": ");
-                                message.append(error.getMessage());
-                            }
-                            root.appendChild(doc.createTextNode(message
-                                                                .toString()));
-                            AxisFault af = 
-                                new AxisFault( "Server.compileError",
-                                               Messages
-                                               .getMessage("badCompile00",
-                                                           jFile),
-                                               null, new Element[] { root } );
-                            log.warn("Error compiling JWS.", af);
-                            /*
-                             * FIXME [EMAIL PROTECTED] 2004-Sep-23 -- 
-                             * logging error to System.out since I have no idea
-                             * where log.warn is dumping the error.
-                             * Additionally, the error only shows up if a 
method
-                             * is invoked, otherwise, the error is not 
displayed.
-                             */
-                            af.printStackTrace();
-                            throw af;
-                        }
-                   
+                        compileWithApt(ClasspathUtils.getDefaultClasspath(mc), 
outDirPath, clsFile, jFile);
                         ClassUtils.removeClassLoader( clsName );
-                        // And clean out the cached service.
-                        mSoapServiceMap.remove(clsName);
+                        mSoapServiceMap.remove(clsName); // clean out the 
cached service
                     }
                     finally {
                         javaFile.renameTo(srcFile);
                     }
                 }
+
+                // load class from disk & return it
                 ClassLoader cl = ClassUtils.getClassLoader(clsName);
-                if (cl == null) {
-                    cl = new JWSClassLoader(clsName,
-                                            mc.getClassLoader(),
-                                            cFile);
+                if (null == cl)
+                {
+                    //cl = new JWSClassLoader(clsName, mc.getClassLoader(), 
cFile);
+                    System.out.println(outDirectory.getCanonicalPath());
+                    cl = new URLClassLoader(new URL[]{outDirectory.toURL()}, 
+                                            mc.getClassLoader()); 
                 }
                 mc.setClassLoader(cl);
+
                 return cl.loadClass(clsName);
             }
         }
         return null;
     }
-}
+}
\ No newline at end of file

Added: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/InvalidTypeMappingException.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/InvalidTypeMappingException.java
        Thu Oct 14 11:20:46 2004
@@ -0,0 +1,47 @@
+/*
+ * InvalidTypeMappingException.java
+ * 
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beehive.wsm.axis;
+
+/*******************************************************************************
+ *
+ *
+ * @author Jonathan Colwell
+ */
+public class InvalidTypeMappingException extends java.lang.Exception {
+
+    public InvalidTypeMappingException()
+    {
+        super();
+    }
+
+    public InvalidTypeMappingException(String message) 
+    {
+        super(message);
+    }
+    
+    public InvalidTypeMappingException(String message, Throwable cause) 
+    {
+        super(message, cause);
+    }
+
+    public InvalidTypeMappingException(Throwable cause)
+    {
+        super(cause);
+    }
+}

Modified: incubator/beehive/trunk/wsm/test/webapps/AnnotatedAxis/WEB-INF/web.xml
==============================================================================
--- incubator/beehive/trunk/wsm/test/webapps/AnnotatedAxis/WEB-INF/web.xml      
(original)
+++ incubator/beehive/trunk/wsm/test/webapps/AnnotatedAxis/WEB-INF/web.xml      
Thu Oct 14 11:20:46 2004
@@ -1,96 +1,107 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
-Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
-
-<web-app>
-  <display-name>Apache-Axis</display-name>
-    
-    <listener>
-        
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
-    </listener>
-    
-  <servlet>
-    <servlet-name>AxisServlet</servlet-name>
-    <display-name>Apache-Axis Servlet</display-name>
-    <servlet-class>
-        org.apache.axis.transport.http.AxisServlet
-    </servlet-class>
-  </servlet>
-
-  <servlet>
-    <servlet-name>AdminServlet</servlet-name>
-    <display-name>Axis Admin Servlet</display-name>
-    <servlet-class>
-        org.apache.axis.transport.http.AdminServlet
-    </servlet-class>
-    <load-on-startup>100</load-on-startup>
-  </servlet>
-
-  <servlet>
-    <servlet-name>SOAPMonitorService</servlet-name>
-    <display-name>SOAPMonitorService</display-name>
-    <servlet-class>
-        org.apache.axis.monitor.SOAPMonitorService
-    </servlet-class>
-    <init-param>
-      <param-name>SOAPMonitorPort</param-name>
-      <param-value>5001</param-value>
-    </init-param>
-    <load-on-startup>100</load-on-startup>
-  </servlet>
-
-  <servlet-mapping>
-    <servlet-name>AxisServlet</servlet-name>
-    <url-pattern>/servlet/AxisServlet</url-pattern>
-  </servlet-mapping>
-
-  <servlet-mapping>
-    <servlet-name>AxisServlet</servlet-name>
-    <url-pattern>*.jws</url-pattern>
-  </servlet-mapping>
-
-  <servlet-mapping>
-    <servlet-name>AxisServlet</servlet-name>
-    <url-pattern>/services/*</url-pattern>
-  </servlet-mapping>
-
-  <servlet-mapping>
-    <servlet-name>SOAPMonitorService</servlet-name>
-    <url-pattern>/SOAPMonitor</url-pattern>
-  </servlet-mapping>
-
- <!-- uncomment this if you want the admin servlet -->
- <!--
-  <servlet-mapping>
-    <servlet-name>AdminServlet</servlet-name>
-    <url-pattern>/servlet/AdminServlet</url-pattern>
-  </servlet-mapping>
- -->
-
-    <session-config>
-        <!-- Default to 5 minute session timeouts -->
-        <session-timeout>5</session-timeout>
-    </session-config>
-
-    <!-- currently the W3C havent settled on a media type for WSDL;
-    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
-    for now we go with the basic 'it's XML' response -->
-  <mime-mapping>
-    <extension>wsdl</extension>
-     <mime-type>text/xml</mime-type>
-  </mime-mapping>
-  
-
-  <mime-mapping>
-    <extension>xsd</extension>
-    <mime-type>text/xml</mime-type>
-  </mime-mapping>
-
-  <welcome-file-list id="WelcomeFileList">
-    <welcome-file>index.html</welcome-file>
-    <welcome-file>index.jsp</welcome-file>
-    <welcome-file>index.jws</welcome-file>
-  </welcome-file-list>
-
-</web-app>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
+Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
+
+<web-app>
+
+  <display-name>Apache-Axis</display-name>
+    
+  <listener>
+    
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
+  </listener>
+
+  <filter>
+    <filter-name>ControlFilter</filter-name>
+    
<filter-class>org.apache.beehive.controls.runtime.servlet.ControlFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>ControlFilter</filter-name>
+    <url-pattern>*.jws</url-pattern>
+  </filter-mapping>
+
+  <servlet>
+    <servlet-name>AxisServlet</servlet-name>
+    <display-name>Apache-Axis Servlet</display-name>
+    <servlet-class>
+        org.apache.axis.transport.http.AxisServlet
+    </servlet-class>
+  </servlet>
+
+  <servlet>
+    <servlet-name>AdminServlet</servlet-name>
+    <display-name>Axis Admin Servlet</display-name>
+    <servlet-class>
+        org.apache.axis.transport.http.AdminServlet
+    </servlet-class>
+    <load-on-startup>100</load-on-startup>
+  </servlet>
+
+  <servlet>
+    <servlet-name>SOAPMonitorService</servlet-name>
+    <display-name>SOAPMonitorService</display-name>
+    <servlet-class>
+        org.apache.axis.monitor.SOAPMonitorService
+    </servlet-class>
+    <init-param>
+      <param-name>SOAPMonitorPort</param-name>
+      <param-value>5001</param-value>
+    </init-param>
+    <load-on-startup>100</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>AxisServlet</servlet-name>
+    <url-pattern>/servlet/AxisServlet</url-pattern>
+  </servlet-mapping>
+
+  <servlet-mapping>
+    <servlet-name>AxisServlet</servlet-name>
+    <url-pattern>*.jws</url-pattern>
+  </servlet-mapping>
+
+  <servlet-mapping>
+    <servlet-name>AxisServlet</servlet-name>
+    <url-pattern>/services/*</url-pattern>
+  </servlet-mapping>
+
+  <servlet-mapping>
+    <servlet-name>SOAPMonitorService</servlet-name>
+    <url-pattern>/SOAPMonitor</url-pattern>
+  </servlet-mapping>
+
+ <!-- uncomment this if you want the admin servlet -->
+ <!--
+  <servlet-mapping>
+    <servlet-name>AdminServlet</servlet-name>
+    <url-pattern>/servlet/AdminServlet</url-pattern>
+  </servlet-mapping>
+ -->
+
+    <session-config>
+        <!-- Default to 5 minute session timeouts -->
+        <session-timeout>5</session-timeout>
+    </session-config>
+
+    <!-- currently the W3C havent settled on a media type for WSDL;
+    http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
+    for now we go with the basic 'it's XML' response -->
+  <mime-mapping>
+    <extension>wsdl</extension>
+     <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  
+
+  <mime-mapping>
+    <extension>xsd</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+
+  <welcome-file-list id="WelcomeFileList">
+    <welcome-file>index.html</welcome-file>
+    <welcome-file>index.jsp</welcome-file>
+    <welcome-file>index.jws</welcome-file>
+  </welcome-file-list>
+
+</web-app>

Reply via email to