KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > config > ManagedConfigBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: ManagedConfigBean.java,v 1.10 2006/03/18 00:43:22 kravtch Exp $
26  * @author: alexkrav
27  *
28  * $Log: ManagedConfigBean.java,v $
29  * Revision 1.10 2006/03/18 00:43:22 kravtch
30  * Issue #394 (Provide an MBean attribute to get JMXServiceURL of the System JMX Connector ...)
31  * admin-core/admin:
32  * repare for getAttributes():
33  * - BaseConfigMBean.getAttributes() now calls BaseConfigMBean.getAttribute() instead of ManagedConfigBean.getAttributes()
34  * Submitted by: kravtch
35  * Reviewed by: Kedar
36  * Affected modules admin/mbeans
37  * Tests passed: QLT/EE
38  *
39  * Revision 1.9 2006/03/03 23:33:26 kravtch
40  * Bug #6313936 (additional)
41  * admin-core/admin:
42  * - fix typos in ManagedConfigBean
43  * Submitted by: kravtch
44  * Reviewed by: Kedar
45  * Affected modules admin-core/admin
46  * Tests passed: QLT/EE
47  *
48  * Revision 1.8 2006/03/01 23:50:15 kravtch
49  * Bug #6313936(asadmin set allows setting LazyConnectionAssociation=true and LazyConnectionEnlistment=false)
50  * admin/validator:
51  * - new ReportHelper & PropertyHelper classes created to support properties validation;
52  * - AttrType: remove attr report methods (to move them into ReportHelper)
53  * - DomainMgr: instead of plain AFRuntimeException now throws AdminValidationException;
54  * - GenericValidator: new validatePropertyChanges() method calls during validateAsParent();
55  * - LocalStrings: some messages revised;
56  * - new GenericValidator.getTargetElementPrintName() provides names for validation msgs;
57  * - ValidationContext: unused member ownerBean is removed; getTargetBean() is modified;
58  * - tests.JdbcConnectionPoolTest - checks for LazyConnection props are added;
59  * admin-core/admin:
60  * - new AdminValidationException class is added;
61  * - ManagedConfigBean.wrapAndThrowMBeanException() helper method is added
62  * - AdminValidationException are passed without catch;
63  * Submitted by: kravtch
64  * Reviewed by: Parshanth Abbagani
65  * Affected modules admin/validator; admin-core/admin
66  * Tests passed: QLT/EE
67  *
68  * Revision 1.7 2006/02/25 00:05:34 kravtch
69  * Bug #6378808(Unable to set/add a blank password property on JDBC Pool through Web UI)
70  * admin-core/admin/.../config:
71  * - new ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE introduced;
72  * - ManagedConfigBean now checks setting property value; if it equals to SPECIAL_EMPTY_VALUE it will be set to "";
73  * Submitted by: kravtch
74  * Reviewed by: Kedar
75  * Affected modules admin-core/admin
76  * Tests passed: QLT/EE
77  *
78  * Revision 1.6 2005/12/25 03:47:31 tcfujii
79  * Updated copyright text and year.
80  *
81  * Revision 1.5 2005/11/14 22:53:15 kravtch
82  * Bug #6338666 (Adding customRealm in adminGUI in the server-config throws BadRealmException in server.log)
83  * - ManagedConfigMBean.createChildByType() now sets Properties as well;
84  * - BaseConfigMBean: convenience methods getManagedConfigBean() & getConfigBeanObjectName() are added;
85  * - ConfigsMBean.createAuthRealm(): instead of call to MBeanServer - use ManagedConfigBean.createChildByType()
86  *
87  * Submitted by: kravtch
88  * Reviewed by: Kedar
89  * Affected modules admin/mbeans; admin-core/util; tools
90  * Tests passed: QLT/EE + devtests
91  *
92  * Revision 1.4 2005/10/06 21:44:07 kravtch
93  * Bug #6331466
94  * create-ssl for iiop-service procedure has been changed.
95  * First, ssl-client-config is created with ssl subelement in it then it added to condig context.
96  * + ManagedConfigBean swithed from enclosing associated MBean to MBeanInfo.
97  * Submitted by: kravtch
98  * Reviewed by: Sreeni
99  * Affected modules admin/mbeans; admin-core/admin
100  * Tests passed: QLT/EE + devtests
101  *
102  * Revision 1.3 2005/08/16 22:19:30 kravtch
103  * M3: 1. ConfigMBeans: Support for generic getXXXNamesList() operation (request from management-rules).
104  * 2. MBeanRegistry: support for getElementPrintName() to provide readable element's description for validator's messages
105  * Submitted by: kravtch
106  * Reviewed by: Shreedhar
107  * Affected modules admin-core/admin
108  * Tests passed: QLT/EE + devtests
109  *
110  * Revision 1.2 2005/06/27 21:19:41 tcfujii
111  * Issue number: CDDL header updates.
112  *
113  * Revision 1.1.1.1 2005/05/27 22:52:02 dpatil
114  * GlassFish first drop
115  *
116  * Revision 1.29 2005/05/07 04:35:26 ruyakr
117  * Engineer: Rob Ruyak
118  *
119  * Fixed warning messages displayed from jdk1.5 because of introduction of varargs in certain apis such as ja
120  * va.lang.Class.
121  *
122  *
123  * This is my last checkin here at Sun! Thanks for all the good times!
124  *
125  * Revision 1.28 2004/11/14 07:04:17 tcfujii
126  * Updated copyright text and/or year.
127  *
128  * Revision 1.27 2004/09/12 18:39:20 ramakant
129  * Bug# 6172060
130  *
131  * ASAPI => AMX name changes.
132  *
133  * 1) QL EE
134  * 26 pass, 2 fail, 1 did not run
135  *
136  * Failed: ConverterApp. Cause: EJB Timer Service not available.
137  *
138  * Didnot run: ejb-cmp-roster
139  *
140  * 2) Deployment dev tests - DAS, INSTANCE, CLUSTER
141  *
142  * All pass except for known failures.
143  *
144  * Revision 1.26 2004/05/22 00:35:05 kravtch
145  * "system-properties" backend support is added
146  * Reviewer: Sridatta
147  * Tests passed: QLT/CTS PE
148  *
149  * Revision 1.25 2004/04/20 03:10:45 kravtch
150  * Reviewer:Sridatta
151  * cofigbean.setAttributeValue() - cast value to String is replaced by call toString(). Non-string value provided by AMX MBeans - createHTTPListener().
152  * Test passed: QLT, JUnit
153  *
154  * Revision 1.24 2004/02/20 03:56:08 qouyang
155  *
156  *
157  * First pass at code merge.
158  *
159  * Details for the merge will be published at:
160  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
161  *
162  * Revision 1.22.4.4 2004/02/02 07:25:14 tcfujii
163  * Copyright updates notices; reviewer: Tony Ng
164  *
165  * Revision 1.22.4.3 2003/12/23 01:51:44 kravtch
166  * Bug #4959186
167  * Reviewer: Sridatta
168  * Checked in PE8FCS_BRANCH
169  * (1) admin/admin-core/admin-cli/admin-gui/appserv-core/assembly-tool: switch to new domain name "ias:" -> "com.sun.appserv"
170  * (2) admin-core and admin-cli: switch to "dashed" attribute names
171  * (3) admin-core: support both "dashed"/"underscored" names for get/setAttributes
172  * (4) admin-gui: hook for reverse converting attribute names (temporary hack);
173  *
174  * Revision 1.22.4.2 2003/12/18 20:25:13 ramakant
175  * Bug# 4923404
176  * Reviewer: Alex
177  *
178  * Revision 1.22.4.1 2003/12/01 21:52:38 kravtch
179  * Bug #4939964
180  * Reviewer: Sridatta
181  * admin.config.ManagedConfigBean.createChildByType() now analyzes registryEntries.AttributeInfo for each "empty" valued attribute (similar to setAttribute(), but could not use MBeanAttributeInfo because MBean is not exists yet). If "emptyValueAllowed" field in registrEntry.AttributeInfo is not "true", then "empty" attribute will be ignored.
182  *
183  * Revision 1.22 2003/10/11 00:00:04 kravtch
184  * Bug 4933034
185  * Reviewer: Abhijit
186  * New field in attribute descriptor marks attributes which allows empty values.
187  * admin-descrptors file modified for "http-listener" mbean, adding:
188  * <attribute name="server_name" >
189  * <descriptor>
190  * <field name="emptyValueAllowed" value="true" />
191  * </descriptor>
192  * </attribute>
193  * BaseConfigMBean class modified to analyse this flag and properly perform setAttribute().
194  *
195  * Revision 1.21 2003/09/26 21:33:03 kravtch
196  * Bug #4926266
197  * Reviewer: Sridatta
198  * - new test cases added to Validator's ThreadPoolTest DELETE - isThreadPoolReferencedFromOrb and isThreadPoolReferencedFromResAdapter to avoid deleteion of the referenced element
199  * - correspondent localStrings are added;
200  * - ManagedConfigBean.deleteSelf() now throws Exception;
201  * - MBeanHelper.invokeOperationInBean() will not suppress runtime exceptions any more;
202  *
203  * Revision 1.20 2003/09/16 23:19:11 kravtch
204  * Bug #4923642
205  * reviewer: Abhijit
206  * Special MBeanConfigInstanceNotFoundException will be thrown by getXXX()/getXXXbyYYY(name) operations, returning ObjectName in case if correspondent element in domain.xml does not exist.
207  * This exception will be handled specifically on GUI invoke() operation. So, this exception should not be used for other cases (thrown or extended).
208  *
209  * Revision 1.19 2003/09/13 00:40:00 kravtch
210  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211  * Bug #4920070;
212  * Reviewer: Sridatta
213  * More informative Exceptions messeges formed for this and similar cases.
214  *
215  * Revision 1.18 2003/09/11 21:45:57 kravtch
216  * Bug #4910961 and few others
217  * Reviewer: Sridatta
218  *
219  * BaseConfigMBean now throws Exception if ConfIgBeans opeartions getXXXbyYYY() return "null"
220  * I had to wrap into try/catch some calls from MBeans/backendDeployment which relied on old behaviour.
221  *
222  * Revision 1.17 2003/09/10 22:57:52 kravtch
223  * Bug: #4919955
224  * Reviewer: Sridatta
225  * ManagedConfigBean: during removeChild() operation DottedNames manager was notified only if correspondent MBeans were registered. Notification added.
226  *
227  * Revision 1.16 2003/09/10 00:24:22 kravtch
228  * Reviewer: Sridatta
229  * New operation in DomainMBean is returning list of default attribute values according to mbean type. This operation will return DTD defined default values if custom mbean does not implement its own static operation overriding(extending) standard ones.
230  *
231  * Revision 1.15 2003/08/29 02:16:41 kravtch
232  * Bug #4910964 (and similar others)
233  * Reviewer: Sridatta
234  *
235  * Exception handling and logging enchancements:
236  * - extraction target exception for MBeanException and TargetInvocationException:
237  * - switch to localStrings usage;
238  * - throwing exception for config MBeans if error in creation of ConfigBean;
239  * - exceptions for null-results in configbean operations,like getXXbyYYY() [changes commented because of crashing of quick test]
240  *
241  * Revision 1.14 2003/08/20 05:57:24 kravtch
242  * Dotted name registration is added at the end of CreateChildByType():
243  * m_registry.notifyRegisterMBean(objectName, getConfigContext());
244  *
245  * Revision 1.13 2003/08/18 21:48:48 kravtch
246  * new static getParentXPath(xpath) returns xpath of parent element correcly bypassing bracketed values with possible escaping inside of quoted values
247  *
248  * Revision 1.12 2003/08/18 02:49:08 kravtch
249  * deleteSelf() temporary catches all exceptions
250  * and prints info to log
251  *
252  * Revision 1.11 2003/08/18 01:51:15 kravtch
253  * temporary restore deleteConfigElement()
254  *
255  * Revision 1.10 2003/08/15 23:09:52 kravtch
256  * calls to notifyRegisterMBean/UnregisterMBean from posrRegister/postDeregister
257  * removeChild support is added;
258  * new test cases for dotted names testing
259  *
260  * Revision 1.9 2003/08/14 23:16:17 kravtch
261  * invokeOperation() signature changed;
262  * BaseConfigMBean now uses mcb.invokeOperation();
263  *
264  * Revision 1.8 2003/08/12 21:01:32 kravtch
265  * added support for get/setAttribute for String[] attributes through invoke getValues/setValue in ConfigBean
266  *
267  * Revision 1.7 2003/08/07 00:41:04 kravtch
268  * - new DTD related changes;
269  * - properties support added;
270  * - getDefaultAttributeValue() implemented for config MBeans;
271  * - merge Jsr77 and config activity in runtime mbeans;
272  *
273  * Revision 1.6 2003/07/18 20:14:43 kravtch
274  * 1. ALL config mbeans are now covered by descriptors.xml
275  * 2. new infrastructure for runtime mbeans is added
276  * 3. generic constructors added to jsr77Mdl beans (String[])
277  * 4. new test cases are added to admintest
278  * 5. MBeanRegistryFactory has now different methods to obtain admin/runtime registries
279  * 6. runtime-descriptors xml-file is added to build
280  *
281  * Revision 1.5 2003/06/25 20:03:38 kravtch
282  * 1. java file headers modified
283  * 2. properties handling api is added
284  * 3. fixed bug for xpathes containing special symbols;
285  * 4. new testcases added for jdbc-resource
286  * 5. introspector modified by not including base classes operations;
287  *
288  *
289 */

