1 17 package org.apache.geronimo.j2ee.management.impl; 18 19 import java.util.Hashtable ; 20 import java.util.Collection ; 21 import java.util.ArrayList ; 22 import javax.management.ObjectName ; 23 import org.apache.geronimo.gbean.GBeanInfo; 24 import org.apache.geronimo.gbean.GBeanInfoBuilder; 25 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 26 import org.apache.geronimo.kernel.ObjectNameUtil; 27 import org.apache.geronimo.management.AppClientModule; 28 import org.apache.geronimo.management.EJBModule; 29 import org.apache.geronimo.management.J2EEModule; 30 import org.apache.geronimo.management.J2EEResource; 31 import org.apache.geronimo.management.geronimo.J2EEApplication; 32 import org.apache.geronimo.management.geronimo.J2EEServer; 33 import org.apache.geronimo.management.geronimo.ResourceAdapterModule; 34 import org.apache.geronimo.management.geronimo.WebModule; 35 36 39 public class J2EEApplicationImpl implements J2EEApplication { 40 private final String objectName; 41 private final String deploymentDescriptor; 42 private final J2EEServer server; 43 private final Collection resources; 44 private final Collection appClientModules; 45 private final Collection ejbModules; 46 private final Collection resourceAdapterModules; 47 private final Collection webModules; 48 49 public J2EEApplicationImpl(String objectName, 50 String deploymentDescriptor, 51 J2EEServer server, 52 Collection resources, 53 Collection appClientModules, 54 Collection ejbModules, 55 Collection resourceAdapterModules, 56 Collection webModules) { 57 58 this.objectName = objectName; 59 ObjectName myObjectName = ObjectNameUtil.getObjectName(this.objectName); 60 verifyObjectName(myObjectName); 61 62 this.deploymentDescriptor = deploymentDescriptor; 63 this.server = server; 64 this.resources = resources; 65 this.appClientModules = appClientModules; 66 this.ejbModules = ejbModules; 67 this.resourceAdapterModules = resourceAdapterModules; 68 this.webModules = webModules; 69 } 70 71 public String getObjectName() { 72 return objectName; 73 } 74 75 public boolean isStateManageable() { 76 return true; 77 } 78 79 public boolean isStatisticsProvider() { 80 return false; 81 } 82 83 public boolean isEventProvider() { 84 return true; 85 } 86 87 92 private void verifyObjectName(ObjectName objectName) { 93 if (objectName.isPattern()) { 94 throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName); 95 } 96 Hashtable keyPropertyList = objectName.getKeyPropertyList(); 97 if (!"J2EEApplication".equals(keyPropertyList.get("j2eeType"))) { 98 throw new InvalidObjectNameException("J2EEApplication object name j2eeType property must be 'J2EEApplication'", objectName); 99 } 100 if (!keyPropertyList.containsKey("name")) { 101 throw new InvalidObjectNameException("J2EEApplication object must contain a J2EEServer property", objectName); 102 } 103 if (!keyPropertyList.containsKey("J2EEServer")) { 104 throw new InvalidObjectNameException("J2EEApplication object name must contain a J2EEServer property", objectName); 105 } 106 if (keyPropertyList.size() != 3) { 107 throw new InvalidObjectNameException("J2EEApplication object name can only have j2eeType, name, and J2EEServer properties", objectName); 108 } 109 } 110 111 public String [] getModules() { 112 return Util.getObjectNames(getModulesInstances()); 113 } 114 115 public J2EEModule[] getModulesInstances() { 116 ArrayList objects = new ArrayList (); 117 if (appClientModules != null) { 118 objects.addAll(appClientModules); 119 } 120 if (ejbModules != null) { 121 objects.addAll(ejbModules); 122 } 123 if (webModules != null) { 124 objects.addAll(webModules); 125 } 126 if (resourceAdapterModules != null) { 127 objects.addAll(resourceAdapterModules); 128 } 129 130 return (J2EEModule[]) objects.toArray(new J2EEModule[objects.size()]); 131 } 132 133 public J2EEResource[] getResources() { 134 if (resources == null) return new J2EEResource[0]; 135 return (J2EEResource[]) resources.toArray(new J2EEResource[resources.size()]); 136 } 137 138 public AppClientModule[] getClientModules() { 139 if (appClientModules == null) return new AppClientModule[0]; 140 return (AppClientModule[]) appClientModules.toArray(new AppClientModule[appClientModules.size()]); 141 } 142 143 public EJBModule[] getEJBModules() { 144 if (ejbModules == null) return new EJBModule[0]; 145 return (EJBModule[]) ejbModules.toArray(new EJBModule[ejbModules.size()]); 146 } 147 148 public ResourceAdapterModule[] getRAModules() { 149 if (resourceAdapterModules == null) return new ResourceAdapterModule[0]; 150 return (ResourceAdapterModule[]) resourceAdapterModules.toArray(new ResourceAdapterModule[resourceAdapterModules.size()]); 151 } 152 153 public WebModule[] getWebModules() { 154 if (webModules == null) return new WebModule[0]; 155 return (WebModule[]) webModules.toArray(new WebModule[webModules.size()]); 156 } 157 158 public String getDeploymentDescriptor() { 159 return deploymentDescriptor; 160 } 161 162 public String getServer() { 163 return server.getObjectName(); 164 } 165 166 public static final GBeanInfo GBEAN_INFO; 167 168 static { 169 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEApplicationImpl.class, NameFactory.J2EE_APPLICATION); 170 infoFactory.addAttribute("deploymentDescriptor", String .class, true); 171 infoFactory.addReference("Server", J2EEServer.class); 172 infoFactory.addReference("Resources", J2EEResource.class); 173 infoFactory.addReference("AppClientModules", AppClientModule.class); 174 infoFactory.addReference("EJBModules", EJBModule.class); 175 infoFactory.addReference("ResourceAdapterModules", ResourceAdapterModule.class); 176 infoFactory.addReference("WebModules", WebModule.class); 177 178 infoFactory.setConstructor(new String []{ 179 "objectName", 180 "deploymentDescriptor", 181 "Server", 182 "Resources", 183 "AppClientModules", 184 "EJBModules", 185 "ResourceAdapterModules", 186 "WebModules", 187 }); 188 189 GBEAN_INFO = infoFactory.getBeanInfo(); 190 } 191 192 public static GBeanInfo getGBeanInfo() { 193 return GBEAN_INFO; 194 } 195 } 196 | Popular Tags |