[jboss-cvs] JBossAS SVN: r79173 - projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 6 18:03:36 EDT 2008
Author: alesj
Date: 2008-10-06 18:03:36 -0400 (Mon, 06 Oct 2008)
New Revision: 79173
Added:
projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeploymentVisitor.java
projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ComponentAdapter.java
Modified:
projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractComponentVisitor.java
Log:
Port JBDEPLOY-101 to branch.
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractComponentVisitor.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractComponentVisitor.java 2008-10-06 21:57:06 UTC (rev 79172)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractComponentVisitor.java 2008-10-06 22:03:36 UTC (rev 79173)
@@ -30,17 +30,9 @@
* @param <T> exact attachment type
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public abstract class AbstractComponentVisitor<T> implements DeploymentVisitor<T>
+public abstract class AbstractComponentVisitor<T> extends ComponentAdapter<T> implements DeploymentVisitor<T>
{
/**
- * Get component name.
- *
- * @param attachment the attachment
- * @return the component name
- */
- protected abstract String getComponentName(T attachment);
-
- /**
* Get attachment name.
* By default we return visitor type's name.
*
@@ -54,12 +46,11 @@
public void deploy(DeploymentUnit unit, T attachment) throws DeploymentException
{
- DeploymentUnit component = unit.addComponent(getComponentName(attachment));
- component.addAttachment(getAttachmentName(attachment), attachment);
+ addComponent(unit, attachment);
}
public void undeploy(DeploymentUnit unit, T attachment)
{
- unit.removeComponent(getComponentName(attachment));
+ removeComponent(unit, attachment);
}
}
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeploymentVisitor.java (from rev 79172, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeploymentVisitor.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeploymentVisitor.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeploymentVisitor.java 2008-10-06 22:03:36 UTC (rev 79173)
@@ -0,0 +1,116 @@
+/*
+* 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.spi.deployer.helpers;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.logging.Logger;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.spi.DeploymentException;
+
+/**
+ * Simple deployment visitor.
+ *
+ * @param <C> exact component type
+ * @param <T> exact deployment type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractDeploymentVisitor<C, T> extends ComponentAdapter<C> implements DeploymentVisitor<T>
+{
+ private Logger log = Logger.getLogger(getClass());
+
+ protected String getAttachmentName(C attachment)
+ {
+ return getComponentType().getName();
+ }
+
+ /**
+ * Get components from deployment.
+ *
+ * @param deployment the deployment
+ * @return list of components
+ */
+ protected abstract List<? extends C> getComponents(T deployment);
+
+ /**
+ * Get the component type.
+ *
+ * @return the component type
+ */
+ protected abstract Class<C> getComponentType();
+
+ public void deploy(DeploymentUnit unit, T deployment) throws DeploymentException
+ {
+ List<? extends C> components = getComponents(deployment);
+ if (components != null && components.isEmpty() == false)
+ {
+ List<C> visited = new ArrayList<C>();
+ try
+ {
+ for (C component : components)
+ {
+ addComponent(unit, component);
+ visited.add(component);
+ }
+ }
+ catch (Throwable t)
+ {
+ for (int i = visited.size() - 1; i >= 0; i--)
+ {
+ safeRemoveComponent(unit, visited.get(i));
+ }
+ throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
+ }
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit, T deployment)
+ {
+ List<? extends C> components = getComponents(deployment);
+ if (components != null && components.isEmpty() == false)
+ {
+ for (C component : components)
+ {
+ safeRemoveComponent(unit, component);
+ }
+ }
+ }
+
+ /**
+ * Ignore all error during component removal.
+ *
+ * @param unit the deployment unit
+ * @param attachment the attachment
+ */
+ protected void safeRemoveComponent(DeploymentUnit unit, C attachment)
+ {
+ try
+ {
+ removeComponent(unit, attachment);
+ }
+ catch (Throwable ignored)
+ {
+ log.warn("Error during component removal: " + unit.getName(), ignored);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ComponentAdapter.java (from rev 79172, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ComponentAdapter.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ComponentAdapter.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/ComponentAdapter.java 2008-10-06 22:03:36 UTC (rev 79173)
@@ -0,0 +1,73 @@
+/*
+* 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.spi.deployer.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Simple component adapter.
+ *
+ * @param <T> exact attachment type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class ComponentAdapter<T>
+{
+ /**
+ * Get component name.
+ *
+ * @param attachment the attachment
+ * @return the component name
+ */
+ protected abstract String getComponentName(T attachment);
+
+ /**
+ * Get attachment name.
+ * By default we return visitor type's name.
+ *
+ * @param attachment the attachment
+ * @return the attachment name
+ */
+ protected abstract String getAttachmentName(T attachment);
+
+ /**
+ * Add component.
+ *
+ * @param unit the deployment unit
+ * @param attachment the attachment
+ */
+ protected void addComponent(DeploymentUnit unit, T attachment)
+ {
+ DeploymentUnit component = unit.addComponent(getComponentName(attachment));
+ component.addAttachment(getAttachmentName(attachment), attachment);
+ }
+
+ /**
+ * Remove component.
+ *
+ * @param unit the deployment unit
+ * @param attachment the attachment
+ */
+ protected void removeComponent(DeploymentUnit unit, T attachment)
+ {
+ unit.removeComponent(getComponentName(attachment));
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list