1 23 package com.sun.enterprise.config.serverbeans; 24 25 import com.sun.enterprise.config.ConfigContext; 26 import com.sun.enterprise.config.ConfigException; 27 import com.sun.enterprise.config.ConfigBean; 28 import com.sun.enterprise.config.serverbeans.Server; 29 import com.sun.enterprise.config.serverbeans.Cluster; 30 import com.sun.enterprise.config.serverbeans.Applications; 31 import com.sun.enterprise.config.serverbeans.J2eeApplication; 32 import com.sun.enterprise.config.serverbeans.EjbModule; 33 import com.sun.enterprise.config.serverbeans.WebModule; 34 import com.sun.enterprise.config.serverbeans.AppclientModule; 35 import com.sun.enterprise.config.serverbeans.ConnectorModule; 36 import com.sun.enterprise.config.serverbeans.LifecycleModule; 37 import com.sun.enterprise.config.serverbeans.Mbean; 38 import com.sun.enterprise.admin.util.IAdminConstants; 39 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 import java.util.ArrayList ; 43 44 public class ApplicationHelper extends ReferenceHelperBase { 45 46 protected static final StringManager _strMgr=StringManager.getManager(ApplicationHelper.class); 47 private static ApplicationHelper _theInstance; 48 49 public ApplicationHelper() { 50 super(); 51 } 52 53 protected Server[] getReferencingServers(ConfigContext configContext, String name) 54 throws ConfigException 55 { 56 return ServerHelper.getServersReferencingApplication(configContext, name); 57 } 58 59 protected Cluster[] getReferencingClusters(ConfigContext configContext, String name) 60 throws ConfigException 61 { 62 return ClusterHelper.getClustersReferencingApplication(configContext, name); 63 } 64 65 private synchronized static ApplicationHelper getInstance() 66 { 67 if (_theInstance == null) { 68 _theInstance = new ApplicationHelper(); 69 } 70 return _theInstance; 71 } 72 73 76 public static boolean isApplicationReferenced(ConfigContext configContext, String appName) 77 throws ConfigException 78 { 79 return getInstance().isReferenced(configContext, appName); 80 } 81 82 86 public static boolean isApplicationReferencedByServerOnly(ConfigContext configContext, 87 String appName, String serverName) throws ConfigException 88 { 89 return getInstance().isReferencedByServerOnly(configContext, appName, serverName); 90 } 91 92 96 public static boolean isApplicationReferencedByClusterOnly(ConfigContext configContext, 97 String appName, String clusterName) throws ConfigException 98 { 99 return getInstance().isReferencedByClusterOnly(configContext, appName, clusterName); 100 } 101 102 106 public static String getApplicationReferenceesAsString(ConfigContext configContext, String appName) 107 throws ConfigException 108 { 109 return getInstance().getReferenceesAsString(configContext, appName); 110 } 111 112 115 public static String getApplicationType(ConfigContext ctx, String id) 116 throws ConfigException { 117 ConfigBean appBean = findApplication(ctx, id); 118 if (appBean instanceof J2eeApplication) 119 return Applications.J2EE_APPLICATION; 120 if (appBean instanceof EjbModule) 121 return Applications.EJB_MODULE; 122 if (appBean instanceof WebModule) 123 return Applications.WEB_MODULE; 124 if (appBean instanceof LifecycleModule) 125 return Applications.LIFECYCLE_MODULE; 126 if (appBean instanceof AppclientModule) 127 return Applications.APPCLIENT_MODULE; 128 if (appBean instanceof ConnectorModule) 129 return Applications.CONNECTOR_MODULE; 130 if (appBean instanceof Mbean) 131 return Applications.MBEAN; 132 return null; 133 } 134 135 public static ConfigBean findApplication(ConfigContext configContext, 136 String appName) throws ConfigException 137 { 138 Applications root = ((Domain)configContext.getRootConfigBean()). 139 getApplications(); 140 141 ConfigBean app = root.getJ2eeApplicationByName(appName); 142 if ( app != null) 143 return app; 144 145 app = root.getEjbModuleByName(appName); 146 if ( app != null) 147 return app; 148 149 app = root.getWebModuleByName(appName); 150 if ( app != null) 151 return app; 152 153 app = root.getConnectorModuleByName(appName); 154 if ( app != null) 155 return app; 156 157 app = root.getAppclientModuleByName(appName); 158 if ( app != null) 159 return app; 160 161 app = root.getLifecycleModuleByName(appName); 162 if ( app != null) 163 return app; 164 165 app = root.getMbeanByName(appName); 166 if ( app != null) 167 return app; 168 169 return null; 170 } 171 172 public static String [] getApplicationsInDomain(ConfigContext configContext) 173 throws ConfigException 174 { 175 ArrayList result = new ArrayList (); 176 final Domain domain = ConfigAPIHelper.getDomainConfigBean(configContext); 177 final Applications applications = domain.getApplications(); 178 AppclientModule[] appclients = applications.getAppclientModule(); 179 for (int i = 0; i < appclients.length; i++) { 180 result.add(appclients[i].getName()); 181 } 182 ConnectorModule[] connectors = applications.getConnectorModule(); 183 for (int i = 0; i < connectors.length; i++) { 184 result.add(connectors[i].getName()); 185 } 186 EjbModule[] ebjs = applications.getEjbModule(); 187 for (int i = 0; i < ebjs.length; i++) { 188 result.add(ebjs[i].getName()); 189 } 190 J2eeApplication[] apps = applications.getJ2eeApplication(); 191 for (int i = 0; i < apps.length; i++) { 192 result.add(apps[i].getName()); 193 } 194 LifecycleModule[] lifecycles = applications.getLifecycleModule(); 195 for (int i = 0; i < lifecycles.length; i++) { 196 result.add(lifecycles[i].getName()); 197 } 198 WebModule[] webs = applications.getWebModule(); 199 for (int i = 0; i < webs.length; i++) { 200 result.add(webs[i].getName()); 201 } 202 Mbean[] mbeans = applications.getMbean(); 203 for (int i = 0; i < mbeans.length; i++) { 204 result.add(mbeans[i].getName()); 205 } 206 return (String [])result.toArray(new String [result.size()]); 207 } 208 209 public static boolean isSystemApp(ConfigContext ctx, String appId) 210 throws ConfigException 211 { 212 ConfigBean bean = findApplication(ctx, appId); 213 if (bean == null) { 214 throw new ConfigException(_strMgr.getString("noSuchApplication", 215 appId)); 216 } 217 String objectType = null; 218 try { 219 objectType = bean.getAttributeValue(ServerTags.OBJECT_TYPE); 220 } catch (Exception ex) { 221 return false; 224 } 225 if (objectType.equals(IAdminConstants.SYSTEM_ALL) || 226 objectType.equals(IAdminConstants.SYSTEM_ADMIN) || 227 objectType.equals(IAdminConstants.SYSTEM_INSTANCE)) { 228 return true; 229 } else { 230 return false; 231 } 232 } 233 234 243 public static TransformationRule findTransformationRule( 244 ConfigContext cfgContext, String appId, String epName, String 245 ruleName) throws ConfigException { 246 247 ConfigBean appBean = findApplication(cfgContext, appId); 248 if (appBean == null) { 249 throw new ConfigException(_strMgr.getString("noSuchApplication", 250 appId)); 251 } 252 WebServiceEndpoint wsep = null; 253 if (appBean instanceof J2eeApplication) { 254 wsep = ((J2eeApplication) appBean).getWebServiceEndpointByName( 255 epName); 256 } else if (appBean instanceof EjbModule) { 257 wsep = ((EjbModule) appBean).getWebServiceEndpointByName( epName); 258 } else if (appBean instanceof WebModule) { 259 wsep = ((WebModule) appBean).getWebServiceEndpointByName( epName); 260 } 261 if (wsep == null) { 262 throw new ConfigException(_strMgr.getString("noSuchWSEP", 263 epName)); 264 } 265 TransformationRule tRule = wsep.getTransformationRuleByName(ruleName); 266 if (tRule == null) { 267 throw new ConfigException( 268 _strMgr.getString("noSuchTransformationRule", ruleName)); 269 } else { 270 return tRule; 271 } 272 273 } 274 275 276 } 277 | Popular Tags |