001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.providers.simplewebservice.rpc;
013:
014: import com.sun.portal.providers.simplewebservice.WebServiceDescriptor;
015: import com.sun.portal.providers.simplewebservice.SimpleWebServiceParameter;
016: import com.sun.portal.providers.simplewebservice.ParameterDescriptor;
017: import com.sun.portal.providers.simplewebservice.util.XList;
018: import com.sun.xml.rpc.encoding.CombinedSerializer;
019: import com.sun.xml.rpc.encoding.SingletonSerializerFactory;
020: import com.sun.xml.rpc.encoding.SingletonDeserializerFactory;
021: import com.sun.xml.rpc.encoding.literal.LiteralFragmentSerializer;
022:
023: import javax.xml.rpc.Call;
024: import javax.xml.rpc.Service;
025: import javax.xml.rpc.ServiceException;
026: import javax.xml.namespace.QName;
027: import javax.xml.soap.SOAPElement;
028: import java.util.Iterator;
029:
030: /**
031: *
032: * User: Ravikiran
033: * Date: Oct 11, 2003
034: * Time: 3:18:13 PM
035: */
036: class RPCCallHandler {
037: public Call createCall(Service service,
038: WebServiceDescriptor descriptor) throws ServiceException {
039:
040: ParameterDescriptor[] inParams = descriptor.getInputParams();
041: if (inParams != null) {
042: for (int i = 0; i < inParams.length; i++) {
043: registerSerializers(service, inParams[i], descriptor
044: .getInputEncodingStyleURI());
045: }
046: }
047:
048: ParameterDescriptor[] outParam = descriptor.getOutputParams();
049: if (outParam != null && (outParam.length > 0)) {
050:
051: registerSerializers(service, outParam[0], descriptor
052: .getOutputEncodingStyleURI());
053: }
054:
055: // Create call from service
056: String inputNamespace = descriptor.getInputNamespace();
057: if (inputNamespace == null)
058: inputNamespace = "";
059:
060: QName portQName = new QName(descriptor.getPortName());
061: QName methodQName = new QName(inputNamespace, descriptor
062: .getMethodName());
063:
064: Call call = service.createCall(portQName, methodQName);
065:
066: return call;
067: }
068:
069: /*
070: * For each of the input parameters and for the output parameter, register
071: * the corresponding serializers & deserializers. This also results in the
072: * the QName to Java class mapping being determined.
073: *
074: * This function also registers the serializer/deserializers of the constituent
075: * types, if the current parameter's element is a complex type or an array of
076: * complex type, by recursively calling itself.
077: */
078: protected void registerSerializers(Service service,
079: ParameterDescriptor inParam, String encodingToUse) {
080: // Register the serializers & deserializers for this parameter
081: registerParameterDescriptor(service, inParam, encodingToUse);
082:
083: if (inParam.isArrayType()) {
084:
085: if (!inParam.isSimpleTypeArray()) {
086: XList value = (XList) inParam.getValue();
087: Iterator iterator = value.iterator();
088: while (iterator.hasNext()) {
089: ParameterDescriptor elementParam = (ParameterDescriptor) iterator
090: .next();
091: if (!elementParam.isSimpleType()) {
092: registerSerializers(service, elementParam,
093: encodingToUse);
094: }
095: }
096: }
097: } else {
098: if (!inParam.isSimpleType()) {
099: XList value = (XList) inParam.getValue();
100: Iterator iterator = value.iterator();
101: while (iterator.hasNext()) {
102: ParameterDescriptor elementParam = (ParameterDescriptor) iterator
103: .next();
104: if (!elementParam.isSimpleType()) {
105: registerSerializers(service, elementParam,
106: encodingToUse);
107: }
108: }
109: }
110: }
111: }
112:
113: /*
114: * Registers the serializers/deserializers for the type of the parameter.
115: */
116: protected void registerParameterDescriptor(Service service,
117: ParameterDescriptor param, String encodingToUse) {
118:
119: if (param.isArrayType()) {
120: // ArrayTypeName of a ParameterDescriptor holds the type name of the elements
121: // of the array. Hence, if the type name of the elements is primitive, then
122: // register this param as primitive type array, else as a complex type array,
123: // using the appropriate registration handler.
124: if (param.isSimpleTypeArray()) {
125: SimpleTypeHandler simpleHandler = TypeHandlerFactory
126: .getSimpleTypeHandler(service, encodingToUse);
127: simpleHandler.registerSimpleTypeArrayHandlers(param);
128:
129: } else {
130: ComplexTypeHandler complexHandler = TypeHandlerFactory
131: .getComplexTypeHandler(service, encodingToUse);
132:
133: complexHandler
134: .registerComplexTypeHandler(
135: param,
136: ComplexTypeHandler.COMPLEX_ARRAY_TYPE_SERIALIZER);
137: }
138:
139: } else {
140: // Determine if it is a complex type or a simple type.
141: // Register accordingly using the appropriate registration handler.
142: if (!param.isSimpleType()) {
143: ComplexTypeHandler complexHandler = TypeHandlerFactory
144: .getComplexTypeHandler(service, encodingToUse);
145:
146: complexHandler.registerComplexTypeHandler(param,
147: ComplexTypeHandler.COMPLEX_TYPE_SERIALIZER);
148: } else {
149: SimpleTypeHandler simpleHandler = TypeHandlerFactory
150: .getSimpleTypeHandler(service, encodingToUse);
151: simpleHandler.registerSimpleTypeHandlers(param);
152: }
153: }
154: }
155:
156: }
|