1 57 58 package org.apache.soap.server; 59 60 import java.util.*; 61 import java.io.*; 62 import org.w3c.dom.*; 63 import org.apache.soap.util.Bean; 64 import org.apache.soap.util.StringUtils; 65 import org.apache.soap.util.xml.*; 66 import org.apache.soap.Constants; 67 import org.apache.soap.rpc.SOAPContext; 68 import org.apache.soap.encoding.*; 69 import org.apache.soap.encoding.soapenc.SoapEncUtils; 70 71 77 public class TypeMappingSerializer implements Serializer, Deserializer { 78 89 public void marshall (String inScopeEncStyle, Class javaType, Object src, 90 Object context, Writer sink, NSStack nsStack, 91 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 92 throws IllegalArgumentException , IOException { 93 TypeMapping tm = (TypeMapping) src; 94 95 nsStack.pushScope (); 96 SoapEncUtils.generateStructureHeader (inScopeEncStyle, javaType, context, 97 sink, nsStack, xjmr); 98 sink.write (StringUtils.lineSeparator); 99 100 String xsiPrefix = nsStack.getPrefixFromURI (Constants.NS_URI_CURRENT_SCHEMA_XSI); 102 String xsdPrefix = nsStack.getPrefixFromURI (Constants.NS_URI_CURRENT_SCHEMA_XSD); 103 if ((xsiPrefix == null) || (xsdPrefix == null)) { 104 throw new IllegalArgumentException ("required namespace names '" + 105 Constants.NS_URI_CURRENT_SCHEMA_XSI + 106 "' and/or '" + 107 Constants.NS_URI_CURRENT_SCHEMA_XSD + 108 "' is not defined."); 109 } 110 111 if (tm.encodingStyle != null) { 112 sink.write ("<encodingStyle " + xsiPrefix + ":type=\"" + xsdPrefix + 113 ":string\">" + tm.encodingStyle + "</encodingStyle>"); 114 sink.write (StringUtils.lineSeparator); 115 } 116 117 if (tm.elementType != null) { 118 sink.write ("<elementType-ns " + xsiPrefix + ":type=\"" + xsdPrefix + 119 ":string\">" + tm.elementType.getNamespaceURI () + 120 "</elementType-ns>"); 121 sink.write (StringUtils.lineSeparator); 122 123 sink.write ("<elementType-lp " + xsiPrefix + ":type=\"" + xsdPrefix + 124 ":string\">" + tm.elementType.getLocalPart () + 125 "</elementType-lp>"); 126 sink.write (StringUtils.lineSeparator); 127 } 128 129 if (tm.javaType != null) { 130 sink.write ("<javaType " + xsiPrefix + ":type=\"" + xsdPrefix + 131 ":string\">" + tm.javaType + "</javaType>"); 132 sink.write (StringUtils.lineSeparator); 133 } 134 135 if (tm.xml2JavaClassName != null) { 136 sink.write ("<xml2JavaClassName " + xsiPrefix + ":type=\"" + xsdPrefix + 137 ":string\">" + tm.xml2JavaClassName + 138 "</xml2JavaClassName>"); 139 sink.write (StringUtils.lineSeparator); 140 } 141 142 if (tm.java2XMLClassName != null) { 143 sink.write ("<java2XMLClassName " + xsiPrefix + ":type=\"" + xsdPrefix + 144 ":string\">" + tm.java2XMLClassName + 145 "</java2XMLClassName>"); 146 sink.write (StringUtils.lineSeparator); 147 } 148 149 sink.write ("</" + context + '>'); 150 nsStack.popScope (); 151 } 152 153 154 157 public Bean unmarshall (String inScopeEncStyle, QName elementType, Node src, 158 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 159 throws IllegalArgumentException { 160 NodeList nl = src.getChildNodes (); 161 int nKids = nl.getLength (); 162 163 String encodingStyle = null; 165 String elTypeNS = null; 166 String elTypeLP = null; 167 QName qname = null; 168 String javaType = null; 169 String java2XMLClassName = null; 170 String xml2JavaClassName = null; 171 172 for (int i = 0; i < nKids; i++) { 173 Node n = nl.item (i); 174 if (n.getNodeType () != Node.ELEMENT_NODE) { 175 continue; 176 } 177 Element e = (Element) n; 178 String tagName = e.getTagName (); 179 String elData = DOMUtils.getChildCharacterData (e); 180 if (tagName.equals ("encodingStyle")) { 181 encodingStyle = elData; 182 } else if (tagName.equals ("elementType-ns")) { 183 elTypeNS = elData; 184 } else if (tagName.equals ("elementType-lp")) { 185 elTypeLP = elData; 186 } else if (tagName.equals ("javaType")) { 187 javaType = elData; 188 } else if (tagName.equals ("java2XMLClassName")) { 189 java2XMLClassName = elData; 190 } else if (tagName.equals ("xml2JavaClassName")) { 191 xml2JavaClassName = elData; 192 } else { 193 throw new IllegalArgumentException ("unknown element '" + 194 tagName + "' while " + 195 "unmarshalling a TypeMapping"); 196 } 197 } 198 199 if (elTypeNS != null && elTypeLP != null) { 200 qname = new QName (elTypeNS, elTypeLP); 201 } 202 203 return new Bean (TypeMapping.class, 204 new TypeMapping (encodingStyle, 205 qname, 206 javaType, 207 java2XMLClassName, xml2JavaClassName)); 208 } 209 } 210 | Popular Tags |