KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > remote > soap > LZSOAPPart


1 /* *****************************************************************************
2  * LZSOAPPart.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.remote.soap;
11
12 import java.math.BigDecimal JavaDoc;
13 import java.net.URI JavaDoc;
14 import javax.xml.namespace.QName JavaDoc;
15 import javax.xml.rpc.ParameterMode JavaDoc;
16 import javax.xml.rpc.ServiceException JavaDoc;
17 import org.apache.axis.Constants;
18 import org.apache.log4j.Logger;
19
20 public class LZSOAPPart
21 {
22     public static Logger mLogger = Logger.getLogger(LZSOAPPart.class);
23
24     String JavaDoc mName = null;
25     String JavaDoc mElement = null;
26     ComplexType mType = null;
27
28     // Only used when soap message is in request and is rpc
29
ParameterMode JavaDoc mParameterMode = ParameterMode.IN;
30
31     public LZSOAPPart(String JavaDoc name) {
32         mName = name;
33     }
34
35     public String JavaDoc getName() {
36         return mName;
37     }
38
39     public String JavaDoc getElement() {
40         return mElement;
41     }
42
43     public ComplexType getType() {
44         return mType;
45     }
46
47     public ParameterMode JavaDoc getParameterMode() {
48         return mParameterMode;
49     }
50
51     public void setName(String JavaDoc name) {
52         mName = name;
53     }
54
55     public void setElement(String JavaDoc element) {
56         mElement = element;
57     }
58
59     public void setType(ComplexType type) {
60         mType = type;
61     }
62
63     public void setParameterMode(ParameterMode JavaDoc parameterMode) {
64         mParameterMode = parameterMode;
65     }
66
67     /**
68      * Convert string to object value based on part type.
69      * @param param string to convert to object based on part type.
70      * @return object value of string based on part type.
71      * @throws SOAPException if value can't be converted.
72      */

73     public Object JavaDoc valueOf(String JavaDoc param)
74         throws ServiceException JavaDoc {
75
76         // TODO: [2004-06-28 pkang] return more values based on
77
// Constants.XSD_XXX
78
try {
79
80             //----------------------------------------------------------------
81
// From Constants.equals(QName first, QName second)
82
//
83
// The first QName is the current version of the name. The second
84
// qname is compared with the first considering all namespace uri
85
// versions.
86
//----------------------------------------------------------------
87

88             QName JavaDoc typeQName = mType.getName();
89             if (Constants.equals(Constants.XSD_INT, typeQName)) {
90                 return Integer.valueOf(param);
91             } else if (Constants.equals(Constants.XSD_LONG, typeQName)) {
92                 return Long.valueOf(param);
93             } else if (Constants.equals(Constants.XSD_FLOAT, typeQName)) {
94                 return Float.valueOf(param);
95             } else if (Constants.equals(Constants.XSD_DOUBLE, typeQName)) {
96                 return Double.valueOf(param);
97             } else if (Constants.equals(Constants.XSD_BOOLEAN, typeQName)) {
98                 return Boolean.valueOf(param);
99             } else if (Constants.equals(Constants.XSD_DECIMAL, typeQName)) {
100                 return new BigDecimal JavaDoc(param);
101             } else if (Constants.equals(Constants.XSD_SHORT, typeQName)) {
102                 return Short.valueOf(param);
103             } else if (Constants.equals(Constants.XSD_BYTE, typeQName)) {
104                 return Byte.valueOf(param);
105             } else if (Constants.equals(Constants.XSD_ANYURI, typeQName)) {
106                 return new URI JavaDoc(param);
107             }
108             return param;
109         } catch (Exception JavaDoc e) {
110             mLogger.error(e.getMessage());
111             throw new ServiceException JavaDoc(e.getMessage());
112         }
113     }
114
115     public void toXML(StringBuffer JavaDoc sb) {
116         sb.append("<part ")
117             .append(" name=\"").append(mName).append("\"")
118             .append(" element=\"").append(mElement).append("\"")
119             .append(" type=\"").append(mType.getName()).append("\"")
120             .append(" parameterMode=\"").append(mParameterMode).append("\"")
121             .append("/>");
122     }
123 }
124
Popular Tags