1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.*; 27 import javax.mail.Session ; 28 import javax.sql.DataSource ; 29 import java.util.logging.*; 30 import com.sun.enterprise.deployment.util.LogDomains; 31 import com.sun.enterprise.deployment.ResourcePrincipal; 32 import com.sun.enterprise.deployment.web.ResourceReference; 33 import com.sun.enterprise.util.LocalStringManagerImpl; 35 39 40 public class ResourceReferenceDescriptor extends EnvironmentProperty 41 implements NamedDescriptor, ResourceReference { 42 45 public static String APPLICATION_AUTHORIZATION = "Application"; 46 49 public static String CONTAINER_AUTHORIZATION = "Container"; 50 51 public static String RESOURCE_SHAREABLE = "Shareable"; 53 public static String RESOURCE_UNSHAREABLE = "Unshareable"; 54 55 private static final String URL_RESOURCE_TYPE = "java.net.URL"; 56 57 private static final String CONNECTOR_RESOURCE_TYPE = "javax.resource.cci.ConnectionFactory"; 59 private static final String MAIL_RESOURCE_TYPE = "javax.mail.Session"; 61 62 private static final String JDBC_RESOURCE_TYPE = "javax.sql.DataSource"; 64 66 private static final String ORB_RESOURCE_TYPE = "org.omg.CORBA.ORB"; 67 68 private static final String WEBSERVICE_CONTEXT_TYPE = 69 "javax.xml.ws.WebServiceContext"; 70 71 private String rType; 74 private ResourcePrincipal resourcePrincipal = null; 75 private MailConfiguration mailConfiguration; 76 private String authorization; 77 private DataSource dataSource; 78 private String sharingScope; 79 80 private List runtimeProps=null; 81 82 boolean createTablesAtDeploy=false; 84 boolean dropTablesAtUndeploy=false; 85 String databaseVendorName = null; 86 Properties schemaGeneratorProperties = null; 87 88 private static LocalStringManagerImpl localStrings = 90 new LocalStringManagerImpl(ResourceReferenceDescriptor.class); 91 93 100 public ResourceReferenceDescriptor(String name, String description, 101 String type) { 102 super(name, "", description); 103 rType = type; 104 this.sharingScope = RESOURCE_SHAREABLE; 105 } 106 107 110 public ResourceReferenceDescriptor() { 111 this.sharingScope = RESOURCE_SHAREABLE; 112 } 113 114 117 static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 118 119 120 124 public String getJndiName() { 125 String jndiName = super.getValue(); 126 return (jndiName != null && ! jndiName.equals("")) ? 127 jndiName : getMappedName(); 128 } 129 130 134 public void setJndiName(String jndiName) { 135 super.setValue(jndiName); 136 } 137 138 public String getInjectResourceType() { 139 return rType; 140 } 141 142 public void setInjectResourceType(String resourceType) { 143 rType = resourceType; 144 } 145 146 150 public String getSharingScope() { 151 if ( sharingScope == null ) { 152 return ""; 153 } 154 return sharingScope; 155 } 156 157 161 public void setSharingScope(String ss) { 162 sharingScope = ss; 163 } 164 165 166 170 public boolean isResolved() { 171 return true; 172 } 173 174 179 public boolean isContainerAuthorization() { 180 return this.getAuthorization().equals(CONTAINER_AUTHORIZATION); 181 } 182 183 188 public String getAuthorization() { 189 if (this.authorization == null) { 190 this.authorization = APPLICATION_AUTHORIZATION; 191 } 192 return this.authorization; 193 } 194 195 199 public void setAuthorization(String authorization) { 200 this.authorization = authorization; 201 } 202 203 207 public String getType() { 208 return rType; 209 } 210 211 215 public void setType(String type) { 216 rType = type; 217 } 218 219 223 public DataSource getJDBCDataSource() 224 { 225 if ( dataSource == null ) { 226 try { 227 javax.naming.Context ctx = new javax.naming.InitialContext (); 229 dataSource = (DataSource )ctx.lookup(getJndiName()); 231 } catch ( Exception ex ) { } 232 } 233 return dataSource; 234 } 235 236 public boolean isWebServiceContext() { 237 return this.getType().equals(WEBSERVICE_CONTEXT_TYPE); 238 } 239 240 public boolean isORB() { 241 return this.getType().equals(ORB_RESOURCE_TYPE); 242 } 243 244 248 public boolean isMailResource() { 249 return this.getType().equals(MAIL_RESOURCE_TYPE); 252 } 254 255 259 public boolean isJDBCResource() { 260 return this.getType().equals(JDBC_RESOURCE_TYPE); 261 } 262 264 265 269 public boolean isURLResource() { 270 return this.getType().equals(URL_RESOURCE_TYPE); 271 } 272 273 278 public boolean isJMSConnectionFactory() { 279 String myType = this.getType(); 280 return 281 ( myType.equals("javax.jms.QueueConnectionFactory") || 282 myType.equals("javax.jms.TopicConnectionFactory") ); 283 } 284 285 289 public ResourcePrincipal getResourcePrincipal() { 290 return this.resourcePrincipal; 291 } 292 293 297 public void setResourcePrincipal(ResourcePrincipal resourcePrincipal) { 298 this.resourcePrincipal = resourcePrincipal; 299 } 300 301 305 public void setMailConfiguration(MailConfiguration mailConfiguration) { 306 this.mailConfiguration = mailConfiguration; 307 } 308 309 312 public void addProperty(NameValuePairDescriptor newProp) { 313 if (runtimeProps==null) { 314 runtimeProps = new ArrayList(); 315 } 316 runtimeProps.add(newProp); 317 } 318 319 322 public Iterator getProperties() { 323 if (runtimeProps==null) { 324 return null; 325 } 326 return runtimeProps.iterator(); 327 } 328 329 333 public MailConfiguration getMailConfiguration() { 334 return this.mailConfiguration; 335 } 336 337 341 public boolean isCreateTablesAtDeploy() { 342 return createTablesAtDeploy; 343 } 344 345 349 public void setCreateTablesAtDeploy(boolean createTablesAtDeploy) { 350 this.createTablesAtDeploy = createTablesAtDeploy; 351 } 352 353 357 public boolean isDropTablesAtUndeploy() { 358 return dropTablesAtUndeploy; 359 } 360 361 365 public void setDropTablesAtUndeploy(boolean dropTablesAtUndeploy) { 366 this.dropTablesAtUndeploy = dropTablesAtUndeploy; 367 } 368 369 372 public String getDatabaseVendorName() { 373 return databaseVendorName; 374 } 375 376 379 public void setDatabaseVendorName(String vendorName) { 380 this.databaseVendorName = vendorName; 381 } 382 383 386 public Properties getSchemaGeneratorProperties() { 387 return schemaGeneratorProperties; 388 } 389 390 393 public void setSchemaGeneratorProperties(Properties props) { 394 schemaGeneratorProperties = props; 395 } 396 397 400 public boolean equals(Object object) { 401 if (object instanceof ResourceReference) { 402 ResourceReference resourceReference = (ResourceReference) object; 403 return resourceReference.getName().equals(this.getName()); 404 } 405 return false; 406 } 407 408 411 public void print(StringBuffer toStringBuffer) { 412 StringBuffer sb = toStringBuffer; 413 sb.append("Res-Ref-Env-Property: "); 414 sb.append(super.getName()); 415 sb.append("@"); 416 sb.append(getType()); 417 sb.append("@"); 418 sb.append(getDescription()); 419 if (this.isResolved()) { 420 sb.append(" resolved as: jndi: "); 421 sb.append(getJndiName()); 422 sb.append("@res principal: "); 423 sb.append(getResourcePrincipal()); 424 sb.append("@mail: "); 425 sb.append(getMailConfiguration()); 426 } 427 if (runtimeProps!=null) { 428 for (Iterator itr = runtimeProps.iterator();itr.hasNext();) { 429 sb.append("\nPropery : "); 430 sb.append(itr.next()); 431 } 432 } else { 433 sb.append("\nNo Runtime properties"); 434 } 435 sb.append("\nDatabase Vendor : " + databaseVendorName); 436 sb.append("\nCreate Tables at Deploy : " + createTablesAtDeploy); 437 sb.append("\nDelete Tables at Undeploy : " + dropTablesAtUndeploy); 438 439 if (schemaGeneratorProperties!=null) { 440 sb.append("\nSchema Generator Properties : "); 441 sb.append(schemaGeneratorProperties); 442 } 443 444 } 445 451 public boolean isResourceConnectionFactory () { 452 return this.getType().equals(CONNECTOR_RESOURCE_TYPE); 453 } 454 456 462 public void checkType() { 463 if (rType != null) { 464 Class typeClass = null; 465 try { 467 474 typeClass = Class.forName(rType, true, 475 Thread.currentThread().getContextClassLoader()); 476 477 } catch (Throwable t) { 478 if (this.isBoundsChecking()) { 479 throw new IllegalArgumentException (localStrings.getLocalString( 480 "enterprise.deployment.exceptiontypenotallowedpropertytype", 481 "{0} is not an allowed property value type", 482 new Object [] {rType})); 483 } else { 484 return; 485 } 486 } 487 } 488 } 489 491 } 492 | Popular Tags |