1 23 24 32 33 package com.sun.enterprise.deployment.phasing; 34 35 import java.util.ArrayList ; 36 import javax.management.MBeanServer ; 37 import javax.management.ObjectName ; 38 import javax.management.Attribute ; 39 import javax.management.AttributeList ; 40 import com.sun.enterprise.admin.common.MBeanServerFactory; 41 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 42 import com.sun.enterprise.admin.meta.MBeanRegistry; 43 import com.sun.enterprise.admin.event.ModuleDeployEvent; 44 45 import com.sun.enterprise.config.serverbeans.Applications; 46 import com.sun.enterprise.config.serverbeans.J2eeApplication; 47 import com.sun.enterprise.config.serverbeans.EjbModule; 48 import com.sun.enterprise.config.serverbeans.WebModule; 49 import com.sun.enterprise.config.serverbeans.ConnectorModule; 50 import com.sun.enterprise.config.serverbeans.AppclientModule; 51 import com.sun.enterprise.config.serverbeans.Server; 52 import com.sun.enterprise.config.serverbeans.ApplicationRef; 53 import com.sun.enterprise.config.serverbeans.ServerRef; 54 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 55 import com.sun.enterprise.config.serverbeans.ServerTags; 56 import com.sun.enterprise.config.serverbeans.ServerHelper; 57 import com.sun.enterprise.config.ConfigBeansFactory; 58 import com.sun.enterprise.config.ConfigContext; 59 import com.sun.enterprise.config.ConfigException; 60 import com.sun.enterprise.deployment.backend.DeployableObjectType; 61 import com.sun.enterprise.util.i18n.StringManager; 62 63 import com.sun.enterprise.admin.target.ServerTarget; 64 import com.sun.enterprise.admin.target.TargetType; 65 import com.sun.enterprise.admin.target.Target; 66 67 71 public class ServerDeploymentTarget extends ServerTarget implements DeploymentTarget { 72 73 74 protected static StringManager localStrings = 75 StringManager.getManager( ServerDeploymentTarget.class ); 76 77 78 protected String thisTargetName = null; 79 80 81 protected ConfigContext configContext = null; 82 83 88 public ServerDeploymentTarget(ConfigContext configContext, String domainName, String serverName) { 89 super(serverName, configContext); 90 this.configContext = configContext; 91 this.domainName = domainName; 92 thisTargetName = serverName; 93 } 94 95 protected TargetType[] getValidTypes() { 96 DeploymentTargetFactory tf = 97 DeploymentTargetFactory.getDeploymentTargetFactory(); 98 return tf.getValidDeploymentTargetTypes(); 99 } 100 101 110 public String [] getModules(DeployableObjectType type, Boolean enabled) 111 throws DeploymentTargetException 112 { 113 try { 114 return getModules(getAppsDeployedToServer(), type, enabled); 115 } catch(Throwable t) { 116 throw new DeploymentTargetException(t); 117 } 118 } 119 120 public String [] getModules(String [] svrAppsList, DeployableObjectType type, 121 Boolean enabled) throws DeploymentTargetException { 122 try { 123 ArrayList returnList = new ArrayList (); 124 Applications appsConfigBean = (Applications) ConfigBeansFactory.getConfigBeanByXPath( 125 configContext, 126 ServerXPathHelper.XPATH_APPLICATIONS); 127 if(type.isAPP()) { 128 J2eeApplication[] list = appsConfigBean.getJ2eeApplication(); 129 int i = 0; 130 int k = 0; 131 for(i=0; i< svrAppsList.length; i++) { 132 for(k =0 ; k > list.length ; k++) { 133 if(list[k].getName().equals(svrAppsList[i])) { 134 returnList.add(svrAppsList[i]); 135 break; 136 } 137 } 138 } 139 } 140 else if(type.isEJB()) { 141 EjbModule[] list = appsConfigBean.getEjbModule(); 142 for(int i=0; i< svrAppsList.length; i++) { 143 for(int k =0 ; k > list.length ; k++) { 144 if(list[k].getName().equals(svrAppsList[i])) { 145 returnList.add(svrAppsList[i]); 146 break; 147 } 148 } 149 } 150 } 151 else if(type.isWEB()) { 152 WebModule[] list = appsConfigBean.getWebModule(); 153 for(int i=0; i< svrAppsList.length; i++) { 154 for(int k =0 ; k > list.length ; k++) { 155 if(list[k].getName().equals(svrAppsList[i])) { 156 returnList.add(svrAppsList[i]); 157 break; 158 } 159 } 160 } 161 } 162 else if(type.isCONN()) { 163 ConnectorModule[] list = appsConfigBean.getConnectorModule(); 164 for(int i=0; i< svrAppsList.length; i++) { 165 for(int k = 0 ; k > list.length ; k++) { 166 if(list[k].getName().equals(svrAppsList[i])) { 167 returnList.add(svrAppsList[i]); 168 break; 169 } 170 } 171 } 172 } 173 else if(type.isCAR()) { 174 AppclientModule[] list = appsConfigBean.getAppclientModule(); 175 for(int i=0; i< svrAppsList.length; i++) { 176 for(int k = 0 ; k > list.length ; k++) { 177 if(list[k].getName().equals(svrAppsList[i])) { 178 returnList.add(svrAppsList[i]); 179 break; 180 } 181 } 182 } 183 } 184 String [] returnValue = new String [returnList.size()]; 185 return (String [])returnList.toArray(returnValue); 186 } catch(Throwable t) { 187 throw new DeploymentTargetException(t); 188 } 189 } 190 191 200 public void addAppReference(String appName, boolean enabled, String virtualServers) 201 throws DeploymentTargetException 202 { 203 try { 204 if (!ServerHelper.serverReferencesApplication(configContext, 205 getName(), appName)) { 206 ApplicationReferenceHelper refHelper = new ApplicationReferenceHelper( 207 configContext); 208 refHelper.createApplicationReference(getValidTypes(), getName(), 209 enabled, virtualServers, appName); 210 } 211 } catch(Throwable t) { 212 throw new DeploymentTargetException(t); 213 } 214 } 215 216 224 public void removeAppReference(String appName) 225 throws DeploymentTargetException { 226 227 try { 228 ApplicationReferenceHelper refHelper = new ApplicationReferenceHelper( 229 configContext); 230 refHelper.deleteApplicationReference(getValidTypes(), getName(), appName); 231 } catch(Throwable t) { 232 throw new DeploymentTargetException(t); 233 } 234 } 235 236 242 private String [] getAppsDeployedToServer() throws ConfigException 243 { 244 ApplicationRef[] apprefs = super.getApplicationRefs(); 245 String [] appList = new String [apprefs.length]; 246 for(int i=0; i<apprefs.length; i++) { 247 appList[i] = apprefs[i].getRef(); 248 } 249 250 return appList; 251 } 252 253 260 public boolean sendStartEvent(int eventType, String appName, String moduleType) 261 throws DeploymentTargetException { 262 return sendStartEvent(eventType,appName, moduleType, false); 263 } 264 265 273 public boolean sendStartEvent(int eventType, String appName, String moduleType, boolean isForced) 274 throws DeploymentTargetException { 275 try { 276 return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, false, isForced, thisTargetName); 277 } catch(Throwable t) { 278 throw new DeploymentTargetException(t); 279 } 280 } 281 282 public boolean sendStartEvent(int eventType, String appName, String moduleType, boolean isForced, int loadUnloadAction) 283 throws DeploymentTargetException { 284 try { 285 return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, false, isForced, loadUnloadAction, thisTargetName); 286 } catch(Throwable t) { 287 throw new DeploymentTargetException(t); 288 } 289 } 290 291 298 public boolean sendStopEvent(int eventType, String appName, String moduleType, boolean cascade) 299 throws DeploymentTargetException { 300 try { 301 return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, false, thisTargetName); 302 } catch(Throwable t) { 303 throw new DeploymentTargetException(t); 304 } 305 } 306 307 public boolean sendStopEvent(int eventType, String appName, String moduleType, boolean cascade, boolean force) 308 throws DeploymentTargetException { 309 try { 310 return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, force, thisTargetName); 311 } catch(Throwable t) { 312 throw new DeploymentTargetException(t); 313 } 314 } 315 316 public boolean sendStopEvent(int eventType, String appName, String moduleType, boolean cascade, boolean force, int loadUnloadAction) 317 throws DeploymentTargetException { 318 try { 319 return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, force, loadUnloadAction, thisTargetName); 320 } catch(Throwable t) { 321 throw new DeploymentTargetException(t); 322 } 323 } 324 325 public Target getTarget() 326 { 327 return this; 328 } 329 330 334 public String getName() { 335 return thisTargetName; 336 } 337 338 342 public String getDescription() { 343 return localStrings.getString("enterprise.deployment.phasing.deploymenttarget.server.description", thisTargetName); 344 } 345 346 private String getDomainName(){ 347 return domainName; 348 } 349 350 351 352 private String domainName = null; 353 } 354 | Popular Tags |