package org.jboss.test.jmx.deployer;
import java.io.File;
import java.net.URL;
import javax.management.ObjectName;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.system.ServiceMBeanSupport;
public class BrokenDeployer
extends ServiceMBeanSupport
implements BrokenDeployerMBean
{
public BrokenDeployer ()
{
}
public String getName()
{
return "Broken Deployer";
}
protected void startService() throws Exception
{
try
{
server.invoke(
org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"addDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
}
catch (Exception e) {log.error("Could not register with MainDeployer", e);}
log.info("BrokenDeployer started");
}
protected void stopService()
{
log.info("BrokenDeployer stopped");
try
{
server.invoke(
org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"removeDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
}
catch (Exception e) {log.error("Could not register with MainDeployer", e);}
}
public boolean accepts(DeploymentInfo sdi)
{
log.info("asking about file: " + sdi.url.toString());
String file = new File(sdi.url.getFile()).toString();
log.info("now asking about file: " + file);
return file.endsWith("xaa")
|| file.endsWith("xbb")
|| file.endsWith("xcc")
|| file.endsWith("xdd")
|| file.endsWith("xee")
|| file.endsWith("xff")
|| file.endsWith("xgg");
}
public void init(DeploymentInfo sdi)
throws DeploymentException
{
String file = new File(sdi.url.getFile()).toString();
if (file.endsWith("xaa"))
{
throw new DeploymentException("DeploymentException in init");
} if (file.endsWith("xbb"))
{
throw new NullPointerException("NullPointerException in init");
} if (file.endsWith("xgg"))
{
try
{
sdi.watch = new URL("File:/nowhere.jar");
}
catch (Exception e)
{
log.error("could not create fake url");
}
}
}
public void deploy(DeploymentInfo sdi)
throws DeploymentException
{
String file = new File(sdi.url.getFile()).toString();
if (file.endsWith("xcc"))
{
throw new DeploymentException("DeploymentException in deploy");
} if (file.endsWith("xdd"))
{
throw new NullPointerException("NullPointerException in deploy");
} }
public void undeploy(DeploymentInfo sdi)
throws DeploymentException
{
String file = new File(sdi.url.getFile()).toString();
if (file.endsWith("xee"))
{
throw new DeploymentException("DeploymentException in undeploy");
} if (file.endsWith("xff"))
{
throw new NullPointerException("NullPointerException in undeploy");
} }
}