1 57 58 package org.apache.soap.encoding.literalxml; 59 60 import java.io.*; 61 import org.w3c.dom.*; 62 import org.apache.soap.util.*; 63 import org.apache.soap.util.xml.*; 64 import org.apache.soap.*; 65 import org.apache.soap.rpc.*; 66 67 76 public class XMLParameterSerializer implements Serializer, Deserializer 77 { 78 public void marshall(String inScopeEncStyle, Class javaType, Object src, 79 Object context, Writer sink, NSStack nsStack, 80 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 81 throws IllegalArgumentException , IOException 82 { 83 nsStack.pushScope(); 84 85 Parameter param = (Parameter)src; 86 Class type = param.getType(); 87 String name = param.getName(); 88 89 if (type == Element.class) 90 { 91 Element el = (Element)param.getValue(); 92 93 sink.write('<' + name); 94 95 if (inScopeEncStyle == null 96 || !inScopeEncStyle.equals(Constants.NS_URI_LITERAL_XML)) 97 { 98 String soapEnvNSPrefix = nsStack.getPrefixFromURI( 101 Constants.NS_URI_SOAP_ENV, sink); 102 103 sink.write(' ' + soapEnvNSPrefix + ':' + 104 Constants.ATTR_ENCODING_STYLE + "=\"" + 105 Constants.NS_URI_LITERAL_XML + '\"'); 106 } 107 108 sink.write('>' + StringUtils.lineSeparator); 109 Utils.marshallNode(el, sink); 110 sink.write(StringUtils.lineSeparator + "</" + name + '>'); 111 } 112 else 113 { 114 throw new IllegalArgumentException ("I only know how to serialize " + 115 "an 'org.w3c.dom.Element'."); 116 } 117 118 nsStack.popScope(); 119 } 120 121 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 122 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 123 throws IllegalArgumentException 124 { 125 Element paramEl = (Element)src; 126 String name = paramEl.getTagName(); 127 Element el = DOMUtils.getFirstChildElement(paramEl); 128 Parameter parameter = new Parameter(name, 129 Element.class, 130 el, 131 null); 132 133 return new Bean(Parameter.class, parameter); 134 } 135 } 136 | Popular Tags |