1 23 24 package com.sun.enterprise.server; 25 33 34 import com.sun.enterprise.config.*; 35 import com.sun.enterprise.config.serverbeans.*; 36 import com.sun.enterprise.util.RelativePathResolver; 37 import com.sun.enterprise.connectors.DeferredResourceConfig; 38 39 import java.util.logging.Level ; 40 41 public class DASResourcesUtil extends ResourcesUtil { 42 43 51 public boolean getConnectionFromConnectorRuntime_ = false; 52 53 protected DASResourcesUtil() { 54 super(); 55 } 56 57 66 protected boolean isReferenced(String resourceName) throws ConfigException { 67 if (_logger.isLoggable(Level.FINE)) { 68 _logger.fine("isReferenced in DASResourcesUtil:: " + resourceName); 69 } 70 71 if (isGetConnectionFromConnectorRuntime()) { 72 if (_logger.isLoggable(Level.FINE)) { 73 _logger.fine("getConnectionFromConnectorRuntime :: true"); 74 } 75 return true; 76 } 77 78 return super.isReferenced( resourceName ); 79 } 80 81 public boolean isGetConnectionFromConnectorRuntime() { 82 return getConnectionFromConnectorRuntime_; 83 } 84 85 public void setGetConnectionFromConnectorRuntime(boolean flag) { 86 getConnectionFromConnectorRuntime_ = flag; 87 } 88 89 public String getLocation(String moduleName) { 90 if(moduleName == null) { 91 return null; 92 } 93 94 ConfigContext adminConfigCtx = com.sun.enterprise.admin.server.core. 98 AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 99 100 try { 101 ConnectorModule connectorModule = ServerBeansFactory.getDomainBean(adminConfigCtx). 102 getApplications().getConnectorModuleByName(moduleName); 103 104 if (connectorModule == null) { 105 return null; 106 } 107 108 String connectorModuleLocation = connectorModule.getLocation(); 109 String connectorModuleLocationResolved = RelativePathResolver. 110 resolvePath(connectorModuleLocation); 111 return connectorModuleLocationResolved; 112 } catch (ConfigException e) { 113 _logger.warning(e.getMessage()); 114 _logger.log(Level.FINE, "Exception while tryign to find location" + 115 "of connector module " + moduleName, new Object []{e}); 116 } 117 return null; 118 } 119 120 125 public String getApplicationDeployLocation(String appName) { 126 ConfigContext adminConfigCtx = com.sun.enterprise.admin.server.core. 127 AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 128 129 try { 130 J2eeApplication app = ServerBeansFactory.getDomainBean(adminConfigCtx). 131 getApplications().getJ2eeApplicationByName(appName); 132 return RelativePathResolver.resolvePath(app.getLocation()); 133 } catch (ConfigException e) { 134 e.printStackTrace(); 135 } 136 return null; 137 } 138 139 147 public PersistenceManagerFactoryResource getPMFResourceByJndiName( 148 String jndiName ) { 149 reinitialize(); 150 151 Resources localRes = getResourcesServerBean(); 152 if ( localRes == null) { 153 return null; 154 } 155 156 if (_logger.isLoggable(Level.FINE)) { 157 _logger.fine("ResourceUtil :: looking up pmf resource, jndiName is :" 158 + jndiName ); 159 } 160 PersistenceManagerFactoryResource pmf = 161 localRes.getPersistenceManagerFactoryResourceByJndiName( jndiName ); 162 163 if (_logger.isLoggable(Level.FINE)) { 164 _logger.fine("getPMFResourceByJndiName:: looked up pmf resource : " 165 + pmf); 166 } 167 if (pmf == null) { 169 return null; 170 } 171 172 try { 173 return isReferenced( jndiName ) ? pmf : null; 174 }catch( ConfigException ce ) { 175 return null; 176 } 177 } 178 179 186 public JdbcResource getJdbcResourceByJndiName( String jndiName) { 187 reinitialize(); 188 189 Resources localRes = getResourcesServerBean(); 190 if ( localRes == null ) { 191 return null; 192 } 193 194 if (_logger.isLoggable(Level.FINE)) { 195 _logger.fine("ResourcesUtil :: looking up jdbc resource, jndiName is :" 196 + jndiName ); 197 } 198 199 JdbcResource jdbcRes = 200 localRes.getJdbcResourceByJndiName( jndiName ); 201 202 if (_logger.isLoggable(Level.FINE)) { 203 _logger.fine("ResourcesUtil :: looked up jdbc resource:" + jdbcRes.getJndiName() ); 204 } 205 if (jdbcRes == null) { 207 return null; 208 } 209 210 try { 211 return isReferenced( jndiName ) ? jdbcRes : null; 212 }catch( ConfigException ce ) { 213 return null; 214 } 215 } 216 217 223 public boolean isPMFResource( String jndiName) { 224 225 if (_logger.isLoggable(Level.FINE)) { 226 _logger.fine("ResourcesUtil :: checking if this is a pmf resource:" 227 + jndiName ); 228 } 229 return (getPMFResourceByJndiName(jndiName) != null); 230 } 231 232 233 protected DeferredResourceConfig getDeferredJdbcResourceConfigs( 234 String resourceName) 235 { 236 237 if(resourceName == null) { 238 return null; 239 } 240 reinitialize(); 241 try { 242 if(!(resourceName.endsWith("__pm"))){ 245 if(!isReferenced(resourceName)){ 246 return null; 247 } 248 } 249 } catch (ConfigException e) { 250 _logger.log(Level.WARNING, e.getMessage()); 251 _logger.log(Level.FINE, "Error while finding resource references " , e); 252 } 253 254 Resources localRes = getResourcesServerBean(); 255 if ( localRes == null ) { 256 return null; 257 } 258 259 ConfigBean[] resourcesToload = new ConfigBean[2]; 260 JdbcResource jdbcResource = localRes.getJdbcResourceByJndiName(resourceName); 261 if(jdbcResource == null || !jdbcResource.isEnabled()) { 262 String cmpResourceName = 263 getCorrespondingCmpResourceName(resourceName); 264 jdbcResource = localRes.getJdbcResourceByJndiName(cmpResourceName); 265 if(jdbcResource == null) { 266 return null; 267 } 268 } 269 JdbcConnectionPool jdbcPool = 270 localRes.getJdbcConnectionPoolByName(jdbcResource.getPoolName()); 271 if(jdbcPool == null) { 272 return null; 273 } 274 String rarName = getRAForJdbcConnectionPool(jdbcPool); 275 if(rarName != null && belongToSystemRar(rarName)) { 276 resourcesToload[0] = jdbcPool; 277 resourcesToload[1] = jdbcResource; 278 DeferredResourceConfig resourceConfig = 279 new DeferredResourceConfig(rarName,null,null, 280 null,jdbcPool,jdbcResource,null); 281 resourceConfig.setResourcesToLoad(resourcesToload); 282 return resourceConfig; 283 } 284 return null; 285 } 286 287 protected DeferredResourceConfig getDeferredJdbcPoolConfigs( 288 String poolName) 289 { 290 if(poolName == null) { 291 return null; 292 } 293 reinitialize(); 294 295 Resources localRes = getResourcesServerBean(); 296 JdbcConnectionPool jdbcPool = 297 localRes.getJdbcConnectionPoolByName(poolName); 298 if(jdbcPool == null) { 299 return null; 300 } 301 String rarName = getRAForJdbcConnectionPool(jdbcPool); 302 303 ConfigBean[] resourcesToload = new ConfigBean[1]; 304 if(rarName != null && belongToSystemRar(rarName)) { 305 resourcesToload[0] = jdbcPool; 306 DeferredResourceConfig resourceConfig = 307 new DeferredResourceConfig(rarName,null,null, 308 null,jdbcPool,null,null); 309 resourceConfig.setResourcesToLoad(resourcesToload); 310 return resourceConfig; 311 } 312 return null; 313 } 314 315 protected Resources getResourcesServerBean() { 316 321 if (! isGetConnectionFromConnectorRuntime() ) { 322 return super.getResourcesServerBean(); 325 } 326 327 ConfigContext adminConfigCtx = com.sun.enterprise.admin.server.core. 328 AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 329 330 Domain localdom = null; 331 Resources localres = null; 332 try { 333 localdom = ServerBeansFactory.getDomainBean( adminConfigCtx ); 334 localres = localdom.getResources(); 335 } catch( ConfigException ce ) { 336 _logger.log( Level.WARNING, ce.getMessage() ); 337 return null; 338 } 339 340 return localres; 341 } 342 343 protected DeferredResourceConfig getDeferredConnectorResourceConfigs( 344 String resourceName) 345 { 346 347 if(resourceName == null) { 348 return null; 349 } 350 351 reinitialize(); 352 353 try { 354 if(!isReferenced(resourceName)){ 355 return null; 356 } 357 } catch (ConfigException e) { 358 _logger.log(Level.WARNING, e.getMessage()); 359 _logger.log(Level.FINE, "Error while finding resource references " , e); 360 } 361 362 Resources localRes = getResourcesServerBean(); 363 if ( localRes == null ) { 364 return null; 365 } 366 ConfigBean[] resourcesToload = new ConfigBean[2]; 367 ConnectorResource connectorResource = 368 localRes.getConnectorResourceByJndiName(resourceName); 369 if(connectorResource == null || !connectorResource.isEnabled()) { 370 return null; 371 } 372 String poolName = connectorResource.getPoolName(); 373 ConnectorConnectionPool ccPool = 374 localRes.getConnectorConnectionPoolByName(poolName); 375 if(ccPool == null) { 376 return null; 377 } 378 String rarName = ccPool.getResourceAdapterName(); 379 if(rarName != null && belongToSystemRar(rarName)) { 380 resourcesToload[0] = ccPool; 381 resourcesToload[1] = connectorResource; 382 ResourceAdapterConfig[] resourceAdapterConfig = 383 new ResourceAdapterConfig[1]; 384 resourceAdapterConfig[0] = 385 localRes.getResourceAdapterConfigByResourceAdapterName( 386 rarName); 387 DeferredResourceConfig resourceConfig = 388 new DeferredResourceConfig(rarName,null,ccPool, 389 connectorResource,null,null, 390 resourceAdapterConfig); 391 resourceConfig.setResourcesToLoad(resourcesToload); 392 return resourceConfig; 393 } 394 return null; 395 } 396 397 protected DeferredResourceConfig getDeferredConnectorPoolConfigs( 398 String poolName) 399 { 400 401 if(poolName == null) { 402 return null; 403 } 404 405 reinitialize(); 406 Resources localRes = getResourcesServerBean(); 407 408 ConfigBean[] resourcesToload = new ConfigBean[1]; 409 ConnectorConnectionPool ccPool = 410 localRes.getConnectorConnectionPoolByName(poolName); 411 if(ccPool == null) { 412 return null; 413 } 414 415 String rarName = ccPool.getResourceAdapterName(); 416 417 if(rarName != null) { resourcesToload[0] = ccPool; 425 ResourceAdapterConfig[] resourceAdapterConfig = 426 new ResourceAdapterConfig[1]; 427 resourceAdapterConfig[0] = 428 localRes.getResourceAdapterConfigByResourceAdapterName( 429 rarName); 430 DeferredResourceConfig resourceConfig = 431 new DeferredResourceConfig(rarName,null,ccPool, 432 null,null,null,resourceAdapterConfig); 433 resourceConfig.setResourcesToLoad(resourcesToload); 434 return resourceConfig; 435 } 436 return null; 437 } 438 439 440 protected DeferredResourceConfig getDeferredAdminObjectConfigs( 441 String resourceName) 442 { 443 444 if(resourceName == null) { 445 return null; 446 } 447 reinitialize(); 448 449 try { 450 if(!isReferenced(resourceName)){ 451 return null; 452 } 453 } catch (ConfigException e) { 454 _logger.log(Level.WARNING, e.getMessage()); 455 _logger.log(Level.FINE, "Error while finding resource references " , e); 456 } 457 458 Resources localRes = getResourcesServerBean(); 459 if ( localRes == null) { 460 return null; 461 } 462 463 ConfigBean[] resourcesToload = new ConfigBean[1]; 464 AdminObjectResource adminObjectResource = 465 localRes.getAdminObjectResourceByJndiName(resourceName); 466 if(adminObjectResource == null || !adminObjectResource.isEnabled()) { 467 return null; 468 } 469 String rarName = adminObjectResource.getResAdapter(); 470 if(rarName != null && belongToSystemRar(rarName)) { 471 resourcesToload[0] = adminObjectResource; 472 ResourceAdapterConfig[] resourceAdapterConfig = 473 new ResourceAdapterConfig[1]; 474 resourceAdapterConfig[0] = 475 localRes.getResourceAdapterConfigByResourceAdapterName(rarName); 476 DeferredResourceConfig resourceConfig = 477 new DeferredResourceConfig(rarName,adminObjectResource, 478 null,null,null,null,resourceAdapterConfig); 479 resourceConfig.setResourcesToLoad(resourcesToload); 480 return resourceConfig; 481 } 482 return null; 483 } 484 485 public JdbcConnectionPool[] getJdbcConnectionPools() { 486 Resources localRes = null; 496 497 setGetConnectionFromConnectorRuntime( true ); 498 try { 499 localRes = getResourcesServerBean(); 500 } finally { 501 setGetConnectionFromConnectorRuntime( false ); 502 } 503 504 JdbcConnectionPool[] jdbcConnectionPool = localRes.getJdbcConnectionPool(); 505 if(jdbcConnectionPool == null) return null; 506 if (jdbcConnectionPool.length == 0) { 507 return null; 508 } else { 509 return jdbcConnectionPool; 510 } 511 } 512 513 public ConnectorConnectionPool[] getConnectorConnectionPools() { 514 Resources localRes = null; 519 setGetConnectionFromConnectorRuntime( true ); 520 try { 521 localRes = getResourcesServerBean(); 522 } finally { 523 setGetConnectionFromConnectorRuntime( false ); 524 } 525 526 ConnectorConnectionPool[] connectorConnectionPools = 527 localRes.getConnectorConnectionPool(); 528 if(connectorConnectionPools == null) return null; 529 if (connectorConnectionPools.length == 0) { 530 return null; 531 } else { 532 return connectorConnectionPools; 533 } 534 } 535 536 } 537 | Popular Tags |