290
291 package com.sun.enterprise.admin.config;
292
293 import java.text.CharacterIterator JavaDoc;
294 import java.text.StringCharacterIterator JavaDoc;
295 import java.lang.reflect.Method JavaDoc;
296 import java.lang.reflect.InvocationTargetException JavaDoc;
297 import java.util.Iterator JavaDoc;
298 import java.util.ArrayList JavaDoc;
299 import java.util.Properties JavaDoc;
300 import java.util.Enumeration JavaDoc;
301
302 import java.util.logging.Level JavaDoc;
303 import java.util.logging.Logger JavaDoc;
304 import com.sun.logging.LogDomains;
305
306 import com.sun.enterprise.util.i18n.StringManager;
307
308 //JMX imports
309
import javax.management.*;
310 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
311 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
312 import javax.management.Descriptor JavaDoc;
313 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
314
315 //Config imports
316
import com.sun.enterprise.config.ConfigBean;
317 import com.sun.enterprise.config.ConfigBeansFactory;
318 import com.sun.enterprise.config.ConfigContext;
319 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
320 import com.sun.enterprise.config.serverbeans.ElementProperty;
321 import com.sun.enterprise.config.serverbeans.SystemProperty;
322
323 //naming
324
//import com.sun.enterprise.admin.meta.MBeanDescriptor;
325
import com.sun.enterprise.admin.meta.naming.MBeanNamingDescriptor;
326 import com.sun.enterprise.admin.meta.naming.MBeanNamingInfo;
327 import com.sun.enterprise.admin.meta.MBeanMetaConstants;
328 import com.sun.enterprise.admin.meta.MBeanRegistry;
329 import com.sun.enterprise.admin.meta.MBeanMetaHelper;
330 import com.sun.enterprise.admin.meta.MBeanRegistryEntry;
331 import com.sun.enterprise.admin.meta.MBeanMetaException;
332
333 import com.sun.enterprise.admin.MBeanHelper;
334 import com.sun.enterprise.admin.BaseAdminMBean;
335 import com.sun.enterprise.admin.AdminValidationException;
336
337
338 /****************************************************************************************************************
339  */

