KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > deployer > DeployerWrapper


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.deployer;
23
24 import org.jboss.deployers.spi.DeploymentException;
25 import org.jboss.deployers.spi.deployer.Deployer;
26 import org.jboss.deployers.spi.deployer.DeploymentUnit;
27 import org.jboss.logging.Logger;
28
29 /**
30  * DeployerWrapper.<p>
31  *
32  * To avoid any problems with error handling by the deployers.
33  *
34  * TODO change logging when full protocol is implemented
35  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
36  * @version $Revision: 1.1 $
37  */

38 public class DeployerWrapper implements Deployer
39 {
40    /** The log */
41    private Logger log;
42    
43    /** The deployer */
44    private Deployer deployer;
45    
46    /**
47     * Create a new DeployerWrapper.
48     *
49     * @param deployer the deployer
50     */

51    public DeployerWrapper(Deployer deployer)
52    {
53       if (deployer == null)
54          throw new IllegalArgumentException JavaDoc("Null deployer");
55       this.deployer = deployer;
56       this.log = Logger.getLogger(deployer.getClass());
57    }
58    
59    public boolean isRelevant(DeploymentUnit unit)
60    {
61       if (unit == null)
62          throw new IllegalArgumentException JavaDoc("Null unit");
63
64       try
65       {
66          boolean result = deployer.isRelevant(unit);
67          if (log.isTraceEnabled())
68             log.trace("isRelevant " + unit.getName() + " result=" + result);
69          return result;
70       }
71       catch (Throwable JavaDoc t)
72       {
73          log.warn("Error during isRelevant: " + unit.getName(), t);
74          return false;
75       }
76    }
77
78    public void prepareDeploy(DeploymentUnit unit) throws DeploymentException
79    {
80       if (unit == null)
81          throw new IllegalArgumentException JavaDoc("Null unit");
82
83       try
84       {
85          log.trace("Preparing deployment: " + unit.getName());
86          deployer.prepareDeploy(unit);
87          log.trace("Prepared deployment: " + unit.getName());
88       }
89       catch (Throwable JavaDoc t)
90       {
91          log.error("Error during prepare deployment: " + unit.getName(), t);
92          throw DeploymentException.rethrowAsDeploymentException("Error during prepare deployment: " + unit.getName(), t);
93       }
94    }
95
96    public void prepareUndeploy(DeploymentUnit unit)
97    {
98       if (unit == null)
99          throw new IllegalArgumentException JavaDoc("Null unit");
100
101       try
102       {
103          // TODO log.trace("Prepare undeployment: " + unit.getName());
104
log.trace("Undeploying: " + unit.getName());
105          deployer.prepareUndeploy(unit);
106          // TODO log.trace("Prepared undeployment: " + unit.getName());
107
log.trace("Undeployed: " + unit.getName());
108       }
109       catch (Throwable JavaDoc t)
110       {
111          // TODO log.warn("Error during prepare undeployment: " + unit.getName(), t);
112
log.warn("Error during undeployment: " + unit.getName(), t);
113       }
114    }
115
116    public void handoff(DeploymentUnit from, DeploymentUnit to) throws DeploymentException
117    {
118       if (from == null)
119          throw new IllegalArgumentException JavaDoc("Null from deployment");
120       if (to == null)
121          throw new IllegalArgumentException JavaDoc("Null to deployment");
122
123       try
124       {
125          log.trace("Handing off from=" + from.getName() + " to=" + to.getName());
126          deployer.handoff(from, to);
127          log.trace("Handed off from=" + from.getName() + " to=" + to.getName());
128       }
129       catch (Throwable JavaDoc t)
130       {
131          log.warn("Error during handoff from=" + from.getName() + " to=" + to.getName(), t);
132          throw DeploymentException.rethrowAsDeploymentException("Error during handoff from=" + from.getName() + " to=" + to.getName(), t);
133       }
134    }
135
136    public void commitDeploy(DeploymentUnit unit) throws DeploymentException
137    {
138       if (unit == null)
139          throw new IllegalArgumentException JavaDoc("Null unit");
140
141       try
142       {
143          // TODO log.debug("Commiting deployment: " + unit.getName());
144
log.trace("Deploying: " + unit.getName());
145          deployer.commitDeploy(unit);
146          // TODO log.debug("Commited deployment: " + unit.getName());
147
log.trace("Deployed: " + unit.getName());
148       }
149       catch (Throwable JavaDoc t)
150       {
151          // TODO log.error("Error during commit deploy: " + unit.getName(), t);
152
log.error("Error during deployment: " + unit.getName(), t);
153          // TODO throw DeploymentException.rethrowAsDeploymentException("Error during commit deployment: " + unit.getName(), t);
154
throw DeploymentException.rethrowAsDeploymentException("Error during deployment: " + unit.getName(), t);
155       }
156    }
157
158    public void commitUndeploy(DeploymentUnit unit)
159    {
160       if (unit == null)
161          throw new IllegalArgumentException JavaDoc("Null unit");
162
163       try
164       {
165          log.trace("Commiting undeployment: " + unit.getName());
166          deployer.commitUndeploy(unit);
167          log.trace("Commited undeployment: " + unit.getName());
168       }
169       catch (Throwable JavaDoc t)
170       {
171          log.warn("Error during commit undeployment: " + unit.getName(), t);
172       }
173    }
174    
175    public int getRelativeOrder()
176    {
177       return deployer.getRelativeOrder();
178    }
179    public void setRelativeOrder(int order)
180    {
181       deployer.setRelativeOrder(order);
182    }
183
184    @Override JavaDoc
185    public boolean equals(Object JavaDoc obj)
186    {
187       if (obj == this)
188          return true;
189       if (obj == null || obj instanceof Deployer == false)
190          return false;
191       if (obj instanceof DeployerWrapper)
192          obj = ((DeployerWrapper) obj).deployer;
193       return deployer.equals(obj);
194    }
195    
196    @Override JavaDoc
197    public int hashCode()
198    {
199       return deployer.hashCode();
200    }
201    
202    @Override JavaDoc
203    public String JavaDoc toString()
204    {
205       return deployer.toString();
206    }
207 }
208
Popular Tags