Source Code Cross Referenced for ComponentConfiguration.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:         * @(#)ComponentConfiguration.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.management.ComponentInfo.Variable;
0032:        import com.sun.jbi.management.descriptor.ComponentDescriptor;
0033:        import com.sun.jbi.management.system.ManagementException;
0034:        import com.sun.jbi.management.message.MessageBuilder;
0035:        import com.sun.jbi.management.message.MessageHelper;
0036:        import com.sun.jbi.management.registry.Registry;
0037:        import com.sun.jbi.management.registry.xml.RegistryDocument;
0038:        import com.sun.jbi.management.repository.Archive;
0039:        import com.sun.jbi.management.repository.ArchiveType;
0040:        import com.sun.jbi.util.ComponentConfigurationHelper;
0041:        import java.io.InputStream;
0042:        import java.io.StringBufferInputStream;
0043:
0044:        import java.util.Map;
0045:        import java.util.Properties;
0046:        import java.util.Set;
0047:        import java.util.logging.Logger;
0048:        import java.lang.reflect.Method;
0049:        import javax.management.Attribute;
0050:        import javax.management.AttributeList;
0051:        import javax.management.ObjectName;
0052:        import javax.management.AttributeNotFoundException;
0053:        import javax.management.InvalidAttributeValueException;
0054:        import javax.management.MBeanException;
0055:        import javax.management.MBeanInfo;
0056:        import javax.management.MBeanAttributeInfo;
0057:        import javax.management.MBeanOperationInfo;
0058:        import javax.management.MBeanConstructorInfo;
0059:        import javax.management.MBeanNotificationInfo;
0060:        import javax.management.MBeanParameterInfo;
0061:        import javax.management.ReflectionException;
0062:        import javax.management.openmbean.CompositeData;
0063:        import javax.management.openmbean.CompositeDataSupport;
0064:        import javax.management.openmbean.CompositeType;
0065:        import javax.management.openmbean.TabularData;
0066:        import javax.management.openmbean.TabularDataSupport;
0067:        import javax.management.openmbean.TabularType;
0068:        import javax.management.openmbean.OpenDataException;
0069:        import javax.xml.parsers.DocumentBuilder;
0070:        import javax.xml.parsers.DocumentBuilderFactory;
0071:        import org.w3c.dom.Document;
0072:
0073:        /**
0074:         * The ComponentConfiguration is a dynamic facade MBean for component configuration.
0075:         * This MBean provides a facade for managing component static, variable and
0076:         * named configuration.
0077:         *
0078:         * This ComponentExtension MBean is registered for each installation of the component
0079:         * on a target i.e it is target specific. 
0080:         *
0081:         * @author Sun Microsystems, Inc.
0082:         */
0083:        public class ComponentConfiguration implements 
0084:                com.sun.jbi.management.ComponentConfiguration {
0085:            /** The component name */
0086:            private String mComponentName;
0087:
0088:            /** The context */
0089:            private EnvironmentContext mEnvCtx;
0090:
0091:            /** The MessageBuilder */
0092:            private MessageBuilder mMsgBuilder;
0093:
0094:            /** String Translator */
0095:            private StringTranslator mTranslator;
0096:
0097:            /** The Logger */
0098:            private Logger mLog;
0099:
0100:            /** "*****" */
0101:            private static final String MASKED_FIELD_VALUE = "*****";
0102:
0103:            /** PASSWORD Field */
0104:            private static final String PASSWORD = "PASSWORD";
0105:
0106:            /** Component Configuration Helper */
0107:            private ComponentConfigurationHelper mCfgHlpr;
0108:
0109:            public ComponentConfiguration(EnvironmentContext ctx,
0110:                    String compName) {
0111:                mComponentName = compName;
0112:                mEnvCtx = ctx;
0113:                mTranslator = (StringTranslator) mEnvCtx
0114:                        .getStringTranslatorFor(this );
0115:                mLog = mEnvCtx.getLogger();
0116:                mCfgHlpr = new ComponentConfigurationHelper();
0117:                try {
0118:                    mMsgBuilder = new MessageBuilder(mTranslator);
0119:                } catch (com.sun.jbi.management.system.ManagementException mex) {
0120:                    // rare
0121:                    mLog.warning(mex.getMessage());
0122:                }
0123:            }
0124:
0125:            /*----------------------------------------------------------------------------------*\
0126:             *                   javax.management.DynamicMBean Methods                          *
0127:            \*----------------------------------------------------------------------------------*/
0128:
0129:            /**
0130:             * Obtain the value of a specific attribute of the Dynamic MBean.
0131:             *
0132:             * @param attribute The name of the attribute to be retrieved
0133:             * @return The value of the attribute retrieved.
0134:             * @exception AttributeNotFoundException
0135:             * @exception MBeanException  Wraps a <CODE>java.lang.Exception</CODE> 
0136:             *           thrown by the MBean's getter.
0137:             * @exception ReflectionException  Wraps a <CODE>java.lang.Exception</CODE>
0138:             *            thrown while trying to invoke the getter.
0139:             * @see #setAttribute
0140:             */
0141:            public Object getAttribute(String attribute)
0142:                    throws AttributeNotFoundException, MBeanException,
0143:                    ReflectionException {
0144:                /**
0145:                 * This gets the attribute from the registry, converts the String to
0146:                 * the attribute type and then returns it. 
0147:                 * 
0148:                 * Note : Special case handling is required for Environment Variables, since
0149:                 *        those are TabularData. For Milestone 2 ignore getEnvironmentVariables
0150:                 *
0151:                 */
0152:
0153:                if ("ApplicationVariables".equals(attribute)) {
0154:                    return getApplicationVariables();
0155:                }
0156:
0157:                if ("ApplicationConfigurations".equals(attribute)) {
0158:                    return getApplicationConfigurations();
0159:                }
0160:
0161:                AttributeList attribList = getAttributes(new String[] { attribute });
0162:
0163:                if (!attribList.isEmpty()) {
0164:                    return ((Attribute) attribList.get(0)).getValue();
0165:                } else {
0166:                    throw new AttributeNotFoundException(attribute);
0167:                }
0168:
0169:            }
0170:
0171:            /**
0172:             * Set the value of a specific attribute of the Dynamic MBean.
0173:             * 
0174:             * @param attribute The identification of the attribute to
0175:             *        be set and  the value it is to be set to.
0176:             * @exception AttributeNotFoundException
0177:             * @exception InvalidAttributeValueException
0178:             * @exception MBeanException Wraps a <CODE>java.lang.Exception</CODE> 
0179:             *           thrown by the MBean's setter.
0180:             * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> 
0181:             *           thrown while trying to invoke the MBean's setter.
0182:             * @see #getAttribute
0183:             */
0184:            public void setAttribute(Attribute attribute)
0185:                    throws AttributeNotFoundException,
0186:                    InvalidAttributeValueException, MBeanException,
0187:                    ReflectionException {
0188:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0189:
0190:                if (configMBeanName == null) {
0191:                    throw new RuntimeException(
0192:                            mTranslator
0193:                                    .getString(
0194:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0195:                                            mComponentName));
0196:                }
0197:
0198:                /**
0199:                 * This first invokes setAttribute on the original configuration MBean and
0200:                 * then updates the registry for the attributes set successfully.
0201:                 */
0202:                try {
0203:                    mEnvCtx.getMBeanServer().setAttribute(configMBeanName,
0204:                            attribute);
0205:                } catch (javax.management.InstanceNotFoundException iex) {
0206:                    throw new MBeanException(iex);
0207:                }
0208:
0209:                // Update the registry
0210:                persistAttribute(attribute);
0211:
0212:            }
0213:
0214:            /**
0215:             * Allows an action to be invoked on the Dynamic MBean.
0216:             * 
0217:             * @param actionName The name of the action to be invoked.
0218:             * @param params An array containing the parameters to be set when the 
0219:             *        action is invoked.
0220:             * @param signature An array containing the signature of the action. The 
0221:             *        class objects will be loaded through the same class loader as the
0222:             *        one used for loading the MBean on which the action is invoked.
0223:             * @return The object returned by the action, which represents the result of
0224:             *         invoking the action on the MBean specified.
0225:             * @exception MBeanException  Wraps a <CODE>java.lang.Exception</CODE> thrown
0226:             *            by the MBean's invoked method.
0227:             * @exception ReflectionException  Wraps a <CODE>java.lang.Exception</CODE> 
0228:             *            thrown while trying to invoke the method
0229:             */
0230:            public Object invoke(String actionName, Object[] params,
0231:                    String[] signature) throws MBeanException,
0232:                    ReflectionException {
0233:
0234:                if (actionName.equals("addApplicationVariable")) {
0235:                    return addApplicationVariable((String) params[0],
0236:                            (CompositeData) params[1]);
0237:                }
0238:                if (actionName.equals("setApplicationVariable")) {
0239:                    return setApplicationVariable((String) params[0],
0240:                            (CompositeData) params[1]);
0241:                }
0242:
0243:                if (actionName.equals("deleteApplicationVariable")) {
0244:                    return deleteApplicationVariable((String) params[0]);
0245:                }
0246:
0247:                if (actionName.equals("getApplicationVariables")) {
0248:                    return getApplicationVariables();
0249:                }
0250:
0251:                if (actionName.equals("getApplicationConfigurations")) {
0252:                    return getApplicationConfigurations();
0253:                }
0254:
0255:                if (actionName.equals("addApplicationConfiguration")) {
0256:                    if (params[1] instanceof  Properties) {
0257:                        return addApplicationConfiguration((String) params[0],
0258:                                (Properties) params[1]);
0259:                    } else {
0260:                        return addApplicationConfiguration((String) params[0],
0261:                                (CompositeData) params[1]);
0262:                    }
0263:                }
0264:
0265:                if (actionName.equals("setApplicationConfiguration")) {
0266:                    if (params[1] instanceof  Properties) {
0267:                        return setApplicationConfiguration((String) params[0],
0268:                                (Properties) params[1]);
0269:                    } else {
0270:                        return setApplicationConfiguration((String) params[0],
0271:                                (CompositeData) params[1]);
0272:                    }
0273:                }
0274:
0275:                if (actionName.equals("deleteApplicationConfiguration")) {
0276:                    return deleteApplicationConfiguration((String) params[0]);
0277:                }
0278:
0279:                if (actionName.equals("queryApplicationConfigurationType")) {
0280:                    return queryApplicationConfigurationType();
0281:                }
0282:
0283:                if (actionName.equals("retrieveConfigurationDisplaySchema")) {
0284:                    return retrieveConfigurationDisplaySchema();
0285:                }
0286:
0287:                if (actionName.equals("retrieveConfigurationDisplayData")) {
0288:                    return retrieveConfigurationDisplayData();
0289:                }
0290:
0291:                if (actionName.equals("isAppVarsSupported")) {
0292:                    return isAppVarsSupported();
0293:                }
0294:
0295:                if (actionName.equals("isAppConfigSupported")) {
0296:                    return isAppConfigSupported();
0297:                }
0298:
0299:                if (actionName.equals("isComponentConfigSupported")) {
0300:                    return isComponentConfigSupported();
0301:                }
0302:
0303:                throw new UnsupportedOperationException(actionName);
0304:            }
0305:
0306:            /**
0307:             * Sets the values of several attributes of the Dynamic MBean.
0308:             * 
0309:             * @param attributes A list of attributes: The identification of the
0310:             *        attributes to be set and  the values they are to be set to.
0311:             * @return The list of attributes that were set, with their new values.
0312:             * @see #getAttributes
0313:             */
0314:            public AttributeList setAttributes(AttributeList attributes) {
0315:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0316:
0317:                if (configMBeanName == null) {
0318:                    throw new RuntimeException(
0319:                            mTranslator
0320:                                    .getString(
0321:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0322:                                            mComponentName));
0323:                }
0324:                /**
0325:                 * This first invokes setAttribute on the original configuration MBean and
0326:                 * then updates the registry for the attributes set successfully.
0327:                 */
0328:                AttributeList attribs = new AttributeList();
0329:                try {
0330:                    attribs = (AttributeList) mEnvCtx.getMBeanServer()
0331:                            .setAttributes(configMBeanName, attributes);
0332:                } catch (Exception iex) {
0333:                    throw new RuntimeException(iex);
0334:                }
0335:
0336:                // Parse the attribute list and update the registry with the set attributes
0337:                persistAttributes(attribs);
0338:
0339:                return attribs;
0340:            }
0341:
0342:            /**
0343:             * Provides the exposed attributes and actions of the Dynamic MBean using 
0344:             * an MBeanInfo object.
0345:             * 
0346:             * @return An instance of <CODE>MBeanInfo</CODE> allowing all attributes 
0347:             *         and actions exposed by this Dynamic MBean to be retrieved.
0348:             */
0349:            public MBeanInfo getMBeanInfo() {
0350:                // Get the MbeanInfo from the actual component configuration MBean and
0351:                // augment it with the facade configuration operations
0352:                MBeanInfo mbeanInfo = getComponentMBeanInfo();
0353:                MBeanInfo augInfo = mbeanInfo;
0354:
0355:                try {
0356:                    Method[] methods = Class.forName(
0357:                            "com.sun.jbi.management.ComponentConfiguration")
0358:                            .getDeclaredMethods();
0359:                    MBeanOperationInfo[] opInfos = new MBeanOperationInfo[methods.length];
0360:                    int i = 0;
0361:                    for (Method mtd : methods) {
0362:                        opInfos[i++] = new MBeanOperationInfo(mtd.getName(),
0363:                                mtd);
0364:                    }
0365:
0366:                    augInfo = new MBeanInfo(mbeanInfo.getClassName(), mbeanInfo
0367:                            .getDescription(), mbeanInfo.getAttributes(),
0368:                            mbeanInfo.getConstructors(), merge(mbeanInfo
0369:                                    .getOperations(), opInfos), mbeanInfo
0370:                                    .getNotifications());
0371:                } catch (Exception ex) {
0372:                    // log exception
0373:                    mLog.log(java.util.logging.Level.FINEST, ex.getMessage(),
0374:                            ex);
0375:                }
0376:
0377:                return augInfo;
0378:            }
0379:
0380:            /**
0381:             * Get the values of several attributes of the Dynamic MBean.
0382:             * 
0383:             * @param attributes A list of the attributes to be retrieved.
0384:             * @return The list of attributes retrieved.
0385:             * @see #setAttributes
0386:             */
0387:            public AttributeList getAttributes(String[] attributes) {
0388:                /**
0389:                 * If the framework is ready ( i.e. JAXB initialized ) get the attribute from
0390:                 * the JAXB model
0391:                 *
0392:                 * If framework not ready then get the attribute from the registry using DOM/XPath
0393:                 *
0394:                 * If the attribute is not defined in the registry get the attribute values from
0395:                 * the actual MBean and persist it.
0396:                 */
0397:
0398:                Properties props = retrieveAttributes();
0399:
0400:                if (!props.isEmpty()) {
0401:                    AttributeList list = new AttributeList(props.size());
0402:
0403:                    for (String key : attributes) {
0404:                        MBeanAttributeInfo attribInfo = getAttributeInfo(key);
0405:                        String strValue = props.getProperty(key);
0406:                        if (strValue != null) {
0407:                            if (attribInfo != null) {
0408:                                try {
0409:                                    Object value = (Object) com.sun.jbi.management.util.StringHelper
0410:                                            .convertStringToType(attribInfo
0411:                                                    .getType(), strValue);
0412:                                    list.add(new Attribute(key, value));
0413:                                } catch (Exception ex) {
0414:                                    mLog
0415:                                            .warning(MessageHelper
0416:                                                    .getMsgString(ex));
0417:                                    list.add(new Attribute(key, strValue));
0418:                                }
0419:
0420:                            } else {
0421:                                list.add(new Attribute(key, strValue));
0422:                            }
0423:                        }
0424:                    }
0425:                    return list;
0426:                }
0427:
0428:                // -- Call getAttributes on the actual MBean
0429:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0430:
0431:                if (configMBeanName != null) {
0432:                    if (mEnvCtx.getMBeanServer().isRegistered(configMBeanName)) {
0433:                        try {
0434:                            AttributeList attribList = mEnvCtx.getMBeanServer()
0435:                                    .getAttributes(configMBeanName, attributes);
0436:
0437:                            // persist all the attributes
0438:                            persistMBeanAttributes(configMBeanName);
0439:                            return attribList;
0440:                        } catch (javax.management.JMException iex) {
0441:                            mLog.warning(iex.getMessage());
0442:                            // -- should never occur
0443:                        }
0444:
0445:                    }
0446:                }
0447:
0448:                // Instance config MBean not available and attributes not persisted
0449:                return new AttributeList();
0450:            }
0451:
0452:            /*---------------------------------------------------------------------------------*\
0453:             *          Operations for Static Configuration Management                         *
0454:            \*---------------------------------------------------------------------------------*/
0455:            /**
0456:             * Set a single configuration attribute on a target.
0457:             *
0458:             * @param attrib - the configuration attribute to be set.
0459:             * @return a management message string with the status of the operation.
0460:             */
0461:            public String setConfigurationAttribute(Attribute attrib)
0462:                    throws javax.jbi.JBIException {
0463:                throw new UnsupportedOperationException();
0464:            }
0465:
0466:            /**
0467:             *
0468:             */
0469:            public String setConfigurationAttributes(AttributeList attribList)
0470:                    throws javax.jbi.JBIException {
0471:                throw new UnsupportedOperationException();
0472:            }
0473:
0474:            /**
0475:             * Detect the components support for component configuration. This method
0476:             * returns true if the component has a configuration MBean with
0477:             * configuration attributes.
0478:             *
0479:             * @return true if the components configuration MBean has configuration
0480:             *         attributes.
0481:             * @throws MBeanException if the component is not installed or is not 
0482:             *         in the Started state.
0483:             * 
0484:             */
0485:            public boolean isComponentConfigSupported() throws MBeanException {
0486:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0487:                if (configMBeanName == null) {
0488:                    // Component does not register a component configuration MBean
0489:                    return false;
0490:                }
0491:
0492:                MBeanInfo mbnInfo = getComponentMBeanInfo();
0493:
0494:                MBeanAttributeInfo[] attrInfos = mbnInfo.getAttributes();
0495:
0496:                int realAttrCount = 0;
0497:
0498:                for (MBeanAttributeInfo attrInfo : attrInfos) {
0499:                    if (!"ApplicationVariables".equals(attrInfo.getName())
0500:                            && !"ApplicationConfigurations".equals(attrInfo
0501:                                    .getName()) && attrInfo.isReadable()
0502:                            && attrInfo.isWritable()) {
0503:                        realAttrCount++;
0504:                    }
0505:                }
0506:
0507:                return (realAttrCount > 0);
0508:
0509:            }
0510:
0511:            /*---------------------------------------------------------------------------------*\
0512:             *          Operations for Application Variables Management                        *
0513:            \*---------------------------------------------------------------------------------*/
0514:
0515:            /**
0516:             * Detect the components support for application variables. This method
0517:             * returns true if the component has a configuration MBean and implements 
0518:             * all the operations for application variable management.
0519:             *
0520:             * @return true if the components configuration MBean implements all the
0521:             *         operations for application variables.
0522:             * @throws MBeanException if the component is not installed or is not 
0523:             *         in the Started state.
0524:             * 
0525:             */
0526:            public boolean isAppVarsSupported() throws MBeanException {
0527:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0528:                if (configMBeanName == null) {
0529:                    // Component does not register a component configuration MBean
0530:                    return false;
0531:                }
0532:
0533:                MBeanInfo mbnInfo = getComponentMBeanInfo();
0534:
0535:                MBeanOperationInfo[] opInfos = mbnInfo.getOperations();
0536:
0537:                int numOpsSupported = 0;
0538:                for (MBeanOperationInfo opInfo : opInfos) {
0539:                    if (opInfo.getName().equals("addApplicationVariable")) {
0540:                        MBeanParameterInfo[] params = opInfo.getSignature();
0541:
0542:                        if (params.length == 2) {
0543:                            if (params[0].getType().equals("java.lang.String")
0544:                                    && params[1]
0545:                                            .getType()
0546:                                            .equals(
0547:                                                    "javax.management.openmbean.CompositeData")) {
0548:                                numOpsSupported++;
0549:                            }
0550:                        }
0551:                    } else if (opInfo.getName()
0552:                            .equals("setApplicationVariable")) {
0553:                        MBeanParameterInfo[] params = opInfo.getSignature();
0554:
0555:                        if (params.length == 2) {
0556:                            if (params[0].getType().equals("java.lang.String")
0557:                                    && params[1]
0558:                                            .getType()
0559:                                            .equals(
0560:                                                    "javax.management.openmbean.CompositeData")) {
0561:                                numOpsSupported++;
0562:                            }
0563:                        }
0564:                    } else if (opInfo.getName().equals(
0565:                            "deleteApplicationVariable")) {
0566:                        MBeanParameterInfo[] params = opInfo.getSignature();
0567:
0568:                        if (params.length == 1) {
0569:                            if (params[0].getType().equals("java.lang.String")) {
0570:                                numOpsSupported++;
0571:                            }
0572:                        }
0573:                    }
0574:                }
0575:
0576:                boolean isAppVarsAttribSupported = false;
0577:                MBeanAttributeInfo[] attrInfos = mbnInfo.getAttributes();
0578:
0579:                for (MBeanAttributeInfo attrInfo : attrInfos) {
0580:                    // -- Check if "ApplicationConfigurations" attribute is present
0581:                    if (attrInfo.getName().equals("ApplicationVariables")) {
0582:                        isAppVarsAttribSupported = true;
0583:                    }
0584:                }
0585:
0586:                return (numOpsSupported == 3 && isAppVarsAttribSupported);
0587:            }
0588:
0589:            /**
0590:             * This operation adds a new application variable. If a variable already exists with 
0591:             * the same name as that specified then the operation fails.
0592:             * 
0593:             * @param name - name of the application variable
0594:             * @param appVar - this is the application variable compoiste
0595:             * @throws MBeanException if an error occurs in adding the application variables to the 
0596:             *         component. 
0597:             * @return management message string which gives the status of the operation. For 
0598:             *         target=cluster, instance specific details are included. 
0599:             */
0600:            public String addApplicationVariable(String name,
0601:                    CompositeData appVar) throws MBeanException {
0602:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0603:                String response = null;
0604:
0605:                if (configMBeanName == null) {
0606:                    throw new RuntimeException(
0607:                            mTranslator
0608:                                    .getString(
0609:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0610:                                            mComponentName));
0611:                }
0612:
0613:                // If the application variables element in the registry is empty
0614:                // get the application variables from the actual MBean and persist them.
0615:                persistApplicationVariables(configMBeanName);
0616:
0617:                /**
0618:                 * This first invokes addApplicationVariable on the original configuration MBean and
0619:                 * then updates the registry for the attributes set successfully.
0620:                 */
0621:                try {
0622:                    Object[] params = new Object[] { name, appVar };
0623:                    String[] sign = new String[] { "java.lang.String",
0624:                            "javax.management.openmbean.CompositeData" };
0625:                    operationSupportedCheck(configMBeanName,
0626:                            "addApplicationVariable", sign);
0627:
0628:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
0629:                            "addApplicationVariable", params, sign);
0630:
0631:                    // Update the registry
0632:                    addApplicationVariable(appVar);
0633:
0634:                    response = mMsgBuilder.buildFrameworkMessage(
0635:                            "addApplicationVariable",
0636:                            MessageBuilder.TaskResult.SUCCESS);
0637:
0638:                } catch (Exception iex) {
0639:                    try {
0640:                        response = mMsgBuilder.buildExceptionMessage(
0641:                                "addApplicationVariable", iex);
0642:                    } catch (ManagementException mex) {
0643:                        mLog.warning(MessageHelper.getMsgString(mex));
0644:                        throw new MBeanException(
0645:                                new Exception(mex.getMessage()));
0646:                    }
0647:                }
0648:                return response;
0649:            }
0650:
0651:            /**
0652:             * This operation sets an application variable. If a variable does not exist with 
0653:             * the same name, its an error.
0654:             * 
0655:             * @param name - name of the application variable
0656:             * @param appVar - this is the application variable compoiste to be updated.
0657:             * @throws MBeanException if one or more application variables cannot be deleted
0658:             * @return management message string which gives the status of the operation. For 
0659:             *         target=cluster, instance specific details are included. 
0660:             */
0661:            public String setApplicationVariable(String name,
0662:                    CompositeData appVar) throws MBeanException {
0663:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0664:                String response = null;
0665:
0666:                if (configMBeanName == null) {
0667:                    throw new RuntimeException(
0668:                            mTranslator
0669:                                    .getString(
0670:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0671:                                            mComponentName));
0672:                }
0673:
0674:                // If the application variables element in the registry is empty
0675:                // get the application variables from the actual MBean and persist them.
0676:                persistApplicationVariables(configMBeanName);
0677:
0678:                /**
0679:                 * This first invokes setApplicationVariable on the original configuration MBean and
0680:                 * then updates the registry for the attributes set successfully.
0681:                 */
0682:                try {
0683:                    Object[] params = new Object[] { name, appVar };
0684:                    String[] sign = new String[] { "java.lang.String",
0685:                            "javax.management.openmbean.CompositeData" };
0686:                    operationSupportedCheck(configMBeanName,
0687:                            "setApplicationVariable", sign);
0688:
0689:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
0690:                            "setApplicationVariable", params, sign);
0691:
0692:                    // Update the registry
0693:                    updateApplicationVariable(appVar);
0694:
0695:                    response = mMsgBuilder.buildFrameworkMessage(
0696:                            "setApplicationVariable",
0697:                            MessageBuilder.TaskResult.SUCCESS);
0698:
0699:                } catch (Exception iex) {
0700:                    try {
0701:                        response = mMsgBuilder.buildExceptionMessage(
0702:                                "setApplicationVariable", iex);
0703:                    } catch (ManagementException mex) {
0704:                        mLog.warning(MessageHelper.getMsgString(mex));
0705:                        throw new MBeanException(
0706:                                new Exception(mex.getMessage()));
0707:                    }
0708:                }
0709:                return response;
0710:
0711:            }
0712:
0713:            /**
0714:             * This operation deletes an application variable, if a variable with the specified name does
0715:             * not exist, it's an error.
0716:             *
0717:             * @param name - name of the application variable
0718:             * @throws MBeanException on errors.
0719:             * @return management message string which gives the status of the operation. For 
0720:             *         target=cluster, instance specific details are included. 
0721:             */
0722:            public String deleteApplicationVariable(String name)
0723:                    throws MBeanException {
0724:
0725:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0726:                String response = null;
0727:
0728:                if (configMBeanName == null) {
0729:                    throw new RuntimeException(
0730:                            mTranslator
0731:                                    .getString(
0732:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0733:                                            mComponentName));
0734:                }
0735:
0736:                // If the application variables element in the registry is empty
0737:                // get the application variables from the actual MBean and persist them.
0738:                persistApplicationVariables(configMBeanName);
0739:
0740:                /**
0741:                 * This first invokes deleteApplicationVariable on the original configuration 
0742:                 * MBean and then updates the registry for the attributes set successfully.
0743:                 */
0744:                try {
0745:                    Object[] params = new Object[] { name };
0746:                    String[] sign = new String[] { "java.lang.String" };
0747:                    operationSupportedCheck(configMBeanName,
0748:                            "deleteApplicationVariable", sign);
0749:
0750:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
0751:                            "deleteApplicationVariable", params, sign);
0752:
0753:                    // Update the registry
0754:                    removeApplicationVariable(name);
0755:
0756:                    response = mMsgBuilder.buildFrameworkMessage(
0757:                            "deleteApplicationVariable",
0758:                            MessageBuilder.TaskResult.SUCCESS);
0759:
0760:                } catch (Exception iex) {
0761:                    try {
0762:                        response = mMsgBuilder.buildExceptionMessage(
0763:                                "deleteApplicationVariable", iex);
0764:                    } catch (ManagementException mex) {
0765:                        mLog.warning(MessageHelper.getMsgString(mex));
0766:                        throw new MBeanException(
0767:                                new Exception(mex.getMessage()));
0768:                    }
0769:                }
0770:                return response;
0771:            }
0772:
0773:            /**
0774:             * Get the Application Variable set for a component.
0775:             *
0776:             * @return  a TabularData which has all the applicationvariables set on the component. 
0777:             */
0778:            public TabularData getApplicationVariables() {
0779:
0780:                /**
0781:                 * If framework not ready then get the application variable from the registry 
0782:                 * using DOM.
0783:                 *
0784:                 * If the framework is ready ( i.e. JAXB initialized ) get the application variable 
0785:                 *  from the JAXB model
0786:                 *
0787:                 * If the registry component configuration / application variables is empty get the 
0788:                 * actual values from the MBean.
0789:                 */
0790:
0791:                TabularData appVars = retrieveApplicationVariables();
0792:
0793:                if (appVars.isEmpty()) {
0794:                    // -- Call getAttributes on the actual MBean, the application variables might not
0795:                    //    have been persisted
0796:
0797:                    ObjectName configMBeanName = getComponentConfigurationMBeanName();
0798:
0799:                    if (configMBeanName != null) {
0800:                        if (mEnvCtx.getMBeanServer().isRegistered(
0801:                                configMBeanName)) {
0802:                            try {
0803:                                appVars = (TabularData) mEnvCtx
0804:                                        .getMBeanServer().getAttribute(
0805:                                                configMBeanName,
0806:                                                "ApplicationVariables");
0807:                            } catch (javax.management.JMException iex) {
0808:                                mLog.warning(iex.toString());
0809:                                // -- should never occur
0810:                            }
0811:
0812:                        }
0813:                    }
0814:                }
0815:                return appVars;
0816:            }
0817:
0818:            /*---------------------------------------------------------------------------------*\
0819:             *            Operations for Application Configuration Management                  *
0820:            \*---------------------------------------------------------------------------------*/
0821:
0822:            /**
0823:             * Detect the components support for application configuration. This method
0824:             * returns true if the component has a configuration MBean and implements 
0825:             * all the operations for application configuration management.
0826:             *
0827:             * @return true if the components configuration MBean implements all the
0828:             *         operations for application configuration.
0829:             * @throws MBeanException if the component is not installed or is not 
0830:             *         in the Started state.
0831:             * 
0832:             */
0833:            public boolean isAppConfigSupported() throws MBeanException {
0834:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0835:                if (configMBeanName == null) {
0836:                    return false;
0837:                }
0838:
0839:                MBeanInfo mbnInfo = getComponentMBeanInfo();
0840:
0841:                MBeanOperationInfo[] opInfos = mbnInfo.getOperations();
0842:
0843:                int numOpsSupported = 0;
0844:                for (MBeanOperationInfo opInfo : opInfos) {
0845:                    if (opInfo.getName().equals("addApplicationConfiguration")) {
0846:                        MBeanParameterInfo[] params = opInfo.getSignature();
0847:
0848:                        if (params.length == 2) {
0849:                            if (params[0].getType().equals("java.lang.String")
0850:                                    && params[1]
0851:                                            .getType()
0852:                                            .equals(
0853:                                                    "javax.management.openmbean.CompositeData")) {
0854:                                numOpsSupported++;
0855:                            }
0856:                        }
0857:                    } else if (opInfo.getName().equals(
0858:                            "setApplicationConfiguration")) {
0859:                        MBeanParameterInfo[] params = opInfo.getSignature();
0860:
0861:                        if (params.length == 2) {
0862:                            if (params[0].getType().equals("java.lang.String")
0863:                                    && params[1]
0864:                                            .getType()
0865:                                            .equals(
0866:                                                    "javax.management.openmbean.CompositeData")) {
0867:                                numOpsSupported++;
0868:                            }
0869:                        }
0870:                    } else if (opInfo.getName().equals(
0871:                            "deleteApplicationConfiguration")) {
0872:                        MBeanParameterInfo[] params = opInfo.getSignature();
0873:
0874:                        if (params.length == 1) {
0875:                            if (params[0].getType().equals("java.lang.String")) {
0876:                                numOpsSupported++;
0877:                            }
0878:                        }
0879:                    } else if (opInfo.getName().equals(
0880:                            "queryApplicationConfigurationType")) {
0881:                        MBeanParameterInfo[] params = opInfo.getSignature();
0882:
0883:                        if (params.length == 0) {
0884:                            String returnType = opInfo.getReturnType();
0885:
0886:                            if (returnType
0887:                                    .equals("javax.management.openmbean.CompositeType")) {
0888:                                numOpsSupported++;
0889:                            }
0890:                        }
0891:                    }
0892:                }
0893:
0894:                boolean isAppConfigAttribSupported = false;
0895:                MBeanAttributeInfo[] attrInfos = mbnInfo.getAttributes();
0896:
0897:                for (MBeanAttributeInfo attrInfo : attrInfos) {
0898:                    // -- Check if "ApplicationConfigurations" attribute is present
0899:                    if (attrInfo.getName().equals("ApplicationConfigurations")) {
0900:                        isAppConfigAttribSupported = true;
0901:                    }
0902:                }
0903:
0904:                return (numOpsSupported == 4 && isAppConfigAttribSupported);
0905:            }
0906:
0907:            /**
0908:             * Get the CompositeType definition for the components application configuration 
0909:             *
0910:             * @return the CompositeType for the components application configuration.
0911:             */
0912:            public CompositeType queryApplicationConfigurationType() {
0913:
0914:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0915:                CompositeType ct = null;
0916:
0917:                if (configMBeanName == null) {
0918:                    throw new RuntimeException(
0919:                            mTranslator
0920:                                    .getString(
0921:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0922:                                            mComponentName));
0923:                }
0924:
0925:                try {
0926:                    Object[] params = new Object[] {};
0927:                    String[] sign = new String[] {};
0928:                    operationSupportedCheck(configMBeanName,
0929:                            "queryApplicationConfigurationType", sign);
0930:
0931:                    ct = (CompositeType) mEnvCtx.getMBeanServer().invoke(
0932:                            configMBeanName,
0933:                            "queryApplicationConfigurationType", params, sign);
0934:
0935:                } catch (Exception iex) {
0936:                    mLog.warning(MessageHelper.getMsgString(iex));
0937:                }
0938:                return ct;
0939:            }
0940:
0941:            /**
0942:             * Add an application configuration. The configuration name is a part of the CompositeData.
0943:             * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
0944:             *
0945:             * @param name - configuration name, must match the value of the field "name" in the namedConfig
0946:             * @param appCfgProps - application configuration properties
0947:             * @throws MBeanException if the application configuration cannot be added.
0948:             * @return management message string which gives the status of the operation. For 
0949:             *         target=cluster, instance specific details are included. 
0950:             */
0951:            public String addApplicationConfiguration(String name,
0952:                    Properties appCfgProps) throws MBeanException {
0953:                throw new UnsupportedOperationException(
0954:                        "addApplicationConfiguration");
0955:            }
0956:
0957:            /**
0958:             * Add an application configuration. The configuration name is a part of the CompositeData.
0959:             * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
0960:             *
0961:             * @param name - configuration name, must match the value of the field "name" in the namedConfig
0962:             * @param appConfig - application configuration composite 
0963:             * @throws MBeanException if the application configuration cannot be added.
0964:             * @return management message string which gives the status of the operation. For 
0965:             *         target=cluster, instance specific details are included. 
0966:             */
0967:            public String addApplicationConfiguration(String name,
0968:                    CompositeData appConfig) throws MBeanException {
0969:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
0970:                String response = null;
0971:
0972:                if (configMBeanName == null) {
0973:                    throw new RuntimeException(
0974:                            mTranslator
0975:                                    .getString(
0976:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
0977:                                            mComponentName));
0978:                }
0979:
0980:                // If the application configuration elements in the registry is missing
0981:                // get the application configuration from the actual MBean and persist them.
0982:                persistApplicationConfiguration(configMBeanName);
0983:
0984:                /**
0985:                 * This first invokes addApplicationConfiguration on the original configuration 
0986:                 * MBean and then updates the registry.
0987:                 */
0988:                try {
0989:                    Object[] params = new Object[] { name, appConfig };
0990:                    String[] sign = new String[] { "java.lang.String",
0991:                            "javax.management.openmbean.CompositeData" };
0992:                    operationSupportedCheck(configMBeanName,
0993:                            "addApplicationConfiguration", sign);
0994:
0995:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
0996:                            "addApplicationConfiguration", params, sign);
0997:
0998:                    // Update the registry
0999:                    addApplicationConfiguration(appConfig);
1000:
1001:                    response = mMsgBuilder.buildFrameworkMessage(
1002:                            "addApplicationConfiguration",
1003:                            MessageBuilder.TaskResult.SUCCESS);
1004:
1005:                } catch (Exception iex) {
1006:                    try {
1007:                        response = mMsgBuilder.buildExceptionMessage(
1008:                                "addApplicationConfiguration", iex);
1009:                    } catch (ManagementException mex) {
1010:                        mLog.warning(MessageHelper.getMsgString(mex));
1011:                        throw new MBeanException(
1012:                                new Exception(mex.getMessage()));
1013:                    }
1014:                }
1015:                return response;
1016:            }
1017:
1018:            /**
1019:             * Delete an application configuration. 
1020:             *
1021:             * @param name - identification of the application configuration to be deleted
1022:             * @throws MBeanException if the configuration cannot be deleted.
1023:             * @return management message string which gives the status of the operation. For 
1024:             *         target=cluster, instance specific details are included. 
1025:             */
1026:            public String deleteApplicationConfiguration(String name)
1027:                    throws MBeanException {
1028:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
1029:                String response = null;
1030:
1031:                if (configMBeanName == null) {
1032:                    throw new RuntimeException(
1033:                            mTranslator
1034:                                    .getString(
1035:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
1036:                                            mComponentName));
1037:                }
1038:
1039:                // If the application configuration element in the registry is empty
1040:                // get the application configuration from the actual MBean and persist them.
1041:                persistApplicationConfiguration(configMBeanName);
1042:
1043:                /**
1044:                 * This first invokes deleteApplicationConfiguration on the original configuration 
1045:                 * MBean and then updates the registry.
1046:                 */
1047:                try {
1048:                    Object[] params = new Object[] { name };
1049:                    String[] sign = new String[] { "java.lang.String" };
1050:                    operationSupportedCheck(configMBeanName,
1051:                            "deleteApplicationConfiguration", sign);
1052:
1053:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
1054:                            "deleteApplicationConfiguration", params, sign);
1055:
1056:                    // Update the registry
1057:                    removeApplicationConfiguration(name);
1058:
1059:                    response = mMsgBuilder.buildFrameworkMessage(
1060:                            "deleteApplicationConfiguration",
1061:                            MessageBuilder.TaskResult.SUCCESS);
1062:
1063:                } catch (Exception iex) {
1064:                    try {
1065:                        response = mMsgBuilder.buildExceptionMessage(
1066:                                "deleteApplicationConfiguration", iex);
1067:                    } catch (ManagementException mex) {
1068:                        mLog.warning(MessageHelper.getMsgString(mex));
1069:                        throw new MBeanException(
1070:                                new Exception(mex.getMessage()));
1071:                    }
1072:                }
1073:                return response;
1074:            }
1075:
1076:            /**
1077:             * Update a application configuration. The configuration name is a part of the CompositeData.
1078:             * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
1079:             *
1080:             * @param name - configuration name, must match the value of the field "configurationName" in the appConfig
1081:             * @param appCfgProps - application configuration properties.
1082:             * @throws MBeanException if there are errors encountered when updating the configuration.
1083:             * @return management message string which gives the status of the operation. For 
1084:             *         target=cluster, instance specific details are included. 
1085:             */
1086:            public String setApplicationConfiguration(String name,
1087:                    Properties appCfgProps) throws MBeanException {
1088:                throw new UnsupportedOperationException(
1089:                        "setApplicationConfiguration");
1090:            }
1091:
1092:            /**
1093:             * Update a application configuration. The configuration name is a part of the CompositeData.
1094:             * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
1095:             *
1096:             * @param name - configuration name, must match the value of the field "configurationName" in the appConfig
1097:             * @param appConfig - application configuration composite
1098:             * @throws MBeanException if there are errors encountered when updating the configuration.
1099:             * @return management message string which gives the status of the operation. For 
1100:             *         target=cluster, instance specific details are included. 
1101:             */
1102:            public String setApplicationConfiguration(String name,
1103:                    CompositeData appConfig) throws MBeanException {
1104:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
1105:                String response = null;
1106:
1107:                if (configMBeanName == null) {
1108:                    throw new RuntimeException(
1109:                            mTranslator
1110:                                    .getString(
1111:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
1112:                                            mComponentName));
1113:                }
1114:
1115:                // If the application configuration elements in the registry is missing
1116:                // get the application configuration from the actual MBean and persist them.
1117:                persistApplicationConfiguration(configMBeanName);
1118:
1119:                /**
1120:                 * This first invokes setApplicationConfiguration on the original configuration 
1121:                 * MBean and then updates the registry.
1122:                 */
1123:                try {
1124:                    Object[] params = new Object[] { name, appConfig };
1125:                    String[] sign = new String[] { "java.lang.String",
1126:                            "javax.management.openmbean.CompositeData" };
1127:                    operationSupportedCheck(configMBeanName,
1128:                            "setApplicationConfiguration", sign);
1129:
1130:                    mEnvCtx.getMBeanServer().invoke(configMBeanName,
1131:                            "setApplicationConfiguration", params, sign);
1132:
1133:                    // Update the registry
1134:                    updateApplicationConfiguration(appConfig);
1135:
1136:                    response = mMsgBuilder.buildFrameworkMessage(
1137:                            "setApplicationConfiguration",
1138:                            MessageBuilder.TaskResult.SUCCESS);
1139:
1140:                } catch (Exception iex) {
1141:                    try {
1142:                        response = mMsgBuilder.buildExceptionMessage(
1143:                                "updateApplicationConfiguration", iex);
1144:                    } catch (ManagementException mex) {
1145:                        mLog.warning(MessageHelper.getMsgString(mex));
1146:                        throw new MBeanException(
1147:                                new Exception(mex.getMessage()));
1148:                    }
1149:                }
1150:                return response;
1151:            }
1152:
1153:            /**
1154:             * Get a Map of all application configurations for the component.
1155:             *
1156:             * @return a TabularData of all the application configurations for a 
1157:             *         component keyed by the configuration name. 
1158:             */
1159:            public TabularData getApplicationConfigurations() {
1160:
1161:                /**
1162:                 * If framework not ready then get the application configurations from the registry 
1163:                 * using DOM.
1164:                 *
1165:                 * If the framework is ready ( i.e. JAXB initialized ) get the application configuration 
1166:                 *  from the JAXB model
1167:                 *
1168:                 * If the registry component configuration / application configuration is empty get the 
1169:                 * actual values from the MBean.
1170:                 */
1171:
1172:                TabularData appConfigs = null;
1173:                try {
1174:                    appConfigs = createEmptyAppConfigTable();
1175:                    appConfigs = retrieveApplicationConfiguration();
1176:                } catch (OpenDataException oex) {
1177:                    throw new RuntimeException(oex);
1178:                }
1179:
1180:                if (appConfigs.isEmpty()) {
1181:                    // -- Call getAttributes on the actual MBean, the application variables might not
1182:                    //    have been persisted
1183:
1184:                    ObjectName configMBeanName = getComponentConfigurationMBeanName();
1185:
1186:                    if (configMBeanName != null) {
1187:                        if (mEnvCtx.getMBeanServer().isRegistered(
1188:                                configMBeanName)) {
1189:                            try {
1190:                                appConfigs = (TabularData) mEnvCtx
1191:                                        .getMBeanServer().getAttribute(
1192:                                                configMBeanName,
1193:                                                "ApplicationConfigurations");
1194:                            } catch (javax.management.JMException iex) {
1195:                                mLog.warning(iex.toString());
1196:                                // -- should never occur
1197:                            }
1198:
1199:                        }
1200:                    }
1201:                }
1202:                return appConfigs;
1203:            }
1204:
1205:            /** 
1206:             * Retrieves the component specific configuration schema.
1207:             *
1208:             * @return a String containing the configuration schema.
1209:             */
1210:            public String retrieveConfigurationDisplaySchema() {
1211:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
1212:                String response = null;
1213:
1214:                if (configMBeanName == null) {
1215:                    throw new RuntimeException(
1216:                            mTranslator
1217:                                    .getString(
1218:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
1219:                                            mComponentName));
1220:                }
1221:
1222:                try {
1223:                    operationSupportedCheck(configMBeanName,
1224:                            "retrieveConfigurationDisplaySchema",
1225:                            new String[] {});
1226:                    response = (String) mEnvCtx.getMBeanServer().invoke(
1227:                            configMBeanName,
1228:                            "retrieveConfigurationDisplaySchema",
1229:                            new Object[] {}, new String[] {});
1230:
1231:                } catch (Exception ex) {
1232:                    mLog.warning(MessageHelper.getMsgString(ex));
1233:                    throw new RuntimeException(ex.getMessage());
1234:                }
1235:                return response;
1236:            }
1237:
1238:            /** 
1239:             * Retrieves the component configuration metadata.
1240:             * The XML data conforms to the component 
1241:             * configuration schema.
1242:             *
1243:             * @return a String containing the configuration metadata.
1244:             */
1245:            public String retrieveConfigurationDisplayData() {
1246:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
1247:                String response = null;
1248:
1249:                if (configMBeanName == null) {
1250:                    throw new RuntimeException(
1251:                            mTranslator
1252:                                    .getString(
1253:                                            LocalStringKeys.CCFG_MISSING_COMPONENT_CONFIG_MBEAN,
1254:                                            mComponentName));
1255:                }
1256:
1257:                try {
1258:                    String ns = getComponentConfigurationNS(mComponentName);
1259:
1260:                    if (ComponentConfigurationHelper.CONFIGURATION_NS
1261:                            .equals(ns)) {
1262:                        // New configuration schema
1263:                        response = getComponentConfigurationData(mComponentName);
1264:
1265:                    } else {
1266:                        operationSupportedCheck(configMBeanName,
1267:                                "retrieveConfigurationDisplayData",
1268:                                new String[] {});
1269:                        response = (String) mEnvCtx.getMBeanServer().invoke(
1270:                                configMBeanName,
1271:                                "retrieveConfigurationDisplayData",
1272:                                new Object[] {}, new String[] {});
1273:                    }
1274:
1275:                } catch (Exception ex) {
1276:                    mLog.warning(MessageHelper.getMsgString(ex));
1277:                    throw new RuntimeException(ex.getMessage());
1278:                }
1279:                return response;
1280:            }
1281:
1282:            /*---------------------------------------------------------------------------------*\
1283:             *                                Private Helpers                                  *
1284:            \*---------------------------------------------------------------------------------*/
1285:
1286:            /**
1287:             * Get the MBeanInfo from the actual component configuration MBean. If the component
1288:             * is off-line, this information is not available and a blank MBeanInfo is returned.
1289:             */
1290:            private MBeanInfo getComponentMBeanInfo() {
1291:                ObjectName configMBeanName = getComponentConfigurationMBeanName();
1292:
1293:                if (configMBeanName != null) {
1294:                    try {
1295:                        return mEnvCtx.getMBeanServer().getMBeanInfo(
1296:                                configMBeanName);
1297:                    } catch (javax.management.JMException jmx) {
1298:                        // This should never be the case
1299:                        mLog.finest(jmx.getMessage());
1300:                    }
1301:
1302:                }
1303:                return new MBeanInfo(this .getClass().getName(),
1304:                        "Dynamic Component Configuration instance MBean",
1305:                        new MBeanAttributeInfo[] {},
1306:                        new MBeanConstructorInfo[] {},
1307:                        new MBeanOperationInfo[] {},
1308:                        new MBeanNotificationInfo[] {});
1309:            }
1310:
1311:            /** 
1312:             * Get the JMX ObjectName of the actual Component Configuration MBean. 
1313:             * 
1314:             * @return the JMX ObjectName of the actual Component Configuration MBean, if 
1315:             *         a configuration MBean is not registered by the component a null value
1316:             *         is returned.
1317:             */
1318:            private ObjectName getComponentConfigurationMBeanName() {
1319:                ObjectName configMBeanName = null;
1320:                /**
1321:                 * First check if there is a match for a custom component MBean which uses the
1322:                 * following ObjectName pattern : 
1323:                 *    com.sun.jbi:ControlType=Configuration,ComponentName=<component-name>
1324:                 */
1325:                ObjectName standardPattern = mEnvCtx.getMBeanNames()
1326:                        .getCustomComponentMBeanNameFilter(
1327:                                mEnvCtx.getPlatformContext().getInstanceName(),
1328:                                // CustomControlName="Configuration" 
1329:                                "Configuration", mComponentName);
1330:
1331:                Set<ObjectName> names = mEnvCtx.getMBeanServer().queryNames(
1332:                        standardPattern, null);
1333:
1334:                if (!names.isEmpty()) {
1335:                    if (names.size() > 1) {
1336:                        mLog
1337:                                .finest("More than one MBean matches ObjectName pattern "
1338:                                        + standardPattern
1339:                                        + ".  "
1340:                                        + convertToString(names));
1341:                    }
1342:
1343:                    configMBeanName = (ObjectName) names.iterator().next();
1344:                } else {
1345:                    /**
1346:                     * If a custom component configuration MBean does not follow the standard 
1347:                     * naming convention ( which the open-jbi components don't right now ) then
1348:                     * look for the specific MBean for the component :
1349:                     *   com.sun.ebi:ServiceType=Configuration,IdentificationName=<component-name>,* 
1350:                     */
1351:                    ObjectName ebiPattern = null;
1352:                    try {
1353:                        ebiPattern = new ObjectName(
1354:                                "com.sun.ebi:ServiceType=Configuration,IdentificationName="
1355:                                        + mComponentName + ",*");
1356:                    } catch (Exception ex) {
1357:                        mLog.warning(ex.getMessage());
1358:                    }
1359:
1360:                    Set<ObjectName> ebiNames = mEnvCtx.getMBeanServer()
1361:                            .queryNames(ebiPattern, null);
1362:
1363:                    if (!ebiNames.isEmpty()) {
1364:                        if (ebiNames.size() > 1) {
1365:                            mLog
1366:                                    .finest("More than one MBean matches ObjectName pattern "
1367:                                            + standardPattern
1368:                                            + ".  "
1369:                                            + convertToString(ebiNames));
1370:                        }
1371:
1372:                        configMBeanName = (ObjectName) ebiNames.iterator()
1373:                                .next();
1374:                    }
1375:
1376:                }
1377:                return configMBeanName;
1378:            }
1379:
1380:            /**
1381:             * Convert the objects in a set to string.
1382:             *
1383:             * @param set a non-empty set
1384:             */
1385:            private String convertToString(Set set) {
1386:                StringBuffer strBuf = new StringBuffer("[ ");
1387:                if (!set.isEmpty()) {
1388:                    java.util.Iterator itr = set.iterator();
1389:                    while (itr.hasNext()) {
1390:                        strBuf.append(itr.next().toString());
1391:                        if (itr.hasNext()) {
1392:                            strBuf.append(",  ");
1393:                        } else {
1394:                            strBuf.append("  ");
1395:                        }
1396:                    }
1397:                }
1398:                strBuf.append(" ]");
1399:                return strBuf.toString();
1400:            }
1401:
1402:            /**
1403:             * Merge two MBeanOperationInfo arrays.
1404:             *
1405:             * @param array1 - 
1406:             * @param array2
1407:             * @return an array containing the OperationInfos from both the arrays.
1408:             */
1409:            private MBeanOperationInfo[] merge(MBeanOperationInfo[] a1,
1410:                    MBeanOperationInfo[] a2) {
1411:                MBeanOperationInfo[] array = new MBeanOperationInfo[a1.length
1412:                        + a2.length];
1413:
1414:                // Add the operation infos from the first set
1415:                for (int x = 0; x < a1.length; x++) {
1416:                    array[x] = a1[x];
1417:                }
1418:                // Add the operation infos from the second set
1419:                for (int x = 0; x < a2.length; x++) {
1420:                    array[x + a1.length] = a2[x];
1421:                }
1422:
1423:                return array;
1424:            }
1425:
1426:            /**
1427:             * Persist component configuration static attribute to the registry
1428:             *
1429:             * @param attrib - the attribute to persist
1430:             */
1431:            private void persistAttribute(Attribute attrib) {
1432:                try {
1433:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1434:                            .getRegistry()).getUpdater();
1435:                    String attribValueToPersist = encryptCompConfigPasswordField(
1436:                            attrib.getName(), attrib.getValue().toString());
1437:                    updater.setComponentAttribute(mComponentName, attrib
1438:                            .getName(), attribValueToPersist);
1439:                } catch (Exception rex) {
1440:                    String msg = mTranslator.getString(
1441:                            LocalStringKeys.CCFG_PERSIST_ATTRIBUTE_FAILURE,
1442:                            mComponentName, attrib.getName(), rex.getMessage());
1443:                    mLog.warning(msg);
1444:                }
1445:            }
1446:
1447:            /**
1448:             * Persist component configuration static attributes to the registry
1449:             *
1450:             * @param attribs - list of attributes to persist
1451:             */
1452:            private void persistAttributes(AttributeList attribs) {
1453:                try {
1454:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1455:                            .getRegistry()).getUpdater();
1456:
1457:                    Properties props = new Properties();
1458:                    for (Object attrib : attribs) {
1459:                        Attribute attribute = (Attribute) attrib;
1460:                        String value = (attribute.getValue() == null ? ""
1461:                                : attribute.getValue().toString());
1462:                        String attribValueToPersist = encryptCompConfigPasswordField(
1463:                                attribute.getName(), value);
1464:
1465:                        props.put(attribute.getName(), attribValueToPersist);
1466:                    }
1467:
1468:                    updater.setComponentAttributes(mComponentName, props);
1469:                } catch (Exception rex) {
1470:                    StringBuffer strBuf = new StringBuffer();
1471:                    strBuf.append("[ ");
1472:                    int i = 0;
1473:                    for (Object attrib : attribs) {
1474:                        i++;
1475:                        strBuf.append(((Attribute) attrib).getName());
1476:                        if (i != attribs.size()) {
1477:                            strBuf.append(", ");
1478:                        }
1479:                    }
1480:                    strBuf.append(" ]");
1481:                    String msg = mTranslator
1482:                            .getString(
1483:                                    LocalStringKeys.CCFG_PERSIST_ATTRIBUTE_FAILURE,
1484:                                    mComponentName, strBuf.toString(), rex
1485:                                            .getMessage());
1486:                    mLog.warning(msg);
1487:                }
1488:            }
1489:
1490:            /**
1491:             * @return all the properties set on the component and persisted
1492:             */
1493:            private Properties retrieveAttributes() {
1494:                Properties props = new Properties();
1495:
1496:                try {
1497:
1498:                    if (mEnvCtx.isFrameworkReady(false)) {
1499:                        // Initialization complete can use registry
1500:                        com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) getRegistry()
1501:                                .getComponentQuery().getComponentInfo(
1502:                                        mComponentName);
1503:
1504:                        props = compInfo.getConfiguration();
1505:                    } else {
1506:                        // Get the attribute from the registry using DOM
1507:                        RegistryDocument regDoc = new RegistryDocument(mEnvCtx
1508:                                .getReadOnlyRegistry());
1509:
1510:                        com.sun.jbi.platform.PlatformContext ctx = mEnvCtx
1511:                                .getPlatformContext();
1512:                        String target = ctx
1513:                                .getTargetName(ctx.getInstanceName());
1514:                        props = regDoc.getComponentConfigurationAttributes(
1515:                                target, ctx.isStandaloneServer(target),
1516:                                mComponentName);
1517:                    }
1518:                    props = maskCompConfigPasswordFields(props);
1519:                } catch (Exception ex) {
1520:                    mLog.warning(MessageHelper.getMsgString(ex));
1521:                }
1522:
1523:                return props;
1524:            }
1525:
1526:            /**
1527:             * @param attribute identification of the attribute
1528:             * @return the MBeanAttributeInfo for the specified attribute
1529:             */
1530:            protected MBeanAttributeInfo getAttributeInfo(String attribute) {
1531:                MBeanInfo mbeanInfo = this .getMBeanInfo();
1532:                MBeanAttributeInfo[] attribInfos = null;
1533:                MBeanAttributeInfo aInfo = null;
1534:                if (mbeanInfo != null) {
1535:                    attribInfos = mbeanInfo.getAttributes();
1536:                    for (MBeanAttributeInfo attribInfo : attribInfos) {
1537:                        if (attribInfo.getName().equals(attribute)) {
1538:                            aInfo = attribInfo;
1539:                        }
1540:                    }
1541:                }
1542:                return aInfo;
1543:            }
1544:
1545:            /**
1546:             * Persist the attributes of the component configuration MBean. Skip the 
1547:             * "EnvironmentVariables" attribute
1548:             */
1549:            private void persistMBeanAttributes(ObjectName configMBeanName) {
1550:                MBeanAttributeInfo[] attribInfos = getMBeanInfo()
1551:                        .getAttributes();
1552:                String[] attributes = new String[attribInfos.length];
1553:                int i = 0;
1554:                for (MBeanAttributeInfo attribInfo : attribInfos) {
1555:                    if (!attribInfo.getName().equals("ApplicationVariables")
1556:                            && !attribInfo.getName().equals(
1557:                                    "ApplicationConfigurations")) {
1558:                        attributes[i++] = attribInfo.getName();
1559:                    }
1560:                }
1561:
1562:                if (mEnvCtx.getMBeanServer().isRegistered(configMBeanName)) {
1563:                    try {
1564:                        AttributeList attribList = mEnvCtx.getMBeanServer()
1565:                                .getAttributes(configMBeanName, attributes);
1566:                        persistAttributes(attribList);
1567:                    } catch (javax.management.JMException iex) {
1568:                        mLog.warning(iex.getMessage());
1569:                    }
1570:                }
1571:            }
1572:
1573:            /**
1574:             * Add the application variable to the registry.
1575:             *
1576:             * @param appVar - the application variable to be added to the registry.
1577:             */
1578:            private void addApplicationVariable(CompositeData appVar)
1579:                    throws com.sun.jbi.management.registry.RegistryException {
1580:                com.sun.jbi.management.ComponentInfo.Variable[] vars = new com.sun.jbi.management.ComponentInfo.Variable[1];
1581:
1582:                try {
1583:                    String appVarValue = (String) appVar.get("value");
1584:                    if (PASSWORD.equals((String) appVar.get("type"))) {
1585:                        appVarValue = mEnvCtx.getPlatformContext()
1586:                                .getKeyStoreUtil().encrypt(appVarValue);
1587:                    }
1588:                    vars[0] = new com.sun.jbi.management.ComponentInfo.Variable(
1589:                            (String) appVar.get("name"), appVarValue,
1590:                            (String) appVar.get("type"));
1591:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1592:                            .getRegistry()).getUpdater();
1593:                    updater.addComponentApplicationVariables(mComponentName,
1594:                            vars);
1595:                } catch (Exception rex) {
1596:                    String msg = mTranslator
1597:                            .getString(
1598:                                    LocalStringKeys.CCFG_FAILED_ADD_APP_VAR_REG,
1599:                                    vars[0].getName(), mComponentName, rex
1600:                                            .getMessage());
1601:                    mLog.warning(msg);
1602:                }
1603:            }
1604:
1605:            /**
1606:             * Update the application variable in the registry.
1607:             *
1608:             * @param appVar - the application variable to be updated in the registry.
1609:             */
1610:            private void updateApplicationVariable(CompositeData appVar)
1611:                    throws com.sun.jbi.management.registry.RegistryException {
1612:                com.sun.jbi.management.ComponentInfo.Variable[] vars = new com.sun.jbi.management.ComponentInfo.Variable[1];
1613:
1614:                try {
1615:                    String appVarValue = (String) appVar.get("value");
1616:                    if (PASSWORD.equals((String) appVar.get("type"))) {
1617:                        appVarValue = mEnvCtx.getPlatformContext()
1618:                                .getKeyStoreUtil().encrypt(appVarValue);
1619:                    }
1620:
1621:                    vars[0] = new com.sun.jbi.management.ComponentInfo.Variable(
1622:                            (String) appVar.get("name"), appVarValue,
1623:                            (String) appVar.get("type"));
1624:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1625:                            .getRegistry()).getUpdater();
1626:                    updater.updateComponentApplicationVariables(mComponentName,
1627:                            vars);
1628:                } catch (Exception rex) {
1629:                    String msg = mTranslator
1630:                            .getString(
1631:                                    LocalStringKeys.CCFG_FAILED_UPDATE_APP_VAR_REG,
1632:                                    vars[0].getName(), mComponentName, rex
1633:                                            .getMessage());
1634:                    mLog.warning(msg);
1635:                }
1636:            }
1637:
1638:            /**
1639:             * Delete the application variable from the registry.
1640:             *
1641:             * @param name - identification for the application variable to be deleted.
1642:             */
1643:            private void removeApplicationVariable(String name)
1644:                    throws com.sun.jbi.management.registry.RegistryException {
1645:
1646:                try {
1647:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1648:                            .getRegistry()).getUpdater();
1649:                    updater.deleteComponentApplicationVariables(mComponentName,
1650:                            new String[] { name });
1651:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
1652:                    String msg = mTranslator.getString(
1653:                            LocalStringKeys.CCFG_FAILED_DELETE_APP_VAR_REG,
1654:                            name, mComponentName, rex.getMessage());
1655:                    mLog.warning(msg);
1656:                }
1657:            }
1658:
1659:            /**
1660:             * Get a handle to the registry
1661:             *
1662:             * @return the persisted registry instance
1663:             */
1664:            private com.sun.jbi.management.registry.Registry getRegistry() {
1665:                return (com.sun.jbi.management.registry.Registry) mEnvCtx
1666:                        .getRegistry();
1667:            }
1668:
1669:            /**
1670:             * @return true if the MBean implements the operation.
1671:             *
1672:             * @param mbean - MBean ObjectName
1673:             * @param op - name of the operation
1674:             * @param sign = operation parameter signature
1675:             */
1676:            private boolean operationSupportedCheck(ObjectName mbean,
1677:                    String op, String[] sign) {
1678:                MBeanInfo mbeanInfo = null;
1679:                boolean found = false;
1680:
1681:                try {
1682:                    if (mEnvCtx.getMBeanServer().isRegistered(mbean)) {
1683:                        mbeanInfo = mEnvCtx.getMBeanServer()
1684:                                .getMBeanInfo(mbean);
1685:                    }
1686:                } catch (Exception ex) {
1687:                    mLog.warning(ex.getMessage());
1688:                    return found;
1689:                }
1690:
1691:                MBeanOperationInfo[] opInfos = mbeanInfo.getOperations();
1692:
1693:                for (MBeanOperationInfo opInfo : opInfos) {
1694:                    if (opInfo.getName().equals(op)) {
1695:                        found = true;
1696:                        break;
1697:                    }
1698:                }
1699:                if (!found) {
1700:                    String errMsg = mTranslator.getString(
1701:                            LocalStringKeys.CCFG_UNSUPPORTED_OPERATION, op,
1702:                            mbean.toString());
1703:                    throw new UnsupportedOperationException(errMsg);
1704:                }
1705:                return found;
1706:            }
1707:
1708:            /**
1709:             * @return all the application variables set on the component and persisted
1710:             */
1711:            private TabularData retrieveApplicationVariables() {
1712:                TabularData td = new TabularDataSupport(mCfgHlpr
1713:                        .getApplicationVariableTabularType());
1714:                Variable[] vars = new Variable[0];
1715:                try {
1716:
1717:                    if (mEnvCtx.isFrameworkReady(false)) {
1718:                        // Initialization complete can use registry
1719:                        com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) getRegistry()
1720:                                .getComponentQuery().getComponentInfo(
1721:                                        mComponentName);
1722:
1723:                        vars = compInfo.getVariables();
1724:                    } else {
1725:                        // Get the attribute from the registry using DOM
1726:                        RegistryDocument regDoc = new RegistryDocument(mEnvCtx
1727:                                .getReadOnlyRegistry());
1728:
1729:                        com.sun.jbi.platform.PlatformContext ctx = mEnvCtx
1730:                                .getPlatformContext();
1731:                        String target = ctx
1732:                                .getTargetName(ctx.getInstanceName());
1733:                        vars = regDoc.getComponentApplicationVariables(target,
1734:                                ctx.isStandaloneServer(target), mComponentName);
1735:                    }
1736:
1737:                    for (Variable var : vars) {
1738:                        String[] itemNames = mCfgHlpr
1739:                                .getApplicationVariableItemNames();
1740:
1741:                        String appVarValue = var.getValue();
1742:                        if (PASSWORD.equalsIgnoreCase(var.getType())) {
1743:                            appVarValue = MASKED_FIELD_VALUE;
1744:                        }
1745:                        CompositeDataSupport cd = new CompositeDataSupport(
1746:                                mCfgHlpr.getApplicationVariablesType(),
1747:                                itemNames, new String[] { var.getName(),
1748:                                        appVarValue, var.getType() });
1749:
1750:                        td.put(cd);
1751:                    }
1752:
1753:                } catch (Exception ex) {
1754:                    mLog.warning(MessageHelper.getMsgString(ex));
1755:                }
1756:                // return the retrived values 
1757:                return td;
1758:            }
1759:
1760:            /**
1761:             * If the application variables element in the registry is empty
1762:             * get the application variables from the actual MBean and persist them.
1763:             *
1764:             * @param configMBeanName - the ConfigurationMBean Object Name
1765:             */
1766:            private void persistApplicationVariables(ObjectName configMBeanName) {
1767:                TabularData appVars = null;
1768:                com.sun.jbi.management.ComponentInfo compInfo = null;
1769:                try {
1770:                    // Get the application variables persisted in the registry
1771:                    compInfo = (com.sun.jbi.management.ComponentInfo) getRegistry()
1772:                            .getComponentQuery().getComponentInfo(
1773:                                    mComponentName);
1774:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
1775:                    mLog.warning(MessageHelper.getMsgString(rex));
1776:                }
1777:
1778:                Variable[] vars = compInfo.getVariables();
1779:
1780:                if (vars.length == 0) {
1781:                    if (mEnvCtx.getMBeanServer().isRegistered(configMBeanName)) {
1782:                        try {
1783:                            appVars = (TabularData) mEnvCtx.getMBeanServer()
1784:                                    .getAttribute(configMBeanName,
1785:                                            "ApplicationVariables");
1786:                        } catch (javax.management.JMException iex) {
1787:                            mLog.warning(iex.getMessage());
1788:                            // -- should never occur
1789:                        }
1790:
1791:                        vars = new Variable[appVars.size()];
1792:                        java.util.Collection cds = appVars.values();
1793:                        int i = 0;
1794:                        try {
1795:                            for (java.util.Iterator itr = cds.iterator(); itr
1796:                                    .hasNext();) {
1797:                                CompositeData cd = (CompositeData) itr.next();
1798:
1799:                                String appVarValue = (String) cd.get("value");
1800:                                if (PASSWORD.equals((String) cd.get("type"))) {
1801:                                    appVarValue = mEnvCtx.getPlatformContext()
1802:                                            .getKeyStoreUtil().encrypt(
1803:                                                    appVarValue);
1804:                                }
1805:
1806:                                vars[i++] = new Variable((String) cd
1807:                                        .get("name"), appVarValue, (String) cd
1808:                                        .get("type"));
1809:                            }
1810:
1811:                            // persist them
1812:                            com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1813:                                    .getRegistry()).getUpdater();
1814:                            updater.addComponentApplicationVariables(
1815:                                    mComponentName, vars);
1816:                        } catch (Exception rex) {
1817:                            String msg = mTranslator
1818:                                    .getString(
1819:                                            LocalStringKeys.CCFG_FAILED_ADD_APP_VAR_REG,
1820:                                            vars[0].getName(), mComponentName,
1821:                                            rex.getMessage());
1822:                            mLog.warning(msg);
1823:                        }
1824:                    }
1825:                }
1826:            }
1827:
1828:            /**
1829:             * If the component is offline this returns a null value, since the components
1830:             * application configuration composite type is not known.
1831:             *
1832:             * @return all the application configurations set on the component and persisted
1833:             */
1834:            private TabularData retrieveApplicationConfiguration()
1835:                    throws OpenDataException {
1836:                CompositeType appConfigCompositeType = queryApplicationConfigurationType();
1837:
1838:                TabularData td = null;
1839:
1840:                if (appConfigCompositeType != null) {
1841:                    td = createEmptyAppConfigTable();
1842:                    try {
1843:                        Map<String, Properties> appConfigMap = new java.util.HashMap();
1844:                        if (mEnvCtx.isFrameworkReady(false)) {
1845:                            // Initialization complete can use registry
1846:                            com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) getRegistry()
1847:                                    .getComponentQuery().getComponentInfo(
1848:                                            mComponentName);
1849:
1850:                            String[] configNames = compInfo
1851:                                    .getApplicationConfigurationNames();
1852:                            for (String configName : configNames) {
1853:                                Properties appCfgProps = compInfo
1854:                                        .getApplicationConfiguration(configName);
1855:                                appCfgProps = maskPasswordFields(appCfgProps);
1856:                                appConfigMap.put(configName, appCfgProps);
1857:                            }
1858:                        } else {
1859:                            // Get the attribute from the registry using DOM
1860:                            RegistryDocument regDoc = new RegistryDocument(
1861:                                    mEnvCtx.getReadOnlyRegistry());
1862:
1863:                            com.sun.jbi.platform.PlatformContext ctx = mEnvCtx
1864:                                    .getPlatformContext();
1865:                            String target = ctx.getTargetName(ctx
1866:                                    .getInstanceName());
1867:                            appConfigMap = regDoc
1868:                                    .getComponentApplicationConfiguration(
1869:                                            target,
1870:                                            ctx.isStandaloneServer(target),
1871:                                            mComponentName);
1872:                        }
1873:
1874:                        Set<String> configNames = appConfigMap.keySet();
1875:                        for (String configName : configNames) {
1876:                            Properties appCfgProps = appConfigMap
1877:                                    .get(configName);
1878:                            appCfgProps = maskPasswordFields(appCfgProps);
1879:                            CompositeData cd = mCfgHlpr
1880:                                    .convertPropertiesToCompositeData(
1881:                                            appCfgProps, appConfigCompositeType);
1882:
1883:                            td.put(cd);
1884:                        }
1885:                    } catch (Exception ex) {
1886:                        mLog.warning(MessageHelper.getMsgString(ex));
1887:                    }
1888:                }
1889:                // return the retrieved values 
1890:                return td;
1891:            }
1892:
1893:            /**
1894:             * If the application configuration element in the registry is empty
1895:             * get the application configuration from the actual MBean and persist them.
1896:             *
1897:             * @param configMBeanName - the ConfigurationMBean Object Name
1898:             */
1899:            private void persistApplicationConfiguration(
1900:                    ObjectName configMBeanName) {
1901:                TabularData appConfigs = null;
1902:                com.sun.jbi.management.ComponentInfo compInfo = null;
1903:                try {
1904:                    compInfo = (com.sun.jbi.management.ComponentInfo) getRegistry()
1905:                            .getComponentQuery().getComponentInfo(
1906:                                    mComponentName);
1907:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
1908:                    mLog.warning(MessageHelper.getMsgString(rex));
1909:                }
1910:
1911:                String[] configNames = compInfo
1912:                        .getApplicationConfigurationNames();
1913:
1914:                if (configNames.length == 0) {
1915:                    if (mEnvCtx.getMBeanServer().isRegistered(configMBeanName)) {
1916:                        try {
1917:                            appConfigs = (TabularData) mEnvCtx.getMBeanServer()
1918:                                    .getAttribute(configMBeanName,
1919:                                            "ApplicationConfigurations");
1920:                        } catch (javax.management.JMException iex) {
1921:                            mLog.warning(iex.getMessage());
1922:                            // -- should never occur
1923:                        }
1924:
1925:                        if (appConfigs != null) {
1926:                            java.util.Collection cds = appConfigs.values();
1927:                            int i = 0;
1928:                            for (java.util.Iterator itr = cds.iterator(); itr
1929:                                    .hasNext();) {
1930:                                CompositeData cd = (CompositeData) itr.next();
1931:                                Properties props = mCfgHlpr
1932:                                        .convertCompositeDataToProperties(cd);
1933:
1934:                                // persist them
1935:                                try {
1936:                                    props = encryptPasswordFields(props);
1937:                                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1938:                                            .getRegistry()).getUpdater();
1939:                                    updater
1940:                                            .addComponentApplicationConfiguration(
1941:                                                    mComponentName, props);
1942:                                } catch (Exception rex) {
1943:                                    String msg = mTranslator
1944:                                            .getString(
1945:                                                    LocalStringKeys.CCFG_FAILED_ADD_APP_CFG_REG,
1946:                                                    cd.get("configurationName"),
1947:                                                    mComponentName, rex
1948:                                                            .getMessage());
1949:                                    mLog.warning(msg);
1950:                                }
1951:                            }
1952:                        }
1953:                    }
1954:                }
1955:            }
1956:
1957:            /**
1958:             * Add the application configuration to the registry.
1959:             *
1960:             * @param appConfig - the application configuration to be added to the registry.
1961:             */
1962:            private void addApplicationConfiguration(CompositeData appConfig)
1963:                    throws com.sun.jbi.management.registry.RegistryException {
1964:                try {
1965:                    Properties cfgProps = mCfgHlpr
1966:                            .convertCompositeDataToProperties(appConfig);
1967:                    cfgProps = encryptPasswordFields(cfgProps);
1968:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1969:                            .getRegistry()).getUpdater();
1970:                    updater.addComponentApplicationConfiguration(
1971:                            mComponentName, cfgProps);
1972:                } catch (Exception rex) {
1973:                    String msg = mTranslator.getString(
1974:                            LocalStringKeys.CCFG_FAILED_ADD_APP_CFG_REG,
1975:                            appConfig.get("configurationName"), mComponentName,
1976:                            rex.getMessage());
1977:                    mLog.warning(msg);
1978:                }
1979:            }
1980:
1981:            /**
1982:             * Update the application configuration in the registry.
1983:             *
1984:             * @param appVar - the application configuration to be updated in the registry.
1985:             */
1986:            private void updateApplicationConfiguration(CompositeData appConfig)
1987:                    throws com.sun.jbi.management.registry.RegistryException {
1988:
1989:                try {
1990:                    Properties cfgProps = mCfgHlpr
1991:                            .convertCompositeDataToProperties(appConfig);
1992:                    cfgProps = encryptPasswordFields(cfgProps);
1993:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
1994:                            .getRegistry()).getUpdater();
1995:                    updater.updateComponentApplicationConfiguration(
1996:                            mComponentName, cfgProps);
1997:                } catch (Exception rex) {
1998:                    String msg = mTranslator.getString(
1999:                            LocalStringKeys.CCFG_FAILED_UPDATE_APP_CFG_REG,
2000:                            appConfig.get("configurationName"), mComponentName,
2001:                            rex.getMessage());
2002:                    mLog.warning(msg);
2003:                }
2004:            }
2005:
2006:            /**
2007:             * Delete the application configuration from the registry.
2008:             *
2009:             * @param name - identification for the application configuration to be deleted.
2010:             */
2011:            private void removeApplicationConfiguration(String name)
2012:                    throws com.sun.jbi.management.registry.RegistryException {
2013:
2014:                try {
2015:                    com.sun.jbi.management.registry.Updater updater = ((Registry) mEnvCtx
2016:                            .getRegistry()).getUpdater();
2017:                    updater.deleteComponentApplicationConfiguration(
2018:                            mComponentName, name);
2019:                } catch (com.sun.jbi.management.registry.RegistryException rex) {
2020:                    String msg = mTranslator.getString(
2021:                            LocalStringKeys.CCFG_FAILED_DELETE_APP_CFG_REG,
2022:                            name, mComponentName, rex.getMessage());
2023:                    mLog.warning(msg);
2024:                }
2025:            }
2026:
2027:            /**
2028:             * @return an empty TabularData instance based on the components application
2029:             *         configuration Type.
2030:             */
2031:            private TabularData createEmptyAppConfigTable()
2032:                    throws javax.management.openmbean.OpenDataException {
2033:                CompositeType appConfigCompositeType = queryApplicationConfigurationType();
2034:
2035:                TabularData td = null;
2036:                if (appConfigCompositeType != null) {
2037:                    TabularType tt = new TabularType(
2038:                            "Applcation Configuration",
2039:                            "Table of Application configurations",
2040:                            appConfigCompositeType,
2041:                            new String[] { "configurationName" });
2042:                    td = new TabularDataSupport(tt);
2043:                }
2044:                return td;
2045:            }
2046:
2047:            private Properties encryptPasswordFields(Properties cfgProps)
2048:                    throws Exception {
2049:                Document configDoc = getConfigDoc();
2050:
2051:                Set cfgNames = cfgProps.keySet();
2052:
2053:                for (Object cfgName : cfgNames) {
2054:                    if (mCfgHlpr.isPassword((String) cfgName, configDoc)) {
2055:                        String clearTxt = cfgProps
2056:                                .getProperty((String) cfgName);
2057:                        String encrTxt = mEnvCtx.getPlatformContext()
2058:                                .getKeyStoreUtil().encrypt(clearTxt);
2059:                        cfgProps.setProperty((String) cfgName, encrTxt);
2060:                    }
2061:                }
2062:
2063:                return cfgProps;
2064:            }
2065:
2066:            private Properties maskPasswordFields(Properties cfgProps)
2067:                    throws Exception {
2068:                Document configDoc = getConfigDoc();
2069:
2070:                Set cfgNames = cfgProps.keySet();
2071:
2072:                for (Object cfgName : cfgNames) {
2073:                    if (mCfgHlpr.isPassword((String) cfgName, configDoc)) {
2074:                        cfgProps.setProperty((String) cfgName,
2075:                                MASKED_FIELD_VALUE);
2076:                    }
2077:                }
2078:
2079:                return cfgProps;
2080:            }
2081:
2082:            /**
2083:             * Encrypt component configuration attribute value if it is a password field
2084:             *
2085:             * @param cfgName  - component configuration attribute name
2086:             * @param cfgValue - component configuration attribute value
2087:             */
2088:            private String encryptCompConfigPasswordField(String cfgName,
2089:                    String cfgValue) throws Exception {
2090:                Document configDoc = getConfigDoc();
2091:
2092:                if (mCfgHlpr.isPassword(cfgName, configDoc)) {
2093:                    String encrTxt = mEnvCtx.getPlatformContext()
2094:                            .getKeyStoreUtil().encrypt(cfgValue);
2095:                    return encrTxt;
2096:                }
2097:                return cfgValue;
2098:            }
2099:
2100:            /**
2101:             * If a component configuration attribute is a password field, mask it 
2102:             * i.e. replace value with MASKED_FIELD_VALUE.
2103:             *
2104:             * @param cfgProps - component configuration attributes
2105:             */
2106:            private Properties maskCompConfigPasswordFields(Properties cfgProps)
2107:                    throws Exception {
2108:                Document configDoc = getConfigDoc();
2109:
2110:                Set cfgNames = cfgProps.keySet();
2111:
2112:                for (Object cfgName : cfgNames) {
2113:                    if (mCfgHlpr.isPassword((String) cfgName, configDoc)) {
2114:                        cfgProps.setProperty((String) cfgName,
2115:                                MASKED_FIELD_VALUE);
2116:                    }
2117:                }
2118:
2119:                return cfgProps;
2120:            }
2121:
2122:            private Document getConfigDoc() throws Exception {
2123:                String xmlConfigData = retrieveConfigurationDisplayData();
2124:                Document doc = null;
2125:                if (xmlConfigData != null) {
2126:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
2127:                            .newInstance();
2128:                    dbf.setNamespaceAware(true);
2129:                    DocumentBuilder db = dbf.newDocumentBuilder();
2130:                    InputStream ios = new StringBufferInputStream(xmlConfigData);
2131:
2132:                    doc = db.parse(ios);
2133:                    ios.close();
2134:
2135:                }
2136:                return doc;
2137:            }
2138:
2139:            /**
2140:             * Get the namespace of the "Configuration" element in the jbi.xml, if one 
2141:             * exists. Return an empty string if a "Configuration" emenet is not 
2142:             * defined.
2143:             *
2144:             * @param compName - component name
2145:             * @return the configuration element namespace
2146:             */
2147:            protected String getComponentConfigurationNS(String compName) {
2148:                String ns = "";
2149:
2150:                Archive compArchive = getRegistry().getRepository().getArchive(
2151:                        ArchiveType.COMPONENT, compName);
2152:                if (compArchive != null) {
2153:                    ComponentDescriptor descr = new ComponentDescriptor(
2154:                            compArchive.getJbiXml(true));
2155:                    ns = descr.getComponentConfigurationNS();
2156:                }
2157:
2158:                return ns;
2159:            }
2160:
2161:            /**
2162:             * Get the the "Configuration" element in the jbi.xml. If the Configuration 
2163:             * element is missing in the jbi.xml a null value is returned
2164:             *
2165:             * @param compName - component name
2166:             * @return the configuration xml string
2167:             */
2168:            protected String getComponentConfigurationData(String compName) {
2169:                String xmlStr = null;
2170:
2171:                Archive compArchive = getRegistry().getRepository().getArchive(
2172:                        ArchiveType.COMPONENT, compName);
2173:                if (compArchive != null) {
2174:                    ComponentDescriptor descr = new ComponentDescriptor(
2175:                            compArchive.getJbiXml(true));
2176:                    xmlStr = descr.getComponentConfigurationXml();
2177:                }
2178:
2179:                return xmlStr;
2180:            }
2181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.