1 23 package com.sun.enterprise.deployment; 24 25 import com.sun.enterprise.deployment.types.EjbReference; 26 import com.sun.enterprise.util.LocalStringManagerImpl; 27 28 34 35 public class EjbReferenceDescriptor extends EnvironmentProperty implements com.sun.enterprise.deployment.types.EjbReference, NamedDescriptor { 36 37 private EjbDescriptor ejbDescriptor; 40 41 private static LocalStringManagerImpl localStrings = 42 new LocalStringManagerImpl(EjbReferenceDescriptor.class); 43 44 private BundleDescriptor referringBundle; 46 47 private String refType=null; 49 private String refHomeIntf=null; 50 private String refIntf=null; 51 52 private boolean isLocal=false; 54 55 59 private String ejbLink=null; 60 61 66 public EjbReferenceDescriptor(EjbReferenceDescriptor other) { 67 super(other); 68 isLocal = other.isLocal; refType = other.refType; refHomeIntf = other.refHomeIntf; refIntf = other.refIntf; ejbLink = other.ejbLink; referringBundle = other.referringBundle; ejbDescriptor = other.ejbDescriptor; 75 if (ejbDescriptor != null) { 76 ejbDescriptor.addEjbReferencer(this); } 78 } 79 80 88 public EjbReferenceDescriptor(String name, String description, EjbDescriptor ejbDescriptor) { 89 super(name, "", description); 90 this.setEjbDescriptor(ejbDescriptor); 91 } 92 93 102 public EjbReferenceDescriptor(String name, String description, EjbDescriptor ejbDescriptor, boolean isLocal) { 103 super(name, "", description); 104 this.isLocal = isLocal; 105 this.setEjbDescriptor(ejbDescriptor); 106 } 107 108 111 112 public EjbReferenceDescriptor() { 113 } 114 115 119 public void setReferringBundleDescriptor(BundleDescriptor referringBundle) 120 { 121 this.referringBundle = referringBundle; 122 } 123 124 128 public BundleDescriptor getReferringBundleDescriptor() 129 { 130 return referringBundle; 131 } 132 133 137 public void setEjbDescriptor(EjbDescriptor ejbDescriptor) { 138 if (this.ejbDescriptor != null) { 139 this.ejbDescriptor.removeEjbReferencer(this); } 141 this.ejbDescriptor=ejbDescriptor; 142 if (ejbDescriptor!=null) { 143 ejbDescriptor.addEjbReferencer(this); 144 if (isLocal()) { 145 if (!ejbDescriptor.isLocalInterfacesSupported() && 146 !ejbDescriptor.isLocalBusinessInterfacesSupported()) { 147 throw new RuntimeException (localStrings.getLocalString( 148 "entreprise.deployment.invalidLocalInterfaceReference", 149 "Trying to set an ejb-local-ref on an EJB while the EJB does not define local interfaces")); 150 } 151 } else { 152 if (!ejbDescriptor.isRemoteInterfacesSupported() && 153 !ejbDescriptor.isRemoteBusinessInterfacesSupported()) { 154 throw new RuntimeException (localStrings.getLocalString( 155 "entreprise.deployment.invalidRemoteInterfaceReference", 156 "Trying to set an ejb-ref on an EJB, while the EJB does not define remote interfaces")); 157 } 158 } 159 } 160 } 161 162 163 165 166 public void setJndiName(String jndiName) { 167 this.setValue(jndiName); 168 } 169 170 172 173 public boolean isLinked() { 174 return ejbLink!=null; 175 } 176 177 180 181 public String getLinkName() { 182 if (ejbDescriptor==null) { 183 return ejbLink; 184 } else { 185 if (ejbLink != null && ejbLink.length()!=0) { 186 return ejbLink; 187 } 188 return ejbDescriptor.getName(); 189 } 190 } 191 192 195 public void setLinkName(String linkName) { 196 ejbLink = linkName; 197 } 198 201 202 public String getJndiName() { 203 String jndiName = this.getValue(); 204 if( isLocal() ) { 205 return jndiName; 209 } else { 210 return (jndiName != null && ! jndiName.equals("")) ? 211 jndiName : getMappedName(); 212 } 213 } 214 215 218 219 public String getValue() { 220 if (ejbDescriptor == null) { 221 return super.getValue(); 222 } else { 223 if (isLocal()) { 224 return super.getValue(); 225 } else { 226 return ejbDescriptor.getJndiName(); 227 } 228 } 229 } 230 231 233 234 public EjbDescriptor getEjbDescriptor() { 235 return ejbDescriptor; 236 } 237 238 241 public boolean isLocal() { 242 return isLocal; 243 } 244 245 249 public void setLocal(boolean local) { 250 this.isLocal = local; 251 } 252 253 256 257 public String getType() { 258 if (ejbDescriptor==null) { 259 return refType; 260 } else { 261 return ejbDescriptor.getType(); 262 } 263 } 264 265 267 public void setType(String type) { 268 refType=type; 269 } 270 271 public String getInjectResourceType() { 272 return isEJB30ClientView() ? 273 getEjbInterface() : getEjbHomeInterface(); 274 } 275 276 public void setInjectResourceType(String resourceType) { 277 if (isEJB30ClientView()) { 278 setEjbInterface(resourceType); 279 } else { 280 setEjbHomeInterface(resourceType); 281 } 282 } 283 284 287 public String getHomeClassName() { 288 return refHomeIntf; 289 } 290 291 294 295 public void setHomeClassName(String homeClassName) { 296 refHomeIntf = homeClassName; 297 } 298 299 302 public String getBeanClassName() { 303 return refIntf; 304 } 305 306 310 public void setBeanClassName(String remoteClassName) { 311 refIntf = remoteClassName; 312 } 313 314 318 public String getEjbHomeInterface() { 319 return getHomeClassName(); 320 } 321 322 326 public void setEjbHomeInterface(String homeClassName) { 327 setHomeClassName(homeClassName); 328 } 329 330 334 public String getEjbInterface() { 335 return getBeanClassName(); 336 } 337 341 public void setEjbInterface(String remoteClassName) { 342 setBeanClassName(remoteClassName); 343 } 344 345 348 public boolean isEJB30ClientView() { 349 return (getHomeClassName() == null); 350 } 351 352 354 355 public void print(StringBuffer toStringBuffer) { 356 if (ejbDescriptor!=null) { 357 toStringBuffer.append("Resolved Ejb-Ref ").append(getName()).append("@jndi: ").append(getJndiName()).append( 358 " - > ").append(ejbDescriptor.getName()); 359 } else { 360 toStringBuffer.append("Unresolved Ejb-Ref ").append(getName()).append("@jndi: ").append(getJndiName()).append("@").append( 361 getEjbHomeInterface()).append("@").append(getEjbInterface()).append("@").append(refType).append("@").append(ejbLink) ; 362 } 363 } 364 365 366 public boolean equals(Object object) { 367 if (object instanceof EjbReference) { 368 EjbReference ejbReference = (EjbReference) object; 369 return ejbReference.getName().equals(this.getName()); 370 } 371 return false; 372 } 373 } 374 | Popular Tags |