001: /* *****************************************************************************
002: * LZSOAPPart.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2007 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.remote.swf.soap;
011:
012: import java.math.BigDecimal;
013: import java.net.URI;
014: import javax.xml.namespace.QName;
015: import javax.xml.rpc.ParameterMode;
016: import javax.xml.rpc.ServiceException;
017: import org.apache.axis.Constants;
018: import org.apache.log4j.Logger;
019:
020: public class LZSOAPPart {
021: public static Logger mLogger = Logger.getLogger(LZSOAPPart.class);
022:
023: String mName = null;
024: String mElement = null;
025: ComplexType mType = null;
026:
027: // Only used when soap message is in request and is rpc
028: ParameterMode mParameterMode = ParameterMode.IN;
029:
030: public LZSOAPPart(String name) {
031: mName = name;
032: }
033:
034: public String getName() {
035: return mName;
036: }
037:
038: public String getElement() {
039: return mElement;
040: }
041:
042: public ComplexType getType() {
043: return mType;
044: }
045:
046: public ParameterMode getParameterMode() {
047: return mParameterMode;
048: }
049:
050: public void setName(String name) {
051: mName = name;
052: }
053:
054: public void setElement(String element) {
055: mElement = element;
056: }
057:
058: public void setType(ComplexType type) {
059: mType = type;
060: }
061:
062: public void setParameterMode(ParameterMode parameterMode) {
063: mParameterMode = parameterMode;
064: }
065:
066: /**
067: * Convert string to object value based on part type.
068: * @param param string to convert to object based on part type.
069: * @return object value of string based on part type.
070: * @throws SOAPException if value can't be converted.
071: */
072: public Object valueOf(String param) throws ServiceException {
073:
074: // TODO: [2007-06-28 pkang] return more values based on
075: // Constants.XSD_XXX
076: try {
077:
078: //----------------------------------------------------------------
079: // From Constants.equals(QName first, QName second)
080: //
081: // The first QName is the current version of the name. The second
082: // qname is compared with the first considering all namespace uri
083: // versions.
084: //----------------------------------------------------------------
085:
086: QName typeQName = mType.getName();
087: if (Constants.equals(Constants.XSD_INT, typeQName)) {
088: return Integer.valueOf(param);
089: } else if (Constants.equals(Constants.XSD_LONG, typeQName)) {
090: return Long.valueOf(param);
091: } else if (Constants.equals(Constants.XSD_FLOAT, typeQName)) {
092: return Float.valueOf(param);
093: } else if (Constants
094: .equals(Constants.XSD_DOUBLE, typeQName)) {
095: return Double.valueOf(param);
096: } else if (Constants.equals(Constants.XSD_BOOLEAN,
097: typeQName)) {
098: return Boolean.valueOf(param);
099: } else if (Constants.equals(Constants.XSD_DECIMAL,
100: typeQName)) {
101: return new BigDecimal(param);
102: } else if (Constants.equals(Constants.XSD_SHORT, typeQName)) {
103: return Short.valueOf(param);
104: } else if (Constants.equals(Constants.XSD_BYTE, typeQName)) {
105: return Byte.valueOf(param);
106: } else if (Constants
107: .equals(Constants.XSD_ANYURI, typeQName)) {
108: return new URI(param);
109: }
110: return param;
111: } catch (Exception e) {
112: mLogger.error(e.getMessage());
113: throw new ServiceException(e.getMessage());
114: }
115: }
116:
117: public void toXML(StringBuffer sb) {
118: sb.append("<part ").append(" name=\"").append(mName).append(
119: "\"").append(" element=\"").append(mElement).append(
120: "\"").append(" type=\"").append(mType.getName())
121: .append("\"").append(" parameterMode=\"").append(
122: mParameterMode).append("\"").append("/>");
123: }
124: }
|