Author: mmerz
Date: Mon Apr 18 11:32:02 2005
New Revision: 161780

URL: http://svn.apache.org/viewcvs?view=rev&rev=161780
Log:
Changes to the WSDL processing and type mappings for the the service control to 
work with Amazon's
commerce webservices.

Contributor: Daryoush Mehrtash

Modified:
    
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/registration/AxisTypeRegistrar.java
    
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/databinding/GenericHolder.java
    
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/wsdl/XmlBeanWSDLProcessor.java
    
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/registration/TypeRegistrar.java

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/registration/AxisTypeRegistrar.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/registration/AxisTypeRegistrar.java?view=diff&r1=161779&r2=161780
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/registration/AxisTypeRegistrar.java
 (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/registration/AxisTypeRegistrar.java
 Mon Apr 18 11:32:02 2005
@@ -76,7 +76,7 @@
      */
     protected void registerClassAsWithDefaultSearialization(Class cls, QName 
q) {
         try {
-            logger.debug("Register class: " + cls.getCanonicalName()
+            logger.debug("Assigned Default Serialization to  class: " + 
cls.getCanonicalName()
                     + " qname:" + q);
             TypeDesc td = TypeDesc.getTypeDescForClass(cls); // a class can
                                                                 // provide its
@@ -160,7 +160,8 @@
      * @param q
      */
     protected void registerClassAsXMLBeans(Class cls, QName q) {
-        mTypeMapping.register(cls, q, new XmlBeanSerializerFactory(cls, q),
+        logger.debug("Assigned XMLBeans Serialization to  class: " + 
cls.getCanonicalName()
+                + " qname:" + q);       mTypeMapping.register(cls, q, new 
XmlBeanSerializerFactory(cls, q),
                 new XmlBeanDeserializerFactory(cls, q));
     }
 
@@ -177,7 +178,8 @@
             throws ClassNotFoundException, NoSuchMethodException,
             InstantiationException, IllegalAccessException,
             InvocationTargetException {
-        /*
+        logger.debug("Assigned DataHandler to  class: " + 
cls.getCanonicalName()
+                + " qname:" + q);        /*
          * NOTE [EMAIL PROTECTED] 2004-Oct-08 -- doing reflection here in case
          * AXIS was built without attachment support.
          */
@@ -200,7 +202,8 @@
      * @param q
      */
     protected void registerClassAsArray(Class cls, QName q) {
-        mTypeMapping.register(cls, q, new ArraySerializerFactory(cls, q),
+        logger.debug("Assigned Array Serialization to  class: " + 
cls.getCanonicalName()
+                + " qname:" + q);       mTypeMapping.register(cls, q, new 
ArraySerializerFactory(cls, q),
                 new ArrayDeserializerFactory());
     }
 

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/databinding/GenericHolder.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/databinding/GenericHolder.java?view=diff&r1=161779&r2=161780
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/databinding/GenericHolder.java
 (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/databinding/GenericHolder.java
 Mon Apr 18 11:32:02 2005
@@ -19,6 +19,9 @@
  */
 package org.apache.beehive.wsm.databinding;
 
+
+import java.lang.reflect.Field;
+
 import javax.xml.rpc.holders.Holder;
 
 
/*******************************************************************************
@@ -34,6 +37,13 @@
         this.value = value;
     }
 
-    public GenericHolder() {}
+       // The blank constructore is made private so that the value is always 
set in the holder.  The type of the value
+       // is used by the service control to determine the type of class 
conversion it would need to stuff value to the
+       // holder from the soap message result.    The only way I have been 
able to get the type of the Value is by
+       // looking at its class, which requires that  for the value class to 
have been instantiated.
+    private GenericHolder() {}
+       
+       
+
 
 }

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/wsdl/XmlBeanWSDLProcessor.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/wsdl/XmlBeanWSDLProcessor.java?view=diff&r1=161779&r2=161780
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/wsdl/XmlBeanWSDLProcessor.java
 (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/wsdl/XmlBeanWSDLProcessor.java
 Mon Apr 18 11:32:02 2005
@@ -149,7 +149,7 @@
 
       for (TOperation op : operations) {
 
-        processTOperation(op, wsm, methodMap, messageMap, types);
+        processTOperation(op, wsm, methodMap, messageMap, tBind, types);
       }
     }
 
@@ -162,14 +162,20 @@
 
   private void processTOperation(TOperation op, BeehiveWsTypeMetadata wsm,
       Map<String, BeehiveWsMethodMetadata> methodMap,
-      Map<String, TPart[]> messageMap, TTypes types) throws Exception {
+      Map<String, TPart[]> messageMap, TBinding tBind, TTypes types) throws 
Exception {
     String opName = op.getName();
     TParam outputParam = op.getOutput();
 
     Map<String, BeehiveWsParameterMetadata> outParamMap = null;
 
-    BeehiveWsParameterMetadata[] paraMeta = processParameters(outputParam, 
types,
-        messageMap, wsm);
+    BeehiveWsParameterMetadata[] paraMeta = new BeehiveWsParameterMetadata[0]; 
 // defualt value
+    if( null != outputParam ) {
+
+             TPart[] messageParts = messageMap.get(outputParam.getMessage()
+                 .getLocalPart());
+                               paraMeta = processParameters(opName, 
messageParts, tBind, types,
+                                               messageMap, wsm, true);  // 
output parameters are not wrapped
+    }
     Class returnType;
     QName returnXMLType;
 
@@ -221,8 +227,12 @@
     TParam inputParam = op.getInput();
     if (inputParam != null) {
 
-      BeehiveWsParameterMetadata[] params = processParameters(inputParam, 
types,
-          messageMap, wsm);
+                     TPart[] messageParts = 
messageMap.get(inputParam.getMessage()
+                         .getLocalPart());
+                         
+
+                         BeehiveWsParameterMetadata[] params = 
processParameters(opName, messageParts,  tBind, types,
+          messageMap, wsm, false); 
 
       if (paramOrder != null) { 
         // Paramorder is only used for rpc. 
@@ -294,19 +304,24 @@
 
   }
 
-  private BeehiveWsParameterMetadata[] processParameters(TParam parameter,
-      TTypes types, Map<String, TPart[]> messageMap, BeehiveWsTypeMetadata 
wsm) {
+  private BeehiveWsParameterMetadata[] processParameters(String operationName, 
TPart[] messageParts, TBinding tBind,
+      TTypes types, Map<String, TPart[]> messageMap, BeehiveWsTypeMetadata 
wsm, boolean isOutputParameters) {
 
-      // When there you have parts of the message in the header,   you would 
have multiple wsdl:part.  In case of
-      // wrapped we would have one part that has name="parameters"
+      // When  you have parts of the message in the header,   you would have 
multiple wsdl:part.  In case of
+      // wrapped we would have JUST ONE  part that has name="parameters"
       // but the header parts would have their name which looks like a bare
       // So in the processing if there is any part that has name=parameters 
then the service is called wrapped, and from then
       // on the parameter style is not changed.
+         // Update.... "parameters" test is not enough, in some cases it may 
be called "body" For wrapped there can only be one body element, and the 
element attribute's local
+         // name should be the same as the name of the opeartion.
       boolean paramStyleIsSet = false;  
       
-    if (parameter != null) {
-      TPart[] messageParts = messageMap.get(parameter.getMessage()
-          .getLocalPart());
+         boolean shouldUnwrap;  
+
+         if(isOutputParameters ) {
+                 paramStyleIsSet = true;  // only set this for input parameters
+         }
+                 shouldUnwrap = isWrapped(operationName, messageParts, tBind, 
isOutputParameters);
 
       List<BeehiveWsParameterMetadata> paramList = new 
ArrayList<BeehiveWsParameterMetadata>(
           messageParts.length);
@@ -329,10 +344,15 @@
           String name = messagePart.getName();
           // if name is "parameters" then we need to unwrap the type
           // and the service is doc/literal wrapped./
-          if (0 == "parameters".compareTo(name)  ) {  
-              wsm.getSoapBinding().setParameterStyle(
+          if (shouldUnwrap &&  
+                                 unwrapMessagePart(operationName, 
isOutputParameters, messagePart) // when we do want to unwrap, we should only 
unwrap the parts the parameters
+                                                                               
                                                        // the parts that are 
for headers, for instance, should remain intact.
+                                 ) {  
+                         if( !isOutputParameters)  {// only set the mode if 
this is input parameters
+                                 wsm.getSoapBinding().setParameterStyle(
                       SOAPBinding.ParameterStyle.WRAPPED);
-              paramStyleIsSet = true;
+                                 paramStyleIsSet = true;
+                         }
               if (types != null) { // if there are some type
               try {
                 Schema[] schemas = selectChildren(types, Schema.class);
@@ -420,10 +440,33 @@
         }
       }
       return paramList.toArray(new 
BeehiveWsParameterMetadata[paramList.size()]);
-    }
-    return new BeehiveWsParameterMetadata[0];
+
+  }
+
+  // To detect the wrapped walk the message parts, if there is a part that has 
name="parameters"
+  // or if there is a part that its element name is the same as the operation 
name, return true.
+  // NOTE:  for MIME multiparts, or when there are headers the tBind should be 
checked to determine
+  // if a part is on the header or is a MIME.  The header and MIME parts 
should not effect the wrapped
+  // determination.
+  // TODO: the logic here may not work with MIME types, verify later.
+  private boolean isWrapped( String operationName, TPart[] messagePart,  
TBinding tBind,boolean isOutputParameters) {
+         for( TPart message : messagePart) {
+                 if( true       == unwrapMessagePart(operationName, 
isOutputParameters, message)) return true;
+         }
+         return false;
   }
 
+  private boolean unwrapMessagePart(String operationName, boolean 
isOutputParameters, TPart message) {
+       String name = message.getName();
+       if("parameters".equals(name)) return true;
+       if( isOutputParameters) {
+                 
if(message.getElement().getLocalPart().equals(operationName+"Response")) return 
true;
+                 
+         } else { 
+                 if(message.getElement().getLocalPart().equals(operationName)) 
return true;
+         }
+       return false;
+}
   /**
    * @param paramList
    * @param s

Modified: 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/registration/TypeRegistrar.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/registration/TypeRegistrar.java?view=diff&r1=161779&r2=161780
==============================================================================
--- 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/registration/TypeRegistrar.java
 (original)
+++ 
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/registration/TypeRegistrar.java
 Mon Apr 18 11:32:02 2005
@@ -20,7 +20,9 @@
 package org.apache.beehive.wsm.registration;
 
 import java.io.File;
+import java.lang.reflect.Array;
 import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -121,18 +123,21 @@
         try {
             logger.debug("Register class: " + cls.getCanonicalName()
                     + " qName: " + q);
+                       if (Void.TYPE.equals(cls))
+                return null;
+                       
+            if (isBuiltInType(cls))
+                return getBuiltInTypeQname(cls);
             if (q == null)
                 throw new RuntimeException(
                         "Invalid registeration requestion qname is null");
             
             
-            if (isBuiltInType(cls))
-                return getBuiltInTypeQname(cls);
             if (cls.isArray()) {
-                if (!classIsRegistered(cls, q)) {
-                    registerClassAsArray(cls, q);
-                }
-                q = registerType(cls.getComponentType());
+//                if (!classIsRegistered(cls, q)) {
+//                    registerClassAsArray(cls, q);
+//                }
+                q = registerType(cls.getComponentType(), q);
                 // TODO: fix the expected type thing for arrays.
                 // if (expectedType != null) {
                 // q = expectedType;
@@ -229,7 +234,12 @@
             Type raw = pt.getRawType();
             if( GenericHolder.class.isAssignableFrom((Class)raw)) {
                 Type[] typeArgs = pt.getActualTypeArguments();
-                res = (Class) typeArgs[0];
+                               if(typeArgs[0] instanceof GenericArrayType) {
+                                       Class arrayElementType =  (Class) 
((GenericArrayType)typeArgs[0]).getGenericComponentType();
+                                       res = 
Array.newInstance(arrayElementType, 0).getClass();
+                               } else { 
+                                       res = (Class) typeArgs[0];
+                               }
             }else {
                 throw new RuntimeException("Invalid parameterized type for 
holder: " + t);
             }


Reply via email to