001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.j2ee.management.impl;
017:
018: import java.util.Hashtable;
019: import javax.management.ObjectName;
020:
021: import org.apache.geronimo.gbean.GBeanInfo;
022: import org.apache.geronimo.gbean.GBeanInfoBuilder;
023: import org.apache.geronimo.management.J2EEApplication;
024: import org.apache.geronimo.management.J2EEServer;
025: import org.apache.geronimo.management.AppClientModule;
026: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
027: import org.apache.geronimo.kernel.ObjectNameUtil;
028:
029: /**
030: * @version $Revision: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
031: */
032: public class J2EEAppClientModuleImpl implements AppClientModule {
033: private final String deploymentDescriptor;
034: private final J2EEServer server;
035: private final J2EEApplication application;
036: private final ClassLoader classLoader;
037: private final String objectName;
038:
039: public J2EEAppClientModuleImpl(String objectName,
040: J2EEServer server, J2EEApplication application,
041: String deploymentDescriptor, ClassLoader classLoader) {
042: this .objectName = objectName;
043: ObjectName myObjectName = ObjectNameUtil
044: .getObjectName(this .objectName);
045: verifyObjectName(myObjectName);
046:
047: this .server = server;
048: this .application = application;
049: this .deploymentDescriptor = deploymentDescriptor;
050: this .classLoader = classLoader;
051: }
052:
053: public String getObjectName() {
054: return objectName;
055: }
056:
057: public boolean isStateManageable() {
058: return true;
059: }
060:
061: public boolean isStatisticsProvider() {
062: return false;
063: }
064:
065: public boolean isEventProvider() {
066: return true;
067: }
068:
069: /**
070: * ObjectName must match this pattern:
071: * <p/>
072: * domain:j2eeType=AppClientModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
073: */
074: private void verifyObjectName(ObjectName objectName) {
075: if (objectName.isPattern()) {
076: throw new InvalidObjectNameException(
077: "ObjectName can not be a pattern", objectName);
078: }
079: Hashtable keyPropertyList = objectName.getKeyPropertyList();
080: if (!"AppClientModule".equals(keyPropertyList.get("j2eeType"))) {
081: throw new InvalidObjectNameException(
082: "AppClientModule object name j2eeType property must be 'AppClientModule'",
083: objectName);
084: }
085: if (!keyPropertyList.containsKey("name")) {
086: throw new InvalidObjectNameException(
087: "AppClientModule object must contain a name property",
088: objectName);
089: }
090: if (!keyPropertyList.containsKey("J2EEServer")) {
091: throw new InvalidObjectNameException(
092: "AppClientModule object name must contain a J2EEServer property",
093: objectName);
094: }
095: if (!keyPropertyList.containsKey("J2EEApplication")) {
096: throw new InvalidObjectNameException(
097: "AppClientModule object name must contain a J2EEApplication property",
098: objectName);
099: }
100: if (keyPropertyList.size() != 4) {
101: throw new InvalidObjectNameException(
102: "AppClientModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties",
103: objectName);
104: }
105: }
106:
107: public String getDeploymentDescriptor() {
108: return deploymentDescriptor;
109: }
110:
111: public String getServer() {
112: return server.getObjectName();
113: }
114:
115: public String getApplication() {
116: if (application == null) {
117: return null;
118: }
119: return application.getObjectName();
120: }
121:
122: public String[] getJavaVMs() {
123: return server.getJavaVMs();
124: }
125:
126: public ClassLoader getClassLoader() {
127: return classLoader;
128: }
129:
130: public static final GBeanInfo GBEAN_INFO;
131:
132: static {
133: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
134: J2EEAppClientModuleImpl.class,
135: NameFactory.APP_CLIENT_MODULE);
136: infoFactory.addReference("J2EEServer", J2EEServer.class);
137: infoFactory.addReference("J2EEApplication",
138: J2EEApplication.class);
139:
140: infoFactory.addAttribute("deploymentDescriptor", String.class,
141: true);
142:
143: infoFactory.addAttribute("objectName", String.class, false);
144: infoFactory.addAttribute("server", String.class, false);
145: infoFactory.addAttribute("application", String.class, false);
146: infoFactory.addAttribute("javaVMs", String[].class, false);
147: infoFactory.addAttribute("classLoader", ClassLoader.class,
148: false);
149: infoFactory.addInterface(AppClientModule.class);
150:
151: infoFactory.setConstructor(new String[] { "objectName",
152: "J2EEServer", "J2EEApplication",
153: "deploymentDescriptor", "classLoader" });
154:
155: GBEAN_INFO = infoFactory.getBeanInfo();
156: }
157:
158: public static GBeanInfo getGBeanInfo() {
159: return GBEAN_INFO;
160: }
161: }
|