antelder    2003/01/13 14:36:52

  Modified:    java/src/org/apache/wsif/providers/soap/apacheaxis
                        WSIFOperation_ApacheAxis.java
               java/src/org/apache/wsif WSIFConstants.java
  Added:       java/src/org/apache/wsif/util TypeSerializer.java
  Log:
  Fix bugzilla bug 16041 - first attempt - allow overriding the AXIS default 
(de)serializer for a type
  
  Revision  Changes    Path
  1.58      +159 -23   
xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java
  
  Index: WSIFOperation_ApacheAxis.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- WSIFOperation_ApacheAxis.java     13 Jan 2003 20:46:30 -0000      1.57
  +++ WSIFOperation_ApacheAxis.java     13 Jan 2003 22:36:52 -0000      1.58
  @@ -124,6 +124,7 @@
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.providers.WSIFDynamicTypeMap;
   import org.apache.wsif.providers.WSIFDynamicTypeMapping;
  +import org.apache.wsif.util.TypeSerializer;
   import org.apache.wsif.util.WSIFUtils;
   import org.apache.wsif.util.jms.WSIFJMSDestination;
   import org.apache.wsif.wsdl.extensions.jms.JMSProperty;
  @@ -1133,7 +1134,11 @@
                                (org.apache.axis.encoding.TypeMapping) 
