package org.jboss.naming;
import javax.naming.InitialContext;
import org.jboss.deployment.DeploymentException;
import org.jboss.system.ServiceMBeanSupport;
public class LinkRefPairService extends ServiceMBeanSupport
implements LinkRefPairServiceMBean
{
private String jndiName;
private String remoteJndiName;
private String localJndiName;
public String getJndiName()
{
return jndiName;
}
public String getLocalJndiName()
{
return localJndiName;
}
public String getRemoteJndiName()
{
return remoteJndiName;
}
public void setJndiName(String jndiName)
{
this.jndiName = jndiName;
}
public void setLocalJndiName(String jndiName)
{
this.localJndiName = jndiName;
}
public void setRemoteJndiName(String jndiName)
{
this.remoteJndiName = jndiName;
}
protected void startService() throws Exception
{
if (jndiName == null)
throw new DeploymentException("The jndiName is null for LinkRefPair " + getServiceName());
if (remoteJndiName == null)
throw new DeploymentException("The remoteJndiName is null for LinkRefPair " + getServiceName());
if (localJndiName == null)
throw new DeploymentException("The localJndiName is null for LinkRefPair " + getServiceName());
LinkRefPair pair = new LinkRefPair(remoteJndiName, localJndiName);
InitialContext ctx = new InitialContext();
try
{
Util.bind(ctx, jndiName, pair);
}
finally
{
ctx.close();
}
}
protected void stopService() throws Exception
{
LinkRefPair pair = new LinkRefPair(remoteJndiName, localJndiName);
InitialContext ctx = new InitialContext();
try
{
Util.unbind(ctx, jndiName);
}
finally
{
ctx.close();
}
}
}