340 public class ManagedConfigBean {
341     public final String JavaDoc PROPERTY_NAME_PREFIX = "property."; //FIXME: should be exrternal
342
public final String JavaDoc SYSTEM_PROPERTY_NAME_PREFIX = "system-property."; //FIXME: should be exrternal
343

344     public static final Logger JavaDoc _sLogger = LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
345     private final static String JavaDoc MSG_BASE_GET_ATTRIBUTE = "mbean.config.base_get_attribute";
346     private final static String JavaDoc MSG_BASE_SET_ATTRIBUTE = "mbean.config.base_set_attribute";
347     private final static String JavaDoc MSG_BASE_GOT_ATTRIBUTE = "mbean.config.base_got_attribute";
348     private final static String JavaDoc MSG_BASE_GET_PROPERTY = "mbean.config.base_get_property";
349     private final static String JavaDoc MSG_BASE_GET_PROPERTIES = "mbean.config.base_get_properties";
350     private final static String JavaDoc MSG_BASE_SET_PROPERTY = "mbean.config.base_set_property";
351     private final static String JavaDoc MSG_BASE_GET_DEF_ATTR_VALUE = "mbean.config.get_def_attr_value";
352     private final static String JavaDoc MSG_GET_CONFBEANBYXPATH = "mbean.config.get_confbeanbyxpath";
353     private final static String JavaDoc MSG_BASE_GET_CUSTOM_PROPERTIESLIST = "mbean.config.base_get_custom_property";
354     
355     private ConfigBean m_baseConfigBean;
356     private MBeanInfo JavaDoc m_mbeanInfo;
357     private MBeanRegistry m_registry;
358     private ConfigContext m_configContext; //we need it for keeping trace to deleted element context
359

360     // i18n StringManager
361
private static StringManager localStrings = StringManager.getManager( BaseAdminMBean.class );
362     
363         
364     public ManagedConfigBean(DynamicMBean mbean, ConfigBean cb, MBeanRegistry registry)
365     {
366         this(mbean.getMBeanInfo(), cb, registry);
367     }
368     
369     public ManagedConfigBean(MBeanInfo JavaDoc mbeanInfo, ConfigBean cb, MBeanRegistry registry)
370     {
371         m_baseConfigBean = cb;
372         m_mbeanInfo = mbeanInfo;
373         m_configContext = cb.getConfigContext();
374         m_registry = registry;
375     }
376
377     public ManagedConfigBean(ConfigBean cb,
378             MBeanRegistry registry, String JavaDoc domainName) throws Exception JavaDoc
379     {
380         this(cb, null, registry, domainName);
381     }
382     
383     public ManagedConfigBean(ConfigBean cb, String JavaDoc xpath,
384             MBeanRegistry registry, String JavaDoc domainName) throws Exception JavaDoc
385     {
386         if(xpath==null)
387             xpath = cb.getAbsoluteXPath("");
388         MBeanRegistryEntry entry = registry.findMBeanRegistryEntryByXPath(xpath);
389         MBeanNamingDescriptor descr = entry.getNamingDescriptor();
390         String JavaDoc[] parms = descr.extractParmListFromXPath(xpath);
391         MBeanNamingInfo namingInfo = new MBeanNamingInfo(descr, descr.getType(), parms);
392         
393         m_mbeanInfo = (MBeanInfo JavaDoc)entry.createMBeanInfo(namingInfo, domainName);
394         m_baseConfigBean = cb;
395         m_configContext = cb.getConfigContext();
396         m_registry = registry;
397     }
398     /****************************************************************************************************************
399     public static ManagedConfigBean getManagedConfigBean(cb
400     /****************************************************************************************************************
401      */

402     public ConfigContext getConfigContext() {
403         return m_configContext;
404     }
405     /****************************************************************************************************************
406      */

407     public MBeanNamingInfo getConfigMBeanNamingInfo() {
408         return null; //FIXME return m_MBeanNamingInfo;
409
}
410     
411     
412     /****************************************************************************************************************
413      * Get base node Config Bean;
414      * @return ConfigBean related to the ConfigNode object of node which is used as base for locationg of the attributes.
415      */

416     public ConfigBean getBaseConfigBean() {
417         return m_baseConfigBean;
418     }
419     
420     
421     /****************************************************************************************************************
422       Get <code>ConfigBean</code> object which contains correspondent attribute.
423       @param externalName external name of the attribute
424       @return <code>ConfigBean</code> object which contains correspondent attribute
425      */

426     public ConfigBean getConfigBean(String JavaDoc externalName)
427     {
428         //in 8.0 we support only base config bean attributes and properties access
429
return m_baseConfigBean;
430 /*7.0 //this method can be overriten in child class (temporary until Config static method getBeanByXPath will be ready)
431         AttrDescriptor descr = getDescriptor(externalName);
432         try
433         {
434             return descr.getConfigBean();
435         }
436         catch (Exception e)
437         {
438             return null;
439         }
440 */

441     }
442     
443     
444     /****************************************************************************************************************
445      * Gets MBean's attribute value.
446      * @param externalName the MBean's attribute name.
447      * @return The value of the attribute retrieved.
448      * @throws MBeanException exception
449      * @throws AttributeNotFoundException exception
450      */

451     public Object JavaDoc getAttribute(ModelMBeanAttributeInfo JavaDoc attrInfo, String JavaDoc externalName) throws MBeanException,AttributeNotFoundException {
452         _sLogger.log(Level.FINEST, MSG_BASE_GET_ATTRIBUTE, externalName);
453         
454         MBeanAttributeInfo JavaDoc ai = getAttrInfo(externalName);
455         boolean isProperty = externalName.startsWith(PROPERTY_NAME_PREFIX);
456         boolean isSystemProperty = externalName.startsWith(SYSTEM_PROPERTY_NAME_PREFIX);
457         boolean isArray = false;
458         
459         if(externalName.equals("modelerType"))
460             return null;
461         if(ai==null && !isProperty && !isSystemProperty) {
462             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_defined", externalName );
463             throw new AttributeNotFoundException( msg );
464         }
465         if(ai!=null && !ai.isReadable()) {
466             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_readable", externalName );
467             throw new AttributeNotFoundException( msg );
468         }
469         
470         
471         
472 // try {
473
if(isProperty)
474         {
475             // get property value
476
return getPropertyValue(externalName.substring(PROPERTY_NAME_PREFIX.length()));
477         }
478         else if(isSystemProperty)
479         {
480             // get system property value
481
return getSystemPropertyValue(externalName.substring(SYSTEM_PROPERTY_NAME_PREFIX.length()));
482         }
483         else
484         {
485             AttrDescriptor descr = getDescriptor(externalName);
486             ConfigBean bean = getConfigBean(externalName);
487             Object JavaDoc value = null;
488             if(descr.isElement())
489             {
490                 //it looks that now we have no Elements with values
491
//value = descr.getNode().getContent();
492
wrapAndThrowMBeanException(null, "getattribute_not_implemented_for_xml", externalName);
493             }
494             else
495             {
496                 if(ai.getType().startsWith("[")) //array
497
{
498                     Class JavaDoc cl = bean.getClass();
499                     try
500                     {
501                         Method JavaDoc method = cl.getMethod("getValues", new Class JavaDoc[]{Class.forName("java.lang.String")});
502                         value = method.invoke(bean, new Object JavaDoc[]{ConfigBean.camelize(descr.getAttributeName())});
503                     }
504                     catch (Exception JavaDoc e)
505                     {
506                         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_invocation_error", externalName );
507                         throw MBeanHelper.extractAndWrapTargetException(e, msg);
508                     }
509                 }
510                 else
511                 {
512                     value = bean.getAttributeValue(descr.getAttributeName());
513                 }
514                 
515                 
516                 
517                 //value = descr.getNode().getAttributeValue(descr.getAttributeName());
518
}
519             _sLogger.log(Level.FINEST, MSG_BASE_GOT_ATTRIBUTE, new Object JavaDoc[]
520             {externalName,value});
521             return value;
522         }
523  // }
524
// catch (MBeanConfigException e) {
525
// String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_attribute_exception", externalName, e.getMessage() );
526
// throw new MBeanException(new MBeanConfigException( msg ));
527
// }
528

529     }
530     
531     /****************************************************************************************************************
532      */

533     public MBeanAttributeInfo JavaDoc getAttributeInfo(String JavaDoc attrName)
534     {
535         attrName = MBeanMetaHelper.mapToMBeanAttributeName(attrName);
536         return (ModelMBeanAttributeInfo JavaDoc)
537               MBeanHelper.findMatchingAttributeInfo(m_mbeanInfo, attrName);
538     }
539     
540     /****************************************************************************************************************
541      * Gets MBean's child element.
542      * @param childName the MBean's child element name.
543      * @return The value of the property retrieved.
544      * @throws MBeanException exception
545      * @throws AttributeNotFoundException exception
546      */

547     public ConfigBean getChildElementByName(String JavaDoc methodName, String JavaDoc name) throws MBeanException,AttributeNotFoundException
548     {
549
550         ConfigBean baseBean = getBaseConfigBean();
551         Class JavaDoc cl = baseBean.getClass();
552         ConfigBean bean;
553         try
554         {
555            Method JavaDoc method = cl.getDeclaredMethod(methodName, new Class JavaDoc[]{Class.forName("java.lang.String")});
556            return (ConfigBean)method.invoke(baseBean, new Object JavaDoc[]{name});
557         }
558         catch (Exception JavaDoc e)
559         {
560             wrapAndThrowMBeanException(e, "getattribute.undefined_childelement_in_base_element", name );
561             return null; //just to avoid compiling err
562
}
563     }
564
565     /****************************************************************************************************************
566      */

567     public AttributeList getProperties() throws MBeanException,AttributeNotFoundException {
568         _sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTIES);
569         
570         ConfigBean baseBean = getBaseConfigBean();
571         Class JavaDoc cl = baseBean.getClass();
572         ElementProperty[] props = null;
573         try {
574             Method JavaDoc method = cl.getDeclaredMethod("getElementProperty");
575             props = (ElementProperty[])method.invoke(baseBean);
576         }
577         catch (Exception JavaDoc e) {
578             wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element" );
579         }
580         if(props==null) {
581             return new AttributeList();
582         }
583         AttributeList list = new AttributeList();
584         for(int i=0; i<props.length; i++)
585         {
586             list.add(new Attribute(props[i].getName(), props[i].getValue()));
587         }
588         return list;
589     }
590
591     /****************************************************************************************************************
592      */

