1 57 58 package org.apache.soap.encoding.xmi; 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 73 public class XMIParameterSerializer implements Serializer, Deserializer 74 { 75 XMIDeserializer xmideserializer = new XMIDeserializer(); 76 77 public void marshall(String inScopeEncStyle, Class javaType, Object src, 78 Object context, Writer sink, NSStack nsStack, 79 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 80 throws IllegalArgumentException , IOException 81 { 82 nsStack.pushScope(); 83 84 Parameter param = (Parameter)src; 85 Class type = param.getType(); 86 String name = param.getName(); 87 Object value = param.getValue(); 88 89 xjmr.marshall(Constants.NS_URI_XMI_ENC, type, value, name, 90 sink, nsStack, ctx); 91 92 nsStack.popScope(); 93 } 94 95 public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, 96 XMLJavaMappingRegistry xjmr, SOAPContext ctx) 97 throws IllegalArgumentException 98 { 99 100 Element paramEl = (Element)src; 101 String name = paramEl.getTagName(); 102 103 if (name.equals("java.lang.String")) 105 { 106 String st = paramEl.getAttribute("value"); 107 108 if (st == null) 109 throw new IllegalArgumentException ("Unable to unmarshall XMI string."); 110 111 Bean bean = new Bean(java.lang.String .class, new String (st)); 112 Parameter parameter = new Parameter(name, bean.type, bean.value, null); 113 114 return new Bean(Parameter.class, parameter); 115 } 116 else if (name.equals("null")) 118 { 119 String typeName = paramEl.getAttribute("type"); 120 121 try 122 { 123 Bean bean = new Bean(Class.forName(typeName), null); 124 Parameter parameter = new Parameter(name, bean.type, bean.value, null); 125 126 return new Bean(Parameter.class, parameter); 127 } 128 catch (Exception e) 129 { 130 throw new IllegalArgumentException ("Unable to unmarshall XMI null."); 131 } 132 } 133 134 Bean bean = xmideserializer.unmarshall(Constants.NS_URI_XMI_ENC, 135 elementType, paramEl, xjmr, ctx); 136 Parameter parameter = new Parameter(name, bean.type, bean.value, null); 137 138 return new Bean(Parameter.class, parameter); 139 140 } 141 } 142 | Popular Tags |