tmr.getTypeMapping(
                                        outputEncodingStyle);
   
  -            registerTypeMappings(tm, typeMap);         
  +             // register any default type mappings           
  +         registerDefaultTypeMappings(tm, getContext());
  +     
  +         // register any mappings from WSIFService.mapType calls
  +         registerDynamicTypes(tm, typeMap, getContext());
   
                        Message resMsg = msgContext.getResponseMessage();
                        SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();
  @@ -1882,8 +1887,14 @@
                    this.inputNamespace = getTargetNamespaceURI();
                }
   
  -             // register any WSIFDynamicTypeMappings
  -             registerTypeMappings(call.getTypeMapping(), typeMap);
  +     TypeMapping tm = call.getTypeMapping();
  +     WSIFMessage context = getContext();
  +     
  +     // register any default type mappings           
  +     registerDefaultTypeMappings(tm, context);
  +     
  +     // register any mappings from WSIFService.mapType calls
  +     registerDynamicTypes(tm, typeMap, context);
                        
                registerMIMETypes(
                        inputMIMEParts,
  @@ -1895,12 +1906,72 @@
   
                Trc.exit();
        }
  +     
  +     /**
  +     * Register any default mappings from the context with the AXIS Call
  +      */
  +     static void registerDefaultTypeMappings(TypeMapping callTypeMappings, 
WSIFMessage context) throws WSIFException {
  +             Object value = null;
  +             try {
  +                     value = 
context.getObjectPart(WSIFConstants.CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS);
  +             } catch (WSIFException e) {
  +                     Trc.ignoredException(e);
  +             }
  +             if (value == null) {
  +                     return;
  +             }
  +        if (!(value instanceof List)) {
  +             throw new WSIFException(
  +                 "context part '"
  +                 + WSIFConstants.CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS
  +                 + "' value is not an instance of java.util.List: "
  +                 + value); 
  +        }
  +        List defaultMappings = (List) value;
  +        for (Iterator i = defaultMappings.iterator(); i.hasNext(); ) {
  +             Object o = i.next();
  +             if (!(o instanceof org.apache.wsif.util.TypeSerializer)) {
  +                 throw new WSIFException(
  +                     "context part '"
  +                     + WSIFConstants.CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS
  +                     + "' value List contains an entry that is not an instance "
  +                     + "of org.apache.wsif.util.TypeSerializer: "
  +                     + value); 
  +             }
  +             TypeSerializer ts = (TypeSerializer) o;
  +             
  +             Class javaType = ts.getJavaType();
  +             QName elementType = ts.getElementType();     
  +             Object tmp = ts.getSerializer();
  +            SerializerFactory sf = null;
  +             if (tmp instanceof SerializerFactory) {
  +                sf = (SerializerFactory) tmp;
  +             }
  +             tmp = ts.getDeserializer();
  +            DeserializerFactory df = null;
  +             if (tmp instanceof DeserializerFactory) {
  +                df = (DeserializerFactory) tmp;
  +             }
  +                   
  +             if (javaType != null
  +             && elementType != null
  +             && (sf != null || df != null) ) {
  +                     callTypeMappings.register(javaType, elementType, sf, df);
  +             } else {
  +                     Trc.event(null, "ignoring default TypeSerializer invalid for 
AXIS:" + ts);
  +             }
  +        } 
  +     }
   
        /**
  -      * Register all the type mappings with the AXIS Call object
  -      * TODO: why is this here and not in the port and done when Cal is created?
  +     * Register any mappings from WSIFService.mapType calls with the AXIS Call
         */
  -     private static void registerTypeMappings(TypeMapping tm, WSIFDynamicTypeMap 
typeMap) throws WSIFException {
  +     static void registerDynamicTypes(
  +         TypeMapping tm, 
  +         WSIFDynamicTypeMap typeMap,
  +         WSIFMessage context) 
  +         throws WSIFException {
  +             
                Class objClass;
                String namespaceURI, localPart;
                WSIFDynamicTypeMapping wsifdynamictypemapping;
  @@ -1912,23 +1983,34 @@
                        SerializerFactory sf = null;
                        DeserializerFactory df = null;
                        
  -             if (tm.getSerializer(objClass, xmlType) == null) {
  -                         if (objClass.isArray()) {
  -                                 sf = new ArraySerializerFactory();
  -                         } else if (SimpleType.class.isAssignableFrom(objClass)) {
  -                                 sf = new SimpleSerializerFactory(objClass, 
xmlType);
  -                         } else {
  -                                 sf = new BeanSerializerFactory(objClass, xmlType);
  -                         }
  +                     // the context may override the default (de)serializer for a 
type
  +                     TypeSerializer contextTypeSerializer = 
  +                         findContextTypeSerialzer(context, objClass, xmlType);
  +                     if (contextTypeSerializer != null) {
  +                             objClass = contextTypeSerializer.getJavaType();
  +                             xmlType = contextTypeSerializer.getElementType();
  +                         sf = (SerializerFactory) 
contextTypeSerializer.getSerializer();
  +                         df = (DeserializerFactory) 
contextTypeSerializer.getDeserializer();
  +                     } 
  +                     
  +                 if (sf == null && tm.getSerializer(objClass, xmlType) == null) {
  +                         if (objClass.isArray()) {
  +                         sf = new ArraySerializerFactory();
  +                 } else if (SimpleType.class.isAssignableFrom(objClass)) {
  +                         sf = new SimpleSerializerFactory(objClass, xmlType);
  +                     } else {
  +                             sf = new BeanSerializerFactory(objClass, xmlType);
  +                     }
                    }
  -                 if (tm.getDeserializer(objClass, xmlType) == null) {
  -                         if (objClass.isArray()) {
  -                                 df = new ArrayDeserializerFactory();
  -                         } else if (SimpleType.class.isAssignableFrom(objClass)) {
  -                                 df = new SimpleDeserializerFactory(objClass, 
xmlType);
  -                         } else {
  -                                 df = new BeanDeserializerFactory(objClass, 
xmlType);
  -                         }
  +
  +                 if (df == null && tm.getDeserializer(objClass, xmlType) == null) {
  +                     if (objClass.isArray()) {
  +                             df = new ArrayDeserializerFactory();
  +                 } else if (SimpleType.class.isAssignableFrom(objClass)) {
  +                         df = new SimpleDeserializerFactory(objClass, xmlType);
  +             } else {
  +                     df = new BeanDeserializerFactory(objClass, xmlType);
  +                     }
                    }
   
                        namespaceURI =
  @@ -1948,7 +2030,61 @@
                        }
                }
        }
  -     
  +
  +    private static TypeSerializer findContextTypeSerialzer(
  +        WSIFMessage context,
  +        Class clazz,
  +        QName xmlType)
  +        throws WSIFException {
  +
  +             Object value = null;
  +             try {
  +                     value = 
context.getObjectPart(WSIFConstants.CONTEXT_SOAP_TYPE_SERIALIZERS);
  +             } catch (WSIFException e) {
  +                     Trc.ignoredException(e);
  +             }
  +             if (value == null) {
  +                     return null;
  +             }
  +        if (!(value instanceof List)) {
  +             throw new WSIFException(
  +                 "context part '"
  +                 + WSIFConstants.CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS
  +                 + "' value is not an instance of java.util.List: "
  +                 + value); 
  +        }
  +        
  +        List typeSerializers = (List) value;
  +        for (Iterator i = typeSerializers.iterator(); i.hasNext(); ) {
  +             Object o = i.next();
  +             if (!(o instanceof TypeSerializer)) {
  +                 throw new WSIFException(
  +                     "context part '"
  +                     + WSIFConstants.CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS
  +                     + "' value List contains an entry that is not an instance "
  +                     + "of org.apache.wsif.util.TypeSerializer: "
  +                     + value); 
  +             }
  +             TypeSerializer tm = (TypeSerializer) o;
  +                 
  +             Class javaType = tm.getJavaType();
  +             QName elementType = tm.getElementType();     
  +             Object serializer = tm.getSerializer();     
  +             Object deserializer = tm.getDeserializer();
  +                  
  +             if ( (javaType != null) || (javaType.isAssignableFrom(clazz))
  +             && ( (elementType != null) || (elementType.equals(xmlType)) ) ){
  +                 if (serializer == null || serializer instanceof SerializerFactory
  +                 && deserializer == null || deserializer instanceof 
DeserializerFactory
  +                 && serializer != null || deserializer != null) {
  +                         return tm;
  +                 }
  +            }
  +        }
  +
  +     return null; // couldn't find a TypeSerializer
  +    }
  +    
        private static boolean isDefaultSOAPNamespace(String ns) {
                boolean soapNamespace = false;
                 if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns)
  
  
  
  1.1                  xml-axis-wsif/java/src/org/apache/wsif/util/TypeSerializer.java
  
  Index: TypeSerializer.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "WSIF" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, 2002, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.wsif.util;
  
  import java.io.Serializable;
  
  import javax.xml.namespace.QName;
  
  import org.apache.wsif.logging.Trc;
  
  /**
   * This class maps a element/java type with its (de)serializers 
   */
  public class TypeSerializer implements Serializable {
  
        private static final long serialVersionUID = 1L;
  
        protected QName elementType;
        protected Class javaType;
        protected Object serializer;
        protected Object deserializer;
  
        public TypeSerializer(
                QName elementType,
                Class javaType,
                Object serializer,
                Object deserializer) {
                Trc.entry(this, elementType, javaType, serializer, deserializer);
                this.elementType = elementType;
                this.javaType = javaType;
                this.serializer = serializer;
                this.deserializer = deserializer;
                Trc.exit();
        }
  
        /**
         * Returns the deserializer.
         * @return Object
         */
        public Object getDeserializer() {
                Trc.entry(this);
                Trc.exit(deserializer);
                return deserializer;
        }
  
        /**
         * Returns the elementType.
         * @return QName
         */
        public QName getElementType() {
                Trc.entry(this);
                Trc.exit(elementType);
                return elementType;
        }
  
        /**
         * Returns the javaType.
         * @return Class
         */
        public Class getJavaType() {
                Trc.entry(this);
                Trc.exit(javaType);
                return javaType;
        }
  
        /**
         * Returns the serializer.
         * @return Object
         */
        public Object getSerializer() {
                Trc.entry(this);
                Trc.exit(serializer);
                return serializer;
        }
  
        /**
         * Sets the deserializer.
         * @param deserializer The deserializer to set
         */
        public void setDeserializer(Object deserializer) {
                Trc.entry(this, deserializer);
                this.deserializer = deserializer;
                Trc.exit();
        }
  
        /**
         * Sets the elementType.
         * @param elementType The elementType to set
         */
        public void setElementType(QName elementType) {
                Trc.entry(this, elementType);
                this.elementType = elementType;
                Trc.exit();
        }
  
        /**
         * Sets the javaType.
         * @param javaType The javaType to set
         */
        public void setJavaType(Class javaType) {
                Trc.entry(this, javaType);
                this.javaType = javaType;
                Trc.exit();
        }
  
        /**
         * Sets the serializer.
         * @param serializer The serializer to set
         */
        public void setSerializer(Object serializer) {
                Trc.entry(this, serializer);
                this.serializer = serializer;
                Trc.exit();
        }
  
        public String toString() {
                return "[TypeSerializer elementType="
                        + elementType
                        + ", "
                        + "javaType="
                        + javaType
                        + ", "
                        + "serializer="
                        + serializer
                        + ", "
                        + "deserializer="
                        + deserializer
                        + "]";
        }
  
  }
  
  
  1.14      +14 -0     xml-axis-wsif/java/src/org/apache/wsif/WSIFConstants.java
  
  Index: WSIFConstants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/WSIFConstants.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- WSIFConstants.java        7 Dec 2002 12:33:43 -0000       1.13
  +++ WSIFConstants.java        13 Jan 2003 22:36:52 -0000      1.14
  @@ -131,6 +131,20 @@
           "org.apache.wsif.soap.RequestHeaders";
   
       /**
  +     *  WSIF context part name for any default type serializers
  +     *  The context value should be an ArrayList of TypeSerializer objects  
  +     */
  +    public static final String CONTEXT_DEFAULT_SOAP_TYPE_MAPPINGS =
  +        "org.apache.wsif.soap.default.type.serializers";
  +
  +    /**
  +     *  WSIF context part name for to override default (de)serializers for a type  
  +     *  The context value should be an ArrayList of TypeSerializer objects  
  +     */
  +    public static final String CONTEXT_SOAP_TYPE_SERIALIZERS =
  +        "org.apache.wsif.soap.type.serializers";
  +
  +    /**
        *  WSIF context part name prefix for JMSProperties
        */
       public static final String CONTEXT_JMS_PREFIX = "JMSProperty.";
  
  
  


Reply via email to