1 22 package org.jboss.webservice.metadata.serviceref; 23 24 26 import java.io.Serializable ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.net.URLClassLoader ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.LinkedHashMap ; 33 import java.util.Properties ; 34 35 import javax.xml.namespace.QName ; 36 37 import org.jboss.deployment.DeploymentException; 38 import org.jboss.logging.Logger; 39 import org.jboss.metadata.MetaData; 40 import org.jboss.metadata.Ref; 41 import org.jboss.xb.QNameBuilder; 42 import org.w3c.dom.DocumentType ; 43 import org.w3c.dom.Element ; 44 45 51 public class ServiceRefMetaData extends Ref 52 implements Serializable 53 { 54 private static final long serialVersionUID = -3723577995017108437L; 55 56 private static Logger log = Logger.getLogger(ServiceRefMetaData.class); 58 59 private String serviceRefName; 61 private String serviceInterface; 63 private String serviceResType; 65 private String wsdlFile; 67 private String jaxrpcMappingFile; 69 private QName serviceQName; 71 private LinkedHashMap portComponentRefs = new LinkedHashMap (); 73 private ArrayList handlers = new ArrayList (); 75 76 private String configName; 78 private String configFile; 80 81 private URL wsdlOverride; 82 83 private Properties callProperties; 84 private String mappedName; 85 86 87 private transient URLClassLoader resourceCL; 88 89 91 public ServiceRefMetaData() 92 { 93 } 94 95 97 public ServiceRefMetaData(String serviceRefName) 98 { 99 this.serviceRefName = serviceRefName; 100 } 101 102 104 public ServiceRefMetaData(URLClassLoader resourceCl) 105 { 106 setResourceCL(resourceCl); 107 } 108 109 112 public void setResourceCL(URLClassLoader resourceCL) 113 { 114 if (resourceCL == null) 115 throw new IllegalArgumentException ("ResourceClassLoader cannot be null"); 116 117 this.resourceCL = resourceCL; 118 } 119 120 public URLClassLoader getResourceCL() 121 { 122 if (resourceCL == null) 123 resourceCL = new URLClassLoader (new URL [] {}, Thread.currentThread().getContextClassLoader()); 124 125 return resourceCL; 126 } 127 128 public String getJaxrpcMappingFile() 129 { 130 return jaxrpcMappingFile; 131 } 132 public void setJaxrpcMappingFile(String file) 133 { 134 this.jaxrpcMappingFile = jaxrpcMappingFile; 135 } 136 137 public URL getJavaWsdlMappingURL() 138 { 139 URL mappingURL = null; 140 if (jaxrpcMappingFile != null) 141 { 142 mappingURL = getResourceCL().findResource(jaxrpcMappingFile); 143 if (mappingURL == null) 144 throw new IllegalStateException ("Cannot find resource: " + jaxrpcMappingFile); 145 } 146 return mappingURL; 147 } 148 149 public PortComponentRefMetaData[] getPortComponentRefs() 150 { 151 PortComponentRefMetaData[] array = new PortComponentRefMetaData[portComponentRefs.size()]; 152 portComponentRefs.values().toArray(array); 153 return array; 154 } 155 156 public HandlerMetaData[] getHandlers() 157 { 158 HandlerMetaData[] array = new HandlerMetaData[handlers.size()]; 159 handlers.toArray(array); 160 return array; 161 } 162 163 public String getServiceInterface() 164 { 165 return serviceInterface; 166 } 167 public void setServiceInterface(String serviceInterface) 168 { 169 this.serviceInterface = serviceInterface; 170 } 171 172 public QName getServiceQName() 173 { 174 return serviceQName; 175 } 176 public void setServiceQName(QName serviceQName) 177 { 178 this.serviceQName = serviceQName; 179 } 180 181 public String getServiceRefName() 182 { 183 return serviceRefName; 184 } 185 public void setServiceRefName(String serviceRefName) 186 { 187 this.serviceRefName = serviceRefName; 188 } 189 190 public String getServiceResType() 191 { 192 return serviceResType; 193 } 194 public void setServiceResType(String serviceResType) 195 { 196 this.serviceResType = serviceResType; 197 } 198 199 public String getWsdlFile() 200 { 201 return wsdlFile; 202 } 203 public void setWsdlFile(String file) 204 { 205 this.wsdlFile = file; 206 } 207 208 public String getConfigFile() 209 { 210 return configFile; 211 } 212 213 public void setConfigFile(String configFile) 214 { 215 this.configFile = configFile; 216 } 217 218 public String getConfigName() 219 { 220 return configName; 221 } 222 223 public String getMappedName() 224 { 225 return mappedName; 226 } 227 228 public void setMappedName(String mappedName) 229 { 230 this.mappedName = mappedName; 231 } 232 233 public void setConfigName(String configName) 234 { 235 this.configName = configName; 236 } 237 public URL getWsdlOverride() 238 { 239 return wsdlOverride; 240 } 241 242 public URL getWsdlURL() 243 { 244 URL wsdlURL = wsdlOverride; 245 if (wsdlURL == null && wsdlFile != null) 246 { 247 wsdlURL = getResourceCL().findResource(wsdlFile); 248 if (wsdlURL == null) 249 throw new IllegalStateException ("Cannot find resource: " + wsdlFile); 250 } 251 return wsdlURL; 252 } 253 254 public Properties getCallProperties() 255 { 256 return callProperties; 257 } 258 259 public static boolean isValidDoctype(Element element) 260 { 261 String nsURI = element.getOwnerDocument().getDocumentElement().getNamespaceURI(); 263 boolean isValid = "http://java.sun.com/xml/ns/j2ee".equals(nsURI); 264 265 DocumentType doctype = element.getOwnerDocument().getDoctype(); 267 if (isValid == false && doctype != null) 268 { 269 String publicId = doctype.getPublicId(); 270 isValid |= "-//JBoss//DTD JBOSS 4.0//EN".equals(publicId); 271 isValid |= "-//JBoss//DTD Web Application 2.4//EN".equals(publicId); 272 isValid |= "-//JBoss//DTD Application Client 4.0//EN".equals(publicId); 273 } 274 275 if (isValid == false) 276 { 277 String dtstr = (doctype != null ? "[public=" + doctype.getPublicId() + ",system=" + doctype.getSystemId() + "]" : null); 278 log.debug("Skip <service-ref> for: nsURI=" + nsURI + ",doctype=" + dtstr); 279 } 280 return isValid; 281 } 282 283 public void importStandardXml(Element element) throws DeploymentException 284 { 285 serviceRefName = MetaData.getUniqueChildContent(element, "service-ref-name"); 286 287 serviceInterface = MetaData.getUniqueChildContent(element, "service-interface"); 288 289 wsdlFile = MetaData.getOptionalChildContent(element, "wsdl-file"); 290 291 jaxrpcMappingFile = MetaData.getOptionalChildContent(element, "jaxrpc-mapping-file"); 292 293 Element qnameElement = MetaData.getOptionalChild(element, "service-qname"); 294 if (qnameElement != null) 295 serviceQName = QNameBuilder.buildQName(qnameElement, MetaData.getElementContent(qnameElement)); 296 297 Iterator iterator = MetaData.getChildrenByTagName(element, "port-component-ref"); 299 while (iterator.hasNext()) 300 { 301 Element pcrefElement = (Element )iterator.next(); 302 PortComponentRefMetaData pcrefMetaData = new PortComponentRefMetaData(this); 303 pcrefMetaData.importStandardXml(pcrefElement); 304 portComponentRefs.put(pcrefMetaData.getServiceEndpointInterface(), pcrefMetaData); 305 } 306 307 iterator = MetaData.getChildrenByTagName(element, "handler"); 309 while (iterator.hasNext()) 310 { 311 Element handlerElement = (Element )iterator.next(); 312 HandlerMetaData handlerMetaData = new HandlerMetaData(); 313 handlerMetaData.importStandardXml(handlerElement); 314 handlers.add(handlerMetaData); 315 } 316 } 317 318 322 public void importJBossXml(Element element) throws DeploymentException 323 { 324 configName = MetaData.getOptionalChildContent(element, "config-name"); 325 326 configFile = MetaData.getOptionalChildContent(element, "config-file"); 327 String wsdlOverrideOption = MetaData.getOptionalChildContent(element, "wsdl-override"); 328 try 329 { 330 if (wsdlOverrideOption != null) 331 wsdlOverride = new URL (wsdlOverrideOption); 332 } 333 catch (MalformedURLException e) 334 { 335 throw new DeploymentException("Invalid WSDL override: " + wsdlOverrideOption); 336 } 337 338 Iterator iterator = MetaData.getChildrenByTagName(element, "port-component-ref"); 340 while (iterator.hasNext()) 341 { 342 Element pcrefElement = (Element )iterator.next(); 343 String name = MetaData.getOptionalChildContent(pcrefElement, "service-endpoint-interface"); 344 if (name != null) 345 { 346 PortComponentRefMetaData pcrefMetaData = (PortComponentRefMetaData)portComponentRefs.get(name); 347 if (pcrefMetaData == null) 348 { 349 pcrefMetaData = new PortComponentRefMetaData(this); 351 pcrefMetaData.importStandardXml(pcrefElement); 352 portComponentRefs.put(pcrefMetaData.getServiceEndpointInterface(), pcrefMetaData); 353 } 354 355 pcrefMetaData.importJBossXml(pcrefElement); 356 } 357 } 358 359 iterator = MetaData.getChildrenByTagName(element, "call-property"); 361 while (iterator.hasNext()) 362 { 363 Element propElement = (Element )iterator.next(); 364 String name = MetaData.getUniqueChildContent(propElement, "prop-name"); 365 String value = MetaData.getUniqueChildContent(propElement, "prop-value"); 366 if (callProperties == null) 367 callProperties = new Properties (); 368 callProperties.setProperty(name, value); 369 } 370 } 371 } 372 | Popular Tags |