1 57 58 package org.apache.wsif.wsdl.extensions.format; 59 60 import java.io.Serializable ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 64 import javax.wsdl.extensions.ExtensionRegistry; 65 import javax.wsdl.factory.WSDLFactory; 66 import javax.wsdl.xml.WSDLReader; 67 import javax.xml.namespace.QName ; 68 69 import org.apache.wsif.logging.Trc; 70 import org.w3c.dom.Element ; 71 72 import com.ibm.wsdl.Constants; 73 import com.ibm.wsdl.util.xml.DOMUtils; 74 import com.ibm.wsdl.util.xml.QNameUtils; 75 76 82 public class FormatBindingSerializer 83 implements 84 javax.wsdl.extensions.ExtensionDeserializer, 85 javax.wsdl.extensions.ExtensionSerializer, 86 Serializable { 87 private static final long serialVersionUID = 1L; 88 91 public FormatBindingSerializer() { 92 super(); 93 Trc.entry(this); 94 Trc.exit(); 95 } 96 97 100 public void marshall( 101 Class parentType, 102 QName elementType, 103 javax.wsdl.extensions.ExtensibilityElement extension, 104 java.io.PrintWriter pw, 105 javax.wsdl.Definition def, 106 javax.wsdl.extensions.ExtensionRegistry extReg) 107 throws javax.wsdl.WSDLException { 108 Trc.entry(this, parentType, elementType, extension, pw, def, extReg); 109 110 if (extension == null) { 111 Trc.exit(); 112 return; 113 } 114 115 if (extension instanceof TypeMapping) { 116 TypeMapping typeMapping = (TypeMapping) extension; 117 pw.print(" <format:typeMapping"); 118 119 String style = typeMapping.getStyle(); 120 if (style != null) 121 DOMUtils.printAttribute("style", style, pw); 122 String encoding = typeMapping.getEncoding(); 123 if (encoding != null) 124 DOMUtils.printAttribute("encoding", encoding, pw); 125 pw.println(">"); 126 127 List maps = typeMapping.getMaps(); 128 Iterator iterator = maps.iterator(); 129 while (iterator.hasNext()) { 130 TypeMap typeMap = (TypeMap) iterator.next(); 131 pw.print(" <format:typeMap"); 132 133 QName elementName = typeMap.getElementName(); 135 if (elementName != null) { 136 String prefix = 137 def.getPrefix(elementName.getNamespaceURI()); 138 DOMUtils.printAttribute( 139 "elementName", 140 prefix + ":" + elementName.getLocalPart(), 141 pw); 142 } 143 QName typeName = typeMap.getTypeName(); 144 if (typeName != null) { 145 String prefix = def.getPrefix(typeName.getNamespaceURI()); 146 DOMUtils.printAttribute( 147 "typeName", 148 prefix + ":" + typeName.getLocalPart(), 149 pw); 150 } 151 String formatType = typeMap.getFormatType(); 152 if (formatType != null) 153 DOMUtils.printAttribute("formatType", formatType, pw); 154 pw.println("/>"); 155 Boolean required = extension.getRequired(); 156 157 if (required != null) { 158 DOMUtils.printQualifiedAttribute( 159 Constants.Q_ATTR_REQUIRED, 160 required.toString(), 161 def, 162 pw); 163 } 164 165 } 166 pw.println(" </format:typeMapping>"); 167 168 } 169 Trc.exit(); 170 } 171 172 175 public void registerSerializer(ExtensionRegistry registry) { 176 Trc.entry(this, registry); 177 178 registry.registerSerializer( 180 javax.wsdl.Binding.class, 181 FormatBindingConstants.Q_ELEM_FORMAT_BINDING, 182 this); 183 184 registry.registerDeserializer( 185 javax.wsdl.Binding.class, 186 FormatBindingConstants.Q_ELEM_FORMAT_BINDING, 187 this); 188 Trc.exit(); 189 } 190 191 194 public javax.wsdl.extensions.ExtensibilityElement unmarshall( 195 Class parentPart, 196 javax.xml.namespace.QName elementPart, 197 org.w3c.dom.Element el, 198 javax.wsdl.Definition def, 199 javax.wsdl.extensions.ExtensionRegistry extReg) 200 throws javax.wsdl.WSDLException { 201 Trc.entry(this, parentPart, elementPart, el, def, extReg); 202 203 javax.wsdl.extensions.ExtensibilityElement returnValue = null; 204 205 if (FormatBindingConstants.Q_ELEM_FORMAT_BINDING.equals(elementPart)) { 206 TypeMapping typeMapping = new TypeMapping(); 207 208 String style = DOMUtils.getAttribute(el, "style"); 209 String encoding = DOMUtils.getAttribute(el, "encoding"); 210 String requiredStr = 211 DOMUtils.getAttributeNS( 212 el, 213 Constants.NS_URI_WSDL, 214 Constants.ATTR_REQUIRED); 215 216 if (style != null) { 217 typeMapping.setStyle(style); 218 } 219 if (encoding != null) { 220 typeMapping.setEncoding(encoding); 221 } 222 223 Element tempEl = DOMUtils.getFirstChildElement(el); 224 while (tempEl != null) { 225 if (QNameUtils 226 .matches( 227 FormatBindingConstants.Q_ELEM_FORMAT_BINDING_MAP, 228 tempEl)) { 229 TypeMap typeMap = new TypeMap(); 230 231 QName qElementName = 232 DOMUtils.getQualifiedAttributeValue( 233 tempEl, 234 "elementName", 235 "typeMap", 236 false); 237 QName qTypeName = 238 DOMUtils.getQualifiedAttributeValue( 239 tempEl, 240 "typeName", 241 "typeMap", 242 false); 243 244 String formatType = 245 DOMUtils.getAttribute(tempEl, "formatType"); 246 if (qElementName != null) { 247 typeMap.setElementName(qElementName); 248 } 249 if (qTypeName != null) { 250 typeMap.setTypeName(qTypeName); 251 } 252 if (formatType != null) { 253 typeMap.setFormatType(formatType); 254 } 255 typeMapping.addMap(typeMap); 256 } 257 tempEl = DOMUtils.getNextSiblingElement(tempEl); 258 } 259 Trc.exit(typeMapping); 260 return typeMapping; 261 } 262 Trc.exit(returnValue); 263 return returnValue; 264 } 265 } | Popular Tags |