Author: richard.opalka(a)jboss.com
Date: 2008-04-17 08:17:25 -0400 (Thu, 17 Apr 2008)
New Revision: 6468
Modified:
stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java
Log:
refactoring - no functional change
Modified:
stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java
===================================================================
---
stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java 2008-04-17
11:42:18 UTC (rev 6467)
+++
stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java 2008-04-17
12:17:25 UTC (rev 6468)
@@ -21,7 +21,7 @@
*/
package org.jboss.wsf.stack.cxf;
-//$Id: XFireServicesDeployer.java 3802 2007-07-05 16:44:32Z thomas.diesler(a)jboss.com $
+//$Id: DescriptorDeploymentAspect.java 3802 2007-07-05 16:44:32Z thomas.diesler(a)jboss.com
$
import java.io.IOException;
import java.net.URL;
@@ -39,7 +39,7 @@
import org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint;
/**
- * A deployer that generates cxf.xml
+ * A deployer that locates or generates cxf.xml
*
* @author Thomas.Diesler(a)jboss.org
* @since 10-May-2007
@@ -61,90 +61,153 @@
{
this.invokerJSE = invokerJSE;
}
-
+
+ @Override
public void create(Deployment dep, WSFRuntime runtime)
{
- // Look for cxf.xml descriptor
+ URL cxfURL = getCXFConfigFromClassLoader(dep);
+ if (cxfURL == null)
+ {
+ cxfURL = getCXFConfigFromDeployment(dep);
+ if (cxfURL == null)
+ {
+ cxfURL = generateCXFConfigFromDeployment(dep);
+ }
+ putCXFConfigToDeployment(dep, cxfURL);
+ }
+ }
+
+ @Override
+ public void destroy(Deployment dep, WSFRuntime runtime)
+ {
+ DDBeans dd = dep.getAttachment(DDBeans.class);
+ if (dd != null)
+ {
+ dd.destroyFileURL();
+ }
+ }
+
+ /**
+ * Looks for <b>cxf.xml</b> in classloader
+ * @param dep deployment which initial classloader will be used
+ * @return <b>cxf.xml URL</b> or <b>null</b> if not found
+ */
+ private static URL getCXFConfigFromClassLoader(Deployment dep)
+ {
ClassLoader initCL = dep.getInitialClassLoader();
URL cxfURL = initCL.getResource("cxf.xml");
if (cxfURL != null)
{
log.info("CXF configuration found: " + cxfURL);
}
+ return cxfURL;
+ }
+
+ /**
+ * Looks for <b>jbossws-cxf.xml</b> in:
+ * <ul>
+ * <li><b>META-INF</b> resource directory for EJB3
deployment</li>
+ * <li><b>WEB-INF</b> resource directory for POJO
deployment</li>
+ * </ul>
+ * @param dep deployment where to look for resources
+ * @return <b>jbossws-cxf.xml URL</b> or <b>null</b> if not
found
+ */
+ private static URL getCXFConfigFromDeployment(Deployment dep)
+ {
+ DeploymentType depType = dep.getType();
+
+ String metadir;
+ if (depType == DeploymentType.JAXWS_EJB3)
+ {
+ // expected resource location for EJB3 deployments
+ metadir = "META-INF";
+ }
+ else if (depType == DeploymentType.JAXWS_JSE)
+ {
+ // expected resource location for POJO deployments
+ metadir = "WEB-INF";
+ }
else
{
- // Look for jbossws-cxf.xml descriptor
- DeploymentType depType = dep.getType();
-
- String metadir;
+ // only POJO and EJB3 deployments are supported
+ throw new IllegalStateException("Unsupported deployment type: " +
depType);
+ }
+
+ URL cxfURL = null;
+ try
+ {
+ // get resource URL
+ ArchiveDeployment archDep = (ArchiveDeployment)dep;
+ cxfURL = archDep.getMetaDataFileURL(metadir + "/jbossws-cxf.xml");
+ log.info("JBossWS-CXF configuration found: " + cxfURL);
+ }
+ catch (IOException ignore)
+ {
+ // resource not found
+ }
+
+ return cxfURL;
+ }
+
+ /**
+ * Generated CXF descriptor from deployment
+ * @param dep deployment
+ * @return CXF descriptor URL
+ */
+ private URL generateCXFConfigFromDeployment(Deployment dep)
+ {
+ // Generate the jbossws-cxf.xml descriptor
+ DeploymentType depType = dep.getType();
+
+ DDBeans dd = new DDBeans();
+ for (Endpoint ep : dep.getService().getEndpoints())
+ {
+ String id = ep.getShortName();
+ String address = ep.getAddress();
+ String implementor = ep.getTargetBeanName();
+
+ DDEndpoint ddep = new DDEndpoint(id, address, implementor);
+
if (depType == DeploymentType.JAXWS_EJB3)
- metadir = "META-INF";
- else if (depType == DeploymentType.JAXWS_JSE)
- metadir = "WEB-INF";
- else
- throw new IllegalStateException("Unsupported deployment type: " +
depType);
-
- try
{
- ArchiveDeployment archdep = (ArchiveDeployment)dep;
- cxfURL = archdep.getMetaDataFileURL(metadir + "/jbossws-cxf.xml");
- log.info("JBossWS-CXF configuration found: " + cxfURL);
+ ddep.setInvoker(invokerEJB3);
}
- catch (IOException ex)
+
+ if (depType == DeploymentType.JAXWS_JSE)
{
- // ignore, jbossws-cxf.xml not found
+ ddep.setInvoker(invokerJSE);
}
-
- // Generate the jbossws-cxf.xml descriptor
- if (cxfURL == null)
- {
- DDBeans dd = new DDBeans();
- for (Endpoint ep : dep.getService().getEndpoints())
- {
- String id = ep.getShortName();
- String address = ep.getAddress();
- String implementor = ep.getTargetBeanName();
- DDEndpoint ddep = new DDEndpoint(id, address, implementor);
+ log.info("Add " + ddep);
+ dd.addEndpoint(ddep);
+ }
- if (depType == DeploymentType.JAXWS_EJB3)
- {
- ddep.setInvoker(invokerEJB3);
- }
+ URL cxfURL = dd.createFileURL();
+ log.info("JBossWS-CXF configuration generated: " + cxfURL);
- if (depType == DeploymentType.JAXWS_JSE)
- {
- ddep.setInvoker(invokerJSE);
- }
+ dep.addAttachment(DDBeans.class, dd);
- log.info("Add " + ddep);
- dd.addEndpoint(ddep);
- }
-
- cxfURL = dd.createFileURL();
- log.info("JBossWS-CXF configuration generated: " + cxfURL);
-
- dep.addAttachment(DDBeans.class, dd);
- }
-
- String propKey = "org.jboss.ws.webapp.ContextParameterMap";
- Map<String, String> contextParams = (Map<String,
String>)dep.getProperty(propKey);
- if (contextParams == null)
- {
- contextParams = new HashMap<String, String>();
- dep.setProperty(propKey, contextParams);
- }
-
- contextParams.put(CXFServletExt.PARAM_CXF_BEANS_URL, cxfURL.toExternalForm());
- }
+ return cxfURL;
}
- public void destroy(Deployment dep, WSFRuntime runtime)
+ /**
+ * Puts CXF config file to deployment property
<b>org.jboss.ws.webapp.ContextParameterMap</b> map
+ * @param dep deployment where to put
+ * @param cxfURL to be put
+ */
+ private static void putCXFConfigToDeployment(Deployment dep, URL cxfURL)
{
- DDBeans dd = dep.getAttachment(DDBeans.class);
- if (dd != null)
+ // get property map
+ String propKey = "org.jboss.ws.webapp.ContextParameterMap";
+ Map<String, String> contextParams = (Map<String,
String>)dep.getProperty(propKey);
+ if (contextParams == null)
{
- dd.destroyFileURL();
+ // if there's no associated map with the property create it now
+ contextParams = new HashMap<String, String>();
+ dep.setProperty(propKey, contextParams);
}
+ // put cxf config URL to the property map
+ contextParams.put(CXFServletExt.PARAM_CXF_BEANS_URL, cxfURL.toExternalForm());
}
-}
\ No newline at end of file
+
+}
Show replies by date