Source Code Cross Referenced for AbstractListStateServiceMBeansImpl.java in  » ESB » open-esb » com » sun » esb » management » base » services » 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 » ESB » open esb » com.sun.esb.management.base.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * BEGIN_HEADER - DO NOT EDIT
0003:         *
0004:         * The contents of this file are subject to the terms
0005:         * of the Common Development and Distribution License
0006:         * (the "License").  You may not use this file except
0007:         * in compliance with the License.
0008:         *
0009:         * You can obtain a copy of the license at
0010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011:         * See the License for the specific language governing
0012:         * permissions and limitations under the License.
0013:         *
0014:         * When distributing Covered Code, include this CDDL
0015:         * HEADER in each file and include the License file at
0016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017:         * If applicable add the following below this CDDL HEADER,
0018:         * with the fields enclosed by brackets "[]" replaced with
0019:         * your own identifying information: Portions Copyright
0020:         * [year] [name of copyright owner]
0021:         */
0022:
0023:        /*
0024:         * @(#)AbstractListStateServiceMBeansImpl.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        package com.sun.esb.management.base.services;
0030:
0031:        import java.io.Serializable;
0032:        import java.io.StringReader;
0033:        import java.util.ArrayList;
0034:        import java.util.Arrays;
0035:        import java.util.Collection;
0036:        import java.util.HashSet;
0037:        import java.util.Iterator;
0038:        import java.util.List;
0039:        import java.util.Map;
0040:        import java.util.HashMap;
0041:        import java.util.Set;
0042:
0043:        import javax.jbi.management.DeploymentServiceMBean;
0044:        import javax.management.Descriptor;
0045:        import javax.management.MBeanServer;
0046:        import javax.management.MalformedObjectNameException;
0047:        import javax.management.MBeanAttributeInfo;
0048:        import javax.management.MBeanInfo;
0049:        import javax.management.modelmbean.ModelMBeanAttributeInfo;
0050:        import javax.management.ObjectName;
0051:
0052:        import com.sun.esb.management.common.ManagementRemoteException;
0053:        import com.sun.jbi.ComponentInfo;
0054:        import com.sun.jbi.ComponentQuery;
0055:        import com.sun.jbi.ComponentState;
0056:        import com.sun.jbi.ComponentType;
0057:        import com.sun.jbi.EnvironmentContext;
0058:        import com.sun.jbi.ui.common.JBIComponentInfo;
0059:        import com.sun.jbi.ui.common.JBIJMXObjectNames;
0060:        import com.sun.jbi.ui.common.ServiceAssemblyInfo;
0061:        import com.sun.jbi.ui.common.ServiceUnitInfo;
0062:
0063:        /**
0064:         * @author graj
0065:         * 
0066:         */
0067:        public class AbstractListStateServiceMBeansImpl extends
0068:                AbstractServiceMBeansImpl implements  Serializable {
0069:
0070:            static final long serialVersionUID = -1L;
0071:
0072:            /**
0073:             * any framework state
0074:             */
0075:            protected static final int ANY_FRAMEWORK_COMPONENT_STATE = -1;
0076:
0077:            /**
0078:             * sa started state
0079:             */
0080:            protected static final String FRAMEWORK_SA_STARTED_STATE = DeploymentServiceMBean.STARTED;
0081:
0082:            /**
0083:             * sa stopped state
0084:             */
0085:            protected static final String FRAMEWORK_SA_STOPPED_STATE = DeploymentServiceMBean.STOPPED;
0086:
0087:            /**
0088:             * sa shutdown state
0089:             */
0090:            protected static final String FRAMEWORK_SA_SHUTDOWN_STATE = DeploymentServiceMBean.SHUTDOWN;
0091:
0092:            /**
0093:             * any state
0094:             */
0095:            protected static final String FRAMEWORK_SA_ANY_STATE = "any";
0096:
0097:            /**
0098:             * state
0099:             */
0100:            protected static final String FRAMEWORK_SU_STARTED_STATE = "started";
0101:
0102:            /**
0103:             * state
0104:             */
0105:            protected static final String FRAMEWORK_SU_STOPPED_STATE = "stopped";
0106:
0107:            /**
0108:             * state
0109:             */
0110:            protected static final String FRAMEWORK_SU_SHUTDOWN_STATE = "shutdown";
0111:
0112:            /**
0113:             * state
0114:             */
0115:            protected static final String FRAMEWORK_SU_UNKNOWN_STATE = "unknown";
0116:
0117:            /**
0118:             * @param anEnvContext
0119:             */
0120:            public AbstractListStateServiceMBeansImpl(
0121:                    EnvironmentContext anEnvContext) {
0122:                super (anEnvContext);
0123:            }
0124:
0125:            /**
0126:             * returns the ObjectName for the lifecycle Mbean of this component.
0127:             * 
0128:             * @return the ObjectName for the lifecycle Mbean.
0129:             * @param componentName
0130:             *            of a binding or engine component.
0131:             * @param targetName
0132:             * @throws ManagementRemoteException
0133:             *             on error
0134:             */
0135:            @SuppressWarnings("unchecked")
0136:            protected ObjectName getComponentLifeCycleMBeanObjectName(
0137:                    String componentName, String targetName)
0138:                    throws ManagementRemoteException {
0139:
0140:                if (!isExistingComponent(componentName, targetName)) {
0141:                    String[] args = { componentName, targetName };
0142:                    Exception exception = this .createManagementException(
0143:                            "ui.mbean.lifecycle.mbean.not.found.with.query",
0144:                            args, null);
0145:                    throw new ManagementRemoteException(exception);
0146:                }
0147:
0148:                ObjectName lifecycleObjectNamePattern = null;
0149:                try {
0150:                    lifecycleObjectNamePattern = JBIJMXObjectNames
0151:                            .getComponentLifeCycleMBeanObjectNamePattern(
0152:                                    componentName, targetName);
0153:                } catch (MalformedObjectNameException ex) {
0154:                    throw new ManagementRemoteException(ex);
0155:                }
0156:
0157:                MBeanServer mbeanServer = this .environmentContext
0158:                        .getMBeanServer();
0159:
0160:                Set objectNames = mbeanServer.queryNames(
0161:                        lifecycleObjectNamePattern, null);
0162:
0163:                if (objectNames.isEmpty()) {
0164:                    String[] args = { componentName, targetName };
0165:                    Exception exception = this .createManagementException(
0166:                            "ui.mbean.lifecycle.mbean.not.found.with.query",
0167:                            args, null);
0168:                    throw new ManagementRemoteException(exception);
0169:
0170:                }
0171:
0172:                if (objectNames.size() > 1) {
0173:                    String[] args = { componentName, targetName };
0174:                    Exception exception = this 
0175:                            .createManagementException(
0176:                                    "ui.mbean.multiple.lifecycle.mbeans.found.with.query",
0177:                                    args, null);
0178:                    throw new ManagementRemoteException(exception);
0179:                }
0180:
0181:                ObjectName lifecyleObjectName = (ObjectName) objectNames
0182:                        .iterator().next();
0183:                logDebug("LifecyleMBean : " + lifecyleObjectName);
0184:
0185:                return lifecyleObjectName;
0186:
0187:            }
0188:
0189:            /**
0190:             * return component info xml text that has service engines or binding
0191:             * components infos or both which satisfies the options passed to the
0192:             * method.
0193:             * 
0194:             * @param type
0195:             *            ComponentInfo.BINDING, ENGINE, BINDING_ENGINE .
0196:             * @param state
0197:             *            return all the components that are in the specified state.
0198:             *            valid states are JBIComponentInfo.STARTED, STOPPED, INSTALLED
0199:             *            or null for ANY state
0200:             * @param sharedLibraryName
0201:             *            return all the components that have a dependency on the
0202:             *            specified shared library. null value to ignore this option.
0203:             * @param serviceAssemblyName
0204:             *            return all the components that have the specified service
0205:             *            assembly deployed on them. null value to ignore this option.
0206:             * @param targetName
0207:             * @return xml text contain the list of component infos
0208:             * @throws ManagementRemoteException
0209:             *             if error or exception occurs.
0210:             */
0211:            protected String listComponents(ComponentType type, String state,
0212:                    String sharedLibraryName, String serviceAssemblyName,
0213:                    String targetName) throws ManagementRemoteException {
0214:
0215:                // ////////////////////////////////////////
0216:                // Start Check to make sure target is valid
0217:                // ////////////////////////////////////////
0218:                ObjectName installerServiceObjectName = this 
0219:                        .getInstallationServiceMBeanObjectName(targetName);
0220:                this 
0221:                        .checkForValidTarget(installerServiceObjectName,
0222:                                targetName);
0223:                // ////////////////////////////////////////
0224:                // End Check to make sure target is valid
0225:                // ////////////////////////////////////////
0226:
0227:                validateUiJBIComponentInfoState(state);
0228:
0229:                ComponentState frameworkCompState = ComponentState.UNKNOWN;
0230:
0231:                if (state != null) {
0232:                    frameworkCompState = toFrameworkComponentInfoState(state);
0233:                }
0234:
0235:                String result = "";
0236:                try {
0237:                    result = JBIComponentInfo
0238:                            .writeAsXmlText(toUiComponentInfoList(
0239:                                    this 
0240:                                            .getFrameworkComponentInfoListForEnginesAndBindings(
0241:                                            /* frameworkCompType */type,
0242:                                                    frameworkCompState,
0243:                                                    sharedLibraryName,
0244:                                                    serviceAssemblyName,
0245:                                                    targetName), targetName));
0246:                } catch (ManagementRemoteException e) {
0247:                    throw new ManagementRemoteException(e);
0248:                }
0249:
0250:                return result;
0251:            }
0252:
0253:            /**
0254:             * validates the state value component info
0255:             * 
0256:             * @state component state. valid values null, "", "started", "stopped",
0257:             *        "shutdown"
0258:             * @throws ManagementRemoteException
0259:             *             on validation failure
0260:             */
0261:            protected void validateUiJBIComponentInfoState(String state)
0262:                    throws ManagementRemoteException {
0263:                if (state == null || state.length() == 0) {
0264:                    // all states
0265:                    return;
0266:                }
0267:                String stateValue = state.toString();
0268:
0269:                if (!(JBIComponentInfo.STARTED_STATE
0270:                        .equalsIgnoreCase(stateValue)
0271:                        || JBIComponentInfo.STOPPED_STATE
0272:                                .equalsIgnoreCase(stateValue)
0273:                        || JBIComponentInfo.SHUTDOWN_STATE
0274:                                .equalsIgnoreCase(stateValue) || JBIComponentInfo.UNKNOWN_STATE
0275:                        .equalsIgnoreCase(stateValue))) {
0276:                    String[] args = { state };
0277:                    Exception exception = this .createManagementException(
0278:                            "ui.mbean.list.error.invalid.state", args, null);
0279:                    throw new ManagementRemoteException(exception);
0280:
0281:                }
0282:
0283:            }
0284:
0285:            /**
0286:             * validates the state value for service assembly
0287:             * 
0288:             * @state component state. valid values null, "", "started", "stopped",
0289:             *        "shutdown"
0290:             * @throws ManagementRemoteException
0291:             *             on validation failure
0292:             */
0293:            protected void validateUiServiceAssemblyInfoState(String state)
0294:                    throws ManagementRemoteException {
0295:                if (state == null || state.length() == 0) {
0296:                    // all sates
0297:                    return;
0298:                }
0299:                String stateValue = state;
0300:
0301:                if (!(ServiceAssemblyInfo.STARTED_STATE
0302:                        .equalsIgnoreCase(stateValue)
0303:                        || ServiceAssemblyInfo.STOPPED_STATE
0304:                                .equalsIgnoreCase(stateValue)
0305:                        || ServiceAssemblyInfo.SHUTDOWN_STATE
0306:                                .equalsIgnoreCase(stateValue) || ServiceAssemblyInfo.UNKNOWN_STATE
0307:                        .equalsIgnoreCase(stateValue))) {
0308:                    String[] args = { state };
0309:                    Exception exception = this .createManagementException(
0310:                            "ui.mbean.list.error.invalid.state", args, null);
0311:                    throw new ManagementRemoteException(exception);
0312:
0313:                }
0314:            }
0315:
0316:            // //////////////////////////////////////////////////////
0317:            // -- Adjusted for ComponentType and ComponentState --
0318:            // //////////////////////////////////////////////////////
0319:            /**
0320:             * framework states
0321:             * 
0322:             * @return state
0323:             * @param uiCompState
0324:             *            state
0325:             */
0326:            protected static ComponentState toFrameworkComponentInfoState(
0327:                    String uiCompState) {
0328:                if (uiCompState == null) {
0329:                    return ComponentState.UNKNOWN;
0330:                }
0331:
0332:                String compState = uiCompState.trim();
0333:
0334:                if (compState.length() <= 0) {
0335:                    return ComponentState.UNKNOWN;
0336:                }
0337:
0338:                if (JBIComponentInfo.SHUTDOWN_STATE.equalsIgnoreCase(compState)) {
0339:                    return ComponentState.SHUTDOWN;
0340:                } else if (JBIComponentInfo.STARTED_STATE
0341:                        .equalsIgnoreCase(compState)) {
0342:                    return ComponentState.STARTED;
0343:                } else if (JBIComponentInfo.STOPPED_STATE
0344:                        .equalsIgnoreCase(compState)) {
0345:                    return ComponentState.STOPPED;
0346:                } else { // any other value
0347:                    return ComponentState.UNKNOWN;
0348:                }
0349:            }
0350:
0351:            /**
0352:             * list of componentinfo objects. this methods check for valid inputs and
0353:             * take only a valid inputs. for example slib, saName both can be null
0354:             * 
0355:             * @param frameworkCompType
0356:             *            component type.
0357:             * @param frameworkCompState
0358:             *            component state
0359:             * @param sharedLibraryName
0360:             *            shared library name
0361:             * @param serviceAssemblyName
0362:             *            service assembly name
0363:             * @param targetName
0364:             * @throws com.sun.jbi.ui.common.ManagementRemoteException
0365:             *             on error
0366:             * @return list of component info
0367:             */
0368:            @SuppressWarnings("unchecked")
0369:            protected List getFrameworkComponentInfoListForEnginesAndBindings(
0370:                    ComponentType frameworkCompType,
0371:                    ComponentState frameworkCompState,
0372:                    String sharedLibraryName, String serviceAssemblyName,
0373:                    String targetName) throws ManagementRemoteException {
0374:                String slibName = null;
0375:                String saName = null;
0376:
0377:                if (sharedLibraryName != null
0378:                        && sharedLibraryName.trim().length() > 0) {
0379:                    slibName = sharedLibraryName.trim();
0380:                }
0381:
0382:                if (serviceAssemblyName != null
0383:                        && serviceAssemblyName.trim().length() > 0) {
0384:                    saName = serviceAssemblyName.trim();
0385:                }
0386:
0387:                logDebug("getFrameworkComponentInfoForEnginesAndBindings : Params : "
0388:                        + frameworkCompType
0389:                        + ", "
0390:                        + frameworkCompState
0391:                        + ", "
0392:                        + slibName + ", " + saName);
0393:
0394:                Collection componentNames = new HashSet();
0395:                // there are 4 options with snsId,auId (00,01,10,11)
0396:                if (slibName == null && saName == null) {
0397:                    // 00
0398:                    componentNames = getComponentNamesWithStatus(
0399:                            frameworkCompType, frameworkCompState, targetName);
0400:                } else if (slibName == null && saName != null) {
0401:                    // 01
0402:                    componentNames = getComponentNamesDependentOnServiceAssembly(
0403:                            frameworkCompType, frameworkCompState, saName,
0404:                            targetName);
0405:
0406:                } else if (slibName != null && saName == null) {
0407:                    // 10
0408:                    componentNames = getComponentNamesDependentOnSharedLibrary(
0409:                            frameworkCompType, frameworkCompState, slibName,
0410:                            targetName);
0411:
0412:                } else if (slibName != null && saName != null) {
0413:                    // 11
0414:                    componentNames = getComponentNamesDependentOnSharedLibraryAndServiceAssembly(
0415:                            frameworkCompType, frameworkCompState, slibName,
0416:                            saName, targetName);
0417:
0418:                } else {
0419:                    // not possible.
0420:                    componentNames = new HashSet();
0421:                }
0422:
0423:                return this .getFrameworkComponentInfoList(componentNames,
0424:                        targetName);
0425:            }
0426:
0427:            /**
0428:             * framework component info list
0429:             * 
0430:             * @param compNameList
0431:             *            list of component names
0432:             * @param targetName
0433:             * @return framework component info list
0434:             */
0435:            @SuppressWarnings("unchecked")
0436:            protected List getFrameworkComponentInfoList(
0437:                    Collection compNameList, String targetName) {
0438:                ArrayList compInfoList = new ArrayList();
0439:                try {
0440:                    ComponentQuery componentQuery = getFrameworkComponentQuery(targetName);
0441:                    if (componentQuery != null) {
0442:                        for (Iterator itr = compNameList.iterator(); itr
0443:                                .hasNext();) {
0444:                            ComponentInfo componentInfo = componentQuery
0445:                                    .getComponentInfo((String) itr.next());
0446:                            if (componentInfo != null) {
0447:                                compInfoList.add(componentInfo);
0448:                            }
0449:                        }
0450:                    }
0451:                } catch (Exception ex) {
0452:                    // TODO propagate the exception to client.
0453:                    logDebug(ex);
0454:                }
0455:                return compInfoList;
0456:            }
0457:
0458:            /**
0459:             * this methods check for valid inputs and take only a valid inputs. for
0460:             * example slib, saName both can be null
0461:             * 
0462:             * @param componentName
0463:             *            name
0464:             * @param targetName
0465:             * @throws com.sun.jbi.ui.common.ManagementRemoteException
0466:             *             on error
0467:             * @return list of componentInfo objects
0468:             */
0469:            @SuppressWarnings("unchecked")
0470:            protected List getFrameworkComponentInfoListForSharedLibraries(
0471:                    String componentName, String targetName)
0472:                    throws ManagementRemoteException {
0473:                String compName = null;
0474:
0475:                if (componentName != null && componentName.trim().length() > 0) {
0476:                    compName = componentName.trim();
0477:                }
0478:
0479:                logDebug("getFrameworkComponentInfoForSharedLibraries: Params : "
0480:                        + compName);
0481:
0482:                List slibNames = new ArrayList();
0483:                List frameworkCompInfoList = new ArrayList();
0484:                ComponentQuery componentQuery = null;
0485:                if (compName == null) {
0486:                    logDebug("Listing All Shared Libraries in the system");
0487:                    componentQuery = this 
0488:                            .getFrameworkComponentQuery(targetName);
0489:                    if (componentQuery != null) {
0490:                        slibNames = componentQuery
0491:                                .getComponentIds(ComponentType.SHARED_LIBRARY);
0492:                    }
0493:                } else {
0494:                    logDebug("Listing Shared Libraries for the component "
0495:                            + compName);
0496:                    componentQuery = this 
0497:                            .getFrameworkComponentQuery(targetName);
0498:                    if (componentQuery != null) {
0499:                        ComponentInfo componentInfo = componentQuery
0500:                                .getComponentInfo(compName);
0501:                        if (componentInfo == null) {
0502:                            String[] args = { compName };
0503:                            Exception exception = this 
0504:                                    .createManagementException(
0505:                                            "ui.mbean.component.id.does.not.exist",
0506:                                            args, null);
0507:                            throw new ManagementRemoteException(exception);
0508:
0509:                        }
0510:                        slibNames = componentInfo.getSharedLibraryNames();
0511:                    }
0512:                }
0513:
0514:                frameworkCompInfoList = this 
0515:                        .getFrameworkComponentInfoListForSharedLibraryNames(
0516:                                slibNames, targetName);
0517:
0518:                return frameworkCompInfoList;
0519:
0520:            }
0521:
0522:            /**
0523:             * list of component infos
0524:             * 
0525:             * @param targetName
0526:             * @return list of component infos
0527:             * @param slibNameList
0528:             *            shared library names
0529:             */
0530:            @SuppressWarnings("unchecked")
0531:            protected List getFrameworkComponentInfoListForSharedLibraryNames(
0532:                    Collection slibNameList, String targetName) {
0533:                ArrayList compInfoList = new ArrayList();
0534:                try {
0535:                    ComponentQuery componentQuery = this 
0536:                            .getFrameworkComponentQuery(targetName);
0537:                    if (componentQuery != null) {
0538:                        for (Iterator itr = slibNameList.iterator(); itr
0539:                                .hasNext();) {
0540:                            ComponentInfo componentInfo = componentQuery
0541:                                    .getSharedLibraryInfo((String) itr.next());
0542:                            if (componentInfo != null) {
0543:                                compInfoList.add(componentInfo);
0544:                            }
0545:                        }
0546:                    }
0547:                } catch (Exception ex) {
0548:                    // TODO propagate the exception to client.
0549:                    logDebug(ex);
0550:                }
0551:                return compInfoList;
0552:            }
0553:
0554:            /**
0555:             * list of ui component infos
0556:             * 
0557:             * @return list of ui component infos
0558:             * @param frameworkCompType
0559:             *            type of the component
0560:             * @param targetName
0561:             */
0562:            @SuppressWarnings("unchecked")
0563:            protected List getUiComponentInfoList(
0564:                    ComponentType frameworkCompType, String targetName)
0565:                    throws ManagementRemoteException {
0566:                Set compNameSet = this .getComponentNamesWithStatus(
0567:                        frameworkCompType, ComponentState.UNKNOWN, targetName);
0568:                List frameworkCompList = this .getFrameworkComponentInfoList(
0569:                        new ArrayList(compNameSet), targetName);
0570:                List uiCompList = new ArrayList();
0571:                for (Iterator itr = frameworkCompList.iterator(); itr.hasNext();) {
0572:                    ComponentInfo frameworkCompInfo = (ComponentInfo) itr
0573:                            .next();
0574:                    JBIComponentInfo uiCompInfo = toUiComponentInfo(
0575:                            frameworkCompInfo, targetName);
0576:                    uiCompList.add(uiCompInfo);
0577:                }
0578:                return uiCompList;
0579:            }
0580:
0581:            /**
0582:             * convert to ui component info list
0583:             * 
0584:             * @return ui component info list
0585:             * @param frameworkCompList
0586:             *            framework component info list
0587:             */
0588:            @SuppressWarnings("unchecked")
0589:            protected List toUiComponentInfoList(List frameworkCompList,
0590:                    String targetName) throws ManagementRemoteException {
0591:                List uiCompList = new ArrayList();
0592:                for (Iterator itr = frameworkCompList.iterator(); itr.hasNext();) {
0593:                    ComponentInfo frameworkCompInfo = (ComponentInfo) itr
0594:                            .next();
0595:                    JBIComponentInfo uiCompInfo = toUiComponentInfo(
0596:                            frameworkCompInfo, targetName);
0597:                    uiCompList.add(uiCompInfo);
0598:                }
0599:                return uiCompList;
0600:            }
0601:
0602:            /**
0603:             * return component info object
0604:             * 
0605:             * @return object
0606:             * @param frameworkCompInfo
0607:             *            framework component info
0608:             * @param targetName
0609:             */
0610:            protected JBIComponentInfo toUiComponentInfo(
0611:                    ComponentInfo frameworkCompInfo, String targetName)
0612:                    throws ManagementRemoteException {
0613:
0614:                String state = JBIComponentInfo.UNKNOWN_STATE;
0615:
0616:                String componentName = frameworkCompInfo.getName();
0617:                String componentDescription = frameworkCompInfo
0618:                        .getDescription();
0619:
0620:                ComponentState componentStatus = ComponentState.UNKNOWN;
0621:                ComponentType componentType = frameworkCompInfo
0622:                        .getComponentType();
0623:                // Figure out the component state
0624:                if ((false == ComponentType.BINDING.equals(componentType))
0625:                        && (false == ComponentType.ENGINE.equals(componentType))
0626:                        && (false == ComponentType.BINDINGS_AND_ENGINES
0627:                                .equals(componentType))) {
0628:                    componentStatus = frameworkCompInfo.getStatus();
0629:                    state = toUiComponentInfoState(componentStatus);
0630:                } else {
0631:                    // /////////////////////////////////////////////////////////
0632:                    // According to the runtime team (as of Nov 09'06):
0633:                    // The ComponentQuery.getStatus() or
0634:                    // ComponentQuery.getComponentInfo().getStatus()
0635:                    // to get the state of the component actually
0636:                    // returns the desired state of the component
0637:                    // persisted in the registry.
0638:                    //
0639:                    // The getCurrentState() operation of the
0640:                    // ComponentLifeCycleMBean returns the actual runtime
0641:                    // state for a component, which can be used to get the
0642:                    // actual runtime state of the component.
0643:                    // Therefore the component state is retrieved from the
0644:                    // facade ComponentLifeCycleMBean instead of
0645:                    // using ComponentQuery
0646:                    //
0647:                    // Use the LifeCycleMBean for the domain target too.
0648:                    // The getCurrentState() for the domain target should
0649:                    // return the most advanced state of the component on all targets.
0650:                    try {
0651:                        ObjectName lifeCycleMBeanObjectName = null;
0652:                        lifeCycleMBeanObjectName = this 
0653:                                .getComponentLifeCycleMBeanObjectName(
0654:                                        componentName, targetName);
0655:                        state = (String) this .getMBeanAttribute(
0656:                                lifeCycleMBeanObjectName, "CurrentState");
0657:                    } catch (ManagementRemoteException exception) {
0658:                        // do not rethrow it. The state is already defaulted to
0659:                        // JBIComponentInfo.UNKNOWN_STATE
0660:                        componentStatus = ComponentState.UNKNOWN;
0661:                        state = JBIComponentInfo.UNKNOWN_STATE;
0662:                    }
0663:                    // /////////////////////////////////////////////////////////
0664:                }
0665:                if (true == RUNNING_STATE.equals(state)) {
0666:                    state = JBIComponentInfo.STARTED_STATE;
0667:                }
0668:
0669:                String type = toUiComponentInfoType(componentType);
0670:
0671:                return new JBIComponentInfo(type, // Integer.toString(comp.getComponentType()),
0672:                        state, // Integer.toString(comp.getStatus()),
0673:                        componentName, componentDescription);
0674:            }
0675:
0676:            /**
0677:             * converts to deployment service service assembly state.
0678:             * 
0679:             * @return state
0680:             * @param uiState
0681:             *            state
0682:             */
0683:            protected static String toFrameworkServiceAssemblyState(
0684:                    String uiState) {
0685:                if (uiState == null) {
0686:                    return FRAMEWORK_SA_ANY_STATE;
0687:                }
0688:
0689:                String saState = uiState.trim();
0690:
0691:                if (saState.length() <= 0) {
0692:                    return FRAMEWORK_SA_ANY_STATE;
0693:                }
0694:
0695:                if (ServiceAssemblyInfo.STARTED_STATE.equalsIgnoreCase(saState)) {
0696:                    return FRAMEWORK_SA_STARTED_STATE;
0697:                } else if (ServiceAssemblyInfo.STOPPED_STATE
0698:                        .equalsIgnoreCase(saState)) {
0699:                    return FRAMEWORK_SA_STOPPED_STATE;
0700:                } else if (ServiceAssemblyInfo.SHUTDOWN_STATE
0701:                        .equalsIgnoreCase(saState)) {
0702:                    return FRAMEWORK_SA_SHUTDOWN_STATE;
0703:                } else { // any other value
0704:                    return FRAMEWORK_SA_ANY_STATE;
0705:                }
0706:            }
0707:
0708:            /**
0709:             * converts to ui service assembly state
0710:             * 
0711:             * @return state
0712:             * @param frameworkState
0713:             *            state
0714:             */
0715:            protected static String toUiServiceAssemblyState(
0716:                    String frameworkState) {
0717:                String uiState = ServiceAssemblyInfo.UNKNOWN_STATE;
0718:
0719:                if (frameworkState == null) {
0720:                    return ServiceAssemblyInfo.UNKNOWN_STATE;
0721:                }
0722:
0723:                String saState = frameworkState.trim();
0724:
0725:                if (saState.length() <= 0) {
0726:                    return ServiceAssemblyInfo.UNKNOWN_STATE;
0727:                }
0728:
0729:                if (FRAMEWORK_SA_STARTED_STATE.equalsIgnoreCase(saState)) {
0730:                    uiState = ServiceAssemblyInfo.STARTED_STATE;
0731:                } else if (FRAMEWORK_SA_STOPPED_STATE.equalsIgnoreCase(saState)) {
0732:                    uiState = ServiceAssemblyInfo.STOPPED_STATE;
0733:                } else if (FRAMEWORK_SA_SHUTDOWN_STATE
0734:                        .equalsIgnoreCase(saState)) {
0735:                    uiState = ServiceAssemblyInfo.SHUTDOWN_STATE;
0736:                } else {
0737:                    uiState = ServiceAssemblyInfo.UNKNOWN_STATE;
0738:                }
0739:                return uiState;
0740:            }
0741:
0742:            /**
0743:             * converts to ui service unit state
0744:             * 
0745:             * @return state
0746:             * @param frameworkState
0747:             *            state
0748:             */
0749:            protected static String toUiServiceUnitState(String frameworkState) {
0750:                String uiState = ServiceUnitInfo.UNKNOWN_STATE;
0751:
0752:                if (frameworkState == null) {
0753:                    return ServiceUnitInfo.UNKNOWN_STATE;
0754:                }
0755:
0756:                String suState = frameworkState.trim();
0757:
0758:                if (suState.length() <= 0) {
0759:                    return ServiceUnitInfo.UNKNOWN_STATE;
0760:                }
0761:
0762:                if (FRAMEWORK_SU_STARTED_STATE.equalsIgnoreCase(suState)) {
0763:                    uiState = ServiceUnitInfo.STARTED_STATE;
0764:                } else if (FRAMEWORK_SU_STOPPED_STATE.equalsIgnoreCase(suState)) {
0765:                    uiState = ServiceUnitInfo.STOPPED_STATE;
0766:                } else if (FRAMEWORK_SU_SHUTDOWN_STATE
0767:                        .equalsIgnoreCase(suState)) {
0768:                    uiState = ServiceUnitInfo.SHUTDOWN_STATE;
0769:                } else {
0770:                    uiState = ServiceUnitInfo.UNKNOWN_STATE;
0771:                }
0772:                return uiState;
0773:            }
0774:
0775:            /**
0776:             * converts state
0777:             * 
0778:             * @return state
0779:             * @param frameworkCompState
0780:             *            state
0781:             */
0782:            protected static String toUiComponentInfoState(
0783:                    ComponentState frameworkCompState) {
0784:                String uiState = JBIComponentInfo.UNKNOWN_STATE;
0785:                switch (frameworkCompState) {
0786:                case SHUTDOWN:
0787:                    uiState = JBIComponentInfo.SHUTDOWN_STATE;
0788:                    break;
0789:                case STARTED:
0790:                    uiState = JBIComponentInfo.STARTED_STATE;
0791:                    break;
0792:                case STOPPED:
0793:                    uiState = JBIComponentInfo.STOPPED_STATE;
0794:                    break;
0795:                default:
0796:                    uiState = JBIComponentInfo.UNKNOWN_STATE;
0797:                    break;
0798:                }
0799:                return uiState;
0800:            }
0801:
0802:            /**
0803:             * converts type
0804:             * 
0805:             * @return int type
0806:             * @param uiCompType
0807:             *            type
0808:             */
0809:            protected static ComponentType toFrameworkComponentInfoType(
0810:                    String uiCompType) {
0811:                if (JBIComponentInfo.BINDING_TYPE.equalsIgnoreCase(uiCompType)) {
0812:                    return ComponentType.BINDING;
0813:                } else if (JBIComponentInfo.ENGINE_TYPE
0814:                        .equalsIgnoreCase(uiCompType)) {
0815:                    return ComponentType.BINDING;
0816:                } else if (JBIComponentInfo.SHARED_LIBRARY_TYPE
0817:                        .equalsIgnoreCase(uiCompType)) {
0818:                    return ComponentType.SHARED_LIBRARY;
0819:                } else {
0820:                    return ComponentType.BINDINGS_AND_ENGINES;
0821:                }
0822:            }
0823:
0824:            /**
0825:             * converts type
0826:             * 
0827:             * @return type
0828:             * @param frameworkCompType
0829:             *            type
0830:             */
0831:            protected static String toUiComponentInfoType(
0832:                    ComponentType frameworkCompType) {
0833:                String uiType = JBIComponentInfo.UNKNOWN_TYPE;
0834:                switch (frameworkCompType) {
0835:                case BINDING:
0836:                    uiType = JBIComponentInfo.BINDING_TYPE;
0837:                    break;
0838:                case ENGINE:
0839:                    uiType = JBIComponentInfo.ENGINE_TYPE;
0840:                    break;
0841:                case SHARED_LIBRARY:
0842:                    uiType = JBIComponentInfo.SHARED_LIBRARY_TYPE;
0843:                    break;
0844:                default:
0845:                    uiType = JBIComponentInfo.UNKNOWN_TYPE;
0846:                    break;
0847:                }
0848:                return uiType;
0849:            }
0850:
0851:            /**
0852:             * list of component names
0853:             * 
0854:             * @return list of component names
0855:             * @param frameworkCompType
0856:             *            component type
0857:             * @param frameworkCompStatus
0858:             *            component state
0859:             * @param targetName
0860:             */
0861:            @SuppressWarnings("unchecked")
0862:            protected Set getComponentNamesWithStatus(
0863:                    ComponentType frameworkCompType,
0864:                    ComponentState frameworkCompStatus, String targetName) {
0865:                List componentIdList = new ArrayList();
0866:                ComponentQuery componentQuery = getFrameworkComponentQuery(targetName);
0867:                if (componentQuery != null) {
0868:                    if (frameworkCompStatus == ComponentState.UNKNOWN) {
0869:                        // ANY STATE
0870:                        componentIdList = componentQuery
0871:                                .getComponentIds(frameworkCompType);
0872:                    } else {
0873:                        componentIdList = componentQuery.getComponentIds(
0874:                                frameworkCompType, frameworkCompStatus);
0875:                    }
0876:                }
0877:
0878:                // now retain only ones that has auID deployed.
0879:                return new HashSet(componentIdList);
0880:            }
0881:
0882:            /**
0883:             * list of component names
0884:             * 
0885:             * @return list of component names
0886:             * @param frameworkCompType
0887:             *            component type
0888:             * @param frameworkCompStatus
0889:             *            component state
0890:             * @param saName
0891:             *            service assembly name
0892:             * @param targetName
0893:             */
0894:            @SuppressWarnings("unchecked")
0895:            protected Collection getComponentNamesDependentOnServiceAssembly(
0896:                    ComponentType frameworkCompType,
0897:                    ComponentState frameworkCompStatus, String saName,
0898:                    String targetName) {
0899:
0900:                Set compNameSet = new HashSet(getComponentNamesWithStatus(
0901:                        frameworkCompType, frameworkCompStatus, targetName));
0902:                Set saNameDepCompNameSet = new HashSet(this 
0903:                        .getComponentNamesDependentOnServiceAssembly(saName,
0904:                                targetName));
0905:                // now retain only ids in the compIdSet that are in compIdSetWithAuId
0906:                compNameSet.retainAll(saNameDepCompNameSet);
0907:                return compNameSet;
0908:            }
0909:
0910:            /**
0911:             * list of component names
0912:             * 
0913:             * @return list of component names
0914:             * @param frameworkCompType
0915:             *            component type
0916:             * @param frameworkCompStatus
0917:             *            component state
0918:             * @param slibName
0919:             *            shared library name
0920:             * @param targetName
0921:             */
0922:            @SuppressWarnings("unchecked")
0923:            protected Collection getComponentNamesDependentOnSharedLibrary(
0924:                    ComponentType frameworkCompType,
0925:                    ComponentState frameworkCompStatus, String slibName,
0926:                    String targetName) {
0927:
0928:                Set compNameSet = new HashSet(this .getComponentNamesWithStatus(
0929:                        frameworkCompType, frameworkCompStatus, targetName));
0930:                Set slibNameDepCompNameSet = new HashSet(this 
0931:                        .getComponentNamesDependentOnSharedLibrary(slibName,
0932:                                targetName));
0933:                // now retain only ids in the compIdSet that are in compIdSetWithSnsd
0934:                compNameSet.retainAll(slibNameDepCompNameSet);
0935:                return compNameSet;
0936:            }
0937:
0938:            /**
0939:             * list of component names. this method requires non null inputs
0940:             * 
0941:             * @return list of component names.
0942:             * @param frameworkCompType
0943:             *            component type
0944:             * @param frameworkCompStatus
0945:             *            component state
0946:             * @param slibName
0947:             *            shared library name
0948:             * @param saName
0949:             *            service assembly name
0950:             * @param targetName
0951:             */
0952:            @SuppressWarnings("unchecked")
0953:            protected Collection getComponentNamesDependentOnSharedLibraryAndServiceAssembly(
0954:                    ComponentType frameworkCompType,
0955:                    ComponentState frameworkCompStatus, String slibName,
0956:                    String saName, String targetName) {
0957:
0958:                Set compNameSet = new HashSet(this .getComponentNamesWithStatus(
0959:                        frameworkCompType, frameworkCompStatus, targetName));
0960:                Set slibNameDepCompNameSet = new HashSet(this 
0961:                        .getComponentNamesDependentOnSharedLibrary(slibName,
0962:                                targetName));
0963:                Set saNameDepCompNameSet = new HashSet(this 
0964:                        .getComponentNamesDependentOnServiceAssembly(saName,
0965:                                targetName));
0966:                // intersection of SLIB and SA
0967:                slibNameDepCompNameSet.retainAll(saNameDepCompNameSet);
0968:                // intersection of type, status, SLIB, SA
0969:                compNameSet.retainAll(slibNameDepCompNameSet);
0970:                return compNameSet;
0971:            }
0972:
0973:            /**
0974:             * list of component names
0975:             * 
0976:             * @return list of component names
0977:             * @param slibName
0978:             *            shared library name.
0979:             * @param targetName
0980:             */
0981:            @SuppressWarnings("unchecked")
0982:            protected Collection getComponentNamesDependentOnSharedLibrary(
0983:                    String slibName, String targetName) {
0984:                List componentNames = new ArrayList();
0985:                try {
0986:                    ComponentQuery componentQuery = this 
0987:                            .getFrameworkComponentQuery(targetName);
0988:                    if (componentQuery != null) {
0989:                        componentNames = componentQuery
0990:                                .getDependentComponentIds(slibName);
0991:                    }
0992:                } catch (Exception ex) {
0993:                    // log exception
0994:                    logDebug(ex);
0995:                }
0996:                return componentNames;
0997:            }
0998:
0999:            /**
1000:             * list of component names
1001:             * 
1002:             * @return list of component names
1003:             * @param saId
1004:             *            service assembly name.
1005:             * @param targetName
1006:             */
1007:            @SuppressWarnings("unchecked")
1008:            protected Collection getComponentNamesDependentOnServiceAssembly(
1009:                    String saId, String targetName) {
1010:                try {
1011:                    String[] componentNames = (String[]) this 
1012:                            .invokeMBeanOperation(
1013:                                    this 
1014:                                            .getDeploymentServiceMBeanObjectName(targetName),
1015:                                    "getComponentsForDeployedServiceAssembly",
1016:                                    saId);
1017:                    if (componentNames == null) {
1018:                        componentNames = new String[0];
1019:                    }
1020:                    return new HashSet(Arrays.asList(componentNames));
1021:                } catch (Exception ex) {
1022:                    // log exception
1023:                    logDebug(ex);
1024:                    // empty set
1025:                    return new HashSet();
1026:                }
1027:            }
1028:
1029:            /**
1030:             * return framework query
1031:             * 
1032:             * @param targetName
1033:             * 
1034:             * @return framework query interface
1035:             */
1036:            protected ComponentQuery getFrameworkComponentQuery(
1037:                    String targetName) {
1038:                ComponentQuery componentQuery = null;
1039:                /*
1040:                 * ==============================================================
1041:                 * According to IN=100359 at
1042:                 * http://inf.central.sun.com/inf/integrationReport.jsp?id=100359
1043:                 * 
1044:                 * The ComponentQueryImpl has been updated to support the "domain"
1045:                 * targetName as well, but is not plugged into the JBI Framework.
1046:                 * ==============================================================
1047:                 */
1048:                // if (JBIAdminCommands.DOMAIN_TARGET_KEY.equals(targetName) == false) {
1049:                // componentQuery = this.environmentContext.getComponentQuery();
1050:                // }
1051:                componentQuery = this .environmentContext
1052:                        .getComponentQuery(targetName);
1053:                return componentQuery;
1054:            }
1055:
1056:            /**
1057:             * checks the component name in the registry
1058:             * 
1059:             * @return true if component exists else false.
1060:             * @param componentName
1061:             *            name of the component
1062:             * @param targetName
1063:             */
1064:            @SuppressWarnings("unchecked")
1065:            protected boolean isExistingComponent(String componentName,
1066:                    String targetName) {
1067:                List list = new ArrayList();
1068:                ComponentQuery componentQuery = this 
1069:                        .getFrameworkComponentQuery(targetName);
1070:                if (componentQuery != null) {
1071:                    list = componentQuery
1072:                            .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
1073:                }
1074:                return list.contains(componentName);
1075:            }
1076:
1077:            /**
1078:             * check for shared namespace
1079:             * 
1080:             * @return true if it is namespace id else false.
1081:             * @param sharedLibraryName
1082:             *            id String
1083:             * @param targetName
1084:             */
1085:            @SuppressWarnings("unchecked")
1086:            protected boolean isExistingSharedLibrary(String sharedLibraryName,
1087:                    String targetName) {
1088:                List list = new ArrayList();
1089:                ComponentQuery componentQuery = this 
1090:                        .getFrameworkComponentQuery(targetName);
1091:                if (componentQuery != null) {
1092:                    list = componentQuery
1093:                            .getComponentIds(ComponentType.SHARED_LIBRARY);
1094:                }
1095:                return list.contains(sharedLibraryName);
1096:            }
1097:
1098:            /**
1099:             * list of service assembly infos
1100:             * 
1101:             * @param frameworkState
1102:             *            state
1103:             * @param componentName
1104:             *            name
1105:             * @param targetName
1106:             * @throws com.sun.jbi.ui.common.ManagementRemoteException
1107:             *             on error
1108:             * @return list of service assembly infos
1109:             */
1110:            @SuppressWarnings("unchecked")
1111:            protected List getServiceAssemblyInfoList(String frameworkState,
1112:                    String componentName, String targetName)
1113:                    throws ManagementRemoteException {
1114:                String compName = null;
1115:
1116:                if (componentName != null) {
1117:                    compName = componentName.trim();
1118:                }
1119:
1120:                String[] saNames = new String[0];
1121:
1122:                ObjectName deploymentServiceObjectName = this 
1123:                        .getDeploymentServiceMBeanObjectName(targetName);
1124:
1125:                // filter them by component name
1126:                if (compName == null || compName.length() <= 0) {
1127:                    logDebug("getting all the deployed service assemblies with state "
1128:                            + frameworkState);
1129:
1130:                    saNames = (String[]) getMBeanAttribute(
1131:                            deploymentServiceObjectName,
1132:                            "DeployedServiceAssemblies");
1133:                } else {
1134:                    logDebug("getting all the deployed service assemblies for the comp "
1135:                            + compName);
1136:
1137:                    if (false == this .isExistingComponent(compName, targetName)) {
1138:                        String[] args = { compName };
1139:                        Exception exception = this .createManagementException(
1140:                                "ui.mbean.component.id.does.not.exist", args,
1141:                                null);
1142:                        throw new ManagementRemoteException(exception);
1143:
1144:                    }
1145:
1146:                    saNames = (String[]) invokeMBeanOperation(
1147:                            deploymentServiceObjectName,
1148:                            "getDeployedServiceAssembliesForComponent",
1149:                            compName);
1150:                }
1151:
1152:                // construct service assembly infos from the descriptor
1153:
1154:                List saInfoByCompNameList = new ArrayList();
1155:
1156:                for (int i = 0; i < saNames.length; ++i) {
1157:                    String saName = saNames[i];
1158:                    logDebug("getting deployment descriptor for " + saName);
1159:                    String saDDText = (String) invokeMBeanOperation(
1160:                            deploymentServiceObjectName,
1161:                            "getServiceAssemblyDescriptor", saName);
1162:                    ServiceAssemblyInfo saInfo = ServiceAssemblyInfo
1163:                            .createFromServiceAssemblyDD(new StringReader(
1164:                                    saDDText));
1165:                    // update the state of the service assembly from runtime.
1166:                    this .updateServiceAssemblyInfoState(saInfo, targetName);
1167:
1168:                    saInfoByCompNameList.add(saInfo);
1169:                }
1170:
1171:                // && filter them by state.
1172:
1173:                List saInfoList = new ArrayList();
1174:
1175:                if (frameworkState.equalsIgnoreCase(FRAMEWORK_SA_ANY_STATE)) {
1176:                    saInfoList.addAll(saInfoByCompNameList);
1177:
1178:                } else {
1179:                    // filter by specific state
1180:                    String uiState = toUiServiceAssemblyState(frameworkState);
1181:                    for (Iterator itr = saInfoByCompNameList.iterator(); itr
1182:                            .hasNext();) {
1183:                        ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr
1184:                                .next();
1185:                        if (uiState.equalsIgnoreCase(saInfo.getState())) {
1186:                            saInfoList.add(saInfo);
1187:                        }
1188:                    }
1189:                }
1190:
1191:                // update Each ServiceUnit's State In ServiceAssembly;
1192:
1193:                for (Iterator itr = saInfoList.iterator(); itr.hasNext();) {
1194:                    ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr
1195:                            .next();
1196:
1197:                    updateEachServiceUnitInfoStateInServiceAssemblyInfo(saInfo,
1198:                            targetName);
1199:                }
1200:
1201:                return saInfoList;
1202:
1203:            }
1204:
1205:            /**
1206:             * update state in service assembly info
1207:             * 
1208:             * @param saInfo
1209:             *            service assembly info
1210:             * @param targetName
1211:             * @throws com.sun.jbi.ui.common.ManagementRemoteException
1212:             *             on error
1213:             */
1214:            protected void updateServiceAssemblyInfoState(
1215:                    ServiceAssemblyInfo saInfo, String targetName)
1216:                    throws ManagementRemoteException {
1217:                ObjectName deploymentServiceObjectName = this 
1218:                        .getDeploymentServiceMBeanObjectName(targetName);
1219:
1220:                String saName = saInfo.getName();
1221:                String frameworkState = FRAMEWORK_SA_ANY_STATE;
1222:                try {
1223:                    frameworkState = (String) invokeMBeanOperation(
1224:                            deploymentServiceObjectName, "getState", saName);
1225:                } catch (Exception ex) {
1226:                    logDebug("issue 30: state invalid: " + ex.getMessage());
1227:                    frameworkState = "Unknown";
1228:                }
1229:                logDebug("Framework State = " + frameworkState
1230:                        + " for Service Assembly = " + saName);
1231:                String uiState = toUiServiceAssemblyState(frameworkState);
1232:                saInfo.setState(uiState);
1233:            }
1234:
1235:            /**
1236:             * update the state in each service unit info in service assembly info
1237:             * 
1238:             * @param saInfo
1239:             *            service assembly info object
1240:             * @param targetName
1241:             * @throws com.sun.jbi.ui.common.ManagementRemoteException
1242:             *             on error
1243:             */
1244:            @SuppressWarnings("unchecked")
1245:            protected void updateEachServiceUnitInfoStateInServiceAssemblyInfo(
1246:                    ServiceAssemblyInfo saInfo, String targetName)
1247:                    throws ManagementRemoteException {
1248:                List list = saInfo.getServiceUnitInfoList();
1249:                if (list == null) {
1250:                    return;
1251:                }
1252:
1253:                // /////////////////////////////////////////////////////
1254:                // As of Nov 09'06 the runtime team says:
1255:                // To get the actual runtime state of a ServiceAssembly
1256:                // invoke the getState() operation on the facade
1257:                // DeploymentServiceMBean(). You should not be using the
1258:                // DeployerMBean for anything, since you do not have
1259:                // access to the remote instance DeployerMBeans and
1260:                // it is not a standard MBean.
1261:                //
1262:                // Note that the DeploymentServiceMBean returns the
1263:                // state as a String (see
1264:                // javax.jbi.management.DeploymentServiceMBean for
1265:                // the string values returned
1266:                // {Started, Stopped, Shutdown}
1267:                // TODO: Need to comment out the following code once the runtime
1268:                // provides a way to get Service Unit State
1269:                ObjectName deploymentServiceMBean = this 
1270:                        .getDeploymentServiceMBeanObjectName(targetName);
1271:                for (Iterator itr = list.iterator(); itr.hasNext();) {
1272:                    ServiceUnitInfo suInfo = (ServiceUnitInfo) itr.next();
1273:                    updateServiceUnitInfoState(suInfo, deploymentServiceMBean);
1274:                }
1275:
1276:                // /////////////////////////////////////////////////////
1277:            }
1278:
1279:            /**
1280:             * updates the state in the service unit info
1281:             * 
1282:             * @param suInfo
1283:             *            service unit info object
1284:             * @param ObjectName
1285:             *            deploymentServiceMBean
1286:             */
1287:            protected void updateServiceUnitInfoState(ServiceUnitInfo suInfo,
1288:                    ObjectName deploymentServiceMBean) {
1289:                suInfo.setState(ServiceUnitInfo.UNKNOWN_STATE);
1290:
1291:                String compName = suInfo.getDeployedOn();
1292:                String suName = suInfo.getName();
1293:                try {
1294:                    // locate the deployer mbean on the component
1295:                    if (deploymentServiceMBean == null) {
1296:                        logDebug("DeployerMBean not found for component "
1297:                                + compName);
1298:                        return;
1299:                    }
1300:
1301:                    // get the state of the service unit from the deployer mbean
1302:                    // String getServiceUnitState(String componentName, String
1303:                    // serviceUnitName)
1304:                    Object[] params = new Object[2];
1305:                    params[0] = compName;
1306:                    params[1] = suName;
1307:
1308:                    String[] signature = new String[2];
1309:                    signature[0] = "java.lang.String";
1310:                    signature[1] = "java.lang.String";
1311:
1312:                    String frameworkState = (String) invokeMBeanOperation(
1313:                            deploymentServiceMBean, "getServiceUnitState",
1314:                            params, signature);
1315:
1316:                    logDebug("Framework State = " + frameworkState
1317:                            + " for Service UNIT = " + suName);
1318:
1319:                    String uiState = toUiServiceUnitState(frameworkState);
1320:
1321:                    suInfo.setState(uiState);
1322:
1323:                } catch (Exception ex) {
1324:                    // ignore the exception and log it
1325:                    log(getI18NBundle().getMessage(
1326:                            "ui.mbean.exception.getting.service.unit.state",
1327:                            suName, compName, ex.getMessage()));
1328:                    logDebug(ex);
1329:                }
1330:            }
1331:
1332:            /**
1333:             * Looks up the cascaded LoggerMBeans for all JBI Framework
1334:             * System Services for a specific instance
1335:             * 
1336:             * @return array of object names for all system service LoggerMBeans.
1337:             */
1338:            @SuppressWarnings("unchecked")
1339:            protected ObjectName[] getSystemLoggerMBeans(String instanceName) {
1340:                com.sun.jbi.management.MBeanNames mbn = environmentContext
1341:                        .getMBeanNames();
1342:                String tmp = mbn.getJmxDomainName();
1343:
1344:                tmp += ":"
1345:                        + com.sun.jbi.management.MBeanNames.INSTANCE_NAME_KEY
1346:                        + "=" + instanceName;
1347:                tmp += ","
1348:                        + com.sun.jbi.management.MBeanNames.COMPONENT_TYPE_KEY
1349:                        + "="
1350:                        + com.sun.jbi.management.MBeanNames.COMPONENT_TYPE_SYSTEM;
1351:                tmp += "," + com.sun.jbi.management.MBeanNames.CONTROL_TYPE_KEY
1352:                        + "="
1353:                        + com.sun.jbi.management.MBeanNames.CONTROL_TYPE_LOGGER;
1354:                //wildcard goes at the end:
1355:                tmp += ",*";
1356:
1357:                //exec the query:
1358:                ObjectName mbeanPattern = null;
1359:                try {
1360:                    mbeanPattern = new ObjectName(tmp);
1361:                } catch (javax.management.MalformedObjectNameException mex) {
1362:                    logDebug(mex.getMessage());
1363:                    return new ObjectName[0];
1364:                }
1365:
1366:                java.util.Set resultSet = environmentContext.getMBeanServer()
1367:                        .queryNames(mbeanPattern, null);
1368:                ObjectName[] names = new ObjectName[0];
1369:
1370:                if (!resultSet.isEmpty()) {
1371:                    names = (ObjectName[]) resultSet.toArray(names);
1372:                } else {
1373:                    logDebug("Logger MBeans with ObjectName pattern " + tmp
1374:                            + " not found.");
1375:                }
1376:
1377:                return names;
1378:            }
1379:
1380:            /**
1381:             * Get the attributes on the MBean
1382:             * 
1383:             * @param mbeanServer
1384:             * @param objectName
1385:             * @return
1386:             * @throws JBIRemoteException
1387:             */
1388:            protected Map<String, Descriptor> getConfigurationDescriptors(
1389:                    ObjectName objectName) throws ManagementRemoteException {
1390:                Map<String, Descriptor> descrMap = new HashMap<String, Descriptor>();
1391:                MBeanServer mbeanServer = environmentContext.getMBeanServer();
1392:                MBeanInfo mbeanInfo = null;
1393:                try {
1394:                    mbeanInfo = mbeanServer.getMBeanInfo(objectName);
1395:                    MBeanAttributeInfo[] mbeanAttrInfoArray = mbeanInfo
1396:                            .getAttributes();
1397:
1398:                    for (MBeanAttributeInfo attributeInfo : mbeanAttrInfoArray) {
1399:                        if (attributeInfo instanceof  ModelMBeanAttributeInfo) {
1400:                            ModelMBeanAttributeInfo modelAttrInfo = (ModelMBeanAttributeInfo) attributeInfo;
1401:                            descrMap.put(modelAttrInfo.getName(), modelAttrInfo
1402:                                    .getDescriptor());
1403:                        }
1404:                    }
1405:                } catch (javax.management.InstanceNotFoundException e) {
1406:                    throw new ManagementRemoteException(e);
1407:                } catch (javax.management.IntrospectionException e) {
1408:                    throw new ManagementRemoteException(e);
1409:                } catch (javax.management.ReflectionException e) {
1410:                    throw new ManagementRemoteException(e);
1411:                }
1412:
1413:                return descrMap;
1414:            }
1415:
1416:            /**
1417:             * Gets the component state
1418:             * 
1419:             * @param componentName
1420:             * @param targetName
1421:             * @return the state of the component
1422:             * @throws ManagementRemoteException
1423:             *             on error
1424:             */
1425:            @SuppressWarnings("unchecked")
1426:            protected String getComponentState(String componentName,
1427:                    String targetName) throws ManagementRemoteException {
1428:                String result = JBIComponentInfo.UNKNOWN_STATE;
1429:                String xmlText = null;
1430:                List<JBIComponentInfo> infoList = null;
1431:                String state = null, sharedLibraryName = null, serviceAssemblyName = null;
1432:                try {
1433:                    xmlText = this .listComponents(ComponentType.BINDING, state,
1434:                            sharedLibraryName, serviceAssemblyName, targetName);
1435:                    if ((xmlText != null) && (xmlText.length() > 0)) {
1436:                        infoList = JBIComponentInfo.readFromXmlText(xmlText);
1437:                        for (JBIComponentInfo info : infoList) {
1438:                            if (info.getName().equals(componentName) == true) {
1439:                                return info.getState();
1440:                            }
1441:                        }
1442:                    }
1443:                } catch (ManagementRemoteException e) {
1444:                    // Ignore exception
1445:                }
1446:                try {
1447:                    xmlText = this .listComponents(ComponentType.ENGINE, state,
1448:                            sharedLibraryName, serviceAssemblyName, targetName);
1449:                    if ((xmlText != null) && (xmlText.length() > 0)) {
1450:                        infoList = JBIComponentInfo.readFromXmlText(xmlText);
1451:                        for (JBIComponentInfo info : infoList) {
1452:                            if (info.getName().equals(componentName) == true) {
1453:                                return info.getState();
1454:                            }
1455:                        }
1456:                    }
1457:                } catch (ManagementRemoteException e) {
1458:                    // Ignore exception
1459:                }
1460:                return result;
1461:            }
1462:
1463:            /**
1464:             * Check if the component is in the "Started" state on the target. A 
1465:             * JBI Management exception is thrown if the component is not in the started
1466:             * state.
1467:             *
1468:             * @param componentName - component name
1469:             * @param target - target name, can be standalone or clustered instance, cluster
1470:             *                 or "server".
1471:             * @throws ManagementRemoteException if component is not started on target.
1472:             */
1473:            protected void componentStartedOnTargetCheck(String componentName,
1474:                    String target) throws ManagementRemoteException {
1475:                String targetName = target;
1476:
1477:                if (this .getPlatformContext().isClusteredServer(targetName)) {
1478:                    // -- The actual Target is the cluster
1479:                    targetName = this .getPlatformContext()
1480:                            .getTargetName(target);
1481:                }
1482:
1483:                String state = this 
1484:                        .getComponentState(componentName, targetName);
1485:
1486:                if (!com.sun.jbi.ui.common.JBIComponentInfo.STARTED_STATE
1487:                        .equalsIgnoreCase(state)) {
1488:                    Exception exception = this 
1489:                            .createManagementException(
1490:                                    "ui.mbean.component.configuration.not.started.on.target.error",
1491:                                    new String[] { componentName, targetName },
1492:                                    null);
1493:                    throw new ManagementRemoteException(exception);
1494:                }
1495:            }
1496:
1497:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.