1 package org.apache.soap.encoding.soapenc; 2 3 import org.apache.soap.Constants; 4 import org.apache.soap.util.Bean; 5 import org.apache.soap.util.xml.*; 6 import org.apache.soap.rpc.SOAPContext; 7 import org.w3c.dom.*; 8 import java.io.*; 9 10 13 public class QNameSerializer implements Serializer, Deserializer 14 { 15 public void marshall(String inScopeEncStyle, Class javaType, Object src, 16 Object context, Writer sink, NSStack nsStack, 17 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 18 throws IllegalArgumentException , IOException 19 { 20 sink.write('<' + context.toString()); 21 22 QName qName = (QName)src; 23 24 String prefix = nsStack.getPrefixFromURI(qName.getNamespaceURI(), sink); 26 27 QName elementType = xjmr.queryElementType(javaType, 28 Constants.NS_URI_SOAP_ENC); 29 30 String xsiNSPrefix = 31 nsStack.getPrefixFromURI(Constants.NS_URI_CURRENT_SCHEMA_XSI, sink); 32 String elementTypeNSPrefix = 33 nsStack.getPrefixFromURI(elementType.getNamespaceURI(), sink); 34 35 sink.write(' ' + xsiNSPrefix + ':' + Constants.ATTR_TYPE + "=\"" + 36 elementTypeNSPrefix + ':' + 37 elementType.getLocalPart() + '\"'); 38 39 sink.write('>' + prefix + ':' + qName.getLocalPart()); 40 sink.write("</" + context.toString() + '>'); 41 } 42 43 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 44 XMLJavaMappingRegistry xjmr, 45 SOAPContext ctx) 46 throws IllegalArgumentException 47 { 48 Element root = (Element)src; 49 String value = DOMUtils.getChildCharacterData(root); 50 51 int idx = value.indexOf(":"); 52 if (idx <= 0) 53 throw new IllegalArgumentException ("No NamespaceURI while deserializing QName"); 54 55 String prefix = value.substring(0,idx); 56 String uri = DOMUtils.getNamespaceURIFromPrefix(src, prefix); 57 58 QName qName = new QName(uri, value.substring(idx + 1)); 59 60 return new Bean(QName.class, qName); 61 } 62 } 63 | Popular Tags |