001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ManagementClient.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.management.client;
030:
031: import java.io.Serializable;
032:
033: import javax.management.MBeanServerConnection;
034:
035: import com.sun.esb.management.api.administration.AdministrationService;
036: import com.sun.esb.management.api.configuration.ConfigurationService;
037: import com.sun.esb.management.api.deployment.DeploymentService;
038: import com.sun.esb.management.api.installation.InstallationService;
039: import com.sun.esb.management.api.notification.NotificationService;
040: import com.sun.esb.management.api.performance.PerformanceMeasurementService;
041: import com.sun.esb.management.api.runtime.RuntimeManagementService;
042: import com.sun.esb.management.common.ImplementationMap;
043: import com.sun.esb.management.common.ManagementRemoteException;
044: import com.sun.esb.management.common.Service;
045: import com.sun.esb.management.impl.administration.AdministrationServiceImpl;
046: import com.sun.esb.management.impl.configuration.ConfigurationServiceImpl;
047: import com.sun.esb.management.impl.deployment.DeploymentServiceImpl;
048: import com.sun.esb.management.impl.installation.InstallationServiceImpl;
049: import com.sun.esb.management.impl.notification.NotificationServiceImpl;
050: import com.sun.esb.management.impl.performance.PerformanceMeasurementServiceImpl;
051: import com.sun.esb.management.impl.runtime.RuntimeManagementServiceImpl;
052: import com.sun.jbi.ui.common.I18NBundle;
053:
054: /**
055: * Retrieves the various services associated with JBI Management and Monitoring
056: * administration commands.
057: *
058: * @author graj
059: */
060: public class ManagementClient implements Serializable {
061:
062: /** i18n */
063: private static I18NBundle I18NBUNDLE = null;
064:
065: static final long serialVersionUID = -1L;
066:
067: /**
068: * gives the I18N bundle
069: *
070: * @return I18NBundle object
071: */
072: protected static I18NBundle getI18NBundle() {
073: // lazzy initialize the Client
074: if (I18NBUNDLE == null) {
075: I18NBUNDLE = new I18NBundle(
076: "com.sun.caps.management.client");
077: }
078: return I18NBUNDLE;
079: }
080:
081: /** is this a local or remote connection */
082: boolean isRemoteConnection;
083:
084: /** remote MBeanServer connection */
085: transient MBeanServerConnection remoteConnection;
086:
087: /** Constructor */
088: public ManagementClient() {
089: this (null, false);
090: }
091:
092: /**
093: * Constructor
094: *
095: * @param serverConnection
096: */
097: public ManagementClient(MBeanServerConnection serverConnection) {
098: this (serverConnection, false);
099: }
100:
101: /**
102: * Constructor
103: *
104: * @param serverConnection
105: * @param isRemoteConnection
106: */
107: public ManagementClient(MBeanServerConnection serverConnection,
108: boolean isRemoteConnection) {
109: this .remoteConnection = serverConnection;
110: this .isRemoteConnection = isRemoteConnection;
111: }
112:
113: /**
114: * Get the Administration Service
115: * @return Administration Service object
116: * @throws ManagementRemoteException
117: */
118: public AdministrationService getAdministrationService()
119: throws ManagementRemoteException {
120: return new AdministrationServiceImpl(this .remoteConnection,
121: this .isRemoteConnection);
122: }
123:
124: /**
125: * Get the Configuration Service
126: * @return Configuration Service object
127: * @throws ManagementRemoteException
128: */
129: public ConfigurationService getConfigurationService()
130: throws ManagementRemoteException {
131: return new ConfigurationServiceImpl(this .remoteConnection,
132: this .isRemoteConnection);
133: }
134:
135: /**
136: * Get the Deployment Service
137: * @return Deployment Service object
138: * @throws ManagementRemoteException
139: */
140: public DeploymentService getDeploymentService()
141: throws ManagementRemoteException {
142: return new DeploymentServiceImpl(this .remoteConnection,
143: this .isRemoteConnection);
144: }
145:
146: /**
147: * Get the Installation Service
148: * @return Installation Service object
149: * @throws ManagementRemoteException
150: */
151: public InstallationService getInstallationService()
152: throws ManagementRemoteException {
153: return new InstallationServiceImpl(this .remoteConnection,
154: this .isRemoteConnection);
155: }
156:
157: /**
158: * Get the Performance Measurement Service
159: * @return Performance Measurement Service object
160: * @throws ManagementRemoteException
161: */
162: public PerformanceMeasurementService getPerformanceMeasurementService()
163: throws ManagementRemoteException {
164: return new PerformanceMeasurementServiceImpl(
165: this .remoteConnection, this .isRemoteConnection);
166: }
167:
168: /**
169: * Get the Runtime Management Service
170: * @return Runtime Management Service object
171: * @throws ManagementRemoteException
172: */
173: public RuntimeManagementService getRuntimeManagementService()
174: throws ManagementRemoteException {
175: return new RuntimeManagementServiceImpl(this .remoteConnection,
176: this .isRemoteConnection);
177: }
178:
179: /**
180: * Get the Notification Service
181: * @return Notification Service object
182: * @throws ManagementRemoteException
183: */
184: public NotificationService getNotificationService()
185: throws ManagementRemoteException {
186: return new NotificationServiceImpl(this .remoteConnection,
187: this .isRemoteConnection);
188: }
189:
190: /**
191: * is this a local or remote connection
192: *
193: * @return true if remote, false if local
194: */
195: public boolean isRemoteConnection() {
196: return this .isRemoteConnection;
197: }
198:
199: /**
200: * Get the generic service
201: *
202: * @param mapperClass
203: * @return <CLASS_TYPE> instance or null if the Service could not be obtained
204: */
205: public <CLASS_TYPE> CLASS_TYPE getService(Class<?> mapperClass) {
206: ImplementationMap map = mapperClass
207: .getAnnotation(ImplementationMap.class);
208: Class<?> implementationClass = map.implementationClass();
209: CLASS_TYPE theObject = null;
210: Service theService = null;
211:
212: try {
213: theService = (Service) implementationClass.newInstance();
214: theObject = theService.<CLASS_TYPE> getService(
215: remoteConnection, isRemoteConnection);
216: } catch (InstantiationException e) {
217: } catch (IllegalAccessException e) {
218: } catch (ManagementRemoteException e) {
219: }
220: return theObject;
221: }
222:
223: /**
224: * Get the client API version
225: * @param mapperClass
226: * @return the version of the Client API
227: */
228: public String getClientAPIVersion(Class mapperClass) {
229: String version = "";
230: ImplementationMap map = (ImplementationMap) mapperClass
231: .getAnnotation(ImplementationMap.class);
232: if (map != null) {
233: return map.clientAPIVersion();
234: }
235: return version;
236: }
237:
238: }
|