1 4 5 9 10 11 65 66 package org.openlaszlo.remote.soap.encoding; 67 68 import javax.xml.namespace.QName ; 69 import java.io.IOException ; 70 import org.apache.axis.encoding.SerializationContext; 71 import org.apache.axis.encoding.Serializer; 72 import org.apache.axis.wsdl.fromJava.Types; 73 import org.w3c.dom.Element ; 74 import org.w3c.dom.Node ; 75 import org.w3c.dom.NodeList ; 76 import org.xml.sax.Attributes ; 77 import org.apache.log4j.Logger; 78 import org.openlaszlo.remote.soap.ArrayWrapper; 79 import org.xml.sax.helpers.AttributesImpl ; 80 import java.util.ArrayList ; 81 import org.openlaszlo.remote.soap.*; 82 import org.apache.axis.MessageContext; 83 import org.apache.axis.schema.SchemaVersion; 84 import org.apache.axis.soap.SOAPConstants; 85 import org.apache.axis.Constants; 86 87 public class LZArraySerializer implements Serializer { 88 89 private static Logger mLogger = Logger.getLogger(LZArraySerializer.class); 90 91 public static String MECHANISM_TYPE = "LZArrayMechanism"; 92 93 public String getMechanismType() { return MECHANISM_TYPE; } 94 95 public void serialize(QName name, Attributes attributes, 96 Object value, SerializationContext context) 97 throws IOException 98 { 99 mLogger.debug("serialize(" + name + "," + attributes + 100 "," + value + "," + context + ")"); 101 102 105 MessageContext msgContext = context.getMessageContext(); 106 SchemaVersion schema = SchemaVersion.SCHEMA_2001; 107 SOAPConstants soap = SOAPConstants.SOAP11_CONSTANTS; 108 boolean encoded = true; 109 if (msgContext != null) { 110 encoded = msgContext.isEncoded(); 111 schema = msgContext.getSchemaVersion(); 112 soap = msgContext.getSOAPConstants(); 113 } 114 115 ArrayWrapper aw = (ArrayWrapper)((ArrayList )value).get(0); 116 Element el = aw.getElement(); 117 ComplexType ct = aw.getType(); 118 119 NodeList list = el.getChildNodes(); 120 int len = getArrayLen(list); 121 122 String brackets = ""; 123 if (encoded) { 124 if (soap == SOAPConstants.SOAP12_CONSTANTS) 125 brackets += len; 126 else 127 brackets += "[" + len + "]"; 128 129 AttributesImpl attrs; 130 if (attributes == null) { 131 attrs = new AttributesImpl (); 132 } else { 133 attrs = new AttributesImpl (attributes); 134 } 135 136 QName componentQName = ct.getArrayItemTypeQName(); 137 String compType = context.attributeQName2String(componentQName); 138 139 if (attrs.getIndex(soap.getEncodingURI(), soap.getAttrItemType()) == -1) { 140 String encprefix = 141 context.getPrefixForURI(soap.getEncodingURI()); 142 143 if (soap != SOAPConstants.SOAP12_CONSTANTS) { 144 compType = compType + brackets; 145 146 attrs.addAttribute(soap.getEncodingURI(), 147 soap.getAttrItemType(), 148 encprefix + ":arrayType", 149 "CDATA", 150 compType); 151 152 } else { 153 attrs.addAttribute(soap.getEncodingURI(), 154 soap.getAttrItemType(), 155 encprefix + ":itemType", 156 "CDATA", 157 compType); 158 159 attrs.addAttribute(soap.getEncodingURI(), 160 "arraySize", 161 encprefix + ":arraySize", 162 "CDATA", 163 brackets); 164 } 165 } 166 167 int typeI = attrs.getIndex(schema.getXsiURI(), 184 "type"); 185 if (typeI != -1) { 186 String qname = 187 context.getPrefixForURI(schema.getXsiURI(), 188 "xsi") + ":type"; 189 QName soapArray; 190 if (soap == SOAPConstants.SOAP12_CONSTANTS) { 191 soapArray = Constants.SOAP_ARRAY12; 192 } else { 193 soapArray = Constants.SOAP_ARRAY; 194 } 195 196 attrs.setAttribute(typeI, 197 schema.getXsiURI(), 198 "type", 199 qname, 200 "CDATA", 201 context.qName2String(soapArray)); 202 } 203 attributes = attrs; 204 } 205 206 context.startElement(name, attributes); 207 for (int i=0; i < list.getLength(); i++) { 208 Node node = (Node )list.item(i); 210 if ( node.getNodeType() == Node.ELEMENT_NODE ) { 211 context.writeDOMElement((Element )node); 212 } 213 } 214 context.endElement(); 215 } 216 217 220 public int getArrayLen(NodeList list){ 221 int count=0; 222 for (int i=0; i < list.getLength(); i++) { 223 Node node = (Node )list.item(i); 224 if ( node.getNodeType() == Node.ELEMENT_NODE ) ++count; 225 } 226 return count; 227 } 228 229 230 233 public Element writeSchema(Class javaType, Types types) throws Exception { 234 throw new Exception ("unimplemented"); 235 } 236 } 237 | Popular Tags |