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.mejb;
018
019 import java.util.Set;
020 import javax.ejb.EJBHome;
021 import javax.ejb.EJBObject;
022 import javax.ejb.Handle;
023 import javax.ejb.RemoveException;
024 import javax.management.Attribute;
025 import javax.management.AttributeList;
026 import javax.management.AttributeNotFoundException;
027 import javax.management.InstanceNotFoundException;
028 import javax.management.IntrospectionException;
029 import javax.management.InvalidAttributeValueException;
030 import javax.management.MBeanException;
031 import javax.management.MBeanInfo;
032 import javax.management.MBeanServer;
033 import javax.management.ObjectName;
034 import javax.management.QueryExp;
035 import javax.management.ReflectionException;
036 import javax.management.j2ee.ListenerRegistration;
037 import javax.management.j2ee.Management;
038
039 import org.apache.geronimo.gbean.GBeanInfo;
040 import org.apache.geronimo.gbean.GBeanInfoBuilder;
041 import org.apache.geronimo.system.jmx.MBeanServerReference;
042 import org.apache.geronimo.management.J2EEManagedObject;
043
044 /**
045 * GBean implementing Management interface and supplying proxies to act as the MEJB container.
046 *
047 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
048 */
049 public class MEJB implements Management {
050 private final String objectName;
051 private final MBeanServer mbeanServer;
052
053 // todo remove this as soon as Geronimo supports factory beans
054 public MEJB(String objectName, MBeanServerReference mbeanServerReference) {
055 this(objectName, mbeanServerReference.getMBeanServer());
056 }
057
058 public MEJB(String objectName, MBeanServer mbeanServer) {
059 this.objectName = objectName;
060 this.mbeanServer = mbeanServer;
061 }
062
063 public MBeanInfo getMBeanInfo(ObjectName objectName) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
064 return mbeanServer.getMBeanInfo(objectName);
065 }
066
067 public String getDefaultDomain() {
068 return mbeanServer.getDefaultDomain();
069 }
070
071 public Object getAttribute(ObjectName objectName, String s) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
072 return mbeanServer.getAttribute(objectName, s);
073 }
074
075 public void setAttribute(ObjectName objectName, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
076 mbeanServer.setAttribute(objectName, attribute);
077 }
078
079 public AttributeList getAttributes(ObjectName objectName, String[] strings) throws InstanceNotFoundException, ReflectionException {
080 return mbeanServer.getAttributes(objectName, strings);
081 }
082
083 public AttributeList setAttributes(ObjectName objectName, AttributeList attributeList) throws InstanceNotFoundException, ReflectionException {
084 return mbeanServer.setAttributes(objectName, attributeList);
085 }
086
087 public Object invoke(ObjectName objectName, String s, Object[] objects, String[] strings) throws InstanceNotFoundException, MBeanException, ReflectionException {
088 return mbeanServer.invoke(objectName, s, objects, strings);
089 }
090
091 public Integer getMBeanCount() {
092 return mbeanServer.getMBeanCount();
093 }
094
095 public boolean isRegistered(ObjectName objectName) {
096 return mbeanServer.isRegistered(objectName);
097 }
098
099 public Set queryNames(ObjectName objectName, QueryExp queryExp) {
100 return mbeanServer.queryNames(objectName, queryExp);
101 }
102
103 public ListenerRegistration getListenerRegistry() {
104 throw new UnsupportedOperationException("Not Yet Implemented");
105 }
106
107
108 // EJBObject implementation
109 public EJBHome getEJBHome() {
110 return null;
111 }
112
113 public Handle getHandle() {
114 return null;
115 }
116
117 public Object getPrimaryKey() {
118 return null;
119 }
120
121 public boolean isIdentical(EJBObject obj) {
122 return false;
123 }
124
125 public void remove() throws RemoveException {
126 }
127
128 public String getObjectName() {
129 return objectName;
130 }
131
132 public boolean isStateManageable() {
133 return false;
134 }
135
136 public boolean isStatisticsProvider() {
137 return false;
138 }
139
140 public boolean isEventProvider() {
141 return false;
142 }
143
144 public static final GBeanInfo GBEAN_INFO;
145
146 static {
147 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(MEJB.class);
148 infoBuilder.addAttribute("objectName", String.class, false);
149 infoBuilder.addReference("MBeanServerReference", MBeanServerReference.class);
150 infoBuilder.addInterface(Management.class);
151 infoBuilder.addInterface(J2EEManagedObject.class);
152
153 infoBuilder.setConstructor(new String[]{"objectName", "MBeanServerReference"});
154
155 GBEAN_INFO = infoBuilder.getBeanInfo();
156 }
157
158 public static GBeanInfo getGBeanInfo() {
159 return GBEAN_INFO;
160 }
161
162 }