1 23 package com.sun.enterprise.config.serverbeans; 24 25 import com.sun.enterprise.config.ConfigBean; 26 import com.sun.enterprise.config.ConfigContext; 27 import com.sun.enterprise.config.ConfigException; 28 import com.sun.enterprise.config.serverbeans.JdbcResource; 29 import com.sun.enterprise.config.serverbeans.ConnectorResource; 30 import com.sun.enterprise.admin.util.IAdminConstants; 31 import com.sun.enterprise.util.i18n.StringManager; 32 33 public class ResourceHelper extends ReferenceHelperBase { 34 35 protected static final StringManager _strMgr=StringManager.getManager(ResourceHelper.class); 36 private static ResourceHelper _theInstance; 37 38 public ResourceHelper() { 39 super(); 40 } 41 42 protected Server[] getReferencingServers(ConfigContext configContext, String name) 43 throws ConfigException 44 { 45 return ServerHelper.getServersReferencingResource(configContext, name); 46 } 47 48 protected Cluster[] getReferencingClusters(ConfigContext configContext, String name) 49 throws ConfigException 50 { 51 return ClusterHelper.getClustersReferencingResource(configContext, name); 52 } 53 54 private synchronized static ResourceHelper getInstance() 55 { 56 if (_theInstance == null) { 57 _theInstance = new ResourceHelper(); 58 } 59 return _theInstance; 60 } 61 62 65 public static boolean isResourceReferenced(ConfigContext configContext, String resourceName) 66 throws ConfigException 67 { 68 return getInstance().isReferenced(configContext, resourceName); 69 } 70 71 75 public static boolean isResourceReferencedByServerOnly(ConfigContext configContext, 76 String resourceName, String serverName) throws ConfigException 77 { 78 return getInstance().isReferencedByServerOnly(configContext, resourceName, serverName); 79 } 80 81 85 public static boolean isResourceReferencedByClusterOnly(ConfigContext configContext, 86 String resourceName, String clusterName) throws ConfigException 87 { 88 return getInstance().isReferencedByClusterOnly(configContext, resourceName, clusterName); 89 } 90 91 95 public static String getResourceReferenceesAsString(ConfigContext configContext, String resourceName) 96 throws ConfigException 97 { 98 return getInstance().getReferenceesAsString(configContext, resourceName); 99 } 100 101 113 public static boolean isJdbcPoolReferenced(ConfigContext ctx, 114 String poolName, String serverName) throws ConfigException { 115 116 if (ctx == null || poolName == null || serverName == null) { 117 return false; 118 } 119 120 Resources rBean = ServerBeansFactory.getDomainBean(ctx).getResources(); 121 122 JdbcResource[] jdbcBeans = rBean.getJdbcResource(); 123 124 if (jdbcBeans == null) { 127 return false; 128 } 129 130 for (int i = 0; i <jdbcBeans.length; i++) { 131 132 if ( !ServerHelper.serverReferencesResource( 134 ctx, serverName, jdbcBeans[i].getJndiName()) ) { 135 136 continue; 137 } else { 138 String pool = jdbcBeans[i].getPoolName(); 139 if ( (pool != null) && pool.equals(poolName) ) { 140 return true; 142 } 143 } 144 } 145 146 return false; 148 } 149 150 162 public static boolean isConnectorPoolReferenced(ConfigContext ctx, 163 String poolName, String serverName) throws ConfigException { 164 165 if (ctx == null || poolName == null || serverName == null) { 166 return false; 167 } 168 169 Resources rBean = ServerBeansFactory.getDomainBean(ctx).getResources(); 170 171 ConnectorResource[] conBeans = rBean.getConnectorResource(); 172 173 if (conBeans == null) { 176 return false; 177 } 178 179 for (int i = 0; i <conBeans.length; i++) { 180 181 if ( !ServerHelper.serverReferencesResource( 183 ctx, serverName, conBeans[i].getJndiName()) ) { 184 185 continue; 186 } else { 187 String pool = conBeans[i].getPoolName(); 188 if ( (pool != null) && pool.equals(poolName) ) { 189 return true; 190 } 191 } 192 } 193 return false; 194 } 195 196 199 public static String getResourceType(ConfigContext ctx, String id) 200 throws ConfigException { 201 202 Resources root = ((Domain)ctx.getRootConfigBean()).getResources(); 203 204 ConfigBean res = root.getJdbcResourceByJndiName(id); 205 if ( res != null ) 206 return Resources.JDBC_RESOURCE; 207 208 res = root.getMailResourceByJndiName(id); 209 if( res != null ) 210 return Resources.MAIL_RESOURCE; 211 212 res = root.getCustomResourceByJndiName(id); 213 if( res != null ) 214 return Resources.CUSTOM_RESOURCE; 215 216 res = root.getExternalJndiResourceByJndiName(id); 217 if ( res != null ) 218 return Resources.EXTERNAL_JNDI_RESOURCE; 219 220 res = root.getPersistenceManagerFactoryResourceByJndiName(id); 221 if ( res != null) 222 return Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE; 223 224 res = root.getAdminObjectResourceByJndiName(id); 225 if ( res != null ) 226 return Resources.ADMIN_OBJECT_RESOURCE; 227 228 res = root.getConnectorResourceByJndiName(id); 229 if ( res != null ) 230 return Resources.CONNECTOR_RESOURCE; 231 232 res = root.getJdbcConnectionPoolByName(id); 233 if ( res != null ) 234 return Resources.JDBC_CONNECTION_POOL; 235 236 res = root.getConnectorConnectionPoolByName(id); 237 if ( res != null ) 238 return Resources.CONNECTOR_CONNECTION_POOL; 239 240 res = root.getResourceAdapterConfigByResourceAdapterName(id); 241 if ( res != null ) 242 return Resources.RESOURCE_ADAPTER_CONFIG; 243 244 return null; 245 } 246 247 public static boolean isSystemResource(ConfigContext ctx, String resourceName) 248 throws ConfigException 249 { 250 ConfigBean bean = findResource(ctx, resourceName); 251 if (bean == null) { 252 throw new ConfigException(_strMgr.getString("noSuchResource", 253 resourceName)); 254 } 255 String objectType = null; 256 try { 257 objectType = bean.getAttributeValue(ServerTags.OBJECT_TYPE); 258 } catch (Exception ex) { 259 return false; 262 } 263 if (objectType.equals(IAdminConstants.SYSTEM_ALL) || 264 objectType.equals(IAdminConstants.SYSTEM_ADMIN) || 265 objectType.equals(IAdminConstants.SYSTEM_INSTANCE)) { 266 return true; 267 } else { 268 return false; 269 } 270 } 271 272 public static ConfigBean findResource(ConfigContext ctx, String id) 273 throws ConfigException { 274 Resources root = ((Domain)ctx.getRootConfigBean()).getResources(); 275 return findResource(root, id); 276 } 277 278 public static ConfigBean findResource(Resources root, String id) 279 throws ConfigException { 280 281 ConfigBean res = root.getJdbcResourceByJndiName(id); 282 if ( res != null ) 283 return res; 284 285 res = root.getMailResourceByJndiName(id); 286 if( res != null ) 287 return res; 288 289 res = root.getCustomResourceByJndiName(id); 290 if( res != null ) 291 return res; 292 293 res = root.getExternalJndiResourceByJndiName(id); 294 if ( res != null ) 295 return res; 296 297 res = root.getPersistenceManagerFactoryResourceByJndiName(id); 298 if ( res != null) 299 return res; 300 301 res = root.getAdminObjectResourceByJndiName(id); 302 if ( res != null ) 303 return res; 304 305 res = root.getConnectorResourceByJndiName(id); 306 if ( res != null ) 307 return res; 308 309 res = root.getJdbcConnectionPoolByName(id); 310 if ( res != null ) 311 return res; 312 313 res = root.getConnectorConnectionPoolByName(id); 314 if ( res != null ) 315 return res; 316 317 res = root.getResourceAdapterConfigByResourceAdapterName(id); 318 if ( res != null ) 319 return res; 320 321 return null; 322 } 323 } 324 | Popular Tags |