KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseConfigMBean.java,v 1.8 2006/03/19 04:09:35 km105526 Exp $
26  * @author: alexkrav
27  *
28  * $Log: BaseConfigMBean.java,v $
29  * Revision 1.8 2006/03/19 04:09:35 km105526
30  * Issue number: BUG 6400594
31  * Obtained from: Anissa
32  * Submitted by: Kedar/Alex
33  * Reviewed by: Alex/Kedar
34  *
35  * Deployment is broken from GUI. It has to do with the attributes
36  * that were named with characters that can't be java identifier characters.
37  * This was a JMX 1.2 limitation.
38  *
39  * PE QL was run successfully.
40  * GUI deployment of apps successful.
41  *
42  * Watching Tinderbox ...
43  *
44  * Revision 1.7 2006/03/18 00:43:21 kravtch
45  * Issue #394 (Provide an MBean attribute to get JMXServiceURL of the System JMX Connector ...)
46  * admin-core/admin:
47  * repare for getAttributes():
48  * - BaseConfigMBean.getAttributes() now calls BaseConfigMBean.getAttribute() instead of ManagedConfigBean.getAttributes()
49  * Submitted by: kravtch
50  * Reviewed by: Kedar
51  * Affected modules admin/mbeans
52  * Tests passed: QLT/EE
53  *
54  * Revision 1.6 2006/03/12 01:26:56 jluehe
55  * Renamed AS's org.apache.commons.* to com.sun.org.apache.commons.*, to avoid collisions with org.apache.commons.* packages bundled by webapps.
56  *
57  * Tests run: QL, Servlet TCK
58  *
59  * Revision 1.5 2005/12/25 03:47:29 tcfujii
60  * Updated copyright text and year.
61  *
62  * Revision 1.4 2005/11/14 22:53:14 kravtch
63  * Bug #6338666 (Adding customRealm in adminGUI in the server-config throws BadRealmException in server.log)
64  * - ManagedConfigMBean.createChildByType() now sets Properties as well;
65  * - BaseConfigMBean: convenience methods getManagedConfigBean() & getConfigBeanObjectName() are added;
66  * - ConfigsMBean.createAuthRealm(): instead of call to MBeanServer - use ManagedConfigBean.createChildByType()
67  *
68  * Submitted by: kravtch
69  * Reviewed by: Kedar
70  * Affected modules admin/mbeans; admin-core/util; tools
71  * Tests passed: QLT/EE + devtests
72  *
73  * Revision 1.3 2005/08/10 23:36:26 kravtch
74  * M3: management-rules MBean support.
75  * - new custom ManagementRulesMBean is added
76  * (two methods -createManagementRule() and addActionToManagementRule())
77  * - operation getConfigNameForTarget() is added to ConfigsMBean
78  * - operation getBaseConfigBean is added to BaseConfigMBean
79  * - "management-rules" element changed in admin-mbean-desriptor
80  * Submitted by: kravtch
81  * Reviewed by: Prashanth
82  * Affected modules admin/mbeans; admin-core/admin
83  * Tests passed: QLT/EE + devtests
84  *
85  * Revision 1.2 2005/06/27 21:19:40 tcfujii
86  * Issue number: CDDL header updates.
87  *
88  * Revision 1.1.1.1 2005/05/27 22:52:02 dpatil
89  * GlassFish first drop
90  *
91  * Revision 1.22 2004/11/14 07:04:16 tcfujii
92  * Updated copyright text and/or year.
93  *
94  * Revision 1.21 2004/06/04 05:55:02 kebbs
95  * Sridatta, Alex, & I have decided that some refactoring of the EE mbeans
96  * is necessary to resolve some issues we are having around MBean classes
97  * being created outside the context of the mbean server. Specifically, the
98  * EE mbeans have some non-JMX compliant constructors (which take a
99  * ConfigContext) and are being instantiated via this constructor in other
100  * EE mbeans.
101  *
102  * We have decided that the appropriate solution is to convert the problematic
103  * mbean classes into non-mbeans and then delegate to them from the mbeans.
104  * A new package named configbeans will be introduced to hold these mbeans.
105  * These configbeans can be freely new'd.
106  *
107  * One benefit of this approach is that the transition to the new ISAPI
108  * mbeans (and removal of the existing MBeans) will go much smoother, since
109  * the business logic in the configbeans (relying only on the schema2beans
110  * classes) is cleanly separated from the MBeans which expose it.
111  *
112  * Reviewer: AK, SV
113  *
114  * Revision 1.20 2004/04/05 16:44:03 kravtch
115  * admin/meta/AdminConfigEventListener: new configcontext listener's code
116  * This listener is for synchronization of ConfigBeans changes with both MBeans and dotted-name spaces.
117  * admin/meta/MBeanRegistry: added methods (adoptConfigBeanDelete/Add) implementing beans ajustment
118  * admin/config/BaseConfigMBean: calls from MBean's postRegister/unregister methods to dotted-name-manager is commented out.
119  *
120  * Reviewer: Sridatta
121  * Tests Passed: QuickLook + UnitTest
122  *
123  * Revision 1.19 2004/03/17 17:45:35 kebbs
124  * 1) Re-factored Server, Node Agent, Cluster, APIs for use by GUI.
125  * 2) Cleaned up all the various stats interfaces and replaced them with
126  * RuntimeStatus for one consistent view
127  * 3) Renamed interfaces from IxxxMBean to xxxMBean to be more compliant
128  * 4) Moved node agent proxy and config mbeans into admin-ee/admin so they
129  * could leverage code ther
130  * 5) Added inherit flag to properties
131  * 6) Object names returned everywhere
132  * 7) Can no longer reference DAS config
133  *
134  * Revision 1.18 2004/02/20 03:56:07 qouyang
135  *
136  *
137  * First pass at code merge.
138  *
139  * Details for the merge will be published at:
140  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
141  *
142  *
143  * Revision 1.17 2003/11/18 23:36:05 kebbs
144  * 1)Added the mbeanapi package with interfaces for all of our "exposed"
145  * mbeans. This will be a way to view and cleanup our interfaces going
146  * forward as well as providing a way to expose them in the proxy.
147  *
148  * 2)Added ResourceHelper and ApplicationHelper classes as well as a way for the
149  * ServerTarget and ClusterTarget objects to be able to fetch resource and
150  * application references.
151  *
152  * 3)Refactored out ApplicationsMBeanHelper and ResourcesMBeanHelper for use
153  * in the PE mbeans. These are also used in the EE implementation of
154  * create/delete/list/resource/application-references.
155  *
156  * 4)And finally, all this was done so that the resource commands (ResourcesMBean)
157  * now fully support cluster and server targets.
158  *
159  * Revision 1.16.4.2 2004/02/02 07:25:13 tcfujii
160  * Copyright updates notices; reviewer: Tony Ng
161  *
162  * Revision 1.16.4.1 2003/12/23 01:51:43 kravtch
163  * Bug #4959186
164  * Reviewer: Sridatta
165  * Checked in PE8FCS_BRANCH
166  * (1) admin/admin-core/admin-cli/admin-gui/appserv-core/assembly-tool: switch to new domain name "ias:" -> "com.sun.appserv"
167  * (2) admin-core and admin-cli: switch to "dashed" attribute names
168  * (3) admin-core: support both "dashed"/"underscored" names for get/setAttributes
169  * (4) admin-gui: hook for reverse converting attribute names (temporary hack);
170  *
171  * Revision 1.16 2003/09/04 05:53:49 kravtch
172  * bugs #4896268 and #4913653
173  * Reviewer: Sridatta
174  * -AuthRealmMbean's getFielRealm is chaged from creating of the new FileRealm object to gettting it from security pool - Realm.getInstance(name) with casting result to FileRealm.
175  * This approach will work only for PE because DAS and instance have the same auth-realms.
176  * -AdminContext expanded by two new methods getAdminMBeanResourcUrl() and getRuntimeMBeanResourcUrl() which used by MBeanRegistryFactory for initialization admin and runtime registries. So, they are become pluggable.
177  * -AdminContext also notifies MBeanRegistryFactory during its construction. So, AdminContext become "visible" to admin-core/admin classes.
178  * -Hardcoded output changed to appropriate logger calls.
179  *
180  * Revision 1.15 2003/08/29 02:16:41 kravtch
181  * Bug #4910964 (and similar others)
182  * Reviewer: Sridatta
183  *
184  * Exception handling and logging enchancements:
185  * - extraction target exception for MBeanException and TargetInvocationException:
186  * - switch to localStrings usage;
187  * - throwing exception for config MBeans if error in creation of ConfigBean;
188  * - exceptions for null-results in configbean operations,like getXXbyYYY() [changes commented because of crashing of quick test]
189  *
190  * Revision 1.14 2003/08/18 01:51:15 kravtch
191  * temporary restore deleteConfigElement()
192  *
193  * Revision 1.13 2003/08/15 23:09:52 kravtch
194  * calls to notifyRegisterMBean/UnregisterMBean from posrRegister/postDeregister
195  * removeChild support is added;
196  * new test cases for dotted names testing
197  *
198  * Revision 1.12 2003/08/14 23:16:16 kravtch
199  * invokeOperation() signature changed;
200  * BaseConfigMBean now uses mcb.invokeOperation();
201  *
202  * Revision 1.11 2003/08/08 00:11:58 kravtch
203  * new convenience methods are added to BaseConfigMBean
204  * - getDomainName
205  * - getConfigContext
206  * - getChildObjectName
207  * - getMBeanServer
208  *
209  * Revision 1.10 2003/08/07 00:41:04 kravtch
210  * - new DTD related changes;
211  * - properties support added;
212  * - getDefaultAttributeValue() implemented for config MBeans;
213  * - merge Jsr77 and config activity in runtime mbeans;
214  *
215  * Revision 1.9 2003/07/18 20:14:43 kravtch
216  * 1. ALL config mbeans are now covered by descriptors.xml
217  * 2. new infrastructure for runtime mbeans is added
218  * 3. generic constructors added to jsr77Mdl beans (String[])
219  * 4. new test cases are added to admintest
220  * 5. MBeanRegistryFactory has now different methods to obtain admin/runtime registries
221  * 6. runtime-descriptors xml-file is added to build
222  *
223  * Revision 1.8 2003/06/25 20:03:37 kravtch
224  * 1. java file headers modified
225  * 2. properties handling api is added
226  * 3. fixed bug for xpathes containing special symbols;
227  * 4. new testcases added for jdbc-resource
228  * 5. introspector modified by not including base classes operations;
229  *
230  *
231 */

232
233 package com.sun.enterprise.admin.config;
234
235 import java.lang.reflect.InvocationTargetException JavaDoc;
236 import java.util.Iterator JavaDoc;
237 import java.util.Hashtable JavaDoc;
238 import java.util.ArrayList JavaDoc;
239
240 import javax.management.ObjectName JavaDoc;
241
242 //import com.sun.enterprise.admin.meta.MBeanRegistryEntry;
243

244 import javax.management.modelmbean.DescriptorSupport JavaDoc;
245 //import javax.management.modelmbean.InvalidTargetObjectTypeException;
246
//import javax.management.modelmbean.ModelMBean;
247
import javax.management.Descriptor JavaDoc;
248 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
249 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
250 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
251 import javax.management.*;
252
253 import com.sun.org.apache.commons.modeler.BaseModelMBean;
254 //base admin imports
255
import com.sun.enterprise.admin.BaseAdminMBean;
256 import com.sun.enterprise.admin.MBeanHelper;
257
258 //Config imports
259
import com.sun.enterprise.config.ConfigException;
260 //import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
261
import com.sun.enterprise.config.serverbeans.ServerTags;
262 import com.sun.enterprise.config.ConfigContext;
263 import com.sun.enterprise.config.ConfigFactory;
264 import com.sun.enterprise.config.ConfigBean;
265 import com.sun.enterprise.config.ConfigBeansFactory;
266 import com.sun.enterprise.config.serverbeans.ElementProperty;
267
268 import java.util.logging.Level JavaDoc;
269
270 //naming
271
import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
272 import com.sun.enterprise.admin.meta.MBeanRegistry;
273 import com.sun.enterprise.admin.meta.naming.MBeanNamingInfo;
274 import com.sun.enterprise.admin.meta.MBeanMetaConstants;
275 import com.sun.enterprise.admin.meta.MBeanMetaHelper;
276
277 /**
278  * <p>Base class for Config MBeans which implements basic config
279  * activity according to ModelMBeanInfo provided by MBeanRegistry
280  *
281  *
282  */

283
284 public class BaseConfigMBean extends BaseAdminMBean implements MBeanRegistration
285 {
286
287     /**
288      * FIXME: This is temporary. Ideally when we add a node controller or
289      * flush changes, we would like not to overwrite changes made on disk;
290      * however, all of the other flush() calls in the PE code, etc. implicitly
291      * pass overwrite as true. When I try to pass false, I run into the problem
292      * when multiple consecutive writes (e.g two calls to addNodeAgent) throw a "file
293      * has been modified" exception. So there is a bug somewhare.
294      */

295     public static final boolean OVERWRITE = true;
296
297     // ----------------------------------------------------------- Constructors
298

299     private ManagedConfigBean mcb = null;
300     protected MBeanRegistry m_registry = null;
301     
302     /**
303      * Construct a <code>ModelMBean</code> with default
304      * <code>ModelMBeanInfo</code> information.
305      *
306      * @exception MBeanException if the initializer of an object
307      * throws an exception
308      * @exception RuntimeOperationsException if an IllegalArgumentException
309      * occurs
310      */

311     public BaseConfigMBean() {
312         super();
313         m_registry = MBeanRegistryFactory.getAdminMBeanRegistry();
314     }
315
316     // ----------------------------------------------------- Instance Variables
317

318
319
320     // --------------------------------------------------- DynamicMBean Methods
321

322
323     /**
324      * Obtain and return the value of a specific attribute of this MBean.
325      *
326      * @param name Name of the requested attribute
327      *
328      * @exception AttributeNotFoundException if this attribute is not
329      * supported by this MBean
330      * @exception MBeanException if the initializer of an object
331      * throws an exception
332      * @exception ReflectionException if a Java reflection exception
333      * occurs when invoking the getter
334      */

335     public Object JavaDoc getAttribute(String JavaDoc name)
336         throws AttributeNotFoundException, MBeanException,
337             ReflectionException {
338                 name = MBeanMetaHelper.mapToMBeanAttributeName(name);
339                 ModelMBeanAttributeInfo JavaDoc attrInfo = (ModelMBeanAttributeInfo JavaDoc)MBeanHelper.findMatchingAttributeInfo((MBeanInfo JavaDoc)info, name);
340                 if(attrInfo==null)
341                     throw new AttributeNotFoundException(name);
342                 //FIXME add check "is readable"
343
Object JavaDoc o = null;
344                 try {
345                     o = super.getAttribute(name);
346                 } catch (Exception JavaDoc e) {
347 // try {
348
// if(mcb!=null)
349
o=mcb.getAttribute(attrInfo, name);
350 // } catch(Exception e1) {e1.printStackTrace();}
351
}
352                 return o;
353     }
354     
355     public AttributeList getAttributes(String JavaDoc[] attributeNames) {
356         ArrayList JavaDoc names = mcb.getSimpleAttributeNames(attributeNames);
357         AttributeList attrs = new AttributeList();
358         for(int i=0; i<names.size(); i++) {
359             try {
360                 String JavaDoc name = MBeanMetaHelper.mapToMBeanAttributeName((String JavaDoc)names.get(i));
361                 Object JavaDoc value = getAttribute(name);
362                 attrs.add(new Attribute(name, value));
363             } catch (Exception JavaDoc e) {
364 // attrs.add(new Attribute((String)names.get(i), null));
365
}
366         }
367         return attrs;
368     }
369
370    
371  /**
372      * Set the instance handle of the object against which we will execute
373      * all methods in this ModelMBean management interface.
374      *
375      * @param resource The resource object to be managed
376      * @param type The type of reference for the managed resource
377      * ("ObjectReference", "Handle", "IOR", "EJBHandle", or
378      * "RMIReference" OR "ConfigBeanReference" or "Jsr77ModelBeanReference")
379      *
380      * @exception InstanceNotFoundException if the managed resource object
381      * cannot be found
382      * @exception InvalidTargetObjectTypeException if this ModelMBean is
383      * asked to handle a reference type it cannot deal with
384      * @exception MBeanException if the initializer of the object throws
385      * an exception
386      * @exception RuntimeOperationsException if the managed resource or the
387      * resource type is <code>null</code> or invalid
388      */

389     public void setManagedResource(Object JavaDoc resource, String JavaDoc type)
390         throws InstanceNotFoundException, /*InvalidTargetObjectTypeException,*/
391         MBeanException, RuntimeOperationsException {
392
393         if (resource == null)
394         {
395             String JavaDoc msg = _localStrings.getString( "admin.server.core.mbean.config.base.managed_resource_is_null", mbeanType);
396             throw new RuntimeOperationsException(new IllegalArgumentException JavaDoc(msg), msg);
397         }
398         if (MBeanMetaConstants.CONFIG_BEAN_REF.equalsIgnoreCase(type)) {
399             if(! (resource instanceof ConfigBean))
400             {
401                 String JavaDoc msg = _localStrings.getString( "admin.server.core.mbean.config.base.managed_resource_is_not_configbean", mbeanType);
402                 throw new RuntimeOperationsException(new ClassCastException JavaDoc(msg), msg);
403             }
404             this.mcb = new ManagedConfigBean(this, (ConfigBean) resource, m_registry);
405             //Also add all attributes (and methods) to model mbean info
406
// mcb.addResourceInfo();
407

408         } else {
409 // super.setManagedResource(resource, type);
410
}
411     }
412
413     
414     /**
415      * Invoke a particular method on this MBean, and return any returned
416      * value.
417      *
418      * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation will
419      * attempt to invoke this method on the MBean itself, or (if not
420      * available) on the managed resource object associated with this
421      * MBean.</p>
422      *
423      * @param name Name of the operation to be invoked
424      * @param params Array containing the method parameters of this operation
425      * @param signature Array containing the class names representing
426      * the signature of this operation
427      *
428      * @exception MBeanException if the initializer of an object
429      * throws an exception
430      * @exception ReflectioNException if a Java reflection exception
431      * occurs when invoking a method
432      */

433     public Object JavaDoc invoke(String JavaDoc name, Object JavaDoc params[], String JavaDoc signature[])
434         throws MBeanException, ReflectionException {
435             ModelMBeanOperationInfo JavaDoc opInfo = (ModelMBeanOperationInfo JavaDoc)MBeanHelper.findMatchingOperationInfo((MBeanInfo JavaDoc)info, name, signature);
436             if (opInfo == null)
437             {
438                 String JavaDoc msg = _localStrings.getString( "admin.server.core.mbean.config.base.operation_is_not_found", mbeanType, name);
439                 throw new MBeanException
440                     (new ServiceNotFoundException(msg), msg);
441             }
442             Descriptor JavaDoc descr = opInfo.getDescriptor();
443             
444             Object JavaDoc ret;
445             //try MBean self
446
try
447             {
448                 ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
449                 if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
450                 {
451                     return ret;
452                 }
453                 //invoke in config bean
454
if(mcb!=null &&
455                    (ret=mcb.invokeOperation(opInfo, params, signature))!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
456                 {
457                     return ret;
458                 }
459                 return super.invoke(name, params, signature);
460             }
461             catch (MBeanException mbe)
462             {
463                 _sLogger.log(Level.FINE, "mbean.baseconfig.invoke_exception",mbe);
464                 throw mbe;
465             }
466             catch (Exception JavaDoc e)
467             {
468                 _sLogger.log(Level.FINE, "mbean.baseconfig.invoke_exception",e);
469                 String JavaDoc msg = _localStrings.getString( "admin.server.core.mbean.config.base.invoke_error", mbeanType, name);
470                 throw MBeanHelper.extractAndWrapTargetException(e, msg);
471             }
472     }
473
474     //convenient method for deploy operations
475
protected ObjectName JavaDoc createChildElementByType(String JavaDoc childElementName, Attribute[] attrs) throws Exception JavaDoc
476     {
477         return createChildElementByType(childElementName, attrs, true, false);
478     }
479     protected ObjectName JavaDoc createChildElementByType(String JavaDoc childElementName, Attribute[] attrs, boolean bSkipNullValued) throws Exception JavaDoc
480     {
481         return createChildElementByType(childElementName, attrs, bSkipNullValued, false);
482     }
483     protected ObjectName JavaDoc createChildElementByType(String JavaDoc childElementName, Attribute[] attrs, boolean bSkipNullValued, boolean bOnlyOne) throws Exception JavaDoc
484     {
485         AttributeList list = new AttributeList();
486         for(int i=0; i<attrs.length; i++)
487         {
488             if(!bSkipNullValued || attrs[i].getValue()!=null)
489                 list.add(attrs[i]);
490         }
491         ConfigBean bean = mcb.createChildByType(childElementName, list, null, bOnlyOne);
492         return ConfigMBeanHelper.getChildObjectName(m_registry, info, bean);
493     }
494
495     
496      /****************************************************************************************************************
497      * Sets the values of several MBean's attributes.
498      * @param attrList A list of attributes: The identification of the attributes to be set and the values they are to be set to.
499      * @return The list of attributes that were set, with their new values.
500      */

501
502     public AttributeList setAttributes(AttributeList list) {
503             try {
504                 return super.setAttributes(list);
505             } catch (Exception JavaDoc e) {
506
507 // try {
508
//no toString(). remove it. FIXME
509
if(mcb!=null)
510                         return mcb.setAttributes(list);
511 // } catch(Exception e1) {e1.printStackTrace();}
512
}
513             return null;
514     }
515
516     /**
517      * Set the value of a specific attribute of this MBean.
518      *
519      * @param attribute The identification of the attribute to be set
520      * and the new value
521      *
522      * @exception AttributeNotFoundException if this attribute is not
523      * supported by this MBean
524      * @exception MBeanException if the initializer of an object
525      * throws an exception
526      * @exception ReflectionException if a Java reflection exception
527      * occurs when invoking the getter
528      */

529     public void setAttribute(Attribute attribute)
530         throws AttributeNotFoundException, MBeanException,
531         ReflectionException
532     {
533                 attribute = new Attribute(MBeanMetaHelper.mapToMBeanAttributeName(attribute.getName()), attribute.getValue());
534                 ModelMBeanAttributeInfo JavaDoc attrInfo = (ModelMBeanAttributeInfo JavaDoc)MBeanHelper.findMatchingAttributeInfo((MBeanInfo JavaDoc)info, attribute.getName());
535                 if(attrInfo==null)
536                     throw new AttributeNotFoundException();
537                 //FIXME add check "is writable"
538

539                 try {
540                     super.setAttribute(attribute);
541                 } catch (Exception JavaDoc e) {
542                     
543 // try {
544
//no toString(). remove it. FIXME
545
if(mcb!=null)
546                             mcb.setAttribute(attrInfo, attribute);
547 // } catch(Exception e1) {e1.printStackTrace();}
548
}
549         
550     }
551
552
553     // -------------------- Registration --------------------
554
// XXX We can add some method patterns here - like setName() and
555
// setDomain() for code that doesn't implement the Registration
556

557     public ObjectName JavaDoc preRegister(MBeanServer server,
558                                   ObjectName JavaDoc name)
559             throws Exception JavaDoc
560     {
561 /* try
562         {
563             m_registry.notifyRegisterMBean(name, getConfigContext());
564         }
565         catch(Exception e)
566         {
567         }
568  */

569         return name;
570     }
571
572     public void postRegister(Boolean JavaDoc registrationDone) {
573     }
574
575     public void preDeregister() throws Exception JavaDoc {
576     }
577
578     public void postDeregister() {
579 /*
580         ObjectName oName=null;
581         try
582         {
583             oName = ConfigMBeanHelper.getOwnObjectName(m_registry, info);
584             m_registry.notifyUnregisterMBean(oName, getConfigContext());
585         }
586         catch(Exception e)
587         {
588         }
589 */

590     }
591     
592     public boolean destroyConfigElement() throws Exception JavaDoc //FIXME: MBeanException?
593
{
594         if(mcb==null)
595         {//FIXME: should be exception if null
596
return false;
597         }
598         mcb.deleteSelf();
599         //now unregister MBean
600
ObjectName JavaDoc objectName = ConfigMBeanHelper.getOwnObjectName(m_registry, info);
601         if(objectName!=null)
602         {
603             try{
604                 MBeanServer server = (MBeanServer)(MBeanServerFactory.findMBeanServer(null)).get(0);
605                 server.unregisterMBean(objectName);
606                 }
607             catch (Throwable JavaDoc t)
608                 {
609                     _sLogger.fine("!!!!!!!!!!!!!! Can not unregister MBean: "+objectName);
610                 }
611             return true;
612     }
613
614         return false;
615         //FIXME handle exceptions
616
//return false;
617
}
618  
619     // ------------------------------------------------------ Convenient Methods
620
//****************************************************************************
621
protected ConfigContext getConfigContext()
622     {
623         if(mcb!=null) {
624             return mcb.getConfigContext();
625         }
626         return null;
627     }
628     /****************************************************************************************************************
629      * Get base node Config Bean;
630      * @return ConfigBean related to the MBean's related ConfigNode .
631      */

632     public ConfigBean getBaseConfigBean() {
633         if(mcb!=null) {
634            return mcb.getBaseConfigBean();
635         }
636         return null;
637     }
638     //****************************************************************************
639
protected String JavaDoc getDomainName() throws MBeanException
640     {
641         final ModelMBeanInfo JavaDoc info = (ModelMBeanInfo JavaDoc)getMBeanInfo();
642         if (info != null) {
643             String JavaDoc[] location = MBeanHelper.getLocation(info);
644             if(location!=null && location.length>0) {
645                 return location[0];
646             }
647         }
648         return null;
649     }
650     
651     //****************************************************************************
652
protected ManagedConfigBean getManagedConfigBean(ConfigBean cb) throws Exception JavaDoc
653     {
654         return new ManagedConfigBean(cb, m_registry, getDomainName());
655     }
656     
657     //********************************************************************************************************************
658
public ObjectName JavaDoc getConfigBeanObjectName(ConfigBean configBean) throws Exception JavaDoc
659     {
660         return ConfigMBeanHelper.getConfigBeanObjectName(
661                 m_registry, getDomainName(), configBean);
662     }
663     
664     //****************************************************************************
665
protected MBeanServer getMBeanServer() throws MBeanException
666     {
667         return (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
668     }
669     //****************************************************************************
670
protected ObjectName JavaDoc getChildObjectName(String JavaDoc childMBeanType, // type in Registry e.g. "jdbc-resource"
671
String JavaDoc name // e.g. "myJndiName"; can be null for non keyed subelements
672
) throws MBeanException
673     {
674         if(m_registry==null)
675             return null;
676         String JavaDoc[] parentLocation = MBeanHelper.getLocation((ModelMBeanInfo JavaDoc)getMBeanInfo());
677         if(parentLocation==null || parentLocation.length==0)
678             return null;
679         if(name==null)
680             return m_registry.getMbeanObjectName(childMBeanType, parentLocation);
681         String JavaDoc[] childLocation = new String JavaDoc[parentLocation.length+1];
682         for(int i=0; i<parentLocation.length; i++)
683             childLocation[i] = parentLocation[i];
684         childLocation[parentLocation.length] = name;
685         return m_registry.getMbeanObjectName(childMBeanType, childLocation);
686     }
687        
688     protected ObjectName JavaDoc getServerObjectName(String JavaDoc server)
689         throws MBeanException
690     {
691         return m_registry.getMbeanObjectName("server", new String JavaDoc[]{
692             getDomainName(), server});
693     }
694   
695     protected ObjectName JavaDoc[] toServerONArray(String JavaDoc[] ca) throws MBeanException
696     {
697         int num = ca.length;
698         final ObjectName JavaDoc[] result = new ObjectName JavaDoc[num];
699         
700         for (int i = 0; i < num; i++)
701         {
702             result[i] = getServerObjectName(ca[i]);
703         }
704         return result;
705     }
706               
707     protected ObjectName JavaDoc getClusterObjectName(String JavaDoc name)
708         throws MBeanException
709     {
710         return m_registry.getMbeanObjectName("cluster", new String JavaDoc[]{
711             getDomainName(), name});
712     }
713     
714     protected ObjectName JavaDoc[] toClusterONArray(String JavaDoc[] ca) throws MBeanException
715     {
716         int num = ca.length;
717         final ObjectName JavaDoc[] result = new ObjectName JavaDoc[num];
718         for (int i = 0; i < num; i++)
719         {
720             result[i] = getClusterObjectName(ca[i]);
721         }
722         return result;
723     }
724     
725     protected ObjectName JavaDoc getConfigurationObjectName(String JavaDoc name)
726         throws MBeanException
727     {
728         return m_registry.getMbeanObjectName("config", new String JavaDoc[]{
729             getDomainName(), name});
730     }
731     
732     protected ObjectName JavaDoc[] toConfigurationONArray(String JavaDoc[] ca) throws MBeanException
733     {
734         int num = ca.length;
735         final ObjectName JavaDoc[] result = new ObjectName JavaDoc[num];
736         for (int i = 0; i < num; i++)
737         {
738             result[i] = getConfigurationObjectName(ca[i]);
739         }
740         return result;
741     }
742     
743     protected ObjectName JavaDoc getNodeAgentObjectName(String JavaDoc name)
744         throws MBeanException
745     {
746         return m_registry.getMbeanObjectName("node-agent", new String JavaDoc[]{
747             getDomainName(), name});
748     }
749
750     protected ObjectName JavaDoc[] toNodeAgentONArray(String JavaDoc[] names) throws MBeanException
751     {
752         int numNames = names.length;
753         final ObjectName JavaDoc[] result = new ObjectName JavaDoc[numNames];
754         for (int i = 0; i < numNames; i++) {
755             result[i] = getNodeAgentObjectName(names[i]);
756         }
757         return result;
758     }
759 }
760
Popular Tags