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 */ 017 package org.apache.geronimo.j2ee.management.impl; 018 019 import java.util.Hashtable; 020 import javax.management.ObjectName; 021 022 import org.apache.geronimo.gbean.GBeanInfo; 023 import org.apache.geronimo.gbean.GBeanInfoBuilder; 024 import org.apache.geronimo.management.J2EEApplication; 025 import org.apache.geronimo.management.J2EEServer; 026 import org.apache.geronimo.management.AppClientModule; 027 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 028 import org.apache.geronimo.kernel.ObjectNameUtil; 029 030 /** 031 * @version $Revision: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $ 032 */ 033 public class J2EEAppClientModuleImpl implements AppClientModule { 034 private final String deploymentDescriptor; 035 private final J2EEServer server; 036 private final J2EEApplication application; 037 private final ClassLoader classLoader; 038 private final String objectName; 039 040 public J2EEAppClientModuleImpl(String objectName, J2EEServer server, J2EEApplication application, String deploymentDescriptor, ClassLoader classLoader) { 041 this.objectName = objectName; 042 ObjectName myObjectName = ObjectNameUtil.getObjectName(this.objectName); 043 verifyObjectName(myObjectName); 044 045 this.server = server; 046 this.application = application; 047 this.deploymentDescriptor = deploymentDescriptor; 048 this.classLoader = classLoader; 049 } 050 051 public String getObjectName() { 052 return objectName; 053 } 054 055 public boolean isStateManageable() { 056 return true; 057 } 058 059 public boolean isStatisticsProvider() { 060 return false; 061 } 062 063 public boolean isEventProvider() { 064 return true; 065 } 066 067 /** 068 * ObjectName must match this pattern: 069 * <p/> 070 * domain:j2eeType=AppClientModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication 071 */ 072 private void verifyObjectName(ObjectName objectName) { 073 if (objectName.isPattern()) { 074 throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName); 075 } 076 Hashtable keyPropertyList = objectName.getKeyPropertyList(); 077 if (!"AppClientModule".equals(keyPropertyList.get("j2eeType"))) { 078 throw new InvalidObjectNameException("AppClientModule object name j2eeType property must be 'AppClientModule'", objectName); 079 } 080 if (!keyPropertyList.containsKey("name")) { 081 throw new InvalidObjectNameException("AppClientModule object must contain a name property", objectName); 082 } 083 if (!keyPropertyList.containsKey("J2EEServer")) { 084 throw new InvalidObjectNameException("AppClientModule object name must contain a J2EEServer property", objectName); 085 } 086 if (!keyPropertyList.containsKey("J2EEApplication")) { 087 throw new InvalidObjectNameException("AppClientModule object name must contain a J2EEApplication property", objectName); 088 } 089 if (keyPropertyList.size() != 4) { 090 throw new InvalidObjectNameException("AppClientModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName); 091 } 092 } 093 094 public String getDeploymentDescriptor() { 095 return deploymentDescriptor; 096 } 097 098 public String getServer() { 099 return server.getObjectName(); 100 } 101 102 public String getApplication() { 103 if (application == null) { 104 return null; 105 } 106 return application.getObjectName(); 107 } 108 109 public String[] getJavaVMs() { 110 return server.getJavaVMs(); 111 } 112 113 public ClassLoader getClassLoader() { 114 return classLoader; 115 } 116 117 public static final GBeanInfo GBEAN_INFO; 118 119 static { 120 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEAppClientModuleImpl.class, NameFactory.APP_CLIENT_MODULE); 121 infoFactory.addReference("J2EEServer", J2EEServer.class); 122 infoFactory.addReference("J2EEApplication", J2EEApplication.class); 123 124 infoFactory.addAttribute("deploymentDescriptor", String.class, true); 125 126 infoFactory.addAttribute("objectName", String.class, false); 127 infoFactory.addAttribute("server", String.class, false); 128 infoFactory.addAttribute("application", String.class, false); 129 infoFactory.addAttribute("javaVMs", String[].class, false); 130 infoFactory.addAttribute("classLoader", ClassLoader.class, false); 131 infoFactory.addInterface(AppClientModule.class); 132 133 134 infoFactory.setConstructor(new String[]{ 135 "objectName", 136 "J2EEServer", 137 "J2EEApplication", 138 "deploymentDescriptor", 139 "classLoader"}); 140 141 GBEAN_INFO = infoFactory.getBeanInfo(); 142 } 143 144 public static GBeanInfo getGBeanInfo() { 145 return GBEAN_INFO; 146 } 147 }