1 package org.objectweb.celtix.bus.ws.addressing; 2 3 4 import java.util.List ; 5 import java.util.Map ; 6 7 import javax.xml.bind.JAXBContext; 8 import javax.xml.bind.JAXBException; 9 import javax.xml.namespace.QName ; 10 11 import org.objectweb.celtix.ws.addressing.AttributedURIType; 15 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 16 import org.objectweb.celtix.ws.addressing.ReferenceParametersType; 17 import org.objectweb.celtix.ws.addressing.RelatesToType; 18 import org.objectweb.celtix.ws.addressing.v200408.AttributedQName; 19 import org.objectweb.celtix.ws.addressing.v200408.AttributedURI; 20 import org.objectweb.celtix.ws.addressing.v200408.ObjectFactory; 21 import org.objectweb.celtix.ws.addressing.v200408.Relationship; 22 import org.objectweb.celtix.ws.addressing.v200408.ServiceNameType; 23 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 24 25 26 47 public class VersionTransformer { 48 49 protected static final String NATIVE_VERSION = Names.WSA_NAMESPACE_NAME; 50 51 54 public VersionTransformer() { 55 } 56 57 62 public boolean isSupported(String namespace) { 63 return NATIVE_VERSION.equals(namespace) 64 || Names200408.WSA_NAMESPACE_NAME.equals(namespace); 65 } 66 67 73 public static AttributedURI convert(AttributedURIType internal) { 74 AttributedURI exposed = 75 Names200408.WSA_OBJECT_FACTORY.createAttributedURI(); 76 String exposedValue = 77 Names.WSA_ANONYMOUS_ADDRESS.equals(internal.getValue()) 78 ? Names200408.WSA_ANONYMOUS_ADDRESS 79 : Names.WSA_NONE_ADDRESS.equals(internal.getValue()) 80 ? Names200408.WSA_NONE_ADDRESS 81 : internal.getValue(); 82 exposed.setValue(exposedValue); 83 putAll(exposed.getOtherAttributes(), internal.getOtherAttributes()); 84 return exposed; 85 } 86 87 93 public static AttributedURIType convert(AttributedURI exposed) { 94 AttributedURIType internal = 95 ContextUtils.WSA_OBJECT_FACTORY.createAttributedURIType(); 96 String internalValue = 97 Names200408.WSA_ANONYMOUS_ADDRESS.equals(exposed.getValue()) 98 ? Names.WSA_ANONYMOUS_ADDRESS 99 : Names200408.WSA_NONE_ADDRESS.equals(exposed.getValue()) 100 ? Names.WSA_NONE_ADDRESS 101 : exposed.getValue(); 102 internal.setValue(internalValue); 103 putAll(internal.getOtherAttributes(), exposed.getOtherAttributes()); 104 return internal; 105 } 106 107 114 public static org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType convert( 115 EndpointReferenceType internal) { 116 org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType exposed = 117 Names200408.WSA_OBJECT_FACTORY.createEndpointReferenceType(); 118 exposed.setAddress(convert(internal.getAddress())); 119 exposed.setReferenceParameters( 120 convert(internal.getReferenceParameters())); 121 QName serviceQName = EndpointReferenceUtils.getServiceName(internal); 122 if (serviceQName != null) { 123 ServiceNameType serviceName = 124 Names200408.WSA_OBJECT_FACTORY.createServiceNameType(); 125 serviceName.setValue(serviceQName); 126 exposed.setServiceName(serviceName); 127 } 128 String portLocalName = EndpointReferenceUtils.getPortName(internal); 129 if (portLocalName != null) { 130 String namespace = serviceQName.getNamespaceURI() != null 131 ? serviceQName.getNamespaceURI() 132 : Names.WSDL_INSTANCE_NAMESPACE_NAME; 133 QName portQName = 134 new QName (namespace, portLocalName); 135 AttributedQName portType = 136 Names200408.WSA_OBJECT_FACTORY.createAttributedQName(); 137 portType.setValue(portQName); 138 exposed.setPortType(portType); 139 } 140 addAll(exposed.getAny(), internal.getAny()); 142 putAll(exposed.getOtherAttributes(), internal.getOtherAttributes()); 143 return exposed; 144 } 145 146 153 public static EndpointReferenceType convert( 154 org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType exposed) { 155 EndpointReferenceType internal = 156 ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType(); 157 internal.setAddress(convert(exposed.getAddress())); 158 internal.setReferenceParameters( 159 convert(exposed.getReferenceParameters())); 160 ServiceNameType serviceName = exposed.getServiceName(); 161 AttributedQName portName = exposed.getPortType(); 162 if (serviceName != null && portName != null) { 163 EndpointReferenceUtils.setServiceAndPortName(internal, 164 serviceName.getValue(), 165 portName.getValue().getLocalPart()); 166 } 167 168 addAll(internal.getAny(), exposed.getAny()); 170 putAll(internal.getOtherAttributes(), exposed.getOtherAttributes()); 171 return internal; 172 } 173 174 181 public static org.objectweb.celtix.ws.addressing.v200408.ReferenceParametersType convert( 182 ReferenceParametersType internal) { 183 org.objectweb.celtix.ws.addressing.v200408.ReferenceParametersType exposed = 184 null; 185 if (internal != null) { 186 exposed = 187 Names200408.WSA_OBJECT_FACTORY.createReferenceParametersType(); 188 addAll(exposed.getAny(), internal.getAny()); 189 } 190 return exposed; 191 } 192 193 200 public static ReferenceParametersType convert( 201 org.objectweb.celtix.ws.addressing.v200408.ReferenceParametersType exposed) { 202 ReferenceParametersType internal = null; 203 if (exposed != null) { 204 internal = 205 ContextUtils.WSA_OBJECT_FACTORY.createReferenceParametersType(); 206 addAll(internal.getAny(), exposed.getAny()); 207 } 208 return internal; 209 } 210 211 217 public static Relationship convert(RelatesToType internal) { 218 Relationship exposed = null; 219 if (internal != null) { 220 exposed = Names200408.WSA_OBJECT_FACTORY.createRelationship(); 221 exposed.setValue(internal.getValue()); 222 String internalRelationshipType = internal.getRelationshipType(); 223 if (internalRelationshipType != null) { 224 QName exposedRelationshipType = 225 Names.WSA_RELATIONSHIP_REPLY.equals( 226 internalRelationshipType) 227 ? new QName (Names200408.WSA_NAMESPACE_NAME, 228 Names.WSA_REPLY_NAME) 229 : new QName (internalRelationshipType); 230 exposed.setRelationshipType(exposedRelationshipType); 231 } 232 putAll(exposed.getOtherAttributes(), internal.getOtherAttributes()); 233 } 234 return exposed; 235 } 236 237 243 public static RelatesToType convert(Relationship exposed) { 244 RelatesToType internal = null; 245 if (exposed != null) { 246 internal = ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType(); 247 internal.setValue(exposed.getValue()); 248 QName exposedRelationshipType = exposed.getRelationshipType(); 249 if (exposedRelationshipType != null) { 250 String internalRelationshipType = 251 Names.WSA_REPLY_NAME.equals( 252 exposedRelationshipType.getLocalPart()) 253 ? Names.WSA_RELATIONSHIP_REPLY 254 : exposedRelationshipType.toString(); 255 internal.setRelationshipType(internalRelationshipType); 256 } 257 internal.getOtherAttributes().putAll(exposed.getOtherAttributes()); 258 } 259 return internal; 260 } 261 262 266 public static JAXBContext getExposedJAXBContext(String exposedURI) 267 throws JAXBException { 268 return NATIVE_VERSION.equals(exposedURI) 269 ? ContextUtils.getJAXBContext() 270 : Names200408.getJAXBContext(); 271 } 272 273 279 private static void putAll(Map <QName , String > to, Map <QName , String > from) { 280 if (from != null) { 281 to.putAll(from); 282 } 283 } 284 285 291 private static void addAll(List <Object > to, List <Object > from) { 292 if (from != null) { 293 to.addAll(from); 294 } 295 } 296 297 300 public static class Names200408 { 301 public static final String WSA_NAMESPACE_NAME = 302 "http://schemas.xmlsoap.org/ws/2004/08/addressing"; 303 public static final String WSA_ANONYMOUS_ADDRESS = 304 WSA_NAMESPACE_NAME + "/anonymous"; 305 public static final String WSA_NONE_ADDRESS = 306 WSA_NAMESPACE_NAME + "/none"; 307 public static final ObjectFactory WSA_OBJECT_FACTORY = 308 new ObjectFactory(); 309 public static final String WS_ADDRESSING_PACKAGE = 310 AttributedURI.class.getPackage().getName(); 311 public static final Class <org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType> 312 EPR_TYPE = 313 org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType.class; 314 315 private static JAXBContext jaxbContext; 316 317 protected Names200408() { 318 } 319 320 326 public static JAXBContext getJAXBContext() throws JAXBException { 327 synchronized (Names200408.class) { 328 if (jaxbContext == null) { 329 jaxbContext = 330 JAXBContext.newInstance(WS_ADDRESSING_PACKAGE); 331 } 332 } 333 return jaxbContext; 334 } 335 336 341 public static void setJAXBContext(JAXBContext ctx) throws JAXBException { 342 synchronized (Names200408.class) { 343 jaxbContext = ctx; 344 } 345 } 346 } 347 } 348 | Popular Tags |