[jboss-cvs] JBossAS SVN: r85908 - 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 Mar 16 07:38:07 EDT 2009


Author: alesj
Date: 2009-03-16 07:38:07 -0400 (Mon, 16 Mar 2009)
New Revision: 85908

Added:
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAllInputDeployer.java
Log:
[JBDEPLOY-176]; port all input deployer.

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAllInputDeployer.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAllInputDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractAllInputDeployer.java	2009-03-16 11:38:07 UTC (rev 85908)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * Check all required inputs.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractAllInputDeployer extends AbstractDeployer
+{
+   /** Optional inputs */
+   private Set<String> optionalInputs = CollectionsFactory.createLazySet();
+
+   /**
+    * Do we have all required inputs.
+    *
+    * @param unit the deployment unit
+    * @return true if all inputs exist
+    */
+   protected boolean hasAllRequiredInputs(DeploymentUnit unit)
+   {
+      Set<String> inputs = getInputs();
+      if (inputs != null && inputs.isEmpty() == false)
+      {
+         for (String input : inputs)
+         {
+            if (optionalInputs.contains(input) == false && unit.isAttachmentPresent(input) == false)
+            {
+               return false;
+            }
+         }
+      }
+      return true;
+   }
+
+   public final void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      if (hasAllRequiredInputs(unit))
+      {
+         internalDeploy(unit);
+      }
+   }
+
+   /**
+    * Deploy a deployment
+    *
+    * @param unit the unit
+    * @throws DeploymentException for any error
+    */
+   protected abstract void internalDeploy(DeploymentUnit unit) throws DeploymentException;
+
+   public final void undeploy(DeploymentUnit unit)
+   {
+      if (hasAllRequiredInputs(unit))
+      {
+         internalUndeploy(unit);
+      }
+   }
+
+   /**
+    * Undeploy an deployment
+    *
+    * @param unit the unit
+    */
+   protected void internalUndeploy(DeploymentUnit unit)
+   {
+      // nothing
+   }
+
+   /**
+    * Add optional input.
+    *
+    * @param input the input
+    */
+   public void addOptionalInput(Class<?> input)
+   {
+      if (input == null)
+         throw new IllegalArgumentException("Null input");
+
+      addOptionalInput(input.getName());
+   }
+
+   /**
+    * Add optional input.
+    *
+    * @param input the input
+    */
+   public void addOptionalInput(String input)
+   {
+      if (input == null)
+         throw new IllegalArgumentException("Null input");
+
+      optionalInputs.add(input);
+   }
+
+   /**
+    * Set optional inputs.
+    *
+    * @param optionalInputs the optional inputs
+    */
+   public void setOptionalInputs(Set<String> optionalInputs)
+   {
+      this.optionalInputs = optionalInputs;
+   }
+}




More information about the jboss-cvs-commits mailing list