KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > deployers > helpers > AbstractRealDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.deployers.plugins.deployers.helpers;
23
24 import java.util.Set JavaDoc;
25
26 import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
27 import org.jboss.deployers.spi.DeploymentException;
28 import org.jboss.deployers.spi.deployer.DeploymentUnit;
29
30 /**
31  * AbstractRealDeployer.
32  *
33  * @param <T> the deployment type
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 1.1 $
36  */

37 public abstract class AbstractRealDeployer<T> extends AbstractSimpleDeployer
38 {
39    /** The visitor */
40    private SimpleDeploymentVisitor<T> visitor;
41
42    /** The deployment type */
43    private Class JavaDoc<T> deploymentType;
44
45    /** Whether the warning has been displayed */
46    private boolean warned;
47
48    /**
49     * Set the default relative order to REAL_DEPLOYER.
50     *
51     */

52    public AbstractRealDeployer()
53    {
54       setRelativeOrder(REAL_DEPLOYER);
55    }
56
57    /**
58     * Set the deployment visitor
59     *
60     * @param visitor the visitor
61     * @throws IllegalArgumentException if the visitor is null
62     */

63    protected void setDeploymentVisitor(SimpleDeploymentVisitor<T> visitor)
64    {
65       if (visitor == null)
66          throw new IllegalArgumentException JavaDoc("Null visitor");
67       this.visitor = visitor;
68       deploymentType = visitor.getVisitorType();
69       if (deploymentType == null)
70          throw new IllegalArgumentException JavaDoc("Null visitor type");
71    }
72
73    public void deploy(DeploymentUnit unit) throws DeploymentException
74    {
75       if (visitor == null)
76       {
77          if (warned == false)
78          {
79             log.error("INTERNAL ERROR: Visitor is null for " + getClass().getName());
80             warned = true;
81          }
82          return;
83       }
84
85       try
86       {
87          Set JavaDoc<? extends T> deployments = unit.getAllMetaData(deploymentType);
88          for (T deployment : deployments)
89             visitor.deploy(unit, deployment);
90       }
91       catch (Throwable JavaDoc t)
92       {
93          undeploy(unit);
94          throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
95       }
96    }
97
98    public void undeploy(DeploymentUnit unit)
99    {
100       if (visitor == null)
101          return;
102       Set JavaDoc<? extends T> deployments = unit.getAllMetaData(deploymentType);
103       for (T deployment : deployments)
104          visitor.undeploy(unit, deployment);
105    }
106
107 }
108
Popular Tags