Source Code Cross Referenced for EnvironmentContext.java in  » ESB » open-esb » com » sun » jbi » framework » 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.jbi.framework 
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:         * @(#)EnvironmentContext.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        package com.sun.jbi.framework;
0030:
0031:        import com.sun.jbi.JBIProvider;
0032:        import com.sun.jbi.management.ConfigurationCategory;
0033:        import com.sun.jbi.management.MBeanNames;
0034:        import com.sun.jbi.management.config.ConfigurationBuilder;
0035:        import com.sun.jbi.management.registry.Registry;
0036:        import com.sun.jbi.management.registry.xml.UpdaterImpl;
0037:        import com.sun.jbi.platform.PlatformContext;
0038:        import com.sun.jbi.util.EnvironmentAccess;
0039:        import com.sun.jbi.wsdl2.WsdlException;
0040:        import com.sun.jbi.wsdl2.WsdlFactory;
0041:
0042:        import java.io.File;
0043:        import java.io.FileInputStream;
0044:
0045:        import java.util.HashMap;
0046:        import java.util.List;
0047:        import java.util.Enumeration;
0048:        import java.util.logging.Logger;
0049:        import java.util.logging.Level;
0050:        import java.util.Properties;
0051:
0052:        import javax.management.MBeanServer;
0053:        import javax.management.ObjectName;
0054:        import javax.management.StandardMBean;
0055:        import javax.naming.InitialContext;
0056:
0057:        import javax.xml.parsers.DocumentBuilder;
0058:        import javax.xml.parsers.DocumentBuilderFactory;
0059:
0060:        /**
0061:         * This context contains data needed by all components and services running in
0062:         * the JBI environment.
0063:         *
0064:         * @author Sun Microsystems, Inc.
0065:         */
0066:        public class EnvironmentContext implements 
0067:                com.sun.jbi.EnvironmentContext {
0068:            /**
0069:             * Constant for error message when getInstance() called out of sequence.
0070:             */
0071:            private static final String NOT_YET_CREATED = "The Environment Context has not yet been created.";
0072:
0073:            /**
0074:             * Constant for the JBI default log level property value.
0075:             */
0076:            private static final String JBI_DEFAULT_LOG_LEVEL_VALUE = "INFO";
0077:
0078:            /**
0079:             * Constant for the JBI default log level property key.
0080:             */
0081:            private static final String JBI_DEFAULT_LOG_LEVEL_KEY = "com.sun.jbi.defaultLogLevel";
0082:
0083:            /**
0084:             * Constant for the JBI instance name property key.
0085:             */
0086:            private static final String JBI_INSTANCE_NAME_KEY = "com.sun.jbi.framework.JBIFramework.JbiName";
0087:
0088:            /**
0089:             * Constant for the JBI root directory name under the AppServer install
0090:             * root.
0091:             */
0092:            private static final String JBI_ROOT = "jbi";
0093:
0094:            /**
0095:             * Constant for the JMX domain name for all JBI MBeans.
0096:             */
0097:            private static final String JMX_DOMAIN_NAME = "com.sun.jbi";
0098:
0099:            /**
0100:             * Constant for the configuration directory path.
0101:             */
0102:            private static final String CONFIG_PATH = "/system/private/config";
0103:
0104:            /**
0105:             * Constant for property not found.
0106:             */
0107:            private static final String PROPERTY_NOT_FOUND = "PROPERTY_NOT_FOUND";
0108:
0109:            /**
0110:             * Static reference to instance of this context.
0111:             */
0112:            private static EnvironmentContext sEnvironmentContext;
0113:
0114:            /**
0115:             * Handle to the Event Notifier MBean instance.
0116:             */
0117:            private EventNotifier mNotifier;
0118:
0119:            /**
0120:             * Handle to platform-specific context.
0121:             */
0122:            private PlatformContext mPlatformContext;
0123:
0124:            /**
0125:             * AppServer installation root directory path.
0126:             */
0127:            private String mAppServerInstallRoot;
0128:
0129:            /**
0130:             * AppServer instance root directory path.
0131:             */
0132:            private String mAppServerInstanceRoot;
0133:
0134:            /**
0135:             * Handle to the Component Framework.
0136:             */
0137:            private ComponentFramework mComponentFramework;
0138:
0139:            /**
0140:             * Handle to the Component Registry.
0141:             */
0142:            private ComponentRegistry mComponentRegistry;
0143:
0144:            /**
0145:             * Handle to the JBI Registry
0146:             */
0147:            private com.sun.jbi.management.registry.Registry mRegistry;
0148:
0149:            /**
0150:             * JBI default log level.
0151:             */
0152:            private Level mDefaultLogLevel;
0153:
0154:            /**
0155:             * Handle to the framework statistics.
0156:             */
0157:            private FrameworkStatistics mFrameworkStatistics;
0158:
0159:            /**
0160:             * Handle to the Properties from the lifecycle module definition.
0161:             */
0162:            private Properties mInitialProperties;
0163:
0164:            /**
0165:             * JBI installation root directory path.
0166:             */
0167:            private String mJbiInstallRoot;
0168:
0169:            /**
0170:             * JBI instance root directory path.
0171:             */
0172:            private String mJbiInstanceRoot;
0173:
0174:            /**
0175:             * Handle to the top-level Logger for the runtime.
0176:             */
0177:            private Logger mJbiLog;
0178:
0179:            /**
0180:             * Handle to the Logger for the framework.
0181:             */
0182:            private Logger mLog;
0183:
0184:            /**
0185:             * Global JBI logger MBean name; null if none was created.
0186:             */
0187:            private static ObjectName sJbiLogMBeanName;
0188:
0189:            /**
0190:             * Framework logger MBean name; null if none was created.
0191:             */
0192:            private static ObjectName sLogMBeanName;
0193:
0194:            /**
0195:             * Framework notification MBean name; null if none was created.
0196:             */
0197:            private static ObjectName sNotifierMBeanName;
0198:
0199:            /**
0200:             * Framework statistics MBean name; null if none was created.
0201:             */
0202:            private static ObjectName sStatsMBeanName;
0203:
0204:            /**
0205:             * Handle to the Management Service.
0206:             */
0207:            private com.sun.jbi.management.system.ManagementService mManagementService;
0208:
0209:            /**
0210:             * Handle to the Configuration Service.
0211:             */
0212:            private com.sun.jbi.management.system.ConfigurationService mConfigService;
0213:
0214:            /**
0215:             * Handle to the ManagementMessageFactory.
0216:             */
0217:            private com.sun.jbi.management.ManagementMessageFactory mMFactory;
0218:
0219:            /**
0220:             * Handle to the MBeanHelper helper class.
0221:             */
0222:            private com.sun.jbi.management.MBeanHelper mMBeanHelper;
0223:
0224:            /**
0225:             * Handle to the MBeanNames helper class.
0226:             */
0227:            private com.sun.jbi.management.MBeanNames mMBeanNames;
0228:
0229:            /**
0230:             * Handle to the VersionInfo class.
0231:             */
0232:            private com.sun.jbi.VersionInfo mVersionInfo;
0233:
0234:            /**
0235:             * Handle to the MBean server.
0236:             */
0237:            private MBeanServer mMBeanServer;
0238:
0239:            /**
0240:             * Handle to the AppServer's JNDI naming context.
0241:             */
0242:            private InitialContext mNamingContext;
0243:
0244:            /**
0245:             * Handle to the Normalized Message Service.
0246:             */
0247:            private com.sun.jbi.messaging.MessageService mNormalizedMessageService;
0248:
0249:            /**
0250:             * Table of handles to StringTranslators.
0251:             */
0252:            private HashMap mStringTranslators;
0253:
0254:            /**
0255:             * Handle to the Management Runtime Service.
0256:             */
0257:            private com.sun.jbi.management.facade.ManagementRuntimeService mMgmtRuntimeService;
0258:
0259:            /**
0260:             * StringTranslator for the framework.
0261:             */
0262:            private StringTranslator mTranslator;
0263:
0264:            /**
0265:             * TransactionManager for framework users.
0266:             */
0267:            private javax.transaction.TransactionManager mTransactionManager;
0268:
0269:            /**
0270:             * Flag to indicate TransactionManager is unavailable.
0271:             */
0272:            private boolean mTransactionManagerUnavailable;
0273:
0274:            /**
0275:             * JBI provider type.
0276:             */
0277:            private JBIProvider mProvider;
0278:
0279:            /** 
0280:             * Naming prefix.
0281:             */
0282:            private String mNamingPrefix;
0283:
0284:            /** 
0285:             * JBI Framework reference.
0286:             */
0287:            private JBIFramework mFramework;
0288:
0289:            /**
0290:             * The Registry DOM Document
0291:             */
0292:            private org.w3c.dom.Document mRegistryDocument;
0293:
0294:            /**
0295:             * Constructor.
0296:             * @param platform the platform context for the AppServer.
0297:             * @param framework the representing the JBI Framework instance.
0298:             * @param initialProperties is the Properties object provided by
0299:             * the AppServer, containing all properties specified in the
0300:             * definition of the JBI lifecycle module.
0301:             * @throws javax.jbi.JBIException if any error occurs.
0302:             */
0303:            EnvironmentContext(PlatformContext platform,
0304:                    JBIFramework framework, Properties initialProperties)
0305:                    throws javax.jbi.JBIException {
0306:                // Set the static instance references
0307:
0308:                sEnvironmentContext = this ;
0309:                EnvironmentAccess.setContext(this );
0310:
0311:                // Save AppServer and JBI information
0312:                mFramework = framework;
0313:                mProvider = platform.getProvider();
0314:                mPlatformContext = platform;
0315:                mInitialProperties = initialProperties;
0316:
0317:                // Initialize the table of StringTranslators and get a translator
0318:                // for framework messages
0319:
0320:                String pkgName = this .getClass().getPackage().getName();
0321:                mStringTranslators = new HashMap();
0322:                mTranslator = new StringTranslator(pkgName, null);
0323:                mStringTranslators.put(pkgName, mTranslator);
0324:
0325:                // Create the framework logger and set its log level
0326:
0327:                createLogger(pkgName);
0328:
0329:                // Initialize the AppServer and JBI installation and instance root
0330:                // directory paths with the canonical paths and replace backslashes
0331:                // backslashes with forward slashes.
0332:
0333:                mAppServerInstallRoot = platform.getInstallRoot();
0334:                mAppServerInstanceRoot = platform.getInstanceRoot();
0335:
0336:                // Use com.sun.jbi.home if it's provided, otherwise default to 
0337:                // platform install root + /jbi
0338:
0339:                if (initialProperties.getProperty("com.sun.jbi.home") != null) {
0340:                    mJbiInstallRoot = initialProperties
0341:                            .getProperty("com.sun.jbi.home");
0342:                } else {
0343:                    mJbiInstallRoot = mAppServerInstallRoot + File.separator
0344:                            + JBI_ROOT;
0345:                }
0346:
0347:                mJbiInstanceRoot = mAppServerInstanceRoot + File.separator
0348:                        + JBI_ROOT;
0349:                File dummyFile = new File(mJbiInstanceRoot);
0350:                try {
0351:                    mJbiInstanceRoot = dummyFile.getCanonicalPath();
0352:                } catch (java.io.IOException ioEx) {
0353:                    ; // Ignore - just fall through
0354:                }
0355:                mJbiInstanceRoot = mJbiInstanceRoot.replace('\\', '/');
0356:
0357:                // Set platform instance root and install root
0358:                System.setProperty(PlatformContext.INSTALL_ROOT_TOKEN,
0359:                        mAppServerInstallRoot);
0360:                System.setProperty(PlatformContext.INSTANCE_ROOT_TOKEN,
0361:                        mAppServerInstanceRoot);
0362:
0363:                // Save MBean server and create MBean helpers and framework MBeans.
0364:                mMBeanServer = platform.getMBeanServer();
0365:                mMBeanNames = new com.sun.jbi.management.support.MBeanNamesImpl(
0366:                        JMX_DOMAIN_NAME, platform.getInstanceName());
0367:
0368:                mMBeanHelper = new com.sun.jbi.management.support.MBeanHelper(
0369:                        mMBeanServer, mMBeanNames, mLog);
0370:
0371:                mFrameworkStatistics = new FrameworkStatistics();
0372:                mNotifier = new EventNotifier(this );
0373:
0374:                createMBeans();
0375:
0376:                // Create version info instance (version info is compiled in)
0377:
0378:                mVersionInfo = (com.sun.jbi.VersionInfo) new com.sun.jbi.management.VersionInfo();
0379:
0380:                if (mLog.isLoggable(Level.FINE)) {
0381:                    // Log JBI information
0382:                    mLog.fine("JBI instance root set to " + mJbiInstanceRoot);
0383:                    if (null != mInitialProperties) {
0384:                        mLog.fine("Initial properties are:");
0385:                        java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
0386:                        mInitialProperties.list(new java.io.PrintWriter(bos));
0387:                        mLog
0388:                                .fine(mTranslator
0389:                                        .getString(
0390:                                                LocalStringKeys.EC_INITIAL_PROPERTIES_LIST,
0391:                                                bos));
0392:                    }
0393:                }
0394:
0395:                // Create instances of all services
0396:                mComponentFramework = new ComponentFramework();
0397:                mComponentRegistry = new ComponentRegistry();
0398:                mConfigService = new com.sun.jbi.management.system.ConfigurationService();
0399:                mManagementService = new com.sun.jbi.management.system.ManagementService();
0400:                mMFactory = new com.sun.jbi.management.system.ManagementMessageFactoryImpl();
0401:                mNormalizedMessageService = new com.sun.jbi.messaging.MessageService();
0402:                mMgmtRuntimeService = new com.sun.jbi.management.facade.ManagementRuntimeService();
0403:            }
0404:
0405:            /**
0406:             * Destroy the instance of this context created by the constructor.
0407:             */
0408:            void destroyInstance() {
0409:                if (null != sJbiLogMBeanName) {
0410:                    unregisterMBean(sJbiLogMBeanName);
0411:                }
0412:                if (null != sLogMBeanName) {
0413:                    unregisterMBean(sLogMBeanName);
0414:                }
0415:                if (null != sNotifierMBeanName) {
0416:                    unregisterMBean(sNotifierMBeanName);
0417:                }
0418:                if (null != sStatsMBeanName) {
0419:                    unregisterMBean(sStatsMBeanName);
0420:                }
0421:                sEnvironmentContext = null;
0422:            }
0423:
0424:            /**
0425:             * Get the instance of this context created by the constructor.
0426:             * @return instance of the EnvironmentContext created by the constructor.
0427:             */
0428:            public static EnvironmentContext getInstance() {
0429:                if (null == sEnvironmentContext) {
0430:                    throw new java.lang.IllegalStateException(NOT_YET_CREATED);
0431:                }
0432:                return sEnvironmentContext;
0433:            }
0434:
0435:            //*****************************************************************************
0436:            //***                                                                       ***
0437:            //*** Framework-internal accessor methods.                                  ***
0438:            //***                                                                       ***
0439:            //*****************************************************************************
0440:
0441:            /**
0442:             * Get the Component Framework service handle.
0443:             * @return The ComponentFramework instance.
0444:             */
0445:            ComponentFramework getComponentFramework() {
0446:                return mComponentFramework;
0447:            }
0448:
0449:            /**
0450:             * Get the Component Registry service handle.
0451:             * @return The ComponentRegistry instance.
0452:             */
0453:            ComponentRegistry getComponentRegistry() {
0454:                return mComponentRegistry;
0455:            }
0456:
0457:            /**
0458:             * Get the framework statistics handle.
0459:             * @return The FrameworkStatistics instance.
0460:             */
0461:            FrameworkStatistics getFrameworkStatistics() {
0462:                return mFrameworkStatistics;
0463:            }
0464:
0465:            /**
0466:             * Get the top-level logger for the runtime.
0467:             * @return The Logger instance.
0468:             */
0469:            Logger getJbiLogger() {
0470:                return mJbiLog;
0471:            }
0472:
0473:            /**
0474:             * Get the logger for the framework.
0475:             * @return The Logger instance.
0476:             */
0477:            Logger getLogger() {
0478:                return mLog;
0479:            }
0480:
0481:            /**
0482:             * Get the timeout value for component life cycle operations.
0483:             * @return The timeout value in milliseconds for calls to the component's
0484:             * ComponentLifeCycle methods.
0485:             */
0486:            long getComponentTimeout() {
0487:                long componentTimeout = 0;
0488:                Object value = getConfigurationAttribute(
0489:                        ConfigurationCategory.Installation,
0490:                        com.sun.jbi.management.config.InstallationConfigurationFactory.COMPONENT_TIMEOUT);
0491:                if (value != null) {
0492:                    componentTimeout = (Integer) value;
0493:                }
0494:                return componentTimeout;
0495:            }
0496:
0497:            /**
0498:             * Get the timeout value for Service Unit deploy/undeploy operations.
0499:             * @return The timeout value in milliseconds for calls to the component's
0500:             * ServiceUnitManager deploy and undeploy methods.
0501:             */
0502:            long getDeploymentTimeout() {
0503:
0504:                long deploymentTimeout = 0;
0505:
0506:                Object value = getConfigurationAttribute(
0507:                        ConfigurationCategory.Deployment,
0508:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.DEPLOYMENT_TIMEOUT);
0509:
0510:                if (value != null) {
0511:                    deploymentTimeout = (Integer) value;
0512:                }
0513:
0514:                return deploymentTimeout;
0515:            }
0516:
0517:            /**
0518:             * Get the timeout value for component install/uninstall operations.
0519:             * @return The timeout value in milliseconds for calls to the component's
0520:             * Bootstrap onInstall and onUninstall methods.
0521:             */
0522:            long getInstallationTimeout() {
0523:                long installationTimeout = 0;
0524:
0525:                Object value = getConfigurationAttribute(
0526:                        ConfigurationCategory.Installation,
0527:                        com.sun.jbi.management.config.InstallationConfigurationFactory.INSTALLATION_TIMEOUT);
0528:
0529:                if (value != null) {
0530:                    installationTimeout = (Integer) value;
0531:                }
0532:
0533:                return installationTimeout;
0534:            }
0535:
0536:            /**
0537:             * Get the timeout value for Service Unit life cycle operations.
0538:             * @return The timeout value in milliseconds for calls to the component's
0539:             * ServiceUnitManager life cycle methods.
0540:             */
0541:            long getServiceUnitTimeout() {
0542:
0543:                long serviceUnitTimeout = 0;
0544:
0545:                Object value = getConfigurationAttribute(
0546:                        ConfigurationCategory.Deployment,
0547:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.SERVICE_UNIT_TIMEOUT);
0548:
0549:                if (value != null) {
0550:                    serviceUnitTimeout = (Integer) value;
0551:                }
0552:
0553:                return serviceUnitTimeout;
0554:            }
0555:
0556:            //*****************************************************************************
0557:            //***                                                                       ***
0558:            //*** Framework-internal mutator methods.                                   ***
0559:            //***                                                                       ***
0560:            //*****************************************************************************
0561:
0562:            /**
0563:             * Set the installation root directory of the AppServer.
0564:             * @param installRoot String containing the installation root directory
0565:             * of the AppServer.
0566:            void setAppServerInstallRoot(String installRoot)
0567:            {
0568:                mAppServerInstallRoot = installRoot;
0569:            }
0570:             */
0571:
0572:            /**
0573:             * Set the instance root directory of the AppServer.
0574:             * @param instanceRoot String containing the instance root directory
0575:             * of the AppServer.
0576:             */
0577:            void setAppServerInstanceRoot(String instanceRoot) {
0578:                mAppServerInstanceRoot = instanceRoot;
0579:            }
0580:
0581:            /**
0582:             * Set the component timeout value (used for junit testing only).
0583:             * @param timeout the timeout value in milliseconds.
0584:             */
0585:            void setComponentTimeout(long timeout) {
0586:                setConfigurationAttribute(
0587:                        ConfigurationCategory.Installation,
0588:                        com.sun.jbi.management.config.InstallationConfigurationFactory.COMPONENT_TIMEOUT,
0589:                        new Long(timeout));
0590:            }
0591:
0592:            /**
0593:             * Set the deployment timeout value (used for junit testing only).
0594:             * @param timeout the timeout value in milliseconds.
0595:             */
0596:            void setDeploymentTimeout(long timeout) {
0597:                setConfigurationAttribute(
0598:                        ConfigurationCategory.Deployment,
0599:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.DEPLOYMENT_TIMEOUT,
0600:                        new Long(timeout));
0601:            }
0602:
0603:            /**
0604:             * Set the installation timeout value (used for junit testing only).
0605:             * @param timeout the timeout value in milliseconds.
0606:             */
0607:            void setInstallationTimeout(long timeout) {
0608:                setConfigurationAttribute(
0609:                        ConfigurationCategory.Installation,
0610:                        com.sun.jbi.management.config.InstallationConfigurationFactory.INSTALLATION_TIMEOUT,
0611:                        new Long(timeout));
0612:            }
0613:
0614:            /**
0615:             * Set the service unit timeout value (used for junit testing only).
0616:             * @param timeout the timeout value in milliseconds.
0617:             */
0618:            void setServiceUnitTimeout(long timeout) {
0619:                setConfigurationAttribute(
0620:                        ConfigurationCategory.Deployment,
0621:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.SERVICE_UNIT_TIMEOUT,
0622:                        new Long(timeout));
0623:            }
0624:
0625:            /**
0626:             * Set the installation root directory of the JBI framework.
0627:             * @param installRoot String containing the installation root directory
0628:             * of the JBI framework
0629:             */
0630:            void setJbiInstallRoot(String installRoot) {
0631:                mJbiInstallRoot = installRoot;
0632:            }
0633:
0634:            /**
0635:             * Set the instance root directory of the JBI framework.
0636:             * @param instanceRoot String containing the instance root directory
0637:             * of the JBI framework
0638:             */
0639:            void setJbiInstanceRoot(String instanceRoot) {
0640:                mJbiInstanceRoot = instanceRoot;
0641:            }
0642:
0643:            /**
0644:             * Set the JNDI naming context.
0645:             * @param namingContext the JNDI naming context from the AppServer.
0646:             */
0647:            void setManagementService(
0648:                    com.sun.jbi.management.system.ManagementService ms) {
0649:                mManagementService = ms;
0650:            }
0651:
0652:            /**
0653:             * Set the JNDI naming context.
0654:             * @param namingContext the JNDI naming context from the AppServer.
0655:             */
0656:            void setNamingContext(InitialContext namingContext) {
0657:                mNamingContext = namingContext;
0658:            }
0659:
0660:            /**
0661:             * Set the JNDI naming prefix.
0662:             * @param prefix naming prefix for binding JNDI names.
0663:             */
0664:            void setNamingPrefix(String prefix) {
0665:                mNamingPrefix = prefix;
0666:            }
0667:
0668:            /**
0669:             * Set the platform context implementation.
0670:             * @param platform platform context impl
0671:             */
0672:            void setPlatformContext(PlatformContext platform) {
0673:                mPlatformContext = platform;
0674:            }
0675:
0676:            //*****************************************************************************
0677:            //***                                                                       ***
0678:            //*** Public accessor methods.                                              ***
0679:            //***                                                                       ***
0680:            //*****************************************************************************
0681:
0682:            /**
0683:             * Get the installation root directory of the AppServer.
0684:             * @return String containing the installation root directory path
0685:             */
0686:            public String getAppServerInstallRoot() {
0687:                return mAppServerInstallRoot;
0688:            }
0689:
0690:            /**
0691:             * Get the instance root directory of the AppServer instance.
0692:             * @return String containing the instance root directory path
0693:             */
0694:            public String getAppServerInstanceRoot() {
0695:                return mAppServerInstanceRoot;
0696:            }
0697:
0698:            /**
0699:             * Get the Component Manager handle.
0700:             * @return The ComponentManager handle, which is a thin interface to the
0701:             * ComponentFramework service.
0702:             */
0703:            public com.sun.jbi.ComponentManager getComponentManager() {
0704:                return (com.sun.jbi.ComponentManager) mComponentFramework;
0705:            }
0706:
0707:            /**
0708:             * Get the Component Query handle. This returns the ComponentQuery with this
0709:             * instances target.
0710:             *
0711:             * @return the ComponentQuery for the current server instance. This ComponentQuery
0712:             * provides information on components and shared libraries installed to the
0713:             * server instance.
0714:             */
0715:            public com.sun.jbi.ComponentQuery getComponentQuery() {
0716:                try {
0717:                    return ((Registry) getRegistry()).getComponentQuery();
0718:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
0719:                    mLog.warning(rex.getMessage());
0720:                    return null;
0721:                }
0722:            }
0723:
0724:            /**
0725:             * Get the ComponentQuery for a specified target
0726:             * @return The ComponentQuery instance.
0727:             * @param targetName - either "domain" or a valid server / cluster name
0728:             */
0729:            public com.sun.jbi.ComponentQuery getComponentQuery(
0730:                    String targetName) {
0731:                try {
0732:                    return ((Registry) getRegistry())
0733:                            .getComponentQuery(targetName);
0734:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
0735:                    mLog.warning(rex.getMessage());
0736:                    return null;
0737:                }
0738:            }
0739:
0740:            /**
0741:             * Get the PlatformContext implementation.
0742:             * @return The PlatformContext instance.
0743:             */
0744:            public PlatformContext getPlatformContext() {
0745:                return mPlatformContext;
0746:            }
0747:
0748:            /**
0749:             * Get a reference to the persisted JBI registry. 
0750:             * 
0751:             * The registry is created if not already available and the result is cached for
0752:             * later callers.
0753:             *
0754:             * The framework will transition from lazy to normal if the registry is requested
0755:             * (or if the Framework is explicitly enabled.) After creating the registry we will
0756:             * make sure the Framework is ready before continuing.
0757:             *
0758:             * Note: JBIFramework.frameReady() will indirectly call getRegistry() and getRegistry()
0759:             * will directly call JBIFramework.frameworkRead(). The recursion is broken by carefully
0760:             * setting the internal framework ready flag. 
0761:             * 
0762:             * See: JBIFramework.readyFramework() and JBIFramework.prepare()
0763:             *
0764:             * @return Registry instance
0765:             */
0766:            public com.sun.jbi.registry.Registry getRegistry() {
0767:                boolean checkFramework = false;
0768:
0769:                synchronized (this ) {
0770:                    if (mRegistry == null) {
0771:                        getJustRegistry();
0772:                        checkFramework = true;
0773:                    }
0774:                }
0775:                if (checkFramework) {
0776:                    mFramework.frameworkReady();
0777:                }
0778:                return mRegistry;
0779:            }
0780:
0781:            /**
0782:             * This is used by the ComponentRegistry Service to bypass the deferred initialization checks.
0783:             */
0784:            public com.sun.jbi.registry.Registry getJustRegistry() {
0785:                if (mRegistry == null) {
0786:                    java.util.Properties props = new java.util.Properties();
0787:                    props
0788:                            .setProperty(
0789:                                    com.sun.jbi.management.registry.Registry.REGISTRY_FOLDER_PROPERTY,
0790:                                    getJbiInstanceRoot()
0791:                                            + java.io.File.separator + "config");
0792:
0793:                    // Create an instance of management context
0794:                    com.sun.jbi.management.system.ManagementContext mgmtCtx = new com.sun.jbi.management.system.ManagementContext(
0795:                            this );
0796:
0797:                    try {
0798:                        mRegistry = com.sun.jbi.management.registry.RegistryBuilder
0799:                                .buildRegistry(new com.sun.jbi.management.registry.RegistrySpecImpl(
0800:                                        com.sun.jbi.management.registry.RegistryType.XML,
0801:                                        props, mgmtCtx));
0802:                        ((UpdaterImpl) mRegistry.getUpdater())
0803:                                .correctTimestamps();
0804:                    } catch (com.sun.jbi.management.registry.RegistryException rEx) {
0805:                        // Registry initialization has failed.
0806:                        String errMsg = mTranslator.getString(
0807:                                LocalStringKeys.EC_JBI_REGISTRY_INIT_FAILED,
0808:                                rEx.getMessage());
0809:                        mLog.warning(rEx.getMessage());
0810:                        throw new RuntimeException(errMsg, rEx);
0811:                    }
0812:                    mLog.fine("JBIEnvironmentContext: Create the registry...");
0813:                }
0814:
0815:                return (mRegistry);
0816:            }
0817:
0818:            /**
0819:             * This method is for junit tests to use a Scaffold registry.
0820:             */
0821:            void setRegistry(Registry registry) {
0822:                mRegistry = registry;
0823:            }
0824:
0825:            /**
0826:             * Get a read-only reference to the persisted JBI Registry. A DOM registry document 
0827:             * object is returned. If the registry file is missing or cannot be read then a null 
0828:             * value is returned.
0829:             *
0830:             * @return the registry document
0831:             */
0832:            public org.w3c.dom.Document getReadOnlyRegistry() {
0833:                if (mRegistryDocument == null) {
0834:                    try {
0835:                        // The registry file
0836:                        File registryFile = new File(getJbiInstanceRoot()
0837:                                + "/config/jbi-registry.xml");
0838:
0839:                        if (registryFile.canRead()) {
0840:                            DocumentBuilderFactory dbf = DocumentBuilderFactory
0841:                                    .newInstance();
0842:                            DocumentBuilder db = dbf.newDocumentBuilder();
0843:                            mRegistryDocument = db.parse(registryFile);
0844:                        }
0845:                    } catch (Exception ex) {
0846:                        mLog.warning(ex.getMessage());
0847:                    }
0848:                }
0849:                return mRegistryDocument;
0850:            }
0851:
0852:            /**
0853:             * Indicates whether or not the JBI framework has been fully started.  This
0854:             * method provides clients with a way of determining if the JBI framework
0855:             * started up in passive mode as a result of on-demand initialization.  
0856:             * The 'start' parameter instructs the framework to
0857:             * start completely if it has not already done so.  If the framework has
0858:             * already been started, the request to start again is ignored.
0859:             * @param start requests that the framework start completely before
0860:             *  returning.
0861:             * @return true if the framework is completely started, false otherwise.
0862:             */
0863:            public boolean isFrameworkReady(boolean start) {
0864:                if (start) {
0865:                    mFramework.frameworkReady();
0866:                }
0867:
0868:                return mFramework.isFrameworkReady();
0869:            }
0870:
0871:            /**
0872:             * Get the Connection Manager handle.
0873:             * @return The ConnectionManager instance.
0874:             */
0875:            public com.sun.jbi.messaging.ConnectionManager getConnectionManager() {
0876:                return mNormalizedMessageService.getConnectionManager();
0877:            }
0878:
0879:            /**
0880:             * Get the default log level specified at startup.
0881:             * @return The default log level as a Level instance.
0882:             */
0883:            public java.util.logging.Level getDefaultLogLevel() {
0884:                return mDefaultLogLevel;
0885:            }
0886:
0887:            /**
0888:             * Get the initial properties provided by the AppServer from the
0889:             * properties specified in the lifecycle module definition in the
0890:             * domain.xml file.
0891:             * @return The initial properties from the AppServer.
0892:             */
0893:            public java.util.Properties getInitialProperties() {
0894:                return mInitialProperties;
0895:            }
0896:
0897:            /**
0898:             * Get the installation root directory of the JBI system.
0899:             * @return The JBI installation root directory path.
0900:             */
0901:            public String getJbiInstallRoot() {
0902:                return mJbiInstallRoot;
0903:            }
0904:
0905:            /**
0906:             * Get the instance root directory of the JBI system.
0907:             * @return The JBI instance root directory path.
0908:             */
0909:            public String getJbiInstanceRoot() {
0910:                return mJbiInstanceRoot;
0911:            }
0912:
0913:            /**
0914:             * Get a handle to the class implementing management for the named
0915:             * JBI system service.
0916:             * @param aServiceName - the name of the JBI system service.
0917:             * @return The class implementing management for the system service.
0918:             */
0919:            public Object getManagementClass(String aServiceName) {
0920:                if (aServiceName
0921:                        .equals(mMBeanNames.SERVICE_NAME_MESSAGE_SERVICE)) {
0922:                    return (Object) mNormalizedMessageService;
0923:                }
0924:
0925:                return null;
0926:            }
0927:
0928:            /**
0929:             * Get the management message factory which enables JBI components
0930:             * to construct status and exception messages.
0931:             * @return The ManagementMessageFactory instance.
0932:             */
0933:            public com.sun.jbi.management.ManagementMessageFactory getManagementMessageFactory() {
0934:                return mMFactory;
0935:            }
0936:
0937:            /**
0938:             * Get the Management Service handle.
0939:             * @return The ManagementService instance.
0940:             */
0941:            public com.sun.jbi.management.system.ManagementService getManagementService() {
0942:                return mManagementService;
0943:            }
0944:
0945:            /**
0946:             * Get the Configuration Service handle.
0947:             * @return The ConfigurationService instance.
0948:             */
0949:            public com.sun.jbi.management.system.ConfigurationService getConfigurationService() {
0950:                return mConfigService;
0951:            }
0952:
0953:            /**
0954:             * Get the MBean helper service which enables JBI components to request
0955:             * that the Management Service create and register MBeans on their behalf.
0956:             * @return The MBeanHelper instance.
0957:             */
0958:            public com.sun.jbi.management.MBeanHelper getMBeanHelper() {
0959:                return mMBeanHelper;
0960:            }
0961:
0962:            /**
0963:             * Get the MBean naming service which enables JBI components to construct
0964:             * MBean names that follow the JBI conventions.
0965:             * @return The MBeanNames instance.
0966:             */
0967:            public com.sun.jbi.management.MBeanNames getMBeanNames() {
0968:                return mMBeanNames;
0969:            }
0970:
0971:            /**
0972:             * Get the MBean server with which all MBeans are registered.
0973:             * @return javax.management.MBeanServer the main MBean server
0974:             */
0975:            public javax.management.MBeanServer getMBeanServer() {
0976:                return mMBeanServer;
0977:            }
0978:
0979:            /**
0980:             * Get the JNDI naming context currently in effect.
0981:             * @return javax.naming.InitialContext the JNDI naming context
0982:             */
0983:            public javax.naming.InitialContext getNamingContext() {
0984:                return mNamingContext;
0985:            }
0986:
0987:            /** Gets the naming prefix.
0988:             * @return naming prefix
0989:             */
0990:            public String getNamingPrefix() {
0991:                return mNamingPrefix;
0992:            }
0993:
0994:            /**
0995:             * Get the Normalized Message Service handle.
0996:             * @return The NormalizedMessageService instance.
0997:             */
0998:            public com.sun.jbi.messaging.MessageService getNormalizedMessageService() {
0999:                return mNormalizedMessageService;
1000:            }
1001:
1002:            /**
1003:             * Get the Event Notifier for emitting event notifications from the runtime.
1004:             * @return The EventNotifier instance.
1005:             */
1006:            public EventNotifierCommon getNotifier() {
1007:                return (EventNotifierCommon) mNotifier;
1008:            }
1009:
1010:            /**
1011:             * Returns the Provider of JBI.
1012:             * @return provider
1013:             */
1014:            public JBIProvider getProvider() {
1015:                return mProvider;
1016:            }
1017:
1018:            /**
1019:             * Get the Service Unit registration handle.
1020:             * @return The ServiceUnitRegistration handle, which is a thin interface
1021:             * to the ComponentRegistry service.
1022:             */
1023:            public com.sun.jbi.ServiceUnitRegistration getServiceUnitRegistration() {
1024:                return (com.sun.jbi.ServiceUnitRegistration) mComponentRegistry;
1025:            }
1026:
1027:            /**
1028:             * Get the StringTranslator for a specified package name.
1029:             * @param packageName - the name of the package containing the resource
1030:             * bundle to be used by this StringTranslator.
1031:             * @return The StringTranslator instance.
1032:             */
1033:            public com.sun.jbi.StringTranslator getStringTranslator(
1034:                    String packageName) {
1035:                StringTranslator translator = (StringTranslator) mStringTranslators
1036:                        .get(packageName);
1037:
1038:                if (null == translator) {
1039:                    translator = new StringTranslator(packageName, null);
1040:                    mStringTranslators.put(packageName, translator);
1041:                    mLog.finer("StringTranslator created for package "
1042:                            + packageName);
1043:                }
1044:
1045:                return (com.sun.jbi.StringTranslator) translator;
1046:            }
1047:
1048:            /**
1049:             * Get the StringTranslator for a specified package name using the class
1050:             * loader for a specified component ID.
1051:             * @param packageName - the name of the package containing the resource
1052:             * bundle to be used by this StringTranslator.
1053:             * @param componentId - the component ID for which the classloader is to
1054:             * be used.
1055:             * @return The StringTranslator instance.
1056:             */
1057:            public com.sun.jbi.StringTranslator getStringTranslator(
1058:                    String packageName, String componentId) {
1059:                ClassLoader cl = null;
1060:                StringTranslator translator = (StringTranslator) mStringTranslators
1061:                        .get(packageName);
1062:
1063:                if (null == translator) {
1064:                    // Try to get the classloader for the specified component ID. If
1065:                    // this fails, log an error, and use the default classloader for
1066:                    // attempting to load the resource bundle. The StringTranslator
1067:                    // constructor will log further diagnostics.
1068:
1069:                    try {
1070:                        cl = ClassLoaderFactory.getInstance()
1071:                                .getComponentClassLoader(componentId);
1072:                    } catch (javax.jbi.JBIException ex) {
1073:                        mLog
1074:                                .severe(mTranslator
1075:                                        .getString(
1076:                                                LocalStringKeys.EC_STRING_TRANSLATOR_CLASSLOADER_NOT_FOUND,
1077:                                                componentId, packageName, ex
1078:                                                        .getMessage()));
1079:                    }
1080:                    translator = new StringTranslator(packageName, cl);
1081:                    mStringTranslators.put(packageName, translator);
1082:                }
1083:
1084:                return (com.sun.jbi.StringTranslator) translator;
1085:            }
1086:
1087:            /**
1088:             * Get the StringTranslator for a specified object.
1089:             * @param object - an object in the package that contains the resource
1090:             * bundle to be used for this StringTranslator.
1091:             * @return The StringTranslator instance.
1092:             */
1093:            public com.sun.jbi.StringTranslator getStringTranslatorFor(
1094:                    Object object) {
1095:                return getStringTranslator(object.getClass().getPackage()
1096:                        .getName());
1097:            }
1098:
1099:            /**
1100:             * Get the Management Runtime Service handle.
1101:             * @return The ManagementRuntimeService instance.
1102:             */
1103:            public com.sun.jbi.management.facade.ManagementRuntimeService getMgmtRuntimeService() {
1104:                return mMgmtRuntimeService;
1105:            }
1106:
1107:            /**
1108:             * Get a TransactionManager from the AppServer.
1109:             * @return A TransactionManager instance.
1110:             */
1111:            public javax.transaction.TransactionManager getTransactionManager() {
1112:                if (null == mTransactionManager
1113:                        && !mTransactionManagerUnavailable) {
1114:                    try {
1115:                        mTransactionManager = mPlatformContext
1116:                                .getTransactionManager();
1117:                    } catch (Exception ex) {
1118:                        mTransactionManagerUnavailable = true;
1119:                        mLog
1120:                                .severe(mTranslator
1121:                                        .getString(
1122:                                                LocalStringKeys.EC_TRANSACTION_MANAGER_NOT_FOUND,
1123:                                                ex.getClass().getName()));
1124:                        mLog.severe(mTranslator.stackTraceToString(ex));
1125:                    }
1126:                }
1127:                return mTransactionManager;
1128:            }
1129:
1130:            /**
1131:             * Get the VersionInfo for this runtime.
1132:             * @return The VersionInfo instance.
1133:             */
1134:            public com.sun.jbi.VersionInfo getVersionInfo() {
1135:                return mVersionInfo;
1136:            }
1137:
1138:            /**
1139:             * Get a copy of the WSDL factory. This needs to be done before
1140:             * any reading, writing, or manipulation of WSDL documents can
1141:             * be performed using the WSDL API.
1142:             *
1143:             * @return An instance of the WSDL factory.
1144:             * @exception WsdlException If the factory cannot be instantiated.
1145:             */
1146:            public WsdlFactory getWsdlFactory() throws WsdlException {
1147:                return com.sun.jbi.wsdl2.impl.WsdlFactory.newInstance();
1148:            }
1149:
1150:            //*****************************************************************************
1151:            //***                                                                       ***
1152:            //*** Private methods                                                       ***
1153:            //***                                                                       ***
1154:            //*****************************************************************************
1155:
1156:            /**
1157:             * Create framework logger and initialize its log level.
1158:             * @param pkgName the name of the framework package to be used as the
1159:             * logger name.
1160:             */
1161:            private void createLogger(String pkgName) {
1162:                // Create the top-level JBI logger which is used primarily to provide
1163:                // a logger from which other loggers can inherit a default log level. 
1164:
1165:                mJbiLog = Logger.getLogger("com.sun.jbi");
1166:
1167:                // Create the logger for the framework. This logger will inherit the
1168:                // level from the top-level logger.
1169:
1170:                mLog = Logger.getLogger(pkgName);
1171:
1172:                // If no log level is set for the top-level logger, see if a level
1173:                // was provided through the initial properties.
1174:
1175:                if (null == mJbiLog.getLevel()) {
1176:                    // Validate the log level specified in the initial properties, if
1177:                    // available, and save it for access by the getDefaultLogLevel()
1178:                    // method. If the value is invalid or missing, use the hard-coded
1179:                    // default.
1180:                    String logLevelString = null;
1181:
1182:                    if (null != mInitialProperties) {
1183:                        logLevelString = mInitialProperties.getProperty(
1184:                                JBI_DEFAULT_LOG_LEVEL_KEY,
1185:                                JBI_DEFAULT_LOG_LEVEL_VALUE);
1186:                    } else {
1187:                        logLevelString = JBI_DEFAULT_LOG_LEVEL_VALUE;
1188:                    }
1189:                    try {
1190:                        mDefaultLogLevel = Level.parse(logLevelString);
1191:                    } catch (Exception e) {
1192:                        mLog.warning(mTranslator.getString(
1193:                                LocalStringKeys.EC_INVALID_LOG_LEVEL,
1194:                                logLevelString, Level.INFO.getName()));
1195:                        mDefaultLogLevel = Level.INFO;
1196:                    }
1197:                    mJbiLog.setLevel(mDefaultLogLevel);
1198:                } else {
1199:                    mDefaultLogLevel = mJbiLog.getLevel();
1200:                }
1201:                System.setProperty(JBI_DEFAULT_LOG_LEVEL_KEY, mDefaultLogLevel
1202:                        .getName());
1203:            }
1204:
1205:            /**
1206:             * Create framework MBeans.
1207:             */
1208:            private void createMBeans() {
1209:                // Create the framework logger MBean for the global JBI top-level
1210:                // logger.
1211:
1212:                try {
1213:                    com.sun.jbi.management.support.DefaultLoggerMBeanImpl logMBean = new com.sun.jbi.management.support.DefaultLoggerMBeanImpl(
1214:                            mJbiLog, "JBI default");
1215:                    sJbiLogMBeanName = registerMBean(logMBean,
1216:                            com.sun.jbi.management.common.LoggerMBean.class,
1217:                            MBeanNames.CONTROL_TYPE_LOGGER,
1218:                            MBeanNames.SERVICE_NAME_JBI, mJbiLog);
1219:                } catch (Exception ex) {
1220:                    mLog.severe(ex.getMessage());
1221:                    mLog.warning(mTranslator
1222:                            .getString(LocalStringKeys.EC_NO_LOGGER_MBEAN));
1223:                }
1224:
1225:                // Create the event notifier MBean
1226:                try {
1227:                    sNotifierMBeanName = registerMBean(mNotifier,
1228:                            EventNotifierMBean.class,
1229:                            MBeanNames.CONTROL_TYPE_NOTIFICATION);
1230:                    mNotifier.instanceStarting();
1231:                } catch (javax.jbi.JBIException ex) {
1232:                    mLog.severe(ex.getMessage());
1233:                    mLog
1234:                            .warning(mTranslator
1235:                                    .getString(LocalStringKeys.EC_NO_NOTIFICATION_MBEAN));
1236:                }
1237:
1238:                // Create the framework Statistics MBean
1239:                try {
1240:                    sStatsMBeanName = registerMBean(
1241:                            mFrameworkStatistics,
1242:                            com.sun.jbi.monitoring.FrameworkStatisticsMBean.class,
1243:                            MBeanNames.CONTROL_TYPE_STATISTICS);
1244:                } catch (javax.jbi.JBIException ex) {
1245:                    mLog.severe(ex.getMessage());
1246:                    mLog.warning(mTranslator
1247:                            .getString(LocalStringKeys.EC_NO_STATISTICS_MBEAN));
1248:                }
1249:
1250:            }
1251:
1252:            /**
1253:             * Create Logger MBean
1254:             */
1255:            public void createLoggerMBeans() {
1256:
1257:                /**
1258:                 * The logger for the Framework is the SystemServiceLoggerMBeanImpl
1259:                 * instance, this instance listens to changes in the log level from
1260:                 * the facade/instance Logger Configuration MBean. 
1261:                 */
1262:                try {
1263:                    com.sun.jbi.management.support.SystemServiceLoggerMBeanImpl logMBean = new com.sun.jbi.management.support.SystemServiceLoggerMBeanImpl(
1264:                            mLog, "Framework");
1265:                    sLogMBeanName = registerMBean(logMBean,
1266:                            com.sun.jbi.management.common.LoggerMBean.class,
1267:                            MBeanNames.CONTROL_TYPE_LOGGER,
1268:                            MBeanNames.SERVICE_NAME_FRAMEWORK, mLog);
1269:                } catch (Exception ex) {
1270:                    mLog.severe(ex.getMessage());
1271:                    mLog.warning(mTranslator
1272:                            .getString(LocalStringKeys.EC_NO_LOGGER_MBEAN));
1273:                }
1274:            }
1275:
1276:            /**
1277:             * Create and register an MBean with the main MBean Server if it is
1278:             * available.
1279:             * @param instance the MBean implementation instance.
1280:             * @param interfaceClass the interface implemented by the instance.
1281:             * @param mbeanType the type of MBean to be registered. The value of this
1282:             * is set using constants from the MBeanNames class.
1283:             * @return the MBean object name of the created MBean or null if no MBean
1284:             * server is available.
1285:             * @throws javax.jbi.JBIException if the MBean creation or registration
1286:             * fails.
1287:             */
1288:            private ObjectName registerMBean(Object instance,
1289:                    Class interfaceClass, String mbeanType)
1290:                    throws javax.jbi.JBIException {
1291:                return registerMBean(instance, interfaceClass, mbeanType, null,
1292:                        null);
1293:            }
1294:
1295:            /**
1296:             * Create and register an MBean with the main MBean Server if it is
1297:             * available.
1298:             * @param instance the MBean implementation instance.
1299:             * @param interfaceClass the interface implemented by the instance.
1300:             * @param mbeanType the type of MBean to be registered. The value of this
1301:             * is set using constants from the MBeanNames class.
1302:             * @param service the service name if a logger MBean is being registered,
1303:             * or null if not. This is to allow the top-level JBI logger and the
1304:             * framework logger to be registered separately.
1305:             * @param logger the Logger if a logger MBean is being registered, or null
1306:             * if not.
1307:             * @return the MBean object name of the created MBean or null if no MBean
1308:             * server is available.
1309:             * @throws javax.jbi.JBIException if the MBean creation or registration
1310:             * fails.
1311:             */
1312:            private ObjectName registerMBean(Object instance,
1313:                    Class interfaceClass, String mbeanType, String service,
1314:                    Logger logger) throws javax.jbi.JBIException {
1315:                // If there is no MBean Server available, give up.
1316:
1317:                if (null == getMBeanServer()) {
1318:                    return null;
1319:                }
1320:
1321:                mLog.finer("Registering framework " + mbeanType + " MBean");
1322:
1323:                // Create the MBean.
1324:
1325:                StandardMBean mbean = null;
1326:                try {
1327:                    /**
1328:                     * If the instance is a StandardMBean register the instance,
1329:                     * JMX introspection will expose the Management Interfaces.
1330:                     */
1331:                    if (instance instanceof  StandardMBean) {
1332:                        mbean = (StandardMBean) instance;
1333:                    } else {
1334:                        mbean = new StandardMBean(instance, interfaceClass);
1335:                    }
1336:                } catch (javax.management.NotCompliantMBeanException ncEx) {
1337:                    String exName = ncEx.getClass().getName();
1338:                    throw new javax.jbi.JBIException(mTranslator.getString(
1339:                            LocalStringKeys.EC_MBEAN_CREATION_FAILED, exName),
1340:                            ncEx);
1341:                }
1342:
1343:                // Create the MBean ObjectName using the MBean control type. Note
1344:                // the special treatment for logger MBeans.
1345:
1346:                ObjectName mbeanName = null;
1347:                if (mMBeanNames.CONTROL_TYPE_LOGGER == mbeanType) {
1348:                    mbeanName = mMBeanNames.getSystemServiceLoggerMBeanName(
1349:                            service, logger);
1350:                } else {
1351:                    mbeanName = mMBeanNames.getSystemServiceMBeanName(
1352:                            mMBeanNames.SERVICE_NAME_FRAMEWORK, mbeanType);
1353:                }
1354:                if (null == mbeanName) {
1355:                    String msg = mTranslator.getString(
1356:                            LocalStringKeys.EC_MBEAN_NAME_CREATION_FAILED,
1357:                            mMBeanNames.SERVICE_NAME_FRAMEWORK, mbeanType);
1358:                    throw new javax.jbi.JBIException(msg);
1359:                }
1360:
1361:                // Register the MBean. If it is already registered, unregister it
1362:                // first, as it is an old registration with a stale instance reference.
1363:
1364:                try {
1365:                    if (getMBeanServer().isRegistered(mbeanName)) {
1366:                        try {
1367:                            getMBeanServer().unregisterMBean(mbeanName);
1368:                        } catch (javax.management.InstanceNotFoundException infEx) {
1369:                            ; // Just ignore this error
1370:                        }
1371:                    }
1372:                    getMBeanServer().registerMBean(mbean, mbeanName);
1373:                } catch (javax.management.InstanceAlreadyExistsException iaeEx) {
1374:                    String exName = iaeEx.getClass().getName();
1375:                    throw new javax.jbi.JBIException(mTranslator.getString(
1376:                            LocalStringKeys.EC_MBEAN_REGISTRATION_FAILED,
1377:                            exName), iaeEx);
1378:                } catch (javax.management.MBeanRegistrationException mbrEx) {
1379:                    String exName = mbrEx.getClass().getName();
1380:                    throw new javax.jbi.JBIException(mTranslator.getString(
1381:                            LocalStringKeys.EC_MBEAN_REGISTRATION_FAILED,
1382:                            exName), mbrEx);
1383:                } catch (javax.management.NotCompliantMBeanException ncEx) {
1384:                    String exName = ncEx.getClass().getName();
1385:                    throw new javax.jbi.JBIException(mTranslator.getString(
1386:                            LocalStringKeys.EC_MBEAN_REGISTRATION_FAILED,
1387:                            exName), ncEx);
1388:                }
1389:                return mbeanName;
1390:            }
1391:
1392:            /**
1393:             * Unregister an MBean with the main MBean Server if it is available.
1394:             * @param mbeanName the MBean ObjectName.
1395:             */
1396:            private void unregisterMBean(ObjectName mbeanName) {
1397:                // If there is no MBean Server available, give up.
1398:
1399:                if (null == getMBeanServer()) {
1400:                    return;
1401:                }
1402:
1403:                mLog.finer("Unregistering framework MBean: " + mbeanName);
1404:
1405:                // Unregister the MBean. If it is already registered, unregister it
1406:                // first, as it is an old registration with a stale instance reference.
1407:
1408:                if (getMBeanServer().isRegistered(mbeanName)) {
1409:                    try {
1410:                        getMBeanServer().unregisterMBean(mbeanName);
1411:                    } catch (javax.management.InstanceNotFoundException infEx) {
1412:                        ; // Just ignore this error
1413:                    } catch (javax.management.MBeanRegistrationException mbrEx) {
1414:                        String exName = mbrEx.getClass().getName();
1415:                        mLog.warning(mTranslator.getString(
1416:                                LocalStringKeys.EC_MBEAN_UNREGISTRATION_FAILED,
1417:                                mbeanName, exName));
1418:                    }
1419:                }
1420:            }
1421:
1422:            /**
1423:             * This method is used to find out if start-on-deploy is enabled.
1424:             * When this is enabled components are started automatically when 
1425:             * there is deployment for them. 
1426:             * 
1427:             * By default start-on-deploy is enabled. 
1428:             *  
1429:             * @return true if startOnDeploy is enabled.
1430:             */
1431:            public boolean isStartOnDeployEnabled() {
1432:
1433:                boolean startOnDeploy = true;
1434:
1435:                Object value = getConfigurationAttribute(
1436:                        ConfigurationCategory.Deployment,
1437:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.START_ON_DEPLOY);
1438:
1439:                if (value != null) {
1440:                    startOnDeploy = (Boolean) value;
1441:                }
1442:
1443:                return startOnDeploy;
1444:            }
1445:
1446:            /**
1447:             * This method is used to find out if startOnVerify is enabled.
1448:             * When this is enabled components are started automatically when 
1449:             * an application has to be verified for them. 
1450:             * 
1451:             * By default startOnVerify is enabled. 
1452:             *  
1453:             * @return true if startOnVerify is enabled.
1454:             */
1455:            public boolean isStartOnVerifyEnabled() {
1456:
1457:                boolean startOnVerify = true;
1458:
1459:                Object value = getConfigurationAttribute(
1460:                        ConfigurationCategory.Deployment,
1461:                        com.sun.jbi.management.config.DeploymentConfigurationFactory.START_ON_VERIFY);
1462:
1463:                if (value != null) {
1464:                    startOnVerify = (Boolean) value;
1465:                }
1466:
1467:                return startOnVerify;
1468:            }
1469:
1470:            /**
1471:             * Get the value of a configuration attribute
1472:             *
1473:             * @param category - configuration category the attribute is defined in
1474:             * @param attrName - name of the attribute
1475:             * @return the value of the requested configuration attribute
1476:             */
1477:            private Object getConfigurationAttribute(
1478:                    ConfigurationCategory category, String attrName) {
1479:                MBeanNames.ServiceType svcType = MBeanNames.ServiceType
1480:                        .valueOf(category.toString());
1481:
1482:                ObjectName configMBeanName = mMBeanNames
1483:                        .getSystemServiceMBeanName(
1484:                                MBeanNames.SERVICE_NAME_CONFIG_SERVICE,
1485:                                ConfigurationBuilder.getControlType(svcType));
1486:
1487:                Object attrValue = null;
1488:                try {
1489:                    if (mMBeanServer.isRegistered(configMBeanName)) {
1490:                        attrValue = mMBeanServer.getAttribute(configMBeanName,
1491:                                attrName);
1492:                    }
1493:                } catch (javax.management.JMException jmex) {
1494:                    mLog.warning(jmex.getMessage());
1495:                }
1496:                return attrValue;
1497:            }
1498:
1499:            /**
1500:             * Set the value of a configuration attribute.
1501:             *
1502:             * @param category - configuration category the attribute is defined in
1503:             * @param attrName - name of the attribute
1504:             * @param attrValue - value of the attribute
1505:             */
1506:            private void setConfigurationAttribute(
1507:                    ConfigurationCategory category, String attrName,
1508:                    Object attrValue) {
1509:
1510:                MBeanNames.ServiceType svcType = MBeanNames.ServiceType
1511:                        .valueOf(category.toString());
1512:
1513:                ObjectName configMBeanName = getMBeanNames()
1514:                        .getSystemServiceMBeanName(
1515:                                MBeanNames.SERVICE_NAME_CONFIG_SERVICE,
1516:                                ConfigurationBuilder.getControlType(svcType));
1517:
1518:                try {
1519:                    javax.management.Attribute attribute = new javax.management.Attribute(
1520:                            attrName, attrValue);
1521:                    mMBeanServer.setAttribute(configMBeanName, attribute);
1522:                } catch (javax.management.JMException jmex) {
1523:                    mLog.warning(jmex.getMessage());
1524:                }
1525:            }
1526:
1527:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.