001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring.client;
006:
007: import javax.management.*;
008: import java.util.List;
009: import java.util.Set;
010: import java.util.ArrayList;
011: import java.lang.reflect.Method;
012:
013: public class BeaClientImpl extends ClientImpl {
014: public BeaClientImpl(String defaultDomain,
015: List immortalMBeanObjectNames, MBeanServer mBeanServer) {
016: setDefaultDomain(defaultDomain);
017: setImmortalMBeanObjectNames(immortalMBeanObjectNames);
018: this .mBeanServer = mBeanServer;
019: }
020:
021: public void addNotificationListener(ObjectName on,
022: NotificationListener listener, NotificationFilter filter,
023: Object handback) throws InstanceNotFoundException {
024: if (mBeanServer != null) {
025: mBeanServer.addNotificationListener(on, listener, filter,
026: handback);
027: }
028: }
029:
030: public Object getAttribute(ObjectName on, String attrName)
031: throws ReflectionException, InstanceNotFoundException,
032: MBeanException, AttributeNotFoundException {
033: if (mBeanServer != null) {
034: return mBeanServer.getAttribute(on, attrName);
035: }
036:
037: return null;
038: }
039:
040: public AttributeList getAttributes(ObjectName on, String[] attrNames)
041: throws ReflectionException, InstanceNotFoundException {
042: if (mBeanServer != null) {
043: return mBeanServer.getAttributes(on, attrNames);
044: }
045:
046: return null;
047: }
048:
049: public Integer getMBeanCount() {
050: if (mBeanServer != null) {
051: return mBeanServer.getMBeanCount();
052: }
053:
054: return new Integer(0);
055: }
056:
057: public MBeanInfo getMBeanInfo(ObjectName on)
058: throws ReflectionException, InstanceNotFoundException,
059: IntrospectionException {
060: if (mBeanServer != null) {
061: return mBeanServer.getMBeanInfo(on);
062: }
063:
064: return null;
065: }
066:
067: public Object invoke(ObjectName on, String operationName,
068: Object[] params, String[] signature)
069: throws ReflectionException, InstanceNotFoundException,
070: MBeanException {
071: if (mBeanServer != null) {
072: return mBeanServer.invoke(on, operationName, params,
073: signature);
074: }
075:
076: return null;
077: }
078:
079: public Boolean isInstanceOf(ObjectName on, String className)
080: throws InstanceNotFoundException {
081: if (mBeanServer != null) {
082: return mBeanServer.isInstanceOf(on, className) ? Boolean.TRUE
083: : Boolean.FALSE;
084: }
085:
086: return Boolean.FALSE;
087: }
088:
089: public Boolean isRegistered(ObjectName on) {
090: if (mBeanServer != null) {
091: return mBeanServer.isRegistered(on) ? Boolean.TRUE
092: : Boolean.FALSE;
093: }
094:
095: return Boolean.FALSE;
096: }
097:
098: public Set queryNames(ObjectName pattern, QueryExp expr) {
099: if (mBeanServer != null) {
100: return mBeanServer.queryNames(pattern, expr);
101: }
102:
103: return null;
104: }
105:
106: public void removeNotificationListener(ObjectName on,
107: NotificationListener listener)
108: throws InstanceNotFoundException, ListenerNotFoundException {
109: if (mBeanServer != null) {
110: mBeanServer.removeNotificationListener(on, listener);
111: }
112: }
113:
114: public void setAttribute(ObjectName on, Attribute attr)
115: throws ReflectionException, InstanceNotFoundException,
116: MBeanException, AttributeNotFoundException,
117: InvalidAttributeValueException {
118: if (mBeanServer != null) {
119: mBeanServer.setAttribute(on, attr);
120: }
121: }
122:
123: public AttributeList setAttributes(ObjectName on,
124: AttributeList attrs) throws ReflectionException,
125: InstanceNotFoundException {
126: if (mBeanServer != null) {
127: return mBeanServer.setAttributes(on, attrs);
128: }
129:
130: return null;
131: }
132:
133: public void unregisterMBean(ObjectName on)
134: throws MBeanRegistrationException,
135: InstanceNotFoundException {
136: if (!getImmortalMBeanObjectNames().contains(on)) {
137: if (mBeanServer != null) {
138: mBeanServer.unregisterMBean(on);
139: }
140: }
141: }
142:
143: public void disconnect() {
144: mBeanServer = null;
145: }
146:
147: private MBeanServer mBeanServer;
148:
149: public BeaClientImpl() {
150: }
151:
152: public void setMBeanServer(MBeanServer mBeanServer) {
153: this .mBeanServer = mBeanServer;
154: }
155:
156: public Object invoke(Object proxy, Method method, Object[] params)
157: throws Throwable {
158: List signature = new ArrayList();
159: Class[] paramTypeClasses = method.getParameterTypes();
160: if (paramTypeClasses != null) {
161: } else if (paramTypeClasses.length != 0) {
162: for (int i = 0; i < paramTypeClasses.length; i++) {
163: signature.add(paramTypeClasses[i].getName());
164: }
165: }
166: String[] paramTypes = (signature.size() == 0) ? null
167: : ((String[]) signature.toArray(new String[signature
168: .size()]));
169: return mBeanServer.invoke(objectNameProxy, method.getName(),
170: params, paramTypes);
171: }
172: }
|