1 22 package org.jboss.naming; 23 24 import javax.naming.MalformedLinkException ; 25 import javax.naming.RefAddr ; 26 import javax.naming.Reference ; 27 import javax.naming.StringRefAddr ; 28 29 36 public class LinkRefPair extends Reference 37 { 38 40 41 private static final long serialVersionUID = 6036946190113161492L; 42 43 44 private static final String linkRefPairClassName = LinkRefPair.class.getName(); 45 46 47 static final String remoteAddress = "remoteAddress"; 48 49 50 static final String localAddress = "localAddress"; 51 52 53 private static final String guidAddress = "guid"; 54 55 57 59 61 67 public LinkRefPair(String remote, String local) 68 { 69 super(linkRefPairClassName, LinkRefPairObjectFactory.className, null); 70 add(new StringRefAddr (guidAddress, LinkRefPairObjectFactory.guid)); 71 add(new StringRefAddr (remoteAddress, remote)); 72 add(new StringRefAddr (localAddress, local)); 73 } 74 75 77 83 public String getGUID() throws MalformedLinkException 84 { 85 if (className != null && className.equals(linkRefPairClassName)) 86 { 87 RefAddr refAddr = get(guidAddress); 88 if (refAddr != null && refAddr instanceof StringRefAddr ) 89 { 90 Object content = refAddr.getContent(); 91 if (content != null && content instanceof String ) 92 return (String ) content; 93 else 94 throw new MalformedLinkException ("Content is not a string: " + content); 95 } 96 else 97 throw new MalformedLinkException ("RefAddr is not a string reference: " + refAddr); 98 } 99 else 100 throw new MalformedLinkException ("Class is not a LinkRefPair: " + className); 101 } 102 103 109 public String getRemoteLinkName() throws MalformedLinkException 110 { 111 if (className != null && className.equals(linkRefPairClassName)) 112 { 113 RefAddr refAddr = get(remoteAddress); 114 if (refAddr != null && refAddr instanceof StringRefAddr ) 115 { 116 Object content = refAddr.getContent(); 117 if (content != null && content instanceof String ) 118 return (String ) content; 119 else 120 throw new MalformedLinkException ("Content is not a string: " + content); 121 } 122 else 123 throw new MalformedLinkException ("RefAddr is not a string reference: " + refAddr); 124 } 125 else 126 throw new MalformedLinkException ("Class is not a LinkRefPair: " + className); 127 } 128 129 135 public String getLocalLinkName() throws MalformedLinkException 136 { 137 if (className != null && className.equals(linkRefPairClassName)) 138 { 139 RefAddr refAddr = get(localAddress); 140 if (refAddr != null && refAddr instanceof StringRefAddr ) 141 { 142 Object content = refAddr.getContent(); 143 if (content != null && content instanceof String ) 144 return (String ) content; 145 else 146 throw new MalformedLinkException ("Content is not a string: " + content); 147 } 148 else 149 throw new MalformedLinkException ("RefAddr is not a string reference: " + refAddr); 150 } 151 else 152 throw new MalformedLinkException ("Class is not a LinkRefPair: " + className); 153 } 154 155 157 159 161 } 163 | Popular Tags |