Source Code Cross Referenced for ManagementBean.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » mejb » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.mejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2005 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: ManagementBean.java 9680 2006-10-06 12:08:33Z danesa $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.mejb;
025:
026:        import java.io.IOException;
027:        import java.rmi.RemoteException;
028:        import java.util.Collection;
029:        import java.util.Iterator;
030:        import java.util.Set;
031:
032:        import javax.ejb.CreateException;
033:        import javax.ejb.SessionBean;
034:        import javax.ejb.SessionContext;
035:        import javax.management.Attribute;
036:        import javax.management.AttributeList;
037:        import javax.management.AttributeNotFoundException;
038:        import javax.management.InstanceAlreadyExistsException;
039:        import javax.management.InstanceNotFoundException;
040:        import javax.management.IntrospectionException;
041:        import javax.management.InvalidAttributeValueException;
042:        import javax.management.MBeanAttributeInfo;
043:        import javax.management.MBeanException;
044:        import javax.management.MBeanInfo;
045:        import javax.management.MBeanOperationInfo;
046:        import javax.management.MBeanServerConnection;
047:        import javax.management.ObjectName;
048:        import javax.management.QueryExp;
049:        import javax.management.ReflectionException;
050:        import javax.management.j2ee.ListenerRegistration;
051:
052:        import org.objectweb.jonas.common.Log;
053:        import org.objectweb.jonas.jmx.J2eeObjectName;
054:        import org.objectweb.jonas.jmx.JmxService;
055:        import org.objectweb.jonas.management.j2eemanagement.J2EEDomain;
056:        import org.objectweb.jonas.management.j2eemanagement.ManagementListener;
057:        import org.objectweb.jonas.management.j2eemanagement.ManagementListenerMBean;
058:        import org.objectweb.jonas.service.ServiceManager;
059:        import org.objectweb.util.monolog.api.BasicLevel;
060:        import org.objectweb.util.monolog.api.Logger;
061:
062:        /**
063:         * This is the Management EJB implementation for JOnAS.
064:         * A MEJB instance is created and deployed at JOnAS start time.
065:         * It is registered in the ejb/mgmt naming subcontext.
066:         *
067:         * The current implementation allows access to managed resources registered in
068:         * the current (local) MBean server via the standard management methods defined in the
069:         * javax.management.j2ee.Management interface.
070:         *
071:         * It also allows access to managed resources registered in remote MBean servers
072:         * which belong to the current management domain, via management methods exposed as a
073:         * WebService endpoint (defined in the ManagementEndpoint interface).
074:         *
075:         * @author Adriana Danes
076:         * @author Vivek Lakshmanan
077:         * @author Matt Wringe
078:         */
079:        public class ManagementBean implements  SessionBean, ManagementEndpoint {
080:
081:            /**
082:             * Logger
083:             */
084:            private static Logger logger = Log.getLogger(Log.JONAS_MEJB);
085:            /**
086:             * reference to the context object
087:             */
088:            private SessionContext sessionContext = null;
089:            /**
090:             * The current JOnAS server's jmx service.
091:             * The jmx service is used to get connections to remote MBean servers
092:             */
093:            private JmxService jmxService = null;
094:            /**
095:             * Connection to the current JOnAS server's MBean server
096:             */
097:            private MBeanServerConnection jmxServerConnection = null;
098:            /**
099:             * The current server name
100:             */
101:            private String serverName = null;
102:            /**
103:             * The current domain name
104:             */
105:            private String domainName = null;
106:            /**
107:             * The remote NotificationListener proxy name
108:             */
109:            private String proxyName = "MEJB_listener";
110:
111:            /**
112:             * ejbCreate method
113:             *
114:             * Get the MBeanServer reference to allow local access
115:             */
116:            public void ejbCreate() throws CreateException {
117:                try {
118:                    jmxService = (JmxService) ServiceManager.getInstance()
119:                            .getJmxService();
120:                    serverName = jmxService.getJonasServerName();
121:                    domainName = jmxService.getDomainName();
122:                    jmxServerConnection = (MBeanServerConnection) jmxService
123:                            .getJmxServer();
124:                } catch (Exception e) {
125:                    throw new CreateException(
126:                            "Could not create Management bean: "
127:                                    + e.getMessage());
128:                }
129:            }
130:
131:            /*====================== javax.ejb.SessionBean implementation =================*/
132:
133:            public void ejbActivate() {
134:                // Nothing to do when the MEJB is activated
135:            }
136:
137:            public void ejbPassivate() {
138:                // Nothing to do when the MEJB is passivated
139:            }
140:
141:            public void ejbRemove() {
142:                // Nothing to do when the MEJB is removed
143:            }
144:
145:            /**
146:             * Sets the associated session context.
147:             * @param sessionContext - A SessionContext interface for the instance.
148:             */
149:            public void setSessionContext(SessionContext sessionContext) {
150:                this .sessionContext = sessionContext;
151:            }
152:
153:            /*========================= Management interface implementation ============================*/
154:            /*=============== The management methods are invoked on the local MBeanServer ========*/
155:
156:            public Object getAttribute(ObjectName name, String attribute)
157:                    throws MBeanException, AttributeNotFoundException,
158:                    InstanceNotFoundException, ReflectionException,
159:                    RemoteException {
160:
161:                try {
162:                    return jmxServerConnection.getAttribute(name, attribute);
163:                } catch (java.io.IOException ioe) {
164:                    throw new RemoteException(
165:                            "Object getAttribute(ObjectName, String) failed",
166:                            ioe);
167:                }
168:            }
169:
170:            public AttributeList getAttributes(ObjectName name,
171:                    String[] attributes) throws InstanceNotFoundException,
172:                    ReflectionException, RemoteException {
173:
174:                try {
175:                    return jmxServerConnection.getAttributes(name, attributes);
176:                } catch (java.io.IOException ioe) {
177:                    throw new RemoteException(
178:                            "AttributeList getAttributes(ObjectName, String[]) failed",
179:                            ioe);
180:                }
181:            }
182:
183:            public String getDefaultDomain() throws RemoteException {
184:
185:                try {
186:                    return jmxServerConnection.getDefaultDomain();
187:                } catch (java.io.IOException ioe) {
188:                    throw new RemoteException(
189:                            "String getDefaultDomain() failed", ioe);
190:                }
191:            }
192:
193:            public Integer getMBeanCount() throws RemoteException {
194:
195:                try {
196:                    return jmxServerConnection.getMBeanCount();
197:                } catch (java.io.IOException ioe) {
198:                    throw new RemoteException("Integer getMBeanCount() failed",
199:                            ioe);
200:                }
201:            }
202:
203:            public MBeanInfo getMBeanInfo(ObjectName name)
204:                    throws IntrospectionException, InstanceNotFoundException,
205:                    ReflectionException, RemoteException {
206:
207:                try {
208:                    return jmxServerConnection.getMBeanInfo(name);
209:                } catch (java.io.IOException ioe) {
210:                    throw new RemoteException(
211:                            "MBeanInfo getMBeanInfo(ObjectName) failed", ioe);
212:                }
213:            }
214:
215:            public Object invoke(ObjectName name, String operationName,
216:                    Object[] params, String[] signature) throws MBeanException,
217:                    InstanceNotFoundException, ReflectionException,
218:                    RemoteException {
219:
220:                try {
221:                    return jmxServerConnection.invoke(name, operationName,
222:                            params, signature);
223:                } catch (java.io.IOException ioe) {
224:                    throw new RemoteException(
225:                            "Object invoke(ObjectName, String, Object[], String[]) failed",
226:                            ioe);
227:                }
228:            }
229:
230:            public boolean isRegistered(ObjectName name) throws RemoteException {
231:
232:                try {
233:                    return jmxServerConnection.isRegistered(name);
234:                } catch (java.io.IOException ioe) {
235:                    throw new RemoteException(
236:                            "boolean isRegistered(ObjectName) failed", ioe);
237:                }
238:            }
239:
240:            public Set queryNames(ObjectName name, QueryExp query)
241:                    throws RemoteException {
242:                try {
243:                    return jmxServerConnection.queryNames(name, query);
244:                } catch (java.io.IOException ioe) {
245:                    throw new RemoteException(
246:                            "Set queryNames(ObjectName, QueryExp)  failed", ioe);
247:                }
248:            }
249:
250:            public void setAttribute(ObjectName name, Attribute attribute)
251:                    throws MBeanException, AttributeNotFoundException,
252:                    InstanceNotFoundException, InvalidAttributeValueException,
253:                    ReflectionException, RemoteException {
254:
255:                try {
256:                    jmxServerConnection.setAttribute(name, attribute);
257:                } catch (java.io.IOException ioe) {
258:                    throw new RemoteException(
259:                            "void setAttribute(ObjectName, Attribute) failed",
260:                            ioe);
261:                }
262:            }
263:
264:            public AttributeList setAttributes(ObjectName name,
265:                    AttributeList attributes) throws InstanceNotFoundException,
266:                    ReflectionException, RemoteException {
267:
268:                try {
269:                    return jmxServerConnection.setAttributes(name, attributes);
270:                } catch (java.io.IOException ioe) {
271:                    throw new RemoteException(
272:                            "AttributeList setAttributes(ObjectName, AttributeList) failed",
273:                            ioe);
274:                }
275:            }
276:
277:            /**
278:             * Returns the ListenerRegistration implementation object which allows the client to register
279:             * a event notification listener.
280:             * This method also creates a MBean
281:             * @return An instance of the class implementing the ListenerRegistration interface.
282:             * <code>null</code> is returned if
283:             */
284:            public ListenerRegistration getListenerRegistry()
285:                    throws RemoteException {
286:                // Create and register the ManagemenentListener MBean if this is not already done
287:                ObjectName listenerOn = J2eeObjectName.ManagementListener(
288:                        domainName, serverName);
289:                boolean isRegisteredListener;
290:                isRegisteredListener = jmxService.getJmxServer().isRegistered(
291:                        listenerOn);
292:                if (!isRegisteredListener) {
293:                    ManagementListenerMBean listenerMBean = new ManagementListener(
294:                            proxyName);
295:                    try {
296:                        jmxService.getJmxServer().registerMBean(listenerMBean,
297:                                listenerOn);
298:                    } catch (InstanceAlreadyExistsException ae) {
299:                        // Not possible as tested before
300:                    } catch (Exception e) {
301:                        // Could not register MBean -> the management bean can't handle notifications
302:                        throw new RemoteException(
303:                                "Can not return ListenerRegistration implementation",
304:                                e);
305:                    }
306:                }
307:                // Create ListenerRegistration object
308:                return new ListenerRegistrationImpl(listenerOn, proxyName);
309:            }
310:
311:            /*=============== The management methods are invoked on Remote MBeanServers ==========*/
312:
313:            /**
314:             * Returns a connection for a server in the domain. Any error messages in getting
315:             * the server connection is thrown as a remote exception.
316:             * @param domainServerName    The server name.
317:             * @return                    A connection to the server.
318:             */
319:            private MBeanServerConnection getServerConnection(
320:                    String domainServerName) {
321:                //if the domainServerName is null, return the connection to the current server
322:                if (domainServerName == null
323:                        || domainServerName.equals(serverName)) {
324:                    return jmxServerConnection;
325:                }
326:                return J2EEDomain.getInstance().getConnection(domainServerName);
327:            }
328:
329:            public Object getAttribute(String domainServerName,
330:                    ObjectName name, String attribute)
331:                    throws AttributeNotFoundException,
332:                    InstanceNotFoundException, MBeanException,
333:                    ReflectionException, RemoteException {
334:
335:                MBeanServerConnection connection = getServerConnection(domainServerName);
336:                if (connection == null) {
337:                    throw new RemoteException("Could not connect to server "
338:                            + domainServerName);
339:                }
340:                try {
341:                    return connection.getAttribute(name, attribute);
342:                } catch (IOException ioe) {
343:                    throw new RemoteException(
344:                            "Object getAttribute(String, ObjectName, String) failed",
345:                            ioe);
346:                }
347:            }
348:
349:            public AttributeList getAttributes(String domainServerName,
350:                    ObjectName name, String[] attributes)
351:                    throws InstanceNotFoundException, ReflectionException,
352:                    RemoteException {
353:
354:                MBeanServerConnection connection = getServerConnection(domainServerName);
355:                if (connection == null) {
356:                    throw new RemoteException("Could not connect to server "
357:                            + domainServerName);
358:                }
359:                try {
360:                    return connection.getAttributes(name, attributes);
361:                } catch (IOException ioe) {
362:                    throw new RemoteException(
363:                            "AttributeList getAttributes(String, ObjectName, String[]) failed",
364:                            ioe);
365:                }
366:            }
367:
368:            public Integer getMBeanCount(String domainServerName)
369:                    throws RemoteException {
370:
371:                MBeanServerConnection connection = getServerConnection(domainServerName);
372:                if (connection == null) {
373:                    throw new RemoteException("Could not connect to server "
374:                            + domainServerName);
375:                }
376:                try {
377:                    return connection.getMBeanCount();
378:                } catch (IOException ioe) {
379:                    throw new RemoteException(
380:                            "Integer getMBeanCount(String) failed", ioe);
381:                }
382:            }
383:
384:            public MBeanInfo getMBeanInfo(String domainServerName,
385:                    ObjectName name) throws IntrospectionException,
386:                    InstanceNotFoundException, ReflectionException,
387:                    RemoteException {
388:
389:                MBeanServerConnection connection = getServerConnection(domainServerName);
390:                if (connection == null) {
391:                    throw new RemoteException("Could not connect to server "
392:                            + domainServerName);
393:                }
394:                try {
395:                    return connection.getMBeanInfo(name);
396:                } catch (IOException ioe) {
397:                    throw new RemoteException(
398:                            "MBeanInfo getMbeanInfo(String, ObjectName) failed",
399:                            ioe);
400:                }
401:            }
402:
403:            public Object invoke(String domainServerName, ObjectName name,
404:                    String operationName, Object[] params, String[] signature)
405:                    throws MBeanException, InstanceNotFoundException,
406:                    ReflectionException, RemoteException {
407:
408:                MBeanServerConnection connection = getServerConnection(domainServerName);
409:                if (connection == null) {
410:                    throw new RemoteException("Could not connect to server "
411:                            + domainServerName);
412:                }
413:                try {
414:                    return connection.invoke(name, operationName, params,
415:                            signature);
416:                } catch (IOException ioe) {
417:                    throw new RemoteException(
418:                            "Object invoke(String, ObjectName, String, Object[], String[]) failed",
419:                            ioe);
420:                }
421:            }
422:
423:            public boolean isRegistered(String domainServerName, ObjectName name)
424:                    throws RemoteException {
425:
426:                MBeanServerConnection connection = getServerConnection(domainServerName);
427:                if (connection == null) {
428:                    throw new RemoteException("Could not connect to server "
429:                            + domainServerName);
430:                }
431:                try {
432:                    return connection.isRegistered(name);
433:                } catch (java.io.IOException ioe) {
434:                    throw new RemoteException(
435:                            "boolean isRegistered(String, ObjectName) failed",
436:                            ioe);
437:                }
438:            }
439:
440:            public Set queryNames(String domainServerName, ObjectName name,
441:                    QueryExp query) throws RemoteException {
442:
443:                MBeanServerConnection connection = getServerConnection(domainServerName);
444:                if (connection == null) {
445:                    throw new RemoteException("Could not connect to server "
446:                            + domainServerName);
447:                }
448:                try {
449:                    return connection.queryNames(name, query);
450:                } catch (java.io.IOException ioe) {
451:                    throw new RemoteException(
452:                            "Set queryNames(String, ObjectName, QueryExp) failed",
453:                            ioe);
454:                }
455:            }
456:
457:            public void setAttribute(String domainServerName, ObjectName name,
458:                    Attribute attribute) throws MBeanException,
459:                    AttributeNotFoundException, InstanceNotFoundException,
460:                    InvalidAttributeValueException, ReflectionException,
461:                    RemoteException {
462:
463:                MBeanServerConnection connection = getServerConnection(domainServerName);
464:                if (connection == null) {
465:                    throw new RemoteException("Could not connect to server "
466:                            + domainServerName);
467:                }
468:                try {
469:                    connection.setAttribute(name, attribute);
470:                } catch (java.io.IOException ioe) {
471:                    throw new RemoteException(
472:                            "void setAttribute(String, ObjectName, Attribute) failed",
473:                            ioe);
474:                }
475:            }
476:
477:            public AttributeList setAttributes(String domainServerName,
478:                    ObjectName name, AttributeList attributes)
479:                    throws InstanceNotFoundException, ReflectionException,
480:                    RemoteException {
481:
482:                MBeanServerConnection connection = getServerConnection(domainServerName);
483:                if (connection == null) {
484:                    throw new RemoteException("Could not connect to server "
485:                            + domainServerName);
486:                }
487:                try {
488:                    return connection.setAttributes(name, attributes);
489:                } catch (java.io.IOException ioe) {
490:                    throw new RemoteException(
491:                            "AttributeList setAttributes(String, ObjectName, AttributeList) failed",
492:                            ioe);
493:                }
494:            }
495:
496:            /*================== ManagementBean Monitoring Endpoint implementation ===============*/
497:            /*=============== The management methods are invoked on Remote MBeanServers ==========*/
498:
499:            /*
500:             * Implementation for the ManagementEndpoint interface begins here
501:             *
502:             * -the ManagementEndpoint allows monitoring of the server remotely using its web
503:             *  service.
504:             * -many of these methods look the same as the ones above but their
505:             *  data types have been changed to make them easier for a web service to use
506:             *  them.
507:             * -The only method used in the ManagementEndpoint interface that is
508:             *  not listed below is getMBeanCount which was already web service friendly
509:             * -Special expections are thrown when errors occur. These persist to the
510:             *  web service client. Exception Class:
511:             *  org.objectweb.jonas.mejb.ManagementEndpointException.
512:             */
513:
514:            /**
515:             * Returns the names of the servers in the domain.
516:             * @return The names of the servers in the domain.
517:             * @throws ManagementEndpointException    If any errors occur.
518:             * @throws RemoteException                If a connection error occurs.
519:             */
520:            public String[] getServers() throws ManagementEndpointException,
521:                    RemoteException {
522:                String j2eeDomainName = domainName
523:                        + ":j2eeType=J2EEDomain,name=" + this .domainName;
524:                return getAttribute(serverName, j2eeDomainName, "serverNames");
525:            }
526:
527:            /**
528:             * @see ManagementEndpoint#getAttribute(String, String, String)
529:             */
530:            public String[] getAttribute(String domainServerName,
531:                    String objectName, String attribute)
532:                    throws ManagementEndpointException {
533:                try {
534:                    return getObjectValue(getAttribute(domainServerName,
535:                            new ObjectName(objectName), attribute));
536:                } catch (Exception e) {
537:                    ManagementEndpointException mex = new ManagementEndpointException();
538:                    mex.setExceptionType(e.getClass().toString());
539:                    mex
540:                            .setMessage("Problem in getAttribute service call for objectname: "
541:                                    + objectName
542:                                    + " - the request was not completed: "
543:                                    + e.getMessage());
544:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
545:                    throw (ManagementEndpointException) mex.initCause(e);
546:                }
547:            }
548:
549:            /**
550:             * @see ManagementEndpoint#isRegistered(String, String)
551:             */
552:            public boolean isRegistered(String domainServerName,
553:                    String objectName) throws ManagementEndpointException {
554:                try {
555:                    return isRegistered(domainServerName, new ObjectName(
556:                            objectName));
557:                } catch (Exception e) {
558:                    ManagementEndpointException mex = new ManagementEndpointException();
559:                    mex.setExceptionType(e.getClass().toString());
560:                    mex
561:                            .setMessage("Problem in isRegistered service call for objectname: "
562:                                    + objectName
563:                                    + " - the request was not completed: "
564:                                    + e.getMessage());
565:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
566:                    throw (ManagementEndpointException) mex.initCause(e);
567:                }
568:            }
569:
570:            /**
571:             * @see ManagementEndpoint#queryNames(String, String, String)
572:             */
573:            public String[] queryNames(String domainServerName,
574:                    String objectName, String query)
575:                    throws ManagementEndpointException {
576:                try {
577:
578:                    // TODO Determine how to use QueryExp. ATM query support disabled.
579:                    return getObjectValue(queryNames(domainServerName,
580:                            new ObjectName(objectName), null));
581:
582:                } catch (Exception e) {
583:                    ManagementEndpointException mex = new ManagementEndpointException();
584:                    mex.setExceptionType(e.getClass().toString());
585:                    mex
586:                            .setMessage("Problem in queryNames service call for objectname: "
587:                                    + objectName
588:                                    + " - the request was not completed: "
589:                                    + e.getMessage());
590:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
591:                    throw (ManagementEndpointException) mex.initCause(e);
592:                }
593:            }
594:
595:            /**
596:             * @see ManagementEndpoint#getAttributesList(String, String)
597:             */
598:            public String[] getAttributesList(String domainServerName,
599:                    String objectName) throws ManagementEndpointException {
600:                try {
601:                    MBeanInfo info = getMBeanInfo(domainServerName,
602:                            new ObjectName(objectName));
603:                    MBeanAttributeInfo[] attrInfo = info.getAttributes();
604:                    String[] attrs = new String[attrInfo.length];
605:                    for (int i = 0; i < attrs.length; i++) {
606:                        attrs[i] = attrInfo[i].getName();
607:                    }
608:                    return attrs;
609:
610:                } catch (Exception e) {
611:                    ManagementEndpointException mex = new ManagementEndpointException();
612:                    mex.setExceptionType(e.getClass().toString());
613:                    mex
614:                            .setMessage("Problem in getAttributeList service call for objectname: "
615:                                    + objectName
616:                                    + " - the request was not completed: "
617:                                    + e.getMessage());
618:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
619:                    throw (ManagementEndpointException) mex.initCause(e);
620:                }
621:            }
622:
623:            /**
624:             * @see ManagementEndpoint#getDescription(String, String)
625:             */
626:            public String getDescription(String domainServerName,
627:                    String objectName) throws ManagementEndpointException {
628:                try {
629:                    MBeanInfo info = getMBeanInfo(domainServerName,
630:                            new ObjectName(objectName));
631:                    return info.getDescription();
632:                } catch (Exception e) {
633:                    ManagementEndpointException mex = new ManagementEndpointException();
634:                    mex.setExceptionType(e.getClass().toString());
635:                    mex
636:                            .setMessage("Problem in getDescription service call for objectname: "
637:                                    + objectName
638:                                    + " - the request was not completed: "
639:                                    + e.getMessage());
640:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
641:                    throw (ManagementEndpointException) mex.initCause(e);
642:                }
643:
644:            }
645:
646:            /**
647:             * @see ManagementEndpoint#getOperations(String, String)
648:             */
649:            public String[] getOperations(String domainServerName,
650:                    String objectName) throws ManagementEndpointException {
651:                try {
652:                    MBeanInfo info = getMBeanInfo(domainServerName,
653:                            new ObjectName(objectName));
654:                    MBeanOperationInfo[] operationInfo = info.getOperations();
655:                    String[] operations = new String[operationInfo.length];
656:                    for (int i = 0; i < operationInfo.length; i++) {
657:                        operations[i] = operationInfo[i].getName();
658:                    }
659:                    return operations;
660:
661:                } catch (Exception e) {
662:                    ManagementEndpointException mex = new ManagementEndpointException();
663:                    mex.setExceptionType(e.getClass().toString());
664:                    mex
665:                            .setMessage("Problem in getOperations service call for objectname: "
666:                                    + objectName
667:                                    + " - the request was not completed: "
668:                                    + e.getMessage());
669:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
670:                    throw (ManagementEndpointException) mex.initCause(e);
671:                }
672:            }
673:
674:            /**
675:             * @see ManagementEndpoint#invoke(String, String, String[])
676:             */
677:            public String[] invoke(String domainServerName, String objectName,
678:                    String operationName, String[] params)
679:                    throws ManagementEndpointException, RemoteException {
680:                try {
681:                    String[] signature = new String[params.length];
682:                    for (int i = 0; i < signature.length; i++) {
683:                        signature[i] = "String";
684:                    }
685:                    return getObjectValue(invoke(domainServerName,
686:                            new ObjectName(objectName), operationName,
687:                            (Object[]) params, signature));
688:                } catch (Exception e) {
689:                    ManagementEndpointException mex = new ManagementEndpointException();
690:                    mex.setExceptionType(e.getClass().toString());
691:                    mex
692:                            .setMessage("Problem in invoke service call for objectname: "
693:                                    + objectName
694:                                    + " - the request was not completed: "
695:                                    + e.getMessage());
696:                    logger.log(BasicLevel.ERROR, mex.getMessage(), e);
697:                    throw (ManagementEndpointException) mex.initCause(e);
698:                }
699:            }
700:
701:            /*
702:             *  Listed below are helper methods for the ManagementEndpoint
703:             *
704:             *  These methods are used to convert complex data types into more simpler
705:             *  types so that they work easier with web services. Most complex data types
706:             *  are converted into a string array
707:             */
708:
709:            /**
710:             * Takes an arbitrary object and returns a string array representation
711:             * of the object. This methods is used to make passing values from a
712:             * web service endpoint to a client easier to handle.
713:             * @param objectValue   An object.
714:             * @return              A string array representation of the object.
715:             */
716:            private String[] getObjectValue(Object objectValue) {
717:                String[] value = null;
718:
719:                if (objectValue == null) {
720:                    value = new String[1];
721:                    value[0] = "null";
722:                } else {
723:                    // Detect Array or Collection
724:                    if (objectValue.getClass().isArray()) {
725:                        // Array
726:                        value = arrayToString((Object[]) objectValue);
727:                    } else {
728:                        try {
729:                            // Collection
730:                            value = collectionToString((Collection) objectValue);
731:                        } catch (Exception e) {
732:                            // Default
733:                            value = new String[1];
734:                            value[0] = objectValue.toString();
735:                        }
736:                    }
737:                }
738:                return value;
739:            }
740:
741:            /**
742:             * Takes an array of objects and returns the string array representation.
743:             * @param pArray    An array of objects.
744:             * @return          A string array representation of the object array.
745:             */
746:            private String[] arrayToString(Object[] pArray) {
747:                String[] retStringArr = new String[pArray.length];
748:                for (int i = 0; i < pArray.length; i++) {
749:                    if (pArray[i] == null) {
750:                        retStringArr[i] = "null";
751:                    } else {
752:                        retStringArr[i] = pArray[i].toString();
753:                    }
754:
755:                }
756:                return retStringArr;
757:            }
758:
759:            /**
760:             * Takes a collection and returns the string array representation of the object.
761:             * @param pCollection    A collection of objects.
762:             * @return               A string array representation of the object.
763:             */
764:            private String[] collectionToString(Collection pCollection) {
765:                String[] retStringArr = new String[pCollection.size()];
766:                Iterator it = pCollection.iterator();
767:                int i = 0;
768:                while (it.hasNext()) {
769:                    retStringArr[i++] = it.next().toString();
770:                }
771:                return retStringArr;
772:            }
773:
774:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.