593     public AttributeList getSystemProperties() throws MBeanException,AttributeNotFoundException {
594         _sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTIES);
595         
596         ConfigBean baseBean = getBaseConfigBean();
597         Class JavaDoc cl = baseBean.getClass();
598         SystemProperty[] props = null;
599         try {
600             Method JavaDoc method = cl.getDeclaredMethod("getSystemProperty");
601             props = (SystemProperty[])method.invoke(baseBean);
602         }
603         catch (Exception JavaDoc e) {
604             wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element" );
605         }
606         if(props==null) {
607             return new AttributeList();
608         }
609         AttributeList list = new AttributeList();
610         for(int i=0; i<props.length; i++)
611         {
612             list.add(new Attribute(props[i].getName(), props[i].getValue()));
613         }
614         return list;
615     }
616
617     public Object JavaDoc getDefaulCustomProperties(String JavaDoc propertyName) throws MBeanException,AttributeNotFoundException {
618         _sLogger.log(Level.FINEST, MSG_BASE_GET_CUSTOM_PROPERTIESLIST, propertyName);
619         return null; //can be overriden
620
}
621
622     /****************************************************************************************************************
623      * Gets MBean's property value.
624      * @param externalName the MBean's property name.
625      * @return The value of the property retrieved.
626      * @throws MBeanException exception
627      * @throws AttributeNotFoundException exception
628      */

629     public Object JavaDoc getPropertyValue(String JavaDoc propertyName) throws MBeanException,AttributeNotFoundException {
630         _sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTY, propertyName);
631         
632         ConfigBean baseBean = getBaseConfigBean();
633         Class JavaDoc cl = baseBean.getClass();
634         ElementProperty prop = null;
635         try {
636             Method JavaDoc method = cl.getDeclaredMethod("getElementPropertyByName", new Class JavaDoc[]{Class.forName("java.lang.String")});
637             prop = (ElementProperty)method.invoke(baseBean, new Object JavaDoc[]{propertyName});
638         }
639         catch (Exception JavaDoc e) {
640             wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element");
641         }
642         if(prop==null) {
643             wrapAndThrowMBeanException(null, "getattribute_properties_not_found_in_base_element", propertyName );
644         }
645         return prop.getValue();
646     }
647     /****************************************************************************************************************
648      * Gets MBean's system property value.
649      * @param externalName the MBean's system property name.
650      * @return The value of the system property retrieved.
651      * @throws MBeanException exception
652      * @throws AttributeNotFoundException exception
653      */

654     public Object JavaDoc getSystemPropertyValue(String JavaDoc propertyName) throws MBeanException,AttributeNotFoundException {
655         _sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTY, propertyName);
656         
657         ConfigBean baseBean = getBaseConfigBean();
658         Class JavaDoc cl = baseBean.getClass();
659         SystemProperty prop = null;
660         try {
661             Method JavaDoc method = cl.getDeclaredMethod("getSystemPropertyByName", new Class JavaDoc[]{Class.forName("java.lang.String")});
662             prop = (SystemProperty)method.invoke(baseBean, new Object JavaDoc[]{propertyName});
663         }
664         catch (Exception JavaDoc e) {
665             wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element");
666         }
667         if(prop==null) {
668             wrapAndThrowMBeanException(null, "getattribute_properties_not_found_in_base_element", propertyName );
669         }
670         return prop.getValue();
671     }
672
673     /****************************************************************************************************************
674      * Sets MBean's property value.
675      * @param attr The identification of the property to be set and the value it is to be set to.
676      * @throws MBeanException exception
677      * @throws AttributeNotFoundException exception
678      */

679     public void setProperty(Attribute attr) throws MBeanException,AttributeNotFoundException {
680         setElementProperty(attr, false);
681     }
682     /****************************************************************************************************************
683      * Sets MBean's system property value.
684      * @param attr The identification of the system property to be set and the value it is to be set to.
685      * @throws MBeanException exception
686      * @throws AttributeNotFoundException exception
687      */

688     public void setSystemProperty(Attribute attr) throws MBeanException,AttributeNotFoundException {
689         setSystemProperty(attr, false);
690     }
691
692     //****************************************************************************************************************
693
private void setElementProperty(Attribute attr, boolean bAllowsEmptyValue) throws MBeanException,AttributeNotFoundException {
694         String JavaDoc propertyName = attr.getName();
695         String JavaDoc value = (String JavaDoc)attr.getValue();
696         _sLogger.log(Level.FINEST, MSG_BASE_SET_PROPERTY, new Object JavaDoc[]{propertyName, value});
697         
698         ConfigBean baseBean = getBaseConfigBean();
699         
700         Class JavaDoc cl = baseBean.getClass();
701         ElementProperty prop = null;
702         try {
703             Method JavaDoc method = cl.getDeclaredMethod("getElementPropertyByName", new Class JavaDoc[]{Class.forName("java.lang.String")});
704             prop = (ElementProperty)method.invoke(baseBean, new Object JavaDoc[]{propertyName});
705         }
706         catch (Exception JavaDoc e) {
707             wrapAndThrowMBeanException(e, "setattribute_undefined_properties_in_base_element", propertyName );
708         }
709         if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals(""))) {
710             prop = new ElementProperty();
711             prop.setName(propertyName);
712             if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
713                prop.setValue("");
714             else
715                prop.setValue(value);
716             try {
717                 Method JavaDoc method = cl.getDeclaredMethod("addElementProperty", new Class JavaDoc[]{prop.getClass()});
718                 method.invoke(baseBean, new Object JavaDoc[]{prop});
719             }
720             catch (Exception JavaDoc e) {
721                 wrapAndThrowMBeanException(e, "setproperty_invoke_error", propertyName );
722             }
723         }
724         else {
725             if(value==null || (!bAllowsEmptyValue && value.equals(""))) {
726                 try {
727                     Method JavaDoc method = cl.getDeclaredMethod("removeElementProperty", new Class JavaDoc[]{prop.getClass()});
728                     method.invoke(baseBean, new Object JavaDoc[]{prop});
729                 }
730                 catch (Exception JavaDoc e) {
731                     wrapAndThrowMBeanException(e, "setproperty_could_not_remove_propery", propertyName );
732                 }
733             }
734             else
735             {
736                 if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
737                    prop.setValue("");
738                 else
739                    prop.setValue(value);
740             }
741         }
742     }
743         
744     private void setSystemProperty(Attribute attr, boolean bAllowsEmptyValue) throws MBeanException,AttributeNotFoundException {
745         String JavaDoc propertyName = attr.getName();
746         String JavaDoc value = (String JavaDoc)attr.getValue();
747         _sLogger.log(Level.FINEST, MSG_BASE_SET_PROPERTY, new Object JavaDoc[]{propertyName, value});
748         
749         ConfigBean baseBean = getBaseConfigBean();
750         
751         Class JavaDoc cl = baseBean.getClass();
752         SystemProperty prop=null;
753         try {
754             Method JavaDoc method = cl.getDeclaredMethod("getSystemPropertyByName", new Class JavaDoc[]{Class.forName("java.lang.String")});
755             prop = (SystemProperty)method.invoke(baseBean, new Object JavaDoc[]{propertyName});
756         }
757         catch (Exception JavaDoc e) {
758             wrapAndThrowMBeanException(e, "setattribute_undefined_properties_in_base_element", propertyName );
759         }
760         if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals(""))) {
761             prop = new SystemProperty();
762             prop.setName(propertyName);
763             if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
764                prop.setValue("");
765             else
766                prop.setValue(value);
767             try {
768                 Method JavaDoc method = cl.getDeclaredMethod("addSystemProperty", new Class JavaDoc[]{prop.getClass()});
769                 method.invoke(baseBean, new Object JavaDoc[]{prop});
770             }
771             catch (Exception JavaDoc e) {
772                 wrapAndThrowMBeanException(e, "setproperty_invoke_error", propertyName );
773             }
774         }
775         else {
776             if(value==null || (!bAllowsEmptyValue && value.equals(""))) {
777                 try {
778                     Method JavaDoc method = cl.getDeclaredMethod("removeSystemProperty", new Class JavaDoc[]{prop.getClass()});
779                     method.invoke(baseBean, new Object JavaDoc[]{prop});
780                 }
781                 catch (Exception JavaDoc e) {
782                     wrapAndThrowMBeanException(e, "setproperty_could_not_remove_propery", propertyName );
783                 }
784             }
785             else
786             {
787                 if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
788                    prop.setValue("");
789                 else
790                    prop.setValue(value);
791             }
792         }
793 /*
794         try {
795             m_configContext.flush();
796         }
797         catch (ConfigException e) {
798             throw new MBeanException(new MBeanConfigException(e.getMessage()));
799         }
800 */

