KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > deployer > BrokenDeployer


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, 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.test.jmx.deployer;
23
24 import java.io.File JavaDoc;
25 import java.net.URL JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import org.jboss.deployment.DeploymentException;
28 import org.jboss.deployment.DeploymentInfo;
29 import org.jboss.system.ServiceMBeanSupport;
30
31 /**
32  * This is a test of many possible problems with deployments.
33  * .xaa DeploymentException in init
34  * .xbb NPE in init
35  * .xcc DeploymentException in deploy
36  * .xdd NPE in deploy
37  * .xee DeploymentException in undeploy
38  * .xff NPE in undeploy
39  * .xgg deployment with a non-existent watch. (caused looping in bug 515537)
40  *
41  * The build script creates a BrokenDeployer.sar, which should be deployed before any
42  * of the test files as noted above are deployed.
43  *
44  * Created: Sun Feb 10 20:41:29 2002
45  *
46  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
47  * @version $Revision: 37406 $
48  *
49  * @jmx:mbean name="jboss.test:service=BrokenDeployer"
50  * @jmx:interface extends="org.jboss.deployment.DeployerMBean"
51  */

52 public class BrokenDeployer
53    extends ServiceMBeanSupport
54    implements BrokenDeployerMBean
55 {
56    public BrokenDeployer ()
57    {
58    }
59
60    public String JavaDoc getName()
61    {
62       return "Broken Deployer";
63    }
64
65    protected void startService() throws Exception JavaDoc
66    {
67       try
68       {
69          // Register with the main deployer
70
server.invoke(
71             org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
72             "addDeployer",
73             new Object JavaDoc[] {this},
74             new String JavaDoc[] {"org.jboss.deployment.DeployerMBean"});
75       }
76       catch (Exception JavaDoc e) {log.error("Could not register with MainDeployer", e);}
77   
78       log.info("BrokenDeployer started");
79    }
80    
81    
82       
83    
84    /** undeploys all deployments */
85    protected void stopService()
86    {
87       log.info("BrokenDeployer stopped");
88       
89       try
90       {
91          // Register with the main deployer
92
server.invoke(
93             org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
94             "removeDeployer",
95             new Object JavaDoc[] {this},
96             new String JavaDoc[] {"org.jboss.deployment.DeployerMBean"});
97       }
98       catch (Exception JavaDoc e) {log.error("Could not register with MainDeployer", e);}
99   
100    }
101
102    public boolean accepts(DeploymentInfo sdi)
103    {
104       log.info("asking about file: " + sdi.url.toString());
105       String JavaDoc file = new File JavaDoc(sdi.url.getFile()).toString();
106       
107       log.info("now asking about file: " + file);
108       return file.endsWith("xaa")
109          || file.endsWith("xbb")
110          || file.endsWith("xcc")
111          || file.endsWith("xdd")
112          || file.endsWith("xee")
113          || file.endsWith("xff")
114          || file.endsWith("xgg");
115    }
116
117    public void init(DeploymentInfo sdi)
118       throws DeploymentException
119    {
120       String JavaDoc file = new File JavaDoc(sdi.url.getFile()).toString();
121       if (file.endsWith("xaa"))
122       {
123          throw new DeploymentException("DeploymentException in init");
124       } // end of if ()
125
if (file.endsWith("xbb"))
126       {
127          throw new NullPointerException JavaDoc("NullPointerException in init");
128       } // end of if ()
129
if (file.endsWith("xgg"))
130       {
131          try
132          {
133             sdi.watch = new URL JavaDoc("File:/nowhere.jar");
134          }
135          catch (Exception JavaDoc e)
136          {
137             log.error("could not create fake url");
138          } // end of try-catch
139

140       } // end of if ()
141

142       
143    }
144
145    public void deploy(DeploymentInfo sdi)
146       throws DeploymentException
147    {
148       String JavaDoc file = new File JavaDoc(sdi.url.getFile()).toString();
149       if (file.endsWith("xcc"))
150       {
151          throw new DeploymentException("DeploymentException in deploy");
152       } // end of if ()
153
if (file.endsWith("xdd"))
154       {
155          throw new NullPointerException JavaDoc("NullPointerException in deploy");
156       } // end of if ()
157
}
158
159    public void undeploy(DeploymentInfo sdi)
160       throws DeploymentException
161    {
162       String JavaDoc file = new File JavaDoc(sdi.url.getFile()).toString();
163       if (file.endsWith("xee"))
164       {
165          throw new DeploymentException("DeploymentException in undeploy");
166       } // end of if ()
167
if (file.endsWith("xff"))
168       {
169          throw new NullPointerException JavaDoc("NullPointerException in undeploy");
170       } // end of if ()
171
}
172 }// BrokenDeployer
173
Popular Tags