1 package org.netbeans.modules.j2ee.sun.ide.controllers; 2 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.List ; 23 import com.sun.appserv.management.base.Util; 24 import com.sun.appserv.management.util.jmx.JMXUtil; 25 import com.sun.appserv.management.j2ee.AppClientModule; 26 import com.sun.appserv.management.j2ee.EJBModule; 27 import com.sun.appserv.management.j2ee.J2EEApplication; 28 import com.sun.appserv.management.j2ee.J2EEServer; 29 import com.sun.appserv.management.j2ee.ResourceAdapterModule; 30 import com.sun.appserv.management.j2ee.WebModule; 31 import com.sun.appserv.management.client.AppserverConnectionSource; 32 import com.sun.appserv.management.config.AppClientModuleConfig; 33 import com.sun.appserv.management.config.EJBModuleConfig; 34 import com.sun.appserv.management.config.J2EEApplicationConfig; 35 import com.sun.appserv.management.config.RARModuleConfig; 36 import com.sun.appserv.management.config.WebModuleConfig; 37 import com.sun.appserv.management.j2ee.J2EEDeployedObject; 38 import java.util.Arrays ; 39 40 import javax.enterprise.deploy.spi.DeploymentManager ; 41 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase; 42 import org.netbeans.modules.j2ee.sun.bridge.apis.Controller; 43 44 51 public class J2EEServerMgmtController 52 extends AppserverMgmtControllerBase implements Controller { 53 54 private J2EEServer j2eeServer; 55 56 62 public J2EEServerMgmtController(final J2EEServer server, 63 final DeploymentManager dplmtMgr, 64 final AppserverConnectionSource connection) { 65 super(server, dplmtMgr, connection); 66 this.j2eeServer = server; 67 } 68 69 70 75 public Map getProperties(List propsToIgnore) { 76 return new java.util.HashMap () {}; 77 } 78 79 80 88 public javax.management.Attribute setProperty(final String attrName, final Object value) { 89 90 testIfServerInDebug(); 91 92 return ControllerUtil.setAttributeValue(j2eeServer, attrName, value, 93 getMBeanServerConnection()); 94 } 95 96 97 101 public J2EEApplicationMgmtController[] getApplications() { 102 103 testIfServerInDebug(); 104 105 Map apps = j2eeServer.getContaineeMap(J2EEApplication.J2EE_TYPE); 106 Map appsMap = getJ2EEAppsAsMap(J2EEApplication.J2EE_TYPE); 107 Map configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(J2EEApplicationConfig.J2EE_TYPE); 108 configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps); 109 110 java.util.Vector controllers = new java.util.Vector (); 111 for(Iterator configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) { 112 J2EEApplicationConfig appConfig = (J2EEApplicationConfig)configPeerItr.next(); 113 J2EEApplication appMod = null; 114 if(appsMap.containsKey(appConfig.getName())){ 115 appMod = (J2EEApplication)appsMap.get(appConfig.getName()); 116 } 117 controllers.add(new J2EEApplicationMgmtController( 118 appMod, appConfig, getDeploymentManager(), 119 appMgmtConnection)); 120 } 121 122 J2EEApplicationMgmtController[] result = 123 new J2EEApplicationMgmtController[controllers.size()]; 124 return (J2EEApplicationMgmtController[]) controllers.toArray(result); 125 } 126 127 128 132 public EJBModuleController[] getEJBModules() { 133 134 testIfServerInDebug(); 135 136 Map apps = j2eeServer.getContaineeMap(EJBModule.J2EE_TYPE); 137 Map appsMap = getJ2EEAppsAsMap(EJBModule.J2EE_TYPE); 138 Map configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(EJBModuleConfig.J2EE_TYPE); 139 configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps); 140 141 java.util.Vector controllers = new java.util.Vector (); 142 for(Iterator configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) { 143 EJBModuleConfig ejbConfig = (EJBModuleConfig)configPeerItr.next(); 144 EJBModule ejbMod = null; 145 if(appsMap.containsKey(ejbConfig.getName())){ 146 ejbMod = (EJBModule)appsMap.get(ejbConfig.getName()); 147 } 148 controllers.add(new EJBModuleController( 149 ejbMod, ejbConfig, getDeploymentManager(), 150 appMgmtConnection)); 151 } 152 153 EJBModuleController[] result = 154 new EJBModuleController[controllers.size()]; 155 return (EJBModuleController[]) controllers.toArray(result); 156 } 157 158 159 163 public ConnectorModuleController[] getConnectorModules() { 164 165 testIfServerInDebug(); 166 Map j2eeApps = j2eeServer.getContaineeMap(ResourceAdapterModule.J2EE_TYPE); 167 Map appsMap = getJ2EEAppsAsMap(ResourceAdapterModule.J2EE_TYPE); 168 Map configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(RARModuleConfig.J2EE_TYPE); 169 configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps); 170 java.util.Vector controllers = new java.util.Vector (); 171 for(Iterator configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) { 172 RARModuleConfig rarConfig = (RARModuleConfig)configPeerItr.next(); 173 ResourceAdapterModule rarMod = null; 174 if(appsMap.containsKey(rarConfig.getName())){ 175 rarMod = (ResourceAdapterModule)appsMap.get(rarConfig.getName()); 176 } 177 178 if(! Arrays.asList(ControllerUtil.RES_ADAPTOR_KEYS).contains(rarConfig.getName())){ 179 controllers.add(new ConnectorModuleController( 180 rarMod, rarConfig, getDeploymentManager(), appMgmtConnection)); 181 } 182 } 183 ConnectorModuleController[] result = 184 new ConnectorModuleController[controllers.size()]; 185 return (ConnectorModuleController[]) controllers.toArray(result); 186 } 187 188 189 193 public WebModuleController[] getWebModules() { 194 195 testIfServerInDebug(); 196 197 Map apps = j2eeServer.getContaineeMap(WebModule.J2EE_TYPE); 198 Map appsMap = getJ2EEAppsAsMap(WebModule.J2EE_TYPE); 199 Map configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(WebModuleConfig.J2EE_TYPE); 200 configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps); 201 202 java.util.Vector controllers = new java.util.Vector (); 203 for(Iterator configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) { 204 WebModuleConfig webConfig = (WebModuleConfig)configPeerItr.next(); 205 WebModule webMod = null; 206 if(appsMap.containsKey(webConfig.getName())){ 207 webMod = (WebModule)appsMap.get(webConfig.getName()); 208 } 209 controllers.add(new WebModuleController( 210 webMod, webConfig, getDeploymentManager(), 211 appMgmtConnection)); 212 } 213 214 WebModuleController[] result = 215 new WebModuleController[controllers.size()]; 216 return (WebModuleController[]) controllers.toArray(result); 217 } 218 219 225 public String getWebModuleName(String contextRoot) { 226 227 testIfServerInDebug(); 228 String modName = null; 229 Map webApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(WebModuleConfig.J2EE_TYPE); 230 webApps = ControllerUtil.stripOutSystemApps(webApps); 231 232 for(Iterator webAppsItr = webApps.values().iterator(); webAppsItr.hasNext(); ) { 233 WebModuleConfig webConfig = (WebModuleConfig)webAppsItr.next(); 234 String cRoot = webConfig.getContextRoot(); 235 if(cRoot.equals(contextRoot)){ 236 modName = webConfig.getName(); 237 break; 238 } 239 } 240 241 if(modName == null){ 242 Map j2eeApps = ControllerUtil.stripOutSystemApps( 243 j2eeServer.getContaineeMap(J2EEApplication.J2EE_TYPE)); 244 for(Iterator itr = j2eeApps.values().iterator(); itr.hasNext(); ) { 245 J2EEApplication j2eeApp = (J2EEApplication)itr.next(); 246 247 Map compWebs = ControllerUtil.stripOutSystemApps( 248 j2eeApp.getContaineeMap(WebModule.J2EE_TYPE)); 249 for(Iterator webItr = compWebs.values().iterator(); webItr.hasNext(); ) { 250 WebModule webApp = (WebModule)webItr.next(); 251 String cRoot = webApp.getPath(); 252 if(cRoot.equals(contextRoot)){ 253 String appName = j2eeApp.getName(); 254 String webName = webApp.getName(); 255 if(webName.indexOf("//server") != -1) webName = webName.substring(8, webName.length()); 257 webName = webName + "_war"; modName = appName + webName; 259 break; 260 } 261 } 263 } 264 } return modName; 266 } 267 268 271 public AppClientModuleController[] getAppClientModules() { 272 273 testIfServerInDebug(); 274 275 String configPeerType = ControllerUtil.getConfigPeerAMXType(AppClientModule.J2EE_TYPE); 276 Map configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(configPeerType); 277 278 Map apps = j2eeServer.getContaineeMap(AppClientModule.J2EE_TYPE); 279 Map appsMap = getJ2EEAppsAsMap(AppClientModule.J2EE_TYPE); 280 281 java.util.Vector controllers = new java.util.Vector (); 282 for(Iterator configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) { 283 AppClientModuleConfig appClientConfig = (AppClientModuleConfig)configPeerItr.next(); 284 AppClientModule appClientMod = null; 285 if(appsMap.containsKey(appClientConfig.getName())){ 286 appClientMod = (AppClientModule)appsMap.get(appClientConfig.getName()); 287 } 288 controllers.add(new AppClientModuleController( 289 appClientMod, appClientConfig, getDeploymentManager(), 290 appMgmtConnection)); 291 } 292 293 AppClientModuleController[] result = 294 new AppClientModuleController[controllers.size()]; 295 return (AppClientModuleController[]) controllers.toArray(result); 296 } 297 298 private Map getJ2EEAppsAsMap(String type){ 299 Map apps = ControllerUtil.stripOutSystemApps(j2eeServer.getContaineeMap(type)); 300 Map j2eePeerMap = new java.util.HashMap (); 301 for(Iterator itr = apps.values().iterator(); itr.hasNext(); ) { 302 J2EEDeployedObject j2eeMod = (J2EEDeployedObject)itr.next(); 303 if(j2eeMod.getConfigPeer() != null) 304 j2eePeerMap.put(j2eeMod.getConfigPeer().getName(), j2eeMod); 305 } 306 return j2eePeerMap; 307 } 308 309 public String getServerName(){ 310 return j2eeServer.getserverVersion(); 311 } 312 } 313 | Popular Tags |