801  }
802     
803     
804     /****************************************************************************************************************
805      * Gets MBean's attribute default value or null (if def value is not defined).
806      * @param externalName the MBean's attribute name.
807      * @return The default value of the attribute retrieved null, if def value is not defined.
808      * @throws MBeanException exception
809      * @throws AttributeNotFoundException exception
810      */

811     public String JavaDoc getDefaultAttributeValue(String JavaDoc externalName) throws Exception JavaDoc //AttributeNotFoundException,MBeanConfigException {
812
{
813         _sLogger.log(Level.FINEST, MSG_BASE_GET_DEF_ATTR_VALUE, externalName);
814         MBeanAttributeInfo JavaDoc ai = getAttrInfo(externalName);
815         if(ai==null) {
816             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.getdefaultattribute_undefined_attribute", externalName );
817             throw new AttributeNotFoundException( msg );
818         }
819         // try
820
{
821             AttrDescriptor descr = getDescriptor(externalName);
822             String JavaDoc value = descr.getDefaultValue();
823             return value;
824         }
825 /* catch (ConfigException e)
826         {
827                         String msg = localStrings.getString( "admin.server.core.mbean.config.getdefaultattributevalue_exception_for_externalname_basexpath", externalName, m_BasePath, e.getMessage() );
828             throw new MBeanException(new ConfigException( msg ));
829         }
830  */

831     }
832     
833     //*******************************************************************************************************
834
/**
835      * @param ai MBeanAttributeInfo
836      * @return true is EmptyValue is allowed for this attribute
837      */

838     private static boolean isEmptyValueAllowed(MBeanAttributeInfo JavaDoc ai) {
839         if(ai!=null && (ai instanceof ModelMBeanAttributeInfo JavaDoc))
840         {
841             try {
842                 Descriptor JavaDoc descr = ((ModelMBeanAttributeInfo JavaDoc)ai).getDescriptor();
843                 String JavaDoc strAllowed = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.EMPTYVALUEALLOWED_FIELD_NAME);
844                 if(Boolean.valueOf(strAllowed).booleanValue())
845                     return true;
846             } catch(Exception JavaDoc e)
847             {
848             }
849         }
850         return false;
851     }
852     /****************************************************************************************************************
853      * Sets MBean's attribute value.
854      * @param attr The identification of the attribute to be set and the value it is to be set to.
855      * @throws MBeanException exception
856      * @throws AttributeNotFoundException exception
857      */

858     public void setAttribute(ModelMBeanAttributeInfo JavaDoc attrInfo, Attribute attr) throws MBeanException,AttributeNotFoundException {
859         String JavaDoc externalName = attr.getName();
860         Object JavaDoc value = attr.getValue();
861         _sLogger.log(Level.FINEST, MSG_BASE_SET_ATTRIBUTE, new Object JavaDoc[]{externalName, value});
862         MBeanAttributeInfo JavaDoc ai = getAttrInfo(externalName);
863         boolean isProperty = externalName.startsWith(PROPERTY_NAME_PREFIX);
864         boolean isSystemProperty = externalName.startsWith(SYSTEM_PROPERTY_NAME_PREFIX);
865         if(ai==null && !isProperty && !isSystemProperty) {
866             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_attribute", externalName );
867             throw new AttributeNotFoundException( msg );
868         }
869         if(ai!=null && !ai.isWritable()) {
870             wrapAndThrowMBeanException(null, "setattribute_attribute_not_writable", externalName );
871         }
872         
873 // try {
874
if(isProperty)
875         {
876             boolean bAllowsEmptyValue = isEmptyValueAllowed(ai);
877             // set property value
878
setElementProperty(new Attribute(externalName.substring(PROPERTY_NAME_PREFIX.length()), value), bAllowsEmptyValue);
879             return;
880         }
881         else if(isSystemProperty)
882         {
883             boolean bAllowsEmptyValue = isEmptyValueAllowed(ai);
884             // set system property value
885
setSystemProperty(new Attribute(externalName.substring(SYSTEM_PROPERTY_NAME_PREFIX.length()), value), bAllowsEmptyValue);
886             return;
887         }
888         else
889         { //normal attribute
890
// check type (now only for exception)
891
// left check for Verifyer now (bug #4725686)
892
// MBeanEasyConfig.convertStringValueToProperType(value.toString(), ai.getType());
893

894             AttrDescriptor descr = getDescriptor(externalName);
895             ConfigBean bean = getConfigBean(externalName);
896             if(descr.isElement())
897             {
898                 //it looks that now we have no Elements with values
899
//bean.set???Value(descr.getAttributeName(), value.toString());
900
wrapAndThrowMBeanException(null, "not_supported_attribute_type", externalName );
901                 
902                 // descr.getNode().setContent(value.toString());
903
// m_configContext.flush();
904
}
905             else
906             {
907                 if(ai.getType().startsWith("[")) //array
908
{
909                     Class JavaDoc cl = bean.getClass();
910                     try
911                     {
912                         Method JavaDoc method = cl.getMethod("setValue", new Class JavaDoc[]{Class.forName("java.lang.String"),(new Object JavaDoc[0]).getClass()});
913                         method.invoke(bean, new Object JavaDoc[]{ConfigBean.camelize(descr.getAttributeName()),value});
914                     }
915                     catch (Exception JavaDoc e)
916                     {
917                         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_invocation_error", externalName );
918                         throw MBeanHelper.extractAndWrapTargetException(e, msg);
919                     }
920                 }
921                 else
922                 {
923                     //descr.getNode().setAttribute(descr.getAttributeName(), value.toString());
924
if(value==null || (value.equals("") && !isEmptyValueAllowed(ai)) )
925                         bean.setAttributeValue(descr.getAttributeName(), null);
926                     else
927                         bean.setAttributeValue(descr.getAttributeName(), value.toString());
928                     // m_configContext.flush();
929
}
930             }
931         }
932         
933 // }
934
// catch (MBeanConfigException mce)
935
// {
936
// String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_attribute_exception", externalName, mce.getMessage() );
937
// throw new MBeanException(new MBeanConfigException( msg ));
938
// }
939
// catch (ConfigException e) {
940
// String msg = localStrings.getString( "admin.server.core.mbean.config.setAttribute_exception_for_externalname_basexpath", externalName, /*m_BasePath,*/ e.getMessage() );
941
// throw new MBeanException(new MBeanConfigException( msg ));
942
// }
943
}
944     
945     
946      //
947
private void addArrayToList(ArrayList JavaDoc list, Object JavaDoc[] objects)
948     {
949         for(int i=0; i<objects.length; i++) {
950             list.add(objects[i]);
951         }
952     }
953     
954     /****************************************************************************************************************
955      * Gets MBean's attribute values.
956      * @param attributeNames A list of the attributes names to be retrieved.
957      * @return The list of attributes retrieved.
958      */

959     protected ArrayList JavaDoc getSimpleAttributeNames(String JavaDoc[] attributeNames) {
960         ArrayList JavaDoc simpleNames = new ArrayList JavaDoc();
961         for(int i=0; i<attributeNames.length; i++) {
962                 if(attributeNames[i].length()==0) {
963                     addArrayToList(simpleNames, getAllAttributeNames());
964                 }
965                 else if(attributeNames[i].equals(PROPERTY_NAME_PREFIX)) {
966                     addArrayToList(simpleNames, getAllPropertyNames(true));
967                 }
968                 else if(attributeNames[i].equals(SYSTEM_PROPERTY_NAME_PREFIX)) {
969                     addArrayToList(simpleNames, getAllSystemPropertyNames(true));
970                 }
971                 else {
972                     simpleNames.add(attributeNames[i]);
973                 }
974                 
975         }
976         return simpleNames;
977     }
978
979     /****************************************************************************************************************
980      * Gets MBean's attribute values.
981      * @param attributeNames A list of the attributes names to be retrieved.
982      * @return The list of attributes retrieved.
983      */

984     public AttributeList getAttributes(String JavaDoc[] attributeNames) {
985         ArrayList JavaDoc names = getSimpleAttributeNames(attributeNames);
986         AttributeList attrs = new AttributeList();
987         for(int i=0; i<names.size(); i++) {
988             try {
989                 String JavaDoc name = MBeanMetaHelper.mapToMBeanAttributeName((String JavaDoc)names.get(i));
990                 Object JavaDoc value = getAttribute(null, name); //FIXME
991
attrs.add(new Attribute(name, value));
992             } catch (MBeanException ce) {
993 // attrs.add(new Attribute(attributeNames[i], null));
994
} catch (AttributeNotFoundException ce) {
995 // attrs.add(new Attribute(attributeNames[i], null));
996
} catch (NullPointerException JavaDoc npe) //ConfigBean returns this exception by many reasons
997
{
998 // attrs.add(new Attribute(attributeNames[i], null));
999
}
1000        }
1001        return attrs;
1002    }
1003    
1004    /****************************************************************************************************************
1005     * Sets the values of several MBean's attributes.
1006     * @param attrList A list of attributes: The identification of the attributes to be set and the values they are to be set to.
1007     * @return The list of attributes that were set, with their new values.
1008     */

1009    public AttributeList setAttributes(AttributeList attrList) {
1010        AttributeList attrs = new AttributeList();
1011        Iterator JavaDoc it = attrList.iterator();
1012        while (it.hasNext()) {
1013            try {
1014                Attribute attribute = (Attribute) it.next();
1015                attribute = new Attribute(MBeanMetaHelper.mapToMBeanAttributeName(attribute.getName()), attribute.getValue());
1016                setAttribute(null, attribute); //FIXME: attrInfos?
1017
attrs.add(attribute);
1018            }
1019            catch (MBeanException mbe) {
1020            }
1021            catch (AttributeNotFoundException anfe) {
1022            }
1023            catch (NullPointerException JavaDoc npe) {
1024            }
1025        }
1026        return attrs;
1027    }
1028    /**
1029     * Every resource MBean should override this method to execute specific
1030     * operations on the MBean.
1031     */

1032    public Object JavaDoc invoke(String JavaDoc methodName, Object JavaDoc[] methodParams,
1033    String JavaDoc[] methodSignature) throws MBeanException, ReflectionException {
1034        return null;
1035    }
1036    
1037    
1038    //****************************************************************************************************************
1039
private AttrDescriptor getDescriptor(String JavaDoc externalName) {
1040        try {
1041            return new AttrDescriptor(externalName); //FIXME
1042
} catch (MBeanConfigException mbce)
1043        {
1044            return null;
1045        }
1046// return (AttrDescriptor)m_Attrs.get(externalName);
1047
}
1048    
1049    //****************************************************************************************************
1050
private MBeanAttributeInfo JavaDoc getAttrInfo(String JavaDoc attrName) {
1051        if(m_mbeanInfo==null )
1052            return null;
1053        MBeanAttributeInfo JavaDoc[] ai = m_mbeanInfo.getAttributes();
1054        if(ai!=null)
1055            for(int i=0; i<ai.length; i++) {
1056                String JavaDoc name = ai[i].getName();
1057                if(attrName.equals(ai[i].getName()))
1058                    return ai[i];
1059            }
1060        return null; //FIXME
1061
}
1062    
1063    //****************************************************************************************************
1064
private String JavaDoc[] getAllAttributeNames() {
1065        MBeanInfo JavaDoc mbi = m_mbeanInfo;
1066        if(mbi==null )
1067            return null;
1068        MBeanAttributeInfo JavaDoc[] ai = mbi.getAttributes();
1069        if(ai==null || ai.length==0)
1070            return null;
1071        ArrayList JavaDoc list = new ArrayList JavaDoc();
1072        if(ai!=null)
1073            for(int i=0; i<ai.length; i++)
1074            {
1075                String JavaDoc name = ai[i].getName();
1076                if(!name.equals("modelerType")) //FIXME: temporary
1077
list.add(name);
1078            }
1079        return (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]);
1080    }
1081    
1082    //****************************************************************************************************
1083
private String JavaDoc[] getAllPropertyNames(boolean bAddPropertyPrefix) {
1084        
1085        ConfigBean baseBean = getBaseConfigBean();
1086        Class JavaDoc cl = baseBean.getClass();
1087        ElementProperty[] props;
1088        try {
1089            Method JavaDoc method = cl.getDeclaredMethod("getElementProperty");
1090            props = (ElementProperty[])method.invoke(baseBean);
1091            String JavaDoc[] names = new String JavaDoc[props.length];
1092            for(int i=0; i<props.length; i++) {
1093                if(bAddPropertyPrefix)
1094                    names[i] = PROPERTY_NAME_PREFIX+props[i].getName();
1095                else
1096                    names[i] = props[i].getName();
1097            }
1098            return names;
1099        }
1100        catch (java.lang.NoSuchMethodException JavaDoc nsme) {
1101            return null;
1102        }
1103        catch (java.lang.IllegalAccessException JavaDoc iae) {
1104            return null;
1105        }
1106        catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
1107            return null;
1108        }
1109    }
1110    
1111    //****************************************************************************************************
1112
private String JavaDoc[] getAllSystemPropertyNames(boolean bAddPropertyPrefix) {
1113        
1114        ConfigBean baseBean = getBaseConfigBean();
1115        Class JavaDoc cl = baseBean.getClass();
1116        SystemProperty[] props;
1117        try {
1118            Method JavaDoc method = cl.getDeclaredMethod("getSystemProperty");
1119            props = (SystemProperty[])method.invoke(baseBean);
1120            String JavaDoc[] names = new String JavaDoc[props.length];
1121            for(int i=0; i<props.length; i++) {
1122                if(bAddPropertyPrefix)
1123                    names[i] = SYSTEM_PROPERTY_NAME_PREFIX+props[i].getName();
1124                else
1125                    names[i] = props[i].getName();
1126            }
1127            return names;
1128        }
1129        catch (java.lang.NoSuchMethodException JavaDoc nsme) {
1130            return null;
1131        }
1132        catch (java.lang.IllegalAccessException JavaDoc iae) {
1133            return null;
1134        }
1135        catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
1136            return null;
1137        }
1138    }
1139    
1140/*
1141    //****************************************************************************************************
1142    public ObjectName[] getChildrenForType(String childName) throws Exception
1143    {
1144        if(m_baseConfigBean==null)
1145            return null;
1146        String xpath = m_baseConfigBean.getAbsoluteXPath(null) +
1147                        ServerXPathHelper.XPATH_SEPARATOR + childName;
1148        Class cl = ConfigMBeanHelper.getConfigBeanClass(xpath);
1149        ConfigBean bean = (ConfigBean)cl.newInstance();
1150        if(childValues!=null)
1151            for(int i=0; i<childValues.size(); i++)
1152            {
1153                Attribute attr = (Attribute)childValues.get(i);
1154                bean.setAttributeValue(attr.getName(), (String)attr.getValue());
1155            }
1156        Class clBase = m_baseConfigBean.getClass();
1157        Method method = clBase.getDeclaredMethod("get"+convertTagName(childName),
1158                                            new Class[]{cl});
1159        Object res = method.invoke(m_baseConfigBean, new Object[]{bean});
1160        return bean;
1161    }
1162*/

1163    //****************************************************************************************************
1164
public ConfigBean createChildByType(String JavaDoc childName, AttributeList childValues, Properties JavaDoc props, boolean bOnlyOneChildPossible) throws Exception JavaDoc
1165    {
1166        //First. Create standalone bean of child type with Attributes and Properties set
1167
ConfigBean bean = createChildByType(childName, childValues, props);
1168        if(bean==null)
1169            return null;
1170        
1171        // Now, connect it to papa bean
1172
addChildBean(childName, bean, bOnlyOneChildPossible);
1173        return bean;
1174    }
1175    
1176    //****************************************************************************************************
1177
public ConfigBean createChildByType(String JavaDoc childName, AttributeList childValues, Properties JavaDoc props) throws Exception JavaDoc
1178    {
1179        if(m_baseConfigBean==null)
1180            return null;
1181        String JavaDoc xpath = MBeanHelper.getXPathPattern( (ModelMBeanInfo JavaDoc)m_mbeanInfo) +
1182                           ServerXPathHelper.XPATH_SEPARATOR + childName;
1183        Class JavaDoc cl = ConfigMBeanHelper.getConfigBeanClass(xpath);
1184        ConfigBean bean = (ConfigBean)cl.newInstance();
1185        MBeanRegistryEntry regEntry = m_registry.findMBeanRegistryEntryByXPathPattern(xpath);
1186        if(childValues!=null)
1187            for(int i=0; i<childValues.size(); i++)
1188            {
1189                
1190                Attribute attr = (Attribute)childValues.get(i);
1191                if( (attr.getValue()==null || attr.getValue().equals("")))
1192                {
1193                    //empty value set bypass if not allowed in the registry
1194
boolean bEmptyValueAllowed = false;
1195                    try {
1196                       // analyze registry_Entry emptyValueAllowed (if mentioned)
1197
bEmptyValueAllowed = regEntry.isAttributeEmptyValueAllowed(attr.getName());
1198                    } catch (MBeanMetaException mme)
1199                    {
1200                        //field not found in registry
1201
}
1202                    if(!bEmptyValueAllowed)
1203                        continue; //skip set of empty value
1204
}
1205                if(attr.getValue()==null)
1206                    bean.setAttributeValue(MBeanMetaHelper.mapToConfigBeanAttributeName(attr.getName()), (String JavaDoc)attr.getValue());
1207                else
1208                    bean.setAttributeValue(MBeanMetaHelper.mapToConfigBeanAttributeName(attr.getName()), ""+attr.getValue());
1209            }
1210        if(props!=null && props.size()>0)
1211        {
1212            final Enumeration JavaDoc e = props.propertyNames();
1213            ArrayList JavaDoc propsList = new ArrayList JavaDoc();
1214            while (e.hasMoreElements())
1215            {
1216                ElementProperty ep = new ElementProperty();
1217                String JavaDoc key = (String JavaDoc)e.nextElement();
1218                ep.setName(key);
1219                ep.setValue(props.getProperty(key));
1220                propsList.add(ep);
1221            }
1222            if(propsList.size()>0)
1223            {
1224               ElementProperty eps[] = (ElementProperty[])propsList.toArray(
1225                                 new ElementProperty[propsList.size()]);
1226               bean.setValue("ElementProperty", eps);
1227            }
1228        }
1229        return bean;
1230    }
1231    
1232    //****************************************************************************************************
1233
public void addChildBean(String JavaDoc childName, ConfigBean bean, boolean bOnlyOneChildPossible) throws Exception JavaDoc
1234    {
1235        Class JavaDoc clBase = m_baseConfigBean.getClass();
1236        Method JavaDoc method;
1237        if(bOnlyOneChildPossible)
1238            method = clBase.getDeclaredMethod("set"+ConfigMBeanHelper.convertTagName(childName), new Class JavaDoc[]{bean.getClass()});
1239        else
1240            method = clBase.getDeclaredMethod("add"+ConfigMBeanHelper.convertTagName(childName), new Class JavaDoc[]{bean.getClass()});
1241        method.invoke(m_baseConfigBean, new Object JavaDoc[]{bean});
1242    }
1243
1244    //****************************************************************************************************
1245
void removeChild(String JavaDoc opName, MBeanOperationInfo JavaDoc opInfo, Object JavaDoc params[], String JavaDoc childTag) throws Exception JavaDoc
1246    {
1247        
1248        MBeanOperationInfo JavaDoc getInfo = new MBeanOperationInfo JavaDoc("get"+opName.substring("remove".length()),
1249                                                            "",
1250                                                            opInfo.getSignature(),
1251                                                            "java.lang.Object",
1252                                                            MBeanOperationInfo.INFO);
1253        Object JavaDoc ret = MBeanHelper.invokeOperationInBean(getInfo, this.getBaseConfigBean(), params);
1254        if(ret==null)
1255        {
1256            String JavaDoc parentName = "";
1257            parentName = this.getBaseConfigBean().getClass().getName();
1258            int last = parentName.lastIndexOf('.');
1259            if(last>=0 && last<(parentName.length()-1))
1260                parentName = parentName.substring(last+1);
1261            String JavaDoc elemName = "";
1262            if(params!=null && params.length==1 && params[0] instanceof String JavaDoc)
1263                elemName = "\""+(String JavaDoc)params[0]+"\"";
1264            wrapAndThrowMBeanException(null, "element_not_found", new Object JavaDoc[]{parentName, childTag, elemName});
1265        }
1266        if(ret==MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
1267        {
1268            String JavaDoc elemName = "";
1269            if(params.length==1 && params[0] instanceof String JavaDoc)
1270                elemName = (String JavaDoc)params[0];
1271            wrapAndThrowMBeanException(null, "remove_get_invocation",
1272                    new Object JavaDoc[]{opName, elemName} );
1273        }
1274        ArrayList JavaDoc arr = new ArrayList JavaDoc();
1275        collectChildrenObjectNames((ConfigBean)ret, arr);
1276        //remove bean
1277
m_baseConfigBean.removeChild((ConfigBean)ret);
1278        //now is time for unregister
1279
MBeanServer server = null;
1280        try {
1281           server = (MBeanServer)(MBeanServerFactory.findMBeanServer(null)).get(0);
1282        } catch(Exception JavaDoc e) {}; //try-catch for AdminTest only
1283

1284        for(int i=0; i<arr.size(); i++)
1285        {
1286            ObjectName objectName = (ObjectName)arr.get(i);
1287            try
1288            {
1289                if(server.isRegistered(objectName))
1290                    server.unregisterMBean(objectName);
1291                else
1292                    //just to unregister dotted name
1293
m_registry.notifyUnregisterMBean(objectName, getConfigContext());
1294            }
1295            catch (Throwable JavaDoc t)
1296            {
1297                _sLogger.fine("!!!!!!!!!!!!!! Can not unregister MBean: "+objectName);
1298            }
1299        }
1300    }
1301
1302   //****************************************************************************************************
1303
void collectChildrenObjectNames(ConfigBean bean, ArrayList JavaDoc arr)
1304   {
1305        try
1306        {
1307            ConfigBean[] beans = bean.getAllChildBeans();
1308            for(int i=0; i<beans.length; i++)
1309            {
1310                collectChildrenObjectNames(beans[i], arr);
1311            }
1312        }
1313        catch(Exception JavaDoc e)
1314        {
1315        }
1316        try
1317        {
1318            ObjectName name = (ObjectName)ConfigMBeanHelper.converConfigBeansToObjectNames(m_registry, (ModelMBeanInfo JavaDoc)m_mbeanInfo, (Object JavaDoc)bean);
1319            if(name!=null)
1320               arr.add(name);
1321        }
1322        catch(Exception JavaDoc e)
1323        {
1324        }
1325   }
1326
1327    //****************************************************************************************************
1328
public void deleteSelf() throws Exception JavaDoc
1329    {
1330        if(m_baseConfigBean==null)
1331            return;
1332        String JavaDoc xpath = null;
1333//try {
1334
xpath = m_baseConfigBean.getAbsoluteXPath(null);
1335        xpath = ServerXPathHelper.getParentXPath(xpath);
1336        ConfigContext ctx = getConfigContext(); //com.sun.enterprise.admin.config.BaseConfigMBean.getConfigContext(); //FIXME: this method should not be in MBEAN
1337
ConfigBean parent = ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
1338        parent.removeChild(m_baseConfigBean);
1339//} catch(Exception e)
1340
//{
1341
//FIXME:temporary solution
1342
// System.out.println("Exception during deleteSelf() xpath="+xpath);
1343
//}
1344
}
1345 
1346    //****************************************************************************************************************
1347
private class AttrDescriptor {
1348        public String JavaDoc m_attributeName;
1349        public boolean m_bAllowsEmptyValue = false;
1350        
1351        //*******************************************************************************************************
1352
public AttrDescriptor(String JavaDoc description) throws MBeanConfigException {
1353            try {
1354                m_attributeName = MBeanMetaHelper.mapToConfigBeanAttributeName(description);
1355                
1356/*FIXME //first investigate: is it element value or attriibute value
1357                int lastSlashIdx = description.lastIndexOf(ServerXPathHelper.XPATH_SEPARATOR);
1358                if(description.charAt(lastSlashIdx+1)==ATTRIBUTE_CHAR) { //element's attribute
1359                    if(description.charAt(lastSlashIdx+2)==ALLOWS_EMPTY_CHAR) {
1360                        m_attributeName = description.substring(lastSlashIdx+3);
1361                        m_bAllowsEmptyValue = true;
1362                    }
1363                    else
1364                        m_attributeName = description.substring(lastSlashIdx+2);
1365                    
1366                    if(lastSlashIdx>0)
1367                        m_xPath = description.substring(0,lastSlashIdx);
1368                }
1369                else { //element's content
1370                    m_attributeName = null; //not attribute
1371                }
1372*/

1373 }
1374            catch (Throwable JavaDoc e) {
1375                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.attrdescriptor_constructor_exception", description, e.getMessage() );
1376                throw new MBeanConfigException( msg );
1377            }
1378        }
1379        
1380        //*******************************************************************************************************
1381
public String JavaDoc getAttributeName() {
1382            return m_attributeName;
1383        }
1384        
1385        //*******************************************************************************************************
1386
public boolean isEmptyValueAllowed() {
1387            return m_bAllowsEmptyValue;
1388        }
1389
1390        //****************************************************************************************************
1391
public String JavaDoc getDefaultValue() throws Exception JavaDoc {
1392            if(m_baseConfigBean==null || isProperty() || isSystemProperty() || isElement())
1393                return null;
1394               //we have to do it through invoke because it's declared as static overriden in extended class
1395
Class JavaDoc clBase = m_baseConfigBean.getClass();
1396               Method JavaDoc method = clBase.getDeclaredMethod("getDefaultAttributeValue", new Class JavaDoc[]{Class.forName("java.lang.String")});
1397               return (String JavaDoc)method.invoke(m_baseConfigBean, new Object JavaDoc[]{m_attributeName});
1398        }
1399        //*******************************************************************************************************
1400
public boolean isProperty() {
1401            if( m_attributeName!=null)
1402                return m_attributeName.startsWith(PROPERTY_NAME_PREFIX);
1403            return false;
1404        }
1405        //*******************************************************************************************************
1406
public boolean isSystemProperty() {
1407            if( m_attributeName!=null)
1408                return m_attributeName.startsWith(SYSTEM_PROPERTY_NAME_PREFIX);
1409            return false;
1410        }
1411        //*******************************************************************************************************
1412
public boolean isElement() {
1413            return (m_attributeName==null);
1414        }
1415    }
1416
1417    public Object JavaDoc invokeOperation(ModelMBeanOperationInfo JavaDoc opInfo, Object JavaDoc params[], String JavaDoc signature[]) throws Exception JavaDoc
1418    {
1419        Descriptor JavaDoc descr = opInfo.getDescriptor();
1420        String JavaDoc opName = opInfo.getName();
1421        String JavaDoc child = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.CHILD_FIELD_NAME);
1422        String JavaDoc multi = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.MULTI_FIELD_NAME);
1423        boolean bOnlyOne = true;
1424        if(multi!=null && multi.length()>0 &&
1425           multi.charAt(0)=='t')
1426            bOnlyOne = false;
1427        if(child!=null && opName.startsWith("create"))
1428        {
1429           ConfigBean bean = createChildByType(child, (AttributeList)params[0], null, bOnlyOne);
1430           ObjectName objectName = ConfigMBeanHelper.getChildObjectName(m_registry, (ModelMBeanInfo JavaDoc)m_mbeanInfo, bean);
1431           m_registry.notifyRegisterMBean(objectName, getConfigContext());
1432           return objectName;
1433        }
1434        
1435        if(child!=null && opName.startsWith("remove"))
1436        {
1437            removeChild(opName, opInfo, params, child);
1438            return null;
1439        }
1440
1441
1442            
1443        //Generic Config invoker
1444
Object JavaDoc ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
1445        if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
1446        {
1447            return ret;
1448        }
1449        
1450        boolean bNamesListOp = false;
1451        String JavaDoc modifiedOpName = opName;
1452        if(!bOnlyOne && child!=null &&
1453           opName.startsWith("get") &&
1454           opName.endsWith(MBeanMetaConstants.GET_LISTNAMES_OP_SUFFIX))
1455        {
1456            bNamesListOp = true;
1457            modifiedOpName = opName.substring(0, opName.length()-
1458                      MBeanMetaConstants.GET_LISTNAMES_OP_SUFFIX.length());
1459        }
1460
1461        ret = MBeanHelper.invokeOperationInBean(modifiedOpName, opInfo,
1462                this.getBaseConfigBean(), params);
1463        
1464        if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
1465        {
1466          if(ret==null && "javax.management.ObjectName".equals(opInfo.getReturnType()))
1467            {
1468                String JavaDoc parentName = "";
1469                parentName = this.getBaseConfigBean().getClass().getName();
1470                int last = parentName.lastIndexOf('.');
1471                if(last>=0 && last<(parentName.length()-1))
1472                    parentName = parentName.substring(last+1);
1473                String JavaDoc elemName = "";
1474                if(params!=null && params.length==1 && params[0] instanceof String JavaDoc)
1475                    elemName = (String JavaDoc)params[0];
1476                String JavaDoc msg;
1477                if(child!=null)
1478                    msg = localStrings.getString( "admin.server.core.mbean.config.element_not_found", new Object JavaDoc[]{parentName, child, elemName});
1479                else
1480                    msg = localStrings.getString( "admin.server.core.mbean.config.oper_element_not_found", new Object JavaDoc[]{parentName, modifiedOpName, elemName});
1481                throw new MBeanConfigInstanceNotFoundException(msg);
1482            }
1483
1484          if(ret!=null)
1485            {
1486                if(bNamesListOp && (ret instanceof ConfigBean[]))
1487                {
1488                    return (Object JavaDoc)ConfigMBeanHelper.getChildNamesList(
1489                            (ConfigBean[])ret);
1490                }
1491                else
1492                {
1493                    ret = ConfigMBeanHelper.converConfigBeansToObjectNames(m_registry,
1494                            (ModelMBeanInfo JavaDoc)m_mbeanInfo, ret);
1495                    if(ret instanceof ConfigBean)
1496                        return (Object JavaDoc)ConfigMBeanHelper.getChildObjectName(m_registry,
1497                                (ModelMBeanInfo JavaDoc)m_mbeanInfo, (ConfigBean)ret);
1498                    if(ret instanceof ConfigBean[])
1499                        return (Object JavaDoc)ConfigMBeanHelper.getChildObjectNames(m_registry,
1500                                (ModelMBeanInfo JavaDoc)m_mbeanInfo, (ConfigBean[])ret);
1501                }
1502            }
1503         return ret;
1504       }
1505       return MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT;
1506    }
1507
1508    private void uncatchValidationException(Exception JavaDoc e)
1509    {
1510        if(e instanceof AdminValidationException)
1511                throw (AdminValidationException)e;
1512        
1513        if(e instanceof InvocationTargetException JavaDoc)
1514        {
1515            Throwable JavaDoc t = ((InvocationTargetException JavaDoc)e).getTargetException();
1516            if(t instanceof AdminValidationException)
1517                throw (AdminValidationException)t;
1518        }
1519    }
1520    
1521    private void wrapAndThrowMBeanException(Exception JavaDoc e,
1522            String JavaDoc strSuffix) throws MBeanException
1523    {
1524        wrapAndThrowMBeanException(e, strSuffix, null);
1525    }
1526    private void wrapAndThrowMBeanException(Exception JavaDoc e,
1527            String JavaDoc strSuffix, Object JavaDoc val) throws MBeanException
1528    {
1529        if(e!=null)
1530            uncatchValidationException(e);
1531        String JavaDoc msg;
1532        if(val instanceof Object JavaDoc[])
1533           msg = localStrings.getString( "admin.server.core.mbean.config."+strSuffix, (Object JavaDoc[])val );
1534        else
1535           msg = localStrings.getString( "admin.server.core.mbean.config."+strSuffix, val );
1536        throw new MBeanException(new MBeanConfigException( msg ));
1537    }
1538    
1539}
1540 
1541
Popular Tags