Author: richard.opalka(a)jboss.com
Date: 2009-07-03 08:31:04 -0400 (Fri, 03 Jul 2009)
New Revision: 10311
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/DeployerUtils.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java
Log:
[JBWS-2332][JBWS-2382] refactoring (WIP)
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/DeployerUtils.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/DeployerUtils.java 2009-07-03
09:34:24 UTC (rev 10310)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/DeployerUtils.java 2009-07-03
12:31:04 UTC (rev 10311)
@@ -33,6 +33,7 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
+import org.jboss.metadata.web.jboss.JBossServletMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.ServletMetaData;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -168,4 +169,18 @@
}
return endpointClass;
}
+
+ static ServletMetaData getServletForName( final JBossWebMetaData jbossWebMD, final
String servletName )
+ {
+ for ( JBossServletMetaData servlet : jbossWebMD.getServlets() )
+ {
+ if ( servlet.getName().equals( servletName ) )
+ {
+ return servlet;
+ }
+ }
+
+ throw new IllegalStateException( "Cannot find servlet for link: " +
servletName );
+ }
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java 2009-07-03
09:34:24 UTC (rev 10310)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentDeployer.java 2009-07-03
12:31:04 UTC (rev 10311)
@@ -21,6 +21,7 @@
*/
package org.jboss.webservices.integration.deployers;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -34,7 +35,6 @@
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.serviceref.VirtualFileAdaptor;
-import org.jboss.metadata.web.jboss.JBossServletMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.ServletMetaData;
import org.jboss.virtual.VirtualFile;
@@ -44,12 +44,11 @@
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
import org.jboss.wsf.spi.deployment.DeploymentModelFactory;
import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.deployment.Service;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.jboss.wsf.spi.deployment.WSFDeploymentException;
-import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
import org.jboss.wsf.spi.deployment.integration.WebServiceDeclaration;
import org.jboss.wsf.spi.deployment.integration.WebServiceDeployment;
import org.jboss.wsf.spi.metadata.webservices.PortComponentMetaData;
@@ -64,7 +63,9 @@
public final class WSDeploymentDeployer extends AbstractRealDeployer
{
+ /** WSDL and XSD files filter. */
private static final WSVirtualFileFilter WS_FILE_FILTER = new WSVirtualFileFilter();
+ /** Deployment model factory. */
private final DeploymentModelFactory deploymentModelFactory;
/**
@@ -83,16 +84,21 @@
this.addOutput( Deployment.class );
// deployment factory
- SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
- deploymentModelFactory = spiProvider.getSPI(DeploymentModelFactory.class);
+ final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ this.deploymentModelFactory = spiProvider.getSPI( DeploymentModelFactory.class );
}
+ /**
+ * Creates new Web Service deployment and registers it with deployment unit.
+ *
+ * @param unit deployment unit
+ */
@Override
protected void internalDeploy( final DeploymentUnit unit ) throws DeploymentException
{
- if ( ASIntegrationHelper.isJaxrpcEjbDeployment( unit ) )
+ if ( ASIntegrationHelper.isJaxwsPojoDeployment( unit ) )
{
- this.newJaxrpcEjbDeployment( unit );
+ this.newJaxwsPojoDeployment( unit );
}
else if ( ASIntegrationHelper.isJaxwsEjbDeployment( unit ) )
{
@@ -102,215 +108,214 @@
{
this.newJaxrpcPojoDeployment( unit );
}
- else if ( ASIntegrationHelper.isJaxwsPojoDeployment( unit ) )
+ else if ( ASIntegrationHelper.isJaxrpcEjbDeployment( unit ) )
{
- this.newJaxwsPojoDeployment( unit );
+ this.newJaxrpcEjbDeployment( unit );
}
}
-
+
+ /**
+ * Creates new JAXRPC EJB21 deployment and registers it with deployment unit.
+ *
+ * @param unit deployment unit
+ */
private void newJaxrpcEjbDeployment( final DeploymentUnit unit )
{
- ArchiveDeployment dep = newDeployment(unit);
-
- Service service = dep.getService();
-
- JBossMetaData jbmd = unit.getAttachment(JBossMetaData.class);
- if (jbmd == null)
- throw new IllegalStateException("Deployment unit does not contain
application meta data");
-
- WebservicesMetaData wsMetaData = unit.getAttachment(WebservicesMetaData.class);
- if (wsMetaData == null)
- throw new IllegalStateException("Deployment unit does not contain
webservices meta data");
-
- WebServiceDeployment webServiceDeployment =
unit.getAttachment(WebServiceDeployment.class);
- if (webServiceDeployment == null)
- throw new IllegalStateException("Deployment unit does not contain
webServiceDeployment");
+ final ArchiveDeployment dep = this.newDeployment( unit );
+ final JBossMetaData jbmd = this.getAttachment( JBossMetaData.class, unit, dep );
+ final WebservicesMetaData wsMetaData = this.getAttachment(
WebservicesMetaData.class, unit, dep );
+ this.getAttachment( WebServiceDeployment.class, unit, dep );
- // Copy the attachments
- dep.addAttachment(WebservicesMetaData.class, wsMetaData);
- dep.addAttachment(JBossMetaData.class, jbmd);
- dep.addAttachment(WebServiceDeployment.class, webServiceDeployment);
-
- for (WebserviceDescriptionMetaData wsd : wsMetaData.getWebserviceDescriptions())
+ for ( WebserviceDescriptionMetaData wsd : wsMetaData.getWebserviceDescriptions() )
{
- for (PortComponentMetaData pcmd : wsd.getPortComponents())
+ for ( PortComponentMetaData pcmd : wsd.getPortComponents() )
{
- String ejbLink = pcmd.getEjbLink();
- if (ejbLink == null)
- throw new IllegalStateException("ejb-link cannot be null");
+ final String ejbName = pcmd.getEjbLink();
+ final JBossEnterpriseBeanMetaData beanMetaData = jbmd.getEnterpriseBean(
ejbName );
+ final String ejbClass = beanMetaData.getEjbClass();
- JBossEnterpriseBeanMetaData beanMetaData = jbmd.getEnterpriseBean(ejbLink);
- if (beanMetaData == null)
- throw new IllegalStateException("Cannot obtain bean meta data for:
" + ejbLink);
-
- String ejbClass = beanMetaData.getEjbClass();
-
- // Create the endpoint
- Endpoint ep = this.deploymentModelFactory.newEndpoint(ejbClass);
- ep.setShortName(ejbLink);
- service.addEndpoint(ep);
+ this.createEndpoint( ejbClass, ejbName, dep );
}
}
- dep.addAttachment(DeploymentUnit.class, unit);
+ dep.addAttachment( DeploymentUnit.class, unit );
unit.addAttachment( Deployment.class, dep );
}
+ /**
+ * Creates new JAXWS EJB3 deployment and registers it with deployment unit.
+ *
+ * @param unit deployment unit
+ */
private void newJaxwsEjbDeployment( final DeploymentUnit unit )
{
- ArchiveDeployment dep = newDeployment(unit);
+ final ArchiveDeployment dep = this.newDeployment( unit );
+ final WebServiceDeployment webServiceDeployment = this.getAttachment(
WebServiceDeployment.class, unit, dep );
- Service service = dep.getService();
+ final Iterator< WebServiceDeclaration > it =
webServiceDeployment.getServiceEndpoints().iterator();
+ while ( it.hasNext() )
+ {
+ final WebServiceDeclaration container = it.next();
- WebServiceDeployment webServiceDeployment =
unit.getAttachment(WebServiceDeployment.class);
- if (webServiceDeployment == null)
- throw new IllegalStateException("Deployment unit does not contain
webServiceDeployment");
-
- // Copy the attachments
- dep.addAttachment(WebServiceDeployment.class, webServiceDeployment);
-
- Iterator<WebServiceDeclaration> it =
webServiceDeployment.getServiceEndpoints().iterator();
- while (it.hasNext())
- {
- WebServiceDeclaration container = it.next();
- if (DeployerUtils.isWebServiceBean(container))
+ if ( DeployerUtils.isWebServiceBean( container ) )
{
- String ejbName = container.getComponentName();
- String epBean = container.getComponentClassName();
+ final String ejbName = container.getComponentName();
+ final String ejbClass = container.getComponentClassName();
- // Create the endpoint
- Endpoint ep = this.deploymentModelFactory.newEndpoint(epBean);
- ep.setShortName(ejbName);
-
- String containName = container.getContainerName();
- if(null==containName)
- throw new IllegalArgumentException("Target container name not
set");
- ep.setProperty(InvocationHandlerEJB3.CONTAINER_NAME, containName);
-
- service.addEndpoint(ep);
+ final Endpoint ep = this.createEndpoint( ejbClass, ejbName, dep );
+ ep.setProperty( InvocationHandlerEJB3.CONTAINER_NAME,
container.getContainerName() );
}
}
- dep.addAttachment(DeploymentUnit.class, unit);
+ dep.addAttachment( DeploymentUnit.class, unit );
unit.addAttachment( Deployment.class, dep );
}
+ /**
+ * Creates new JAXRPC POJO deployment and registers it with deployment unit.
+ *
+ * @param unit deployment unit
+ */
private void newJaxrpcPojoDeployment( final DeploymentUnit unit )
{
- ArchiveDeployment dep = newDeployment(unit);
+ final ArchiveDeployment dep = this.newDeployment( unit );
+ final JBossWebMetaData webMetaData = this.getAttachment( JBossWebMetaData.class,
unit, dep );
+ final WebservicesMetaData wsMetaData = this.getAttachment(
WebservicesMetaData.class, unit, dep );
- Service service = dep.getService();
-
- JBossWebMetaData webMetaData = unit.getAttachment(JBossWebMetaData.class);
- if (webMetaData == null)
- throw new IllegalStateException("Deployment unit does not contain web meta
data");
-
- WebservicesMetaData wsMetaData = unit.getAttachment(WebservicesMetaData.class);
- if (wsMetaData == null)
- throw new IllegalStateException("Deployment unit does not contain
webservices meta data");
-
- // Copy the attachments
- dep.addAttachment(WebservicesMetaData.class, wsMetaData);
- dep.addAttachment(JBossWebMetaData.class, webMetaData);
-
- for (WebserviceDescriptionMetaData wsd : wsMetaData.getWebserviceDescriptions())
+ for ( WebserviceDescriptionMetaData wsd : wsMetaData.getWebserviceDescriptions() )
{
- for (PortComponentMetaData pcmd : wsd.getPortComponents())
+ for ( PortComponentMetaData pcmd : wsd.getPortComponents() )
{
- String servletLink = pcmd.getServletLink();
- if (servletLink == null)
- throw new IllegalStateException("servlet-link cannot be null");
+ final String pojoName = pcmd.getServletLink();
+ final ServletMetaData servlet = DeployerUtils.getServletForName( webMetaData,
pojoName );
+ final String pojoClass = DeployerUtils.getTargetBean( servlet );
- ServletMetaData servlet = getServletForName(webMetaData, servletLink);
- String targetBean = DeployerUtils.getTargetBean(servlet);
-
- // Create the endpoint
- Endpoint ep = this.deploymentModelFactory.newEndpoint(targetBean);
- ep.setShortName(servletLink);
- service.addEndpoint(ep);
+ this.createEndpoint( pojoClass, pojoName, dep );
}
}
- dep.addAttachment(DeploymentUnit.class, unit);
+ dep.addAttachment( DeploymentUnit.class, unit );
unit.addAttachment( Deployment.class, dep );
}
+ /**
+ * Creates new JAXWS POJO deployment and registers it with deployment unit.
+ *
+ * @param unit deployment unit
+ */
private void newJaxwsPojoDeployment( final DeploymentUnit unit )
{
- ArchiveDeployment dep = newDeployment(unit);
+ final ArchiveDeployment dep = this.newDeployment( unit );
+ this.getAttachment( JBossWebMetaData.class, unit, dep );
- Service service = dep.getService();
-
- JBossWebMetaData webMetaData = unit.getAttachment(JBossWebMetaData.class);
- if (webMetaData == null)
- throw new IllegalStateException("Deployment unit does not contain web meta
data");
-
- // Copy the attachments
- dep.addAttachment(JBossWebMetaData.class, webMetaData);
-
- List<ServletMetaData> servlets = DeployerUtils.getJaxwsServlets(unit);
- for (ServletMetaData servlet : servlets)
+ final List< ServletMetaData > servlets = DeployerUtils.getJaxwsServlets( unit
);
+ for ( ServletMetaData servlet : servlets )
{
- String servletName = servlet.getName();
- String targetBean = DeployerUtils.getTargetBean(servlet);
+ final String pojoName = servlet.getName();
+ final String pojoClass = DeployerUtils.getTargetBean( servlet );
- // Create the endpoint
- Endpoint ep = this.deploymentModelFactory.newEndpoint(targetBean);
- ep.setShortName(servletName);
- service.addEndpoint(ep);
+ this.createEndpoint( pojoClass, pojoName, dep );
}
- dep.addAttachment(DeploymentUnit.class, unit);
+ dep.addAttachment( DeploymentUnit.class, unit );
unit.addAttachment( Deployment.class, dep );
}
-
- private ServletMetaData getServletForName(JBossWebMetaData wmd, String servletLink)
+
+ /**
+ * Creates new Web Service deployment.
+ *
+ * @param unit deployment unit
+ * @return archive deployment
+ */
+ private ArchiveDeployment newDeployment( final DeploymentUnit unit )
{
- for (JBossServletMetaData servlet : wmd.getServlets())
+ final ArchiveDeployment dep = ( ArchiveDeployment ) this.deploymentModelFactory.
+ newDeployment( unit.getSimpleName(), unit.getClassLoader() );
+
+ if ( unit instanceof VFSDeploymentUnit )
{
- if (servletLink.equals(servlet.getName()))
+ final VFSDeploymentUnit vfsUnit = ( VFSDeploymentUnit ) unit;
+ final List< VirtualFile > virtualFiles = vfsUnit.getMetaDataFiles(
WSDeploymentDeployer.WS_FILE_FILTER );
+ final Set< UnifiedVirtualFile > uVirtualFiles = new HashSet<
UnifiedVirtualFile >();
+ for ( VirtualFile vf : virtualFiles )
{
- return servlet;
+ // Adding the roots of the virtual files.
+ try
+ {
+ uVirtualFiles.add( new VirtualFileAdaptor( vf.getVFS().getRoot() ) );
+ }
+ catch ( IOException ioe )
+ {
+ throw new WSFDeploymentException( ioe );
+ }
}
+ dep.setMetadataFiles( new LinkedList<UnifiedVirtualFile>( uVirtualFiles )
);
}
- throw new IllegalStateException("Cannot find servlet for link: " +
servletLink);
+
+ if ( unit.getParent() != null )
+ {
+ final DeploymentUnit parentUnit = unit.getParent();
+ final ArchiveDeployment parentDep = ( ArchiveDeployment )
this.deploymentModelFactory.
+ newDeployment( parentUnit.getSimpleName(), parentUnit.getClassLoader() );
+ dep.setParent( parentDep );
+ }
+
+ dep.setRootFile( new VirtualFileAdaptor( ( ( VFSDeploymentUnit ) unit ).getRoot() )
);
+ dep.setRuntimeClassLoader( unit.getClassLoader() );
+ dep.setType( unit.getAttachment( DeploymentType.class ) );
+
+ return dep;
}
- private ArchiveDeployment newDeployment(DeploymentUnit unit)
+ /**
+ * Creates new Web Service endpoint.
+ *
+ * @param endpointClass endpoint class name
+ * @param endpointName endpoint name
+ * @param dep deployment
+ * @return WS endpoint
+ */
+ private Endpoint createEndpoint( final String endpointClass, final String
endpointName, final Deployment dep )
{
- try
+ if ( endpointName == null )
{
- ArchiveDeployment dep =
(ArchiveDeployment)this.deploymentModelFactory.newDeployment(unit.getSimpleName(),
unit.getClassLoader());
- if (unit instanceof VFSDeploymentUnit)
- {
- VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
- List<VirtualFile> virtualFiles =
vfsUnit.getMetaDataFiles(WS_FILE_FILTER); //get all wsdl and xsd files
- Set<UnifiedVirtualFile> uVirtualFiles = new
HashSet<UnifiedVirtualFile>();
- for (VirtualFile vf : virtualFiles)
- {
- // Adding the roots of the virtual files.
- uVirtualFiles.add(new VirtualFileAdaptor(vf.getVFS().getRoot()));
- }
- dep.setMetadataFiles(new
LinkedList<UnifiedVirtualFile>(uVirtualFiles));
- }
+ throw new NullPointerException( "Null endpoint name" );
+ }
- if (unit.getParent() != null)
- {
- DeploymentUnit parentUnit = unit.getParent();
- ArchiveDeployment parentDep =
(ArchiveDeployment)this.deploymentModelFactory.newDeployment(parentUnit.getSimpleName(),
parentUnit.getClassLoader());
- dep.setParent(parentDep);
- }
-
- dep.setRootFile(new VirtualFileAdaptor(((VFSDeploymentUnit)unit).getRoot()));
- dep.setRuntimeClassLoader(unit.getClassLoader());
- dep.setType(unit.getAttachment( DeploymentType.class ));
-
- return dep;
+ if ( endpointClass == null )
+ {
+ throw new NullPointerException( "Null endpoint class" );
}
- catch (Exception ex)
+
+ final Endpoint endpoint = this.deploymentModelFactory.newEndpoint( endpointClass
);
+ endpoint.setShortName( endpointName );
+ dep.getService().addEndpoint( endpoint );
+
+ return endpoint;
+ }
+
+ /**
+ * Gets specified attachment from deployment unit.
+ * Checks it's not null and then propagates it to <b>dep</b>
+ * attachments. Finally it returns attachment value.
+ *
+ * @param <A> class type
+ * @param attachment attachment
+ * @param unit deployment unit
+ * @param dep deployment
+ * @return attachment value if found in unit
+ */
+ private <A> A getAttachment( final Class< A > attachment, final
DeploymentUnit unit, final Deployment dep )
+ {
+ final A attachmentValue = unit.getAttachment( attachment );
+
+ if ( attachmentValue != null )
{
- throw new WSFDeploymentException("Cannot load spi.deployment.Deployment
class", ex);
+ dep.addAttachment( attachment , attachmentValue );
+ return attachmentValue;
}
+
+ throw new IllegalStateException( "Deployment unit does not contain " +
attachment );
}
-
+
}