You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by mm...@apache.org on 2004/10/09 00:34:01 UTC

svn commit: rev 54121 - in incubator/beehive/trunk/wsm: . src/runtime/org/apache/beehive/wsm/axis src/runtime/org/apache/beehive/wsm/axis/util/encoding src/runtime/org/apache/beehive/wsm/jsr181/model

Author: mmerz
Date: Fri Oct  8 15:33:59 2004
New Revision: 54121

Added:
   incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/
   incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializer.java   (contents, props changed)
   incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializerFactory.java   (contents, props changed)
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/jsr181/model/WebServiceTYPEMetadata.java
Log:
Added some more type mapping capabilities to AxisHook and excluded the
org.apache.beehive.axis.badtiger package from a javadoc task in build.xml
since it imports AXIS classes from a package containing "enum"

Contributor: Jonathan Colwell



Modified: incubator/beehive/trunk/wsm/build.xml
==============================================================================
--- incubator/beehive/trunk/wsm/build.xml	(original)
+++ incubator/beehive/trunk/wsm/build.xml	Fri Oct  8 15:33:59 2004
@@ -327,6 +327,7 @@
         <packageset dir="${api.dir}" defaultexcludes="yes">
         </packageset>
         <packageset dir="${runtime.dir}" defaultexcludes="yes">
+          <exclude name="**/axis/badtiger"/>
         </packageset>
     </javadoc>
   </target>

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	Fri Oct  8 15:33:59 2004
@@ -15,21 +15,26 @@
  */
 package org.apache.beehive.wsm.axis;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import javax.jws.WebParam;
 import javax.xml.namespace.QName;
 import javax.wsdl.OperationType;
 
 import org.apache.axis.wsdl.fromJava.Emitter;
 import org.apache.axis.wsdl.fromJava.Namespaces;
 import org.apache.axis.wsdl.fromJava.Types;
+import org.apache.axis.encoding.SerializerFactory;
+import org.apache.axis.encoding.DeserializerFactory;
 import org.apache.axis.encoding.TypeMapping;
 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
 import org.apache.axis.encoding.ser.BeanSerializerFactory;
+import org.apache.axis.encoding.ser.VectorDeserializerFactory;
 import org.apache.axis.description.FaultDesc;
 import org.apache.axis.description.ServiceDesc;
 import org.apache.axis.description.JavaServiceDesc;
@@ -37,12 +42,12 @@
 import org.apache.axis.description.OperationDesc;
 import org.apache.axis.utils.BeanPropertyDescriptor;
 import org.apache.beehive.wsm.axis.badtiger.EnumWrapper;
+import org.apache.beehive.wsm.axis.util.encoding.CollectionSerializerFactory;
 import org.apache.beehive.wsm.jsr181.model.WebServiceTYPEMetadata;
 import org.apache.beehive.wsm.jsr181.model.WebServiceMETHODMetadata;
 import org.apache.beehive.wsm.jsr181.model.WebServicePARAMETERMetadata;
 import org.apache.beehive.wsm.jsr181.model.SOAPBindingInfo;
 
-import javax.jws.WebParam;
 
 /*******************************************************************************
  * 
@@ -162,23 +167,97 @@
         return sd;
     }
 
-    private static void configureTypeMapping(ServiceDesc desc, Class type) {
+    private static boolean isActivationEnabled()
+    {
+        return null != getDataHandlerClass() && null != getMultipartClass();
+    }
+
+    private static Class getDataHandlerClass()
+    {
+        try {
+            return AxisHook.class.getClassLoader()
+                .loadClass("javax.activation.DataHandler");
+        }
+        catch (Exception e) { }
+        return null;
+    }
 
+    private static Class getMultipartClass()
+    {
+        try {
+            return AxisHook.class.getClassLoader()
+                .loadClass("javax.mail.internet.MimeMultipart");
+        }
+        catch (Exception e) { }
+        return null;
+    }
+
+    private static void configureTypeMapping(ServiceDesc desc, Class type) {
+        
         if (type.isArray()) {
             configureTypeMapping(desc, type.getComponentType());
         }
         else {
-        
+            
             TypeMapping tm = desc.getTypeMapping();
             QName q = tm.getTypeQName(type);
-            if (q == null) {
-                String namespace = Namespaces.makeNamespace( type.getName() ) ;
-                if (namespace == null  || namespace
-                    .endsWith("DefaultNamespace")) {
-                    namespace = desc.getDefaultNamespace();
+            
+            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
+                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))) {
+                
+                if (q == null) {
+                    q = generateQName(type, desc);
                 }
-                q = new QName(namespace,                          
-                              Types.getLocalNameFromFullName( type.getName() ) );
+
+                if (! tm.isRegistered(type, q)) {
+                    try {
+
+                        /*
+                         * NOTE jcolwell@bea.com 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);
+
+                        tm.register(type, q, sf, dsf);
+
+                    }
+                    catch (Exception e) {
+                        /*
+                         * FIXME jcolwell@bea.com 2004-Oct-08 -- 
+                         * log this properly
+                         */
+                        e.printStackTrace();
+                    }
+                }                
+            }
+            else if (q == null) {
+                q = generateQName(type, desc);
                 if (! tm.isRegistered(type, q)) {
                     tm.register( type, q,
                                  new BeanSerializerFactory(type, q),
@@ -193,6 +272,19 @@
                 }
             }
         }
+    }
+
+    private static QName generateQName(Class type, ServiceDesc desc)
+    {
+
+        String namespace = Namespaces.makeNamespace(type.getName()) ;
+        if (namespace == null  || namespace
+            .endsWith("DefaultNamespace")) {
+            namespace = desc.getDefaultNamespace();
+        }
+        return new QName(namespace,                          
+                         Types.getLocalNameFromFullName(type.getName()));
+
     }
 
     protected static void configureSoapBinding(ServiceDesc sd,

Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializer.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializer.java	Fri Oct  8 15:33:59 2004
@@ -0,0 +1,52 @@
+/*
+ * CollectionSerializer.java
+ * 
+ * Copyright (c) 2004 Walt Disney Internet Group. All Rights Reserved.
+ * 
+ * Original author: Jonathan Colwell
+ * 
+ * $Workfile::                                                                $
+ *   $Author::                                                                $
+ * $Revision::                                                                $
+ *     $Date::                                                                $
+ */
+package org.apache.beehive.wsm.axis.util.encoding;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Vector;
+import javax.xml.namespace.QName;
+
+import org.apache.axis.encoding.SerializationContext;
+import org.apache.axis.encoding.ser.VectorSerializer;
+import org.xml.sax.Attributes;
+
+
+
+/******************************************************************************
+ * 
+ * @author Jonathan Colwell
+ * @version
+ * <!--$$Revision:--> <!-- $-->, <!--$$JustDate:--> <!-- $-->
+ */
+public class CollectionSerializer extends VectorSerializer {
+
+    public void serialize(QName name, Attributes attributes,
+                          Object value, SerializationContext context)
+        throws IOException
+    {
+        
+        if (!(value instanceof Collection)) {
+            throw new IOException(((value != null) ? 
+                                   value.getClass().getName() 
+                                   : "null")
+                                  + " is not an instance of " 
+                                  + Collection.class.getName());
+        }
+        else {
+            Vector v = new Vector();
+            v.addAll((Collection)value);
+            super.serialize(name, attributes, v, context);
+        }
+    }
+}

Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializerFactory.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/util/encoding/CollectionSerializerFactory.java	Fri Oct  8 15:33:59 2004
@@ -0,0 +1,30 @@
+/*
+ * 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.util.encoding;
+
+import javax.xml.namespace.QName;
+import org.apache.axis.encoding.ser.BaseSerializerFactory;
+
+/******************************************************************************
+ * 
+ * @author Jonathan Colwell
+ */
+public class CollectionSerializerFactory extends BaseSerializerFactory {
+
+    public CollectionSerializerFactory(Class javaType, QName xmlType) {
+        super(CollectionSerializer.class, xmlType, javaType);
+    }
+}

Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/WebServiceTYPEMetadata.java
==============================================================================
--- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/WebServiceTYPEMetadata.java	(original)
+++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/WebServiceTYPEMetadata.java	Fri Oct  8 15:33:59 2004
@@ -172,7 +172,6 @@
                 if ((null != wpTargetNamespace) && (0 == wpTargetNamespace.length()))
                 {
                     wspm.setWpTargetNamespace(getWsTargetNamespace());
-System.out.println("***" + wspm.getWpTargetNamespace());
                 }
             }