1 23 package com.sun.enterprise.admin.event; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import com.sun.enterprise.admin.server.core.AdminService; 28 import com.sun.enterprise.config.ConfigContext; 29 import com.sun.enterprise.config.serverbeans.JdbcResource; 30 import com.sun.enterprise.config.serverbeans.ResourceAdapterConfig; 31 import com.sun.enterprise.config.serverbeans.Domain; 32 import com.sun.enterprise.config.serverbeans.Server; 33 import com.sun.enterprise.config.serverbeans.Cluster; 34 import com.sun.enterprise.config.serverbeans.ResourceRef; 35 import com.sun.enterprise.config.serverbeans.Resources; 36 import com.sun.enterprise.config.serverbeans.ServerHelper; 37 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 38 import com.sun.enterprise.config.serverbeans.ClusterHelper; 39 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 40 import com.sun.enterprise.config.serverbeans.ConnectorResource; 41 import com.sun.enterprise.config.serverbeans.ConnectorConnectionPool; 42 import com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource; 43 import com.sun.enterprise.config.ConfigBean; 44 import com.sun.enterprise.config.ConfigAdd; 45 import com.sun.enterprise.config.ConfigDelete; 46 import com.sun.enterprise.config.ConfigChangeFactory; 47 import com.sun.enterprise.config.ConfigException; 48 49 61 class DependencyResolver { 62 63 66 DependencyResolver(ConfigContext ctx, String target) { 67 _ctx = ctx; 68 _target = target; 69 } 70 71 89 List resolveResources(String resName, String action, String typeInEvent) 90 throws ConfigException { 91 92 List list = new ArrayList (); 93 if (resName == null 94 || BaseDeployEvent.REMOVE_REFERENCE.equals(action) 96 || BaseDeployEvent.UNDEPLOY.equals(action)) { 97 return list; 98 } 99 100 ConfigBean res = findResource(resName, typeInEvent); 101 if (res == null) { 102 return list; 103 } 104 114 115 if (ResourceDeployEvent.RES_TYPE_JDBC.equals(typeInEvent)) { 117 118 String poolName = ((JdbcResource) res).getPoolName(); 119 list.addAll(resolveJdbcConnectionPool(poolName)); 120 121 } else if (ResourceDeployEvent.RES_TYPE_CR.equals(typeInEvent)) { 123 124 String poolName = ((ConnectorResource) res).getPoolName(); 125 list.addAll(resolveConnectorConnectionPool(poolName)); 126 127 } else if (ResourceDeployEvent.RES_TYPE_PMF.equals(typeInEvent)) { 129 130 String jdbcResName = ((PersistenceManagerFactoryResource) res). 131 getJdbcResourceJndiName(); 132 list.addAll( resolveResources(jdbcResName, action, 133 ResourceDeployEvent.RES_TYPE_JDBC) ); 134 } 135 136 list.addAll( addConfigChangeForResource(res) ); 137 138 return list; 139 } 140 141 151 List resolveApplications(String applicationName, String action) 152 throws ConfigException { 153 154 List list = new ArrayList (); 155 156 if (applicationName == null 157 || BaseDeployEvent.REMOVE_REFERENCE.equals(action) 158 || BaseDeployEvent.REDEPLOY.equals(action) 159 || BaseDeployEvent.UNDEPLOY.equals(action)) { 160 return list; 161 } 162 ConfigBean app=ApplicationHelper.findApplication(_ctx,applicationName); 163 if (app == null) { 164 return list; 165 } 166 String xpath = app.getXPath(); 168 169 ConfigAdd configAdd = ConfigChangeFactory.createConfigAdd(_ctx, xpath); 171 list.add(configAdd); 172 173 ResourceAdapterConfig raConfig = 175 findResourceAdapterConfigByName(applicationName); 176 177 if (raConfig != null) { 179 ConfigAdd raConfigChange = 180 ConfigChangeFactory.createConfigAdd(_ctx, raConfig.getXPath()); 181 182 list.add(raConfigChange); 184 } 185 186 return list; 187 } 188 189 197 private List addConfigChangeForResource(ConfigBean res) 198 throws ConfigException { 199 200 List list = new ArrayList (); 201 if (res == null) { 202 return list; 203 } 204 205 String xpath = res.getXPath(); 206 ConfigAdd configAdd = ConfigChangeFactory.createConfigAdd(_ctx, xpath); 207 list.add(configAdd); 208 209 return list; 210 } 211 212 220 List getConfigDeleteForApplication(String applicationName) 221 throws ConfigException { 222 223 List list = new ArrayList (); 224 225 if (applicationName != null) { 226 ConfigBean app = 227 ApplicationHelper.findApplication(_ctx,applicationName); 228 String xpath = app.getXPath(); 229 ConfigDelete configDelete = 230 ConfigChangeFactory.createConfigDelete(xpath); 231 list.add(configDelete); 232 } 233 return list; 234 } 235 236 246 List getConfigDeleteForResource(String resName, String resTypeInEvent) 247 throws ConfigException { 248 249 ConfigBean res = findResource(resName, resTypeInEvent); 252 return getConfigDeleteForResource(res); 253 } 254 255 263 List getConfigDeleteForResource(ConfigBean res) 264 throws ConfigException { 265 266 List list = new ArrayList (); 267 if (res == null) { 268 return list; 269 } 270 String xpath = res.getXPath(); 271 ConfigDelete configDelete=ConfigChangeFactory.createConfigDelete(xpath); 272 list.add(configDelete); 273 return list; 274 } 275 276 284 private List resolveJdbcConnectionPool(String poolName) 285 throws ConfigException { 286 287 List list = new ArrayList (); 288 289 if (poolName == null) { 290 return list; 291 } 292 293 Resources root = ((Domain)_ctx.getRootConfigBean()).getResources(); 294 JdbcConnectionPool pool = root.getJdbcConnectionPoolByName(poolName); 295 296 if (pool == null) { 298 return list; 299 } 300 list.addAll( addConfigChangeForResource(pool) ); 301 302 return list; 303 } 304 305 313 private List resolveConnectorConnectionPool(String poolName) 314 throws ConfigException { 315 316 List list = new ArrayList (); 317 318 if (poolName == null) { 319 return list; 320 } 321 322 Resources root = ((Domain)_ctx.getRootConfigBean()).getResources(); 323 ConnectorConnectionPool pool = 324 root.getConnectorConnectionPoolByName(poolName); 325 326 if (pool == null) { 327 return list; 328 } 329 330 list.addAll( addConfigChangeForResource(pool) ); 331 332 return list; 333 } 334 335 343 ResourceAdapterConfig findResourceAdapterConfigByName(String name) 344 throws ConfigException { 345 346 Resources root = ((Domain)_ctx.getRootConfigBean()).getResources(); 348 349 ResourceAdapterConfig[] configs = root.getResourceAdapterConfig(); 351 352 353 if (configs != null) { 354 for (int i=0; i<configs.length; i++) { 355 String fullRAName = configs[i].getResourceAdapterName(); 356 String raName = getApplicationNameFromRAName(fullRAName); 357 358 if (raName.equals(name)) { 359 return configs[i]; 360 } 361 } 362 } 363 364 return null; 366 } 367 368 375 String getApplicationNameFromRAName(String fullRAName) { 376 377 String appName = null; 378 379 int idx = fullRAName.indexOf("#"); 381 if (idx > 0) { 382 appName = fullRAName.substring(0, idx); 383 } else { 384 appName = fullRAName; 385 } 386 387 return appName; 388 } 389 390 399 ConfigBean findResource(String resName, String type) 400 throws ConfigException { 401 402 ConfigBean res = null; 403 Resources root = ((Domain)_ctx.getRootConfigBean()).getResources(); 404 405 if (ResourceDeployEvent.RES_TYPE_JDBC.equals(type)) { 406 res = root.getJdbcResourceByJndiName(resName); 407 } else if (ResourceDeployEvent.RES_TYPE_MAIL.equals(type)) { 408 res = root.getMailResourceByJndiName(resName); 409 } else if (ResourceDeployEvent.RES_TYPE_CUSTOM.equals(type)) { 410 res = root.getCustomResourceByJndiName(resName); 411 } else if (ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI.equals(type)) { 412 res = root.getExternalJndiResourceByJndiName(resName); 413 } else if (ResourceDeployEvent.RES_TYPE_PMF.equals(type)) { 414 res = root.getPersistenceManagerFactoryResourceByJndiName(resName); 415 } else if (ResourceDeployEvent.RES_TYPE_AOR.equals(type)) { 416 res = root.getAdminObjectResourceByJndiName(resName); 417 } else if (ResourceDeployEvent.RES_TYPE_CR.equals(type)) { 418 res = root.getConnectorResourceByJndiName(resName); 419 } else if (ResourceDeployEvent.RES_TYPE_JCP.equals(type)) { 420 res = root.getJdbcConnectionPoolByName(resName); 421 } else if (ResourceDeployEvent.RES_TYPE_CCP.equals(type)) { 422 res = root.getConnectorConnectionPoolByName(resName); 423 } else if (ResourceDeployEvent.RES_TYPE_RAC.equals(type)) { 424 res = root.getResourceAdapterConfigByResourceAdapterName(resName); 425 } 426 427 return res; 428 } 429 430 private ConfigContext _ctx; 432 private String _target; 433 } 434 | Popular Tags |