[Jboss-cvs] JBossAS SVN: r56882 - in projects/microcontainer/trunk/deployers/src: main/org/jboss/deployers/plugins/deployer main/org/jboss/deployers/plugins/deployers/helpers main/org/jboss/deployers/plugins/deployers/kernel main/org/jboss/deployers/plugins/deployment main/org/jboss/deployers/plugins/structure main/org/jboss/deployers/spi/deployer main/org/jboss/deployers/spi/structure tests/org/jboss/test/deployers/bean/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 15 06:18:04 EDT 2006
Author: adrian at jboss.org
Date: 2006-09-15 06:17:51 -0400 (Fri, 15 Sep 2006)
New Revision: 56882
Added:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java
Modified:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/KernelDeployerUnitTestCase.java
Log:
[JBMICROCONT-5] - Implement subcomponents of a deployment.
Made a version of the bean deployer that creates components for each Bean
from the KernelDeployment.
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -27,6 +27,7 @@
import java.util.Map;
import org.jboss.deployers.plugins.attachments.AbstractAttachments;
+import org.jboss.deployers.plugins.structure.ComponentDeploymentContext;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.attachments.Attachments;
import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
@@ -88,10 +89,40 @@
return deploymentContext.getMetaDataFiles(name, suffix);
}
+ public DeploymentUnit addComponent(String name)
+ {
+ ComponentDeploymentContext component = new ComponentDeploymentContext(name, deploymentContext);
+ AbstractDeploymentUnit unit = new AbstractDeploymentUnit(component);
+ component.setDeploymentUnit(unit);
+ deploymentContext.addComponent(component);
+ return unit;
+ }
+
+ public boolean removeComponent(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+
+ for (DeploymentContext component : deploymentContext.getComponents())
+ {
+ if (name.equals(component.getName()))
+ return deploymentContext.removeComponent(component);
+ }
+ return false;
+ }
+
public Map<String, Object> getAttachments()
{
- HashMap<String, Object> result = new HashMap<String, Object>(deploymentContext.getTransientAttachments().getAttachments());
+ DeploymentContext parent = deploymentContext.getParent();
+ HashMap<String, Object> result = new HashMap<String, Object>();
+ if (parent != null)
+ result.putAll(parent.getTransientAttachments().getAttachments());
+ result.putAll(deploymentContext.getTransientAttachments().getAttachments());
+ if (parent != null)
+ result.putAll(parent.getTransientManagedObjects().getAttachments());
result.putAll(deploymentContext.getTransientManagedObjects().getAttachments());
+ if (parent != null)
+ result.putAll(parent.getPredeterminedManagedObjects().getAttachments());
result.putAll(deploymentContext.getPredeterminedManagedObjects().getAttachments());
return Collections.unmodifiableMap(result);
}
@@ -103,22 +134,53 @@
public Object getAttachment(String name)
{
+ DeploymentContext parent = deploymentContext.getParent();
Object result = deploymentContext.getPredeterminedManagedObjects().getAttachment(name);
if (result != null)
return result;
+ if (parent != null)
+ {
+ result = parent.getPredeterminedManagedObjects().getAttachment(name);
+ if (result != null)
+ return result;
+ }
result = deploymentContext.getTransientManagedObjects().getAttachment(name);
if (result != null)
return result;
- return deploymentContext.getTransientAttachments().getAttachment(name);
+ if (parent != null)
+ {
+ result = parent.getTransientManagedObjects().getAttachment(name);
+ if (result != null)
+ return result;
+ }
+ result = deploymentContext.getTransientAttachments().getAttachment(name);
+ if (result != null)
+ return result;
+ if (parent != null)
+ {
+ result = parent.getTransientAttachments().getAttachment(name);
+ if (result != null)
+ return result;
+ }
+ return null;
}
public boolean isAttachmentPresent(String name)
{
+ DeploymentContext parent = deploymentContext.getParent();
if (deploymentContext.getPredeterminedManagedObjects().isAttachmentPresent(name))
return true;
+ if (parent != null && parent.getPredeterminedManagedObjects().isAttachmentPresent(name))
+ return true;
if (deploymentContext.getTransientManagedObjects().isAttachmentPresent(name))
return true;
- return deploymentContext.getTransientAttachments().isAttachmentPresent(name);
+ if (parent != null && parent.getTransientAttachments().isAttachmentPresent(name))
+ return true;
+ if (deploymentContext.getTransientAttachments().isAttachmentPresent(name))
+ return true;
+ if (parent != null && parent.getTransientAttachments().isAttachmentPresent(name))
+ return true;
+ return false;
}
public Object removeAttachment(String name)
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -35,6 +35,11 @@
*/
public abstract class AbstractClassLoaderDeployer extends AbstractSimpleDeployer implements ClassLoaderFactory
{
+ public int getRelativeOrder()
+ {
+ return CLASSLOADER_DEPLOYER;
+ }
+
public void deploy(DeploymentUnit unit) throws DeploymentException
{
unit.createClassLoader(this);
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractParsingDeployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -52,7 +52,12 @@
throw new IllegalArgumentException("Null expectedType");
this.expectedType = expectedType;
}
-
+
+ public int getRelativeOrder()
+ {
+ return PARSER_DEPLOYER;
+ }
+
/**
* Get the expected type
*
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanDeployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -50,11 +50,6 @@
super(KernelDeployment.class);
}
- public int getRelativeOrder()
- {
- return 1000;
- }
-
protected void init(DeploymentUnit unit, KernelDeployment metaData, VirtualFile file) throws Exception
{
String name = file.toURI().toString();
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/BeanMetaDataDeployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.deployers.kernel;
+
+import java.util.Set;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * KernelDeployer.<p>
+ *
+ * This deployer is responsible for deploying all metadata of
+ * type {@link org.jboss.kernel.spi.deployment.KernelDeployment}.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanMetaDataDeployer extends AbstractRealDeployer<BeanMetaData>
+{
+ /** The kernel controller */
+ private final KernelController controller;
+
+ /**
+ * Create a new BeanDeployer.
+ *
+ * @param kernel the kernel
+ * @throws IllegalArgumentException for a null kernel
+ */
+ public BeanMetaDataDeployer(Kernel kernel)
+ {
+ super(BeanMetaData.class);
+ if (kernel == null)
+ throw new IllegalArgumentException("Null kernel");
+ controller = kernel.getController();
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ Set<BeanMetaData> beans = getAllMetaData(unit);
+ for (BeanMetaData bean : beans)
+ {
+ KernelControllerContext context = new AbstractKernelControllerContext(null, bean, null);
+
+ try
+ {
+ controller.install(context);
+ }
+ catch (Throwable t)
+ {
+ undeploy(unit); // TODO better unwind
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + bean.getName(), t);
+ }
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ Set<BeanMetaData> beans = getAllMetaData(unit);
+ for (BeanMetaData bean : beans)
+ controller.uninstall(bean.getName());
+ }
+}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/kernel/KernelDeploymentDeployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.deployers.kernel;
+
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.deployers.plugins.deployers.helpers.AbstractRealDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+
+public class KernelDeploymentDeployer extends AbstractRealDeployer<KernelDeployment>
+{
+ /**
+ * Create a new KernelDeploymentDeployer.
+ */
+ public KernelDeploymentDeployer()
+ {
+ super(KernelDeployment.class);
+ }
+
+ public int getRelativeOrder()
+ {
+ return COMPONENT_DEPLOYER;
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ Set<KernelDeployment> deployments = getAllMetaData(unit);
+ for (KernelDeployment deployment : deployments)
+ {
+ List<BeanMetaData> beans = deployment.getBeans();
+ for (BeanMetaData bean : beans)
+ {
+ DeploymentUnit component = unit.addComponent(bean.getName());
+ component.addAttachment(BeanMetaData.class.getName(), bean);
+ }
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ Set<KernelDeployment> deployments = getAllMetaData(unit);
+ for (KernelDeployment deployment : deployments)
+ {
+ List<BeanMetaData> beans = deployment.getBeans();
+ for (BeanMetaData bean : beans)
+ unit.removeComponent(bean.getName());
+ }
+ }
+}
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -319,10 +319,7 @@
{
Deployer deployer = theDeployers[i];
for (DeploymentContext context : undeployContexts)
- {
- DeploymentUnit unit = context.getDeploymentUnit();
- deployer.prepareUndeploy(unit);
- }
+ prepareUndeploy(deployer, context, true);
}
for (DeploymentContext context : undeployContexts)
{
@@ -343,10 +340,10 @@
Set<DeploymentContext> errors = new HashSet<DeploymentContext>();
for (DeploymentContext context : deployContexts)
{
- DeploymentUnit unit = context.getDeploymentUnit();
try
{
- deployer.commitDeploy(unit);
+ Set<DeploymentContext> components = context.getComponents();
+ commitDeploy(deployer, context, components);
}
catch (DeploymentException e)
{
@@ -357,7 +354,7 @@
for (int j = i-1; j >= 0; --j)
{
Deployer other = theDeployers[j];
- other.prepareUndeploy(unit);
+ prepareUndeploy(other, context, true);
}
context.removeClassLoader();
}
@@ -372,6 +369,59 @@
}
}
+ private void prepareUndeploy(Deployer deployer, DeploymentContext context, boolean doComponents)
+ {
+ DeploymentUnit unit = context.getDeploymentUnit();
+ deployer.prepareUndeploy(unit);
+
+ if (doComponents)
+ {
+ Set<DeploymentContext> components = context.getComponents();
+ if (components != null && components.isEmpty() == false)
+ {
+ for (DeploymentContext component : components)
+ prepareUndeploy(deployer, component, true);
+ }
+ }
+ }
+
+ private void commitDeploy(Deployer deployer, DeploymentContext context, Set<DeploymentContext> components) throws DeploymentException
+ {
+ DeploymentContext[] theComponents = null;
+ if (components != null && components.isEmpty() == false)
+ theComponents = components.toArray(new DeploymentContext[components.size()]);
+
+ DeploymentUnit unit = context.getDeploymentUnit();
+ deployer.commitDeploy(unit);
+
+ try
+ {
+ if (theComponents != null)
+ {
+ for (int i = 0; i < theComponents.length; ++i)
+ {
+ try
+ {
+ Set<DeploymentContext> componentComponents = theComponents[i].getComponents();
+ commitDeploy(deployer, theComponents[i], componentComponents);
+ }
+ catch (DeploymentException e)
+ {
+ // Unwind the previous components
+ for (int j = i-1; j >=0; --j)
+ prepareUndeploy(deployer, theComponents[j], true);
+ throw e;
+ }
+ }
+ }
+ }
+ catch (DeploymentException e)
+ {
+ prepareUndeploy(deployer, context, false);
+ throw e;
+ }
+ }
+
public void shutdown()
{
while (topLevelDeployments.isEmpty() == false)
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -87,6 +87,9 @@
/** The child contexts */
private Set<DeploymentContext> children = new CopyOnWriteArraySet<DeploymentContext>();
+
+ /** The component contexts */
+ private Set<DeploymentContext> components = new CopyOnWriteArraySet<DeploymentContext>();
/** The predtermined managed objects */
private Attachments predeterminedManagedObjects = new AttachmentsImpl();
@@ -414,6 +417,33 @@
return children.remove(child);
}
+ public Set<DeploymentContext> getComponents()
+ {
+ return Collections.unmodifiableSet(components);
+ }
+
+ public void addComponent(DeploymentContext component)
+ {
+ if (component == null)
+ throw new IllegalArgumentException("Null component");
+ components.add(component);
+ log.debug("Added component " + component.getName() + " to " + getName());
+ }
+
+ public boolean removeComponent(DeploymentContext component)
+ {
+ if (component == null)
+ throw new IllegalArgumentException("Null component");
+
+ Set<DeploymentContext> componentComponents = component.getComponents();
+ if (componentComponents.isEmpty() == false)
+ log.warn("Removing component " + name + " which still has components " + componentComponents);
+ boolean result = components.remove(component);
+ if (result)
+ log.debug("Removed component " + component.getName() + " from " + getName());
+ return result;
+ }
+
public void visit(DeploymentContextVisitor visitor) throws DeploymentException
{
if (visitor == null)
@@ -598,6 +628,7 @@
for (DeploymentContext child : children)
child.reset();
}
+ components.clear();
classLoader = null;
transientManagedObjects.clear();
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -0,0 +1,381 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.structure;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.deployers.plugins.attachments.AttachmentsImpl;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.spi.structure.DeploymentContextVisitor;
+import org.jboss.deployers.spi.structure.DeploymentState;
+import org.jboss.deployers.spi.structure.StructureDetermined;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * AbstractDeploymentContext.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ComponentDeploymentContext implements DeploymentContext
+{
+ /** The log */
+ protected Logger log = Logger.getLogger(getClass());
+
+ /** The name */
+ private String name;
+
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ /** The parent context */
+ private DeploymentContext parent;
+
+ /** The component contexts */
+ private Set<DeploymentContext> components = new CopyOnWriteArraySet<DeploymentContext>();
+
+ /** The attachments */
+ private Attachments transientAttachments = new AttachmentsImpl();
+
+ /** The managed objects */
+ private Attachments transientManagedObjects = new AttachmentsImpl();
+
+ /**
+ * Create a new ComponentDeploymentContext.
+ *
+ * @param name the name
+ * @param parent the parent
+ * @throws IllegalArgumentException if the name or parent is null
+ */
+ public ComponentDeploymentContext(String name, DeploymentContext parent)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (parent == null)
+ throw new IllegalArgumentException("Null parent");
+ this.name = name;
+ this.parent = parent;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public StructureDetermined getStructureDetermined()
+ {
+ return parent.getStructureDetermined();
+ }
+
+ public void setStructureDetermined(StructureDetermined determined)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public boolean isCandidate()
+ {
+ return parent.isCandidate();
+ }
+
+ public DeploymentState getState()
+ {
+ return parent.getState();
+ }
+
+ public void setState(DeploymentState state)
+ {
+ parent.setState(state);
+ }
+
+ public DeploymentUnit getDeploymentUnit()
+ {
+ if (unit == null)
+ throw new IllegalStateException("Deployment unit has not been set");
+ return unit;
+ }
+
+ public void setDeploymentUnit(DeploymentUnit unit)
+ {
+ this.unit = unit;
+ }
+
+ public VirtualFile getRoot()
+ {
+ return parent.getRoot();
+ }
+
+ /**
+ * Set the root location
+ *
+ * @param root the root
+ */
+ public void setRoot(VirtualFile root)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public void setMetaDataPath(String path)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public VirtualFile getMetaDataLocation()
+ {
+ return parent.getMetaDataLocation();
+ }
+
+ public void setMetaDataLocation(VirtualFile location)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return parent.getClassLoader();
+ }
+
+ public void setClassLoader(ClassLoader classLoader)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException
+ {
+ return false;
+ }
+
+ public void removeClassLoader()
+ {
+ }
+
+ public List<VirtualFile> getClassPath()
+ {
+ return parent.getClassPath();
+ }
+
+ public void setClassPath(List<VirtualFile> paths)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public boolean isTopLevel()
+ {
+ return false;
+ }
+
+ public DeploymentContext getTopLevel()
+ {
+ return parent.getTopLevel();
+ }
+
+ public DeploymentContext getParent()
+ {
+ return parent;
+ }
+
+ public void setParent(DeploymentContext parent)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public Set<DeploymentContext> getChildren()
+ {
+ return Collections.emptySet();
+ }
+
+ public void addChild(DeploymentContext child)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public boolean removeChild(DeploymentContext child)
+ {
+ throw new UnsupportedOperationException("Not supported for components");
+ }
+
+ public Set<DeploymentContext> getComponents()
+ {
+ return Collections.unmodifiableSet(components);
+ }
+
+ public void addComponent(DeploymentContext component)
+ {
+ if (component == null)
+ throw new IllegalArgumentException("Null component");
+ components.add(component);
+ }
+
+ public boolean removeComponent(DeploymentContext component)
+ {
+ if (component == null)
+ throw new IllegalArgumentException("Null component");
+ return components.remove(component);
+ }
+
+ public void visit(DeploymentContextVisitor visitor) throws DeploymentException
+ {
+ if (visitor == null)
+ throw new IllegalArgumentException("Null visitor");
+
+ visit(this, visitor);
+ }
+
+ /**
+ * Visit a context
+ *
+ * @param context the context
+ * @param visitor the visitor
+ * @throws DeploymentException for any error
+ */
+ private void visit(DeploymentContext context, DeploymentContextVisitor visitor) throws DeploymentException
+ {
+ visitor.visit(context);
+ try
+ {
+ Set<DeploymentContext> children = context.getChildren();
+ if (children.isEmpty())
+ return;
+
+ DeploymentContext[] childContexts = children.toArray(new DeploymentContext[children.size()]);
+ for (int i = 0; i < childContexts.length; ++i)
+ {
+ if (childContexts[i] == null)
+ throw new IllegalStateException("Null child context for " + context.getName() + " children=" + children);
+ try
+ {
+ visit(childContexts[i], visitor);
+ }
+ catch (Throwable t)
+ {
+ for (int j = i-1; j >= 0; --j)
+ visitError(childContexts[j], visitor, true);
+ throw DeploymentException.rethrowAsDeploymentException("Error visiting: " + childContexts[i].getName(), t);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ visitError(context, visitor, false);
+ throw DeploymentException.rethrowAsDeploymentException("Error visiting: " + context.getName(), t);
+ }
+ }
+
+ /**
+ * Unwind the visit invoking the previously visited context's error handler
+ *
+ * @param context the context
+ * @param visitor the visitor
+ * @param visitChildren whether to visit the children
+ * @throws DeploymentException for any error
+ */
+ private void visitError(DeploymentContext context, DeploymentContextVisitor visitor, boolean visitChildren) throws DeploymentException
+ {
+ if (visitChildren)
+ {
+ Set<DeploymentContext> children = context.getChildren();
+ if (children.isEmpty())
+ return;
+
+ for (DeploymentContext child : children)
+ {
+ try
+ {
+ visitError(child, visitor, true);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during visit error: " + child.getName(), t);
+ }
+ }
+
+ }
+ try
+ {
+ visitor.error(context);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during visit error: " + context.getName(), t);
+ }
+ }
+
+ public Attachments getPredeterminedManagedObjects()
+ {
+ return parent.getPredeterminedManagedObjects();
+ }
+
+ public Attachments getTransientManagedObjects()
+ {
+ return transientManagedObjects;
+ }
+
+ public Attachments getTransientAttachments()
+ {
+ return transientAttachments;
+ }
+
+ public Throwable getProblem()
+ {
+ return parent.getProblem();
+ }
+
+ public void setProblem(Throwable problem)
+ {
+ parent.setProblem(problem);
+ }
+
+ public VirtualFile getMetaDataFile(String name)
+ {
+ return parent.getMetaDataFile(name);
+ }
+
+ public List<VirtualFile> getMetaDataFiles(String name, String suffix)
+ {
+ return parent.getMetaDataFiles(name, suffix);
+ }
+
+ public void reset()
+ {
+ components.clear();
+
+ transientManagedObjects.clear();
+ transientAttachments.clear();
+ }
+
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(getClass().getSimpleName());
+ buffer.append('@');
+ buffer.append(System.identityHashCode(this));
+ buffer.append('{').append(name).append('}');
+ return buffer.toString();
+ }
+}
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/Deployer.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -35,6 +35,15 @@
*/
public interface Deployer
{
+ /** The parser order */
+ public static final int PARSER_DEPLOYER = 2000;
+
+ /** The class loader order */
+ public static final int CLASSLOADER_DEPLOYER = 4000;
+
+ /** The component order */
+ public static final int COMPONENT_DEPLOYER = 4000;
+
/**
* Whether the deployer is relevant for this unit
*
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -91,6 +91,24 @@
Attachments getTransientManagedObjects();
/**
+ * Add a component
+ *
+ * @param name the name
+ * @return the new deployment unit
+ * @throws IllegalArgumentException for a null name
+ */
+ DeploymentUnit addComponent(String name);
+
+ /**
+ * Remove a component
+ *
+ * @param name the name
+ * @return true when removed
+ * @throws IllegalArgumentException for a null name
+ */
+ boolean removeComponent(String name);
+
+ /**
* Get the deployment contxt
*
* @return the deployment context
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -232,8 +232,30 @@
* @return whether it was removed
*/
boolean removeChild(DeploymentContext child);
+
+ /**
+ * The components
+ *
+ * @return the components
+ */
+ Set<DeploymentContext> getComponents();
/**
+ * Add a component
+ *
+ * @param component the componnet to add
+ */
+ void addComponent(DeploymentContext component);
+
+ /**
+ * Remove a component
+ *
+ * @param component the component to remove
+ * @return whether it was removed
+ */
+ boolean removeComponent(DeploymentContext component);
+
+ /**
* Visit the context and the children
*
* @param visitor the visitor
Modified: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/KernelDeployerUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/KernelDeployerUnitTestCase.java 2006-09-15 06:11:01 UTC (rev 56881)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/bean/test/KernelDeployerUnitTestCase.java 2006-09-15 10:17:51 UTC (rev 56882)
@@ -28,7 +28,8 @@
import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
-import org.jboss.deployers.plugins.deployers.kernel.KernelDeployer;
+import org.jboss.deployers.plugins.deployers.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.plugins.deployers.kernel.KernelDeploymentDeployer;
import org.jboss.deployers.plugins.deployment.MainDeployerImpl;
import org.jboss.deployers.spi.structure.DeploymentContext;
import org.jboss.deployers.spi.structure.DeploymentState;
@@ -76,9 +77,12 @@
main = new MainDeployerImpl();
TestBeanDeployer testDeployer = new TestBeanDeployer();
- KernelDeployer kernelDeployer = new KernelDeployer(kernel);
+ //KernelDeployer kernelDeployer = new KernelDeployer(kernel);
+ KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+ BeanMetaDataDeployer beanMetaDataDeployer = new BeanMetaDataDeployer(kernel);
main.addDeployer(testDeployer);
- main.addDeployer(kernelDeployer);
+ main.addDeployer(kernelDeploymentDeployer);
+ main.addDeployer(beanMetaDataDeployer);
}
catch (Throwable t)
{
More information about the jboss-cvs-commits
mailing list