package org.jboss.naming;
import javax.naming.MalformedLinkException;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import org.jboss.logging.Logger;
public class LinkRefPair extends Reference
{
private static final long serialVersionUID = 6036946190113161492L;
private static final String linkRefPairClassName = LinkRefPair.class.getName();
static final String remoteAddress = "remoteAddress";
static final String localAddress = "localAddress";
private static final String guidAddress = "guid";
public LinkRefPair(String remote, String local)
{
super(linkRefPairClassName, LinkRefPairObjectFactory.className, null);
add(new StringRefAddr(guidAddress, LinkRefPairObjectFactory.guid));
add(new StringRefAddr(remoteAddress, remote));
add(new StringRefAddr(localAddress, local));
}
public String getGUID() throws MalformedLinkException
{
if (className != null && className.equals(linkRefPairClassName))
{
RefAddr refAddr = get(guidAddress);
if (refAddr != null && refAddr instanceof StringRefAddr)
{
Object content = refAddr.getContent();
if (content != null && content instanceof String)
return (String) content;
else
throw new MalformedLinkException("Content is not a string: " + content);
}
else
throw new MalformedLinkException("RefAddr is not a string reference: " + refAddr);
}
else
throw new MalformedLinkException("Class is not a LinkRefPair: " + className);
}
public String getRemoteLinkName() throws MalformedLinkException
{
if (className != null && className.equals(linkRefPairClassName))
{
RefAddr refAddr = get(remoteAddress);
if (refAddr != null && refAddr instanceof StringRefAddr)
{
Object content = refAddr.getContent();
if (content != null && content instanceof String)
return (String) content;
else
throw new MalformedLinkException("Content is not a string: " + content);
}
else
throw new MalformedLinkException("RefAddr is not a string reference: " + refAddr);
}
else
throw new MalformedLinkException("Class is not a LinkRefPair: " + className);
}
public String getLocalLinkName() throws MalformedLinkException
{
if (className != null && className.equals(linkRefPairClassName))
{
RefAddr refAddr = get(localAddress);
if (refAddr != null && refAddr instanceof StringRefAddr)
{
Object content = refAddr.getContent();
if (content != null && content instanceof String)
return (String) content;
else
throw new MalformedLinkException("Content is not a string: " + content);
}
else
throw new MalformedLinkException("RefAddr is not a string reference: " + refAddr);
}
else
throw new MalformedLinkException("Class is not a LinkRefPair: " + className);
}
}