001: /**
002: * $Id: SerializationContext.java,v 1.2 2003/12/01 10:47:40 vv138407 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.providers.simplewebservice.rpc;
014:
015: import javax.xml.namespace.QName;
016:
017: import com.sun.xml.rpc.encoding.CombinedSerializer;
018: import com.sun.xml.rpc.encoding.simpletype.SimpleTypeEncoder;
019: import com.sun.xml.rpc.encoding.simpletype.XSDByteEncoder;
020: import com.sun.xml.rpc.encoding.simpletype.XSDBooleanEncoder;
021: import com.sun.xml.rpc.encoding.simpletype.XSDDoubleEncoder;
022: import com.sun.xml.rpc.encoding.simpletype.XSDFloatEncoder;
023: import com.sun.xml.rpc.encoding.simpletype.XSDIntegerEncoder;
024: import com.sun.xml.rpc.encoding.simpletype.XSDIntEncoder;
025: import com.sun.xml.rpc.encoding.simpletype.XSDLongEncoder;
026: import com.sun.xml.rpc.encoding.simpletype.XSDShortEncoder;
027: import com.sun.xml.rpc.encoding.simpletype.XSDStringEncoder;
028: import com.sun.xml.rpc.wsdl.document.schema.SchemaConstants;
029: import com.sun.portal.providers.simplewebservice.ParameterDescriptor;
030: import com.sun.portal.providers.simplewebservice.util.XList;
031: import com.sun.portal.providers.simplewebservice.util.SimpleWebServiceTypeConstants;
032:
033: /*
034: * Utility class to create the serialization context
035: * information for the given parameter
036: */
037:
038: class SerializationContext {
039:
040: // SimpleTypeHandler specific properties
041: SimpleTypeEncoder primitiveTypeEncoder;
042: CombinedSerializer serializer;
043:
044: // SimpleType and ComplexType Handler properties
045: Class typeHolderClass;
046: QName typeQName;
047: QName typeArrayQName;
048: String registryKeyName;
049:
050: SerializationContext(SimpleTypeEncoder encoder,
051: Class proxyClassName, QName typeQName, QName arrayTypeQName) {
052: this .primitiveTypeEncoder = encoder;
053: this .typeHolderClass = proxyClassName;
054: this .typeQName = typeQName;
055: this .typeArrayQName = arrayTypeQName;
056: }
057:
058: SerializationContext(Class proxyClassName, QName typeQName,
059: QName arrayTypeQName) {
060: this .typeHolderClass = proxyClassName;
061: this .typeQName = typeQName;
062: this .typeArrayQName = arrayTypeQName;
063: }
064:
065: public static SerializationContext createSimpleSerializationContext(
066: ParameterDescriptor descriptor) {
067:
068: SerializationContext context = null;
069: String nmSpace = null;
070: String arrayTypeName = null;
071: String arrayElementTypeName = null;
072:
073: if (descriptor.isArrayType()) {
074: XList value = (XList) descriptor.getValue();
075: // Namespace of Array type
076: nmSpace = value.getTargetNameSpace();
077: // Array type name
078: arrayTypeName = value.getComplexTypeName();
079: // Array element's type name
080: arrayElementTypeName = descriptor.getArrayTypeName();
081:
082: } else {
083: nmSpace = "";
084: arrayTypeName = "";
085: arrayElementTypeName = descriptor.getType().getName();
086: arrayElementTypeName = arrayElementTypeName.substring(
087: arrayElementTypeName.lastIndexOf('.') + 1)
088: .toLowerCase();
089: }
090:
091: if (arrayElementTypeName
092: .equals(SimpleWebServiceTypeConstants.STRING)) {
093: context = new SerializationContext(XSDStringEncoder
094: .getInstance(), // Encoder to use for array element
095: java.lang.String.class, // Java class of array element type
096: new QName(nmSpace, arrayTypeName), // XML type of array
097: SchemaConstants.QNAME_TYPE_STRING); // XML type of array element
098: } else if (arrayElementTypeName
099: .equals(SimpleWebServiceTypeConstants.FLOAT)) {
100: context = new SerializationContext(XSDFloatEncoder
101: .getInstance(), float.class, new QName(nmSpace,
102: arrayTypeName), SchemaConstants.QNAME_TYPE_FLOAT);
103: } else if (arrayElementTypeName
104: .equals(SimpleWebServiceTypeConstants.INT)
105: || arrayElementTypeName
106: .equals(SimpleWebServiceTypeConstants.INTEGER)) {
107: context = new SerializationContext(XSDIntEncoder
108: .getInstance(), int.class, new QName(nmSpace,
109: arrayTypeName), SchemaConstants.QNAME_TYPE_INT);
110: } else if (arrayElementTypeName
111: .equals(SimpleWebServiceTypeConstants.DOUBLE)) {
112: context = new SerializationContext(XSDDoubleEncoder
113: .getInstance(), double.class, new QName(nmSpace,
114: arrayTypeName), SchemaConstants.QNAME_TYPE_DOUBLE);
115: } else if (arrayElementTypeName
116: .equals(SimpleWebServiceTypeConstants.BOOLEAN)) {
117: context = new SerializationContext(XSDBooleanEncoder
118: .getInstance(), boolean.class, new QName(nmSpace,
119: arrayTypeName), SchemaConstants.QNAME_TYPE_BOOLEAN);
120: } else if (arrayElementTypeName
121: .equals(SimpleWebServiceTypeConstants.LONG)) {
122: context = new SerializationContext(XSDLongEncoder
123: .getInstance(), long.class, new QName(nmSpace,
124: arrayTypeName), SchemaConstants.QNAME_TYPE_LONG);
125: } else if (arrayElementTypeName
126: .equals(SimpleWebServiceTypeConstants.BYTE)) {
127: context = new SerializationContext(XSDByteEncoder
128: .getInstance(), byte.class, new QName(nmSpace,
129: arrayTypeName), SchemaConstants.QNAME_TYPE_BYTE);
130: } else if (arrayElementTypeName
131: .equals(SimpleWebServiceTypeConstants.SHORT)) {
132: context = new SerializationContext(XSDShortEncoder
133: .getInstance(), short.class, new QName(nmSpace,
134: arrayTypeName), SchemaConstants.QNAME_TYPE_SHORT);
135: }
136: //System.out.println(context.simpleToString());
137: return context;
138: }
139:
140: public static SerializationContext createComplexSerializationContext(
141: ParameterDescriptor descriptor) {
142:
143: SerializationContext context = null;
144:
145: XList value = (XList) descriptor.getValue();
146: // Note that the value of type attribute in <part name ="xyz" type = "complexType">
147: // is what we need to register. This is the name of the descriptor in complexType
148: // descriptor's case. Also, in our case the namespace is in the XList.
149: String typeName = value.getComplexTypeName();
150: String typeNameSpace = value.getTargetNameSpace();
151:
152: QName complexParamArrayQName = null;
153: QName complexParamQName = null;
154:
155: if (descriptor.isArrayType()) {
156: complexParamQName = new QName(typeNameSpace, typeName);
157: complexParamArrayQName = new QName(typeNameSpace,
158: descriptor.getArrayTypeName());
159: } else {
160: complexParamQName = new QName(typeNameSpace, typeName);
161: }
162:
163: context = new SerializationContext(value.getClass(), // holder/proxy class
164: complexParamQName, // complextype QName
165: complexParamArrayQName); // complextype array's QName
166:
167: //System.out.println(context.complexToString());
168: return context;
169: }
170:
171: String simpleToString() {
172: return "Encoder is " + primitiveTypeEncoder
173: + ", \nElement class name is "
174: + typeHolderClass.toString()
175: + ", \nQName of array class is " + typeQName.toString()
176: + ", \nQName of element class is "
177: + typeArrayQName.toString();
178: }
179:
180: String complexToString() {
181: return "\nQName of element class is " + typeQName.toString();
182:
183: }
184:
185: }
|