owenb 2002/12/04 09:29:03
Modified: java/src/org/apache/wsif/providers/ejb Tag: pre1_2_0-patches
WSIFOperation_EJB.java
java/src/org/apache/wsif/providers/java Tag:
pre1_2_0-patches WSIFOperation_Java.java
Added: java/src/org/apache/wsif/providers Tag: pre1_2_0-patches
ProviderUtils.java
Log:
Updates to compatibility methods so that the Java and EJB providers better
interoperate with the SOAP providers:
- Allow arrays of Strings* to be passed as part values when the method argument is
an array of chars or Characters
* All the Strings must have length 1
- Convert all return values of type Character (char) to Strings
- Move common methods to a new ProviderUtils class
These conversions are useful because the XML schema does not define a char type
Revision Changes Path
No revision
No revision
1.1.2.1 +0 -0
xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java
Index: ProviderUtils.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ProviderUtils.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
No revision
No revision
1.19.2.4 +83 -83
xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java
Index: WSIFOperation_EJB.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java,v
retrieving revision 1.19.2.3
retrieving revision 1.19.2.4
diff -u -r1.19.2.3 -r1.19.2.4
--- WSIFOperation_EJB.java 22 Nov 2002 15:55:03 -0000 1.19.2.3
+++ WSIFOperation_EJB.java 4 Dec 2002 17:29:02 -0000 1.19.2.4
@@ -88,6 +88,7 @@
import org.apache.wsif.base.WSIFDefaultOperation;
import org.apache.wsif.logging.MessageLogger;
import org.apache.wsif.logging.Trc;
+import org.apache.wsif.providers.ProviderUtils;
import org.apache.wsif.wsdl.extensions.ejb.EJBOperation;
import org.apache.wsif.wsdl.extensions.format.TypeMap;
import org.apache.wsif.wsdl.extensions.format.TypeMapping;
@@ -777,7 +778,7 @@
for (int i = 0; i < parmTypes.length; i++) {
// If the arg is a null then skip it
if (args[i] == null) {
- compatibleArgs[i] = getDefaultObject(parmTypes[i]);
+ compatibleArgs[i] = ProviderUtils.getDefaultObject(parmTypes[i]);
continue;
}
// Consider the special cas, squeezing a String into a Character
@@ -798,8 +799,31 @@
protected Object getCompatibleReturn(Method method, Object returnObj) {
Trc.entry(this,method,returnObj);
Object o = null;
- if (method.getReturnType().equals(java.lang.Character.class)) {
+ Class rt = method.getReturnType();
+ Class ct = null;
+ int dims = 0;
+ if (rt.isArray()) {
+ ct = rt.getComponentType();
+ dims++;
+ while (ct.isArray()) {
+ ct = ct.getComponentType();
+ dims++;
+ }
+ }
+ if (returnObj instanceof java.lang.Character) {
o = getCompatibleObject(java.lang.String.class, returnObj);
+ } else if (ct != null && (ct.equals(java.lang.Character.class) ||
ct.equals(char.class))) {
+ String stringArrayClassName = "[Ljava.lang.String;";
+ for (int d=1; d<dims; d++) {
+ stringArrayClassName = "["+stringArrayClassName;
+ }
+ try {
+ Class stringArrayClass = Class.forName(stringArrayClassName,
true, Thread.currentThread().getContextClassLoader());
+ o = getCompatibleObject(stringArrayClass, returnObj);
+ } catch(ClassNotFoundException cnf) {
+ Trc.ignoredException(cnf);
+ o = returnObj;
+ }
} else {
o = returnObj;
}
@@ -818,10 +842,13 @@
// this conversion may be needed on method args AND returns
protected Object getCompatibleObject(Class cls, Object obj) {
Trc.entry(this,cls,obj);
+
+ if (cls.getName().equals(obj.getClass().getName())) return obj;
+
// String -> Character
if ((cls.equals(java.lang.Character.class) || cls.equals(char.class))
&& obj.getClass().equals(java.lang.String.class)) {
- Character charArg = stringToCharacter((String) obj);
+ Character charArg = ProviderUtils.stringToCharacter((String) obj);
if (charArg == null) {
// Can't convert this string to character so return null
Trc.exit(null);
@@ -830,6 +857,59 @@
Trc.exit(charArg);
return charArg;
}
+
+ // String arrays -> char/Character arrays and Character arrays -> String
arrays
+ if (cls.isArray() && obj.getClass().isArray()) {
+ Class cct = cls.getComponentType();
+ Class objct = obj.getClass().getComponentType();
+ while (cct.isArray()) {
+ cct = cct.getComponentType();
+ }
+ while (objct.isArray()) {
+ objct = objct.getComponentType();
+ }
+ if (objct.equals(java.lang.String.class) && cct.equals(char.class)) {
+ try {
+ Object charArray =
ProviderUtils.stringArrayToCharArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(java.lang.String.class) &&
cct.equals(java.lang.Character.class)) {
+ try {
+ Object charArray =
ProviderUtils.stringArrayToCharacterArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(java.lang.Character.class) &&
cct.equals(java.lang.String.class)) {
+ try {
+ Object charArray =
ProviderUtils.characterArrayToStringArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(char.class) &&
cct.equals(java.lang.String.class)) {
+ try {
+ Object charArray =
ProviderUtils.charArrayToStringArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ }
+ }
if (cls.equals(java.lang.String.class)
&& obj.getClass().equals(java.lang.Character.class)) {
@@ -841,40 +921,6 @@
return obj;
}
- protected Character stringToCharacter(String str) {
- if (str.length() != 1)
- return null;
- return new Character(str.charAt(0));
- }
-
- protected Object getDefaultObject(Class cls) {
- if (cls == null) {
- return null;
- } else if (cls.isPrimitive()) {
- if (cls.getName().equals("int")) {
- return new Integer(0);
- } else if (cls.getName().equals("char")) {
- return new Character('0');
- } else if (cls.getName().equals("long")) {
- return new Long(0);
- } else if (cls.getName().equals("short")) {
- short s = 0;
- return new Short(s);
- } else if (cls.getName().equals("double")) {
- return new Double(0);
- } else if (cls.getName().equals("boolean")) {
- return new Boolean(false);
- } else if (cls.getName().equals("byte")) {
- byte b = 0;
- return new Byte(b);
- } else {
- return new Float(0);
- }
- } else {
- return null;
- }
- }
-
protected String getOutputMessageName() throws WSIFException {
Trc.entry(this);
if (fieldOutputMessageName == null) {
@@ -1339,52 +1385,6 @@
Trc.exit();
}
-
- /**
- * Creates a new input WSIFMessage. This overrides the
- * WSIFDefaultOperation method to enable the use of
- * compiled WSIFMessages by using a WSIFMessageFactory
- * to create the message.
- *
- * @param name the name of the message
- * @return a WSIFMessage instance
- * @see WSIFOperation#createInputMessage(String)
- */
- // defect 131672 and disable compiled msg support for now
- // public WSIFMessage createInputMessage(String name) {
- // Tr.entry(this, name);
- // Definition d = (fieldPort == null) ? null : fieldPort.getDefinition();
- // String ns = (d == null) ? "" : d.getTargetNamespace();
- // WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
- // WSIFMessage msg = mf.createMessage(ns, name + "Message");
- // if (msg != null)
- // msg.setName(name);
- // Tr.exit(msg);
- // return msg;
- // }
-
- /**
- * Creates a new input WSIFMessage. This overrides the
- * WSIFDefaultOperation method to enable the use of
- * compiled WSIFMessages by using a WSIFMessageFactory
- * to create the message.
- *
- * @param name the name of the message
- * @return a WSIFMessage instance
- * @see WSIFOperation#createInputMessage(String)
- */
- // defect 131672 and disable compiled msg support for now
- // public WSIFMessage createOutputMessage(String name) {
- // Tr.entry(this, name);
- // Definition d = (fieldPort == null) ? null : fieldPort.getDefinition();
- // String ns = (d == null) ? "" : d.getTargetNamespace();
- // WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
- // WSIFMessage msg = mf.createMessage(ns, name + "Message");
- // if (msg != null)
- // msg.setName(name);
- // Tr.exit(msg);
- // return msg;
- // }
public String deep() {
String buff = "";
No revision
No revision
1.21.2.4 +84 -88
xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java
Index: WSIFOperation_Java.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java,v
retrieving revision 1.21.2.3
retrieving revision 1.21.2.4
diff -u -r1.21.2.3 -r1.21.2.4
--- WSIFOperation_Java.java 22 Nov 2002 15:55:03 -0000 1.21.2.3
+++ WSIFOperation_Java.java 4 Dec 2002 17:29:02 -0000 1.21.2.4
@@ -90,6 +90,7 @@
import org.apache.wsif.base.WSIFServiceImpl;
import org.apache.wsif.logging.MessageLogger;
import org.apache.wsif.logging.Trc;
+import org.apache.wsif.providers.ProviderUtils;
import org.apache.wsif.wsdl.extensions.java.JavaOperation;
/**
@@ -751,7 +752,7 @@
for (int i = 0; i < parmTypes.length; i++) {
// If the arg is a null then skip it
if (args[i] == null) {
- compatibleArgs[i] = getDefaultObject(parmTypes[i]);
+ compatibleArgs[i] = ProviderUtils.getDefaultObject(parmTypes[i]);
continue;
}
// Consider the special cas, squeezing a String into a Character
@@ -771,8 +772,31 @@
protected Object getCompatibleReturn(Method method, Object returnObj) {
Trc.entry(this,method,returnObj);
Object o = null;
- if (method.getReturnType().equals(java.lang.Character.class)) {
+ Class rt = method.getReturnType();
+ Class ct = null;
+ int dims = 0;
+ if (rt.isArray()) {
+ ct = rt.getComponentType();
+ dims++;
+ while (ct.isArray()) {
+ ct = ct.getComponentType();
+ dims++;
+ }
+ }
+ if (returnObj instanceof java.lang.Character) {
o = getCompatibleObject(java.lang.String.class, returnObj);
+ } else if (ct != null && (ct.equals(java.lang.Character.class) ||
ct.equals(char.class))) {
+ String stringArrayClassName = "[Ljava.lang.String;";
+ for (int d=1; d<dims; d++) {
+ stringArrayClassName = "["+stringArrayClassName;
+ }
+ try {
+ Class stringArrayClass = Class.forName(stringArrayClassName,
true, Thread.currentThread().getContextClassLoader());
+ o = getCompatibleObject(stringArrayClass, returnObj);
+ } catch(ClassNotFoundException cnf) {
+ Trc.ignoredException(cnf);
+ o = returnObj;
+ }
} else {
o = returnObj;
}
@@ -791,10 +815,13 @@
// this conversion may be needed on method args AND returns
protected Object getCompatibleObject(Class cls, Object obj) {
Trc.entry(this,cls,obj);
+
+ if (cls.getName().equals(obj.getClass().getName())) return obj;
+
// String -> Character
if ((cls.equals(java.lang.Character.class) || cls.equals(char.class))
&& obj.getClass().equals(java.lang.String.class)) {
- Character charArg = stringToCharacter((String) obj);
+ Character charArg = ProviderUtils.stringToCharacter((String) obj);
if (charArg == null) {
// Can't convert this string to character so return null
Trc.exit(null);
@@ -803,7 +830,60 @@
Trc.exit(charArg);
return charArg;
}
-
+
+ // String arrays -> char/Character arrays and Character arrays -> String
arrays
+ if (cls.isArray() && obj.getClass().isArray()) {
+ Class cct = cls.getComponentType();
+ Class objct = obj.getClass().getComponentType();
+ while (cct.isArray()) {
+ cct = cct.getComponentType();
+ }
+ while (objct.isArray()) {
+ objct = objct.getComponentType();
+ }
+ if (objct.equals(java.lang.String.class) && cct.equals(char.class)) {
+ try {
+ Object charArray =
ProviderUtils.stringArrayToCharArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(java.lang.String.class) &&
cct.equals(java.lang.Character.class)) {
+ try {
+ Object charArray =
ProviderUtils.stringArrayToCharacterArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(java.lang.Character.class) &&
cct.equals(java.lang.String.class)) {
+ try {
+ Object charArray =
ProviderUtils.characterArrayToStringArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ } else if (objct.equals(char.class) &&
cct.equals(java.lang.String.class)) {
+ try {
+ Object charArray =
ProviderUtils.charArrayToStringArray(obj);
+ Trc.exit(charArray);
+ return charArray;
+ } catch (Exception e) {
+ Trc.ignoredException(e);
+ Trc.exit(null);
+ return null;
+ }
+ }
+ }
+
if (cls.equals(java.lang.String.class)
&& obj.getClass().equals(java.lang.Character.class)) {
Trc.exit(obj.toString());
@@ -813,40 +893,6 @@
return obj;
}
- protected Character stringToCharacter(String str) {
- if (str.length() != 1)
- return null;
- return new Character(str.charAt(0));
- }
-
- protected Object getDefaultObject(Class cls) {
- if (cls == null) {
- return null;
- } else if (cls.isPrimitive()) {
- if (cls.getName().equals("int")) {
- return new Integer(0);
- } else if (cls.getName().equals("char")) {
- return new Character('0');
- } else if (cls.getName().equals("long")) {
- return new Long(0);
- } else if (cls.getName().equals("short")) {
- short s = 0;
- return new Short(s);
- } else if (cls.getName().equals("double")) {
- return new Double(0);
- } else if (cls.getName().equals("boolean")) {
- return new Boolean(false);
- } else if (cls.getName().equals("byte")) {
- byte b = 0;
- return new Byte(b);
- } else {
- return new Float(0);
- }
- } else {
- return null;
- }
- }
-
protected String getOutputMessageName() throws WSIFException {
Trc.entry(this);
if (fieldOutputMessageName == null) {
@@ -1360,56 +1406,6 @@
Trc.exit();
}
-
-// /**
-// * Creates a new input WSIFMessage. This overrides the
-// * WSIFDefaultOperation method to enable the use of
-// * compiled WSIFMessages by using a WSIFMessageFactory
-// * to create the message.
-// *
-// * @param name the name of the message
-// * @return a WSIFMessage instance
-// * @see WSIFOperation#createInputMessage(String)
-// */
-// defect 131672 and disable compiled msg support for now
-// public WSIFMessage createInputMessage(String name) {
-// Tr.entry(this, name);
-//
-// Definition d = (fieldPort == null) ? null : fieldPort.getDefinition();
-// String ns = (d == null) ? "" : d.getTargetNamespace();
-// WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
-// WSIFMessage msg = mf.createMessage(ns, name + "Message");
-// if (msg != null)
-// msg.setName(name);
-//
-// Tr.exit(msg);
-// return msg;
-// }
-//
-// /**
-// * Creates a new output WSIFMessage. This overrides the
-// * WSIFDefaultOperation method to enable the use of
-// * compiled WSIFMessages by using a WSIFMessageFactory
-// * to create the message.
-// *
-// * @param name the name of the message
-// * @return a WSIFMessage instance
-// * @see WSIFOperation#createInputMessage(String)
-// */
-// defect 131672 and disable compiled msg support for now
-// public WSIFMessage createOutputMessage(String name) {
-// Tr.entry(this, name);
-//
-// Definition d = (fieldPort == null) ? null : fieldPort.getDefinition();
-// String ns = (d == null) ? "" : d.getTargetNamespace();
-// WSIFMessageFactory mf = WSIFServiceImpl.getMessageFactory();
-// WSIFMessage msg = mf.createMessage(ns, name + "Message");
-// if (msg != null)
-// msg.setName(name);
-//
-// Tr.exit(msg);
-// return msg;
-// }
public String deep() {
String buff = "";