MapSerializerpublic class MapSerializer extends Object implements org.apache.axis.encoding.SerializerA MapSerializer is be used to serialize and
deserialize Maps using the SOAP-ENC
encoding style. |
Fields Summary |
---|
protected static Log | log | private static final QName | QNAME_KEY | private static final QName | QNAME_ITEM | private static final QName | QNAME_VALUE | private static final QName | QNAME_ITEMTYPE |
Methods Summary |
---|
public java.lang.String | getMechanismType() return Constants.AXIS_SAX;
| public void | serialize(javax.xml.namespace.QName name, org.xml.sax.Attributes attributes, java.lang.Object value, org.apache.axis.encoding.SerializationContext context)Serialize a Map
Walk the collection of keys, serializing each key/value pair
inside an - element.
if (!(value instanceof Map))
throw new IOException(
Messages.getMessage("noMap00", "MapSerializer", value.getClass().getName()));
Map map = (Map)value;
context.startElement(name, attributes);
AttributesImpl itemsAttributes = new AttributesImpl();
String encodingURI = context.getMessageContext().getEncodingStyle();
String encodingPrefix = context.getPrefixForURI(encodingURI);
String soapPrefix = context.getPrefixForURI(Constants.SOAP_MAP.getNamespaceURI());
itemsAttributes.addAttribute(encodingURI, "type", encodingPrefix + ":type",
"CDATA", encodingPrefix + ":Array");
itemsAttributes.addAttribute(encodingURI, "arrayType", encodingPrefix + ":arrayType",
"CDATA", soapPrefix + ":item["+map.size()+"]");
for (Iterator i = map.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry) i.next();
Object key = entry.getKey();
Object val = entry.getValue();
context.startElement(QNAME_ITEM, null);
// Since the Key and Value can be any type, send type info
context.serialize(QNAME_KEY, null, key, null, null, Boolean.TRUE);
context.serialize(QNAME_VALUE, null, val, null, null, Boolean.TRUE);
context.endElement();
}
context.endElement();
| public org.w3c.dom.Element | writeSchema(java.lang.Class javaType, org.apache.axis.wsdl.fromJava.Types types)Return XML schema for the specified type, suitable for insertion into
the <types> element of a WSDL document, or underneath an
<element> or <attribute> declaration.
Element complexType = types.createElement("complexType");
complexType.setAttribute("name", "Map");
Element seq = types.createElement("sequence");
complexType.appendChild(seq);
Element element = types.createElement("element");
element.setAttribute("name", "item");
element.setAttribute("minOccurs", "0");
element.setAttribute("maxOccurs", "unbounded");
element.setAttribute("type", types.getQNameString(new QName(Constants.NS_URI_XMLSOAP,"mapItem")));
seq.appendChild(element);
Element itemType = types.createElement("complexType");
itemType.setAttribute("name", "mapItem");
Element seq2 = types.createElement("sequence");
itemType.appendChild(seq2);
Element element2 = types.createElement("element");
element2.setAttribute("name", "key");
element2.setAttribute("nillable", "true");
element2.setAttribute("type", "xsd:anyType");
seq2.appendChild(element2);
Element element3 = types.createElement("element");
element3.setAttribute("name", "value");
element3.setAttribute("nillable", "true");
element3.setAttribute("type", "xsd:anyType");
seq2.appendChild(element3);
types.writeSchemaTypeDecl(QNAME_ITEMTYPE, itemType);
return complexType;
|
|