KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > ConfigFactory


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/config/ConfigFactory.java,v 1.13 2006/03/17 03:34:15 llc Exp $
26  * $Revision: 1.13 $
27  * $Date: 2006/03/17 03:34:15 $
28  */

29 package com.sun.enterprise.management.config;
30
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.Properties JavaDoc;
37 import java.util.Collections JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 import java.lang.reflect.Method JavaDoc;
41
42 import javax.management.ObjectName JavaDoc;
43 import javax.management.MBeanServer JavaDoc;
44 import javax.management.AttributeList JavaDoc;
45 import javax.management.Attribute JavaDoc;
46 import javax.management.InstanceNotFoundException JavaDoc;
47
48 import com.sun.appserv.management.base.AMX;
49 import com.sun.appserv.management.base.Util;
50 import com.sun.appserv.management.base.Container;
51 import com.sun.appserv.management.base.QueryMgr;
52
53 import com.sun.appserv.management.DomainRoot;
54
55 import com.sun.appserv.management.util.misc.MapUtil;
56 import com.sun.appserv.management.util.misc.StringUtil;
57 import com.sun.appserv.management.util.misc.CollectionUtil;
58 import com.sun.appserv.management.util.stringifier.SmartStringifier;
59 import com.sun.appserv.management.util.misc.Output;
60
61 import com.sun.appserv.management.util.jmx.MBeanRegistrationListener;
62 import com.sun.appserv.management.util.jmx.JMXUtil;
63
64 import com.sun.appserv.management.config.DomainConfig;
65 import com.sun.appserv.management.config.PropertiesAccess;
66 import com.sun.appserv.management.config.CommonConfigKeys;
67
68 import com.sun.enterprise.management.support.ParamNameMapper;
69 import com.sun.enterprise.management.support.LoaderMBean;
70 import com.sun.enterprise.management.support.OldConfigTypes;
71 import com.sun.enterprise.management.support.OldTypeToJ2EETypeMapper;
72 import com.sun.enterprise.management.support.oldconfig.OldConfigProxies;
73 import com.sun.enterprise.management.support.oldconfig.OldResourcesMBean;
74
75
76 import com.sun.appserv.management.base.AMXDebug;
77
78 /**
79     Factory for creating and removing configs.
80  */

81 public class ConfigFactory
82 {
83     private final ConfigFactoryCallback mCallbacks;
84     private ParamNameMapper mParamNameMapper = null;
85     private final Output mDebug;
86     
87     /**
88         Whenever a name is required during creation of a new config item,
89         this key is what is used within the Map. Usually, however, the name
90         is passed as the first argument in createXXX().
91      */

92     protected final static String JavaDoc CONFIG_NAME_KEY = "Name";
93     
94         public
95     ConfigFactory( final ConfigFactoryCallback callbacks)
96     {
97         mCallbacks = callbacks;
98         
99         mDebug = AMXDebug.getInstance().getOutput( getClass().getName() );
100     }
101     
102         protected final MBeanServer JavaDoc
103      getMBeanServer()
104      {
105         return getCallbacks().getMBeanServer();
106      }
107     
108         protected final void
109     debug(final Object JavaDoc o)
110     {
111         mDebug.println( o );
112     }
113     
114     
115         protected final ConfigFactoryCallback
116     getCallbacks()
117     {
118         return( mCallbacks );
119     }
120     
121     
122         protected static void
123     putNonNull(
124         final Map JavaDoc<String JavaDoc,String JavaDoc> m,
125         final String JavaDoc key,
126         final Object JavaDoc value)
127     {
128         if ( value != null )
129         {
130             m.put( key, "" + value );
131         }
132     }
133     
134         protected final String JavaDoc
135     getConfigName()
136     {
137         return( getCallbacks().getConfigName() );
138     }
139     
140         protected final String JavaDoc
141     getContainerName()
142     {
143         final String JavaDoc name = getFactoryContainer().getName();
144         if ( name == null )
145         {
146             throw new IllegalArgumentException JavaDoc();
147         }
148         return name;
149     }
150     
151         protected final Logger JavaDoc
152     getLogger()
153     {
154         return( getCallbacks().getLogger() );
155     }
156
157         protected final DomainRoot
158     getDomainRoot()
159     {
160         return( getCallbacks().getDomainRoot() );
161     }
162     
163         protected final QueryMgr
164     getQueryMgr()
165     {
166         return( getDomainRoot().getQueryMgr() );
167     }
168     
169         protected final DomainConfig
170     getDomainConfig()
171     {
172         return( getDomainRoot().getDomainConfig() );
173     }
174     
175         protected final Container
176     getFactoryContainer()
177     {
178         return( getCallbacks().getFactoryContainer() );
179     }
180     
181         protected final OldConfigProxies
182     getOldConfigProxies()
183     {
184         return( getCallbacks().getOldConfigProxies() );
185     }
186     
187         protected final void
188     remove( )
189     {
190         throw new RuntimeException JavaDoc( "form 'remove()' no longer supported" );
191     }
192     
193         protected WaitForUnregistrationListener
194     newWaitForUnregistrationListener( final ObjectName JavaDoc objectName )
195     {
196         try
197         {
198             return new WaitForUnregistrationListener( objectName );
199         }
200         catch( Exception JavaDoc e )
201         {
202             throw new RuntimeException JavaDoc( e );
203         }
204     }
205     
206     protected final class WaitForUnregistrationListener extends MBeanRegistrationListener
207     {
208         private final ObjectName JavaDoc mTarget;
209         private boolean mDone;
210
211         private WaitForUnregistrationListener( final ObjectName JavaDoc objectName )
212             throws InstanceNotFoundException JavaDoc, java.io.IOException JavaDoc
213         {
214             super( getMBeanServer(), null );
215             mDone = false;
216             mTarget = objectName;
217         }
218         
219         public ObjectName JavaDoc getTarget() { return mTarget; }
220         public boolean done() { return mDone; }
221         protected void mbeanRegistered( final ObjectName JavaDoc objectName ) {}
222
223             protected void
224         mbeanUnregistered( final ObjectName JavaDoc objectName )
225         {
226             if ( mTarget.equals( objectName ) )
227             {
228                 mDone = true;
229                 cleanup();
230             }
231         }
232     }
233     
234         protected void
235      waitForUnregistration( final WaitForUnregistrationListener l )
236      {
237         long total = 0;
238         final long SLEEP_MILLIS = 10;
239         final long MAX_WAIT_MILLIS = 5 * 1000;
240         
241         // use a timeout; bugs have been seen before!
242
while ( total < MAX_WAIT_MILLIS && ! l.done() )
243         {
244             sleepMillis( SLEEP_MILLIS );
245             total += SLEEP_MILLIS;
246         }
247         
248         if ( ! l.done() )
249         {
250             throw new RuntimeException JavaDoc( "MBean failed to unregister: " +
251                 JMXUtil.toString( l.getTarget() ) );
252         }
253      }
254      
255     /**
256         Remove the config represented by the AMX MBean with the
257         specified ObjectName.
258      */

259         public final void
260     remove( final ObjectName JavaDoc objectName )
261     {
262         if ( objectName == null )
263         {
264             throw new RuntimeException JavaDoc( new InstanceNotFoundException JavaDoc() );
265         }
266         
267         final WaitForUnregistrationListener l =
268             newWaitForUnregistrationListener( objectName );
269         
270         internalRemove( objectName );
271         
272         // do not return to caller until the MBean actually is unregistered!
273
waitForUnregistration( l );
274         
275         getCallbacks().sendConfigRemovedNotification( objectName );
276     }
277     
278         protected void
279     removeByName( final String JavaDoc name )
280     {
281         throw new UnsupportedOperationException JavaDoc( "removeByNameInternal" );
282     }
283     
284         protected void
285     internalRemove( final ObjectName JavaDoc objectName )
286     {
287         removeByName( Util.getName( objectName ) );
288     }
289     
290     /**
291         Get the names of parameters that don't map via the default algorithms.
292      */

293         protected Map JavaDoc<String JavaDoc,String JavaDoc>
294     getParamNameOverrides()
295     {
296         // none, by default
297
return( Collections.emptyMap() );
298     }
299
300
301         protected synchronized ParamNameMapper
302     getParamNameMapper()
303     {
304         if ( mParamNameMapper == null )
305         {
306             mParamNameMapper =
307                 new ParamNameMapper( getParamNameOverrides() );
308         }
309         
310         return( mParamNameMapper );
311     }
312     
313         protected boolean
314     getBooleanOption( final Map JavaDoc<String JavaDoc,String JavaDoc> m, final String JavaDoc key )
315     {
316         boolean value = false;
317         final Object JavaDoc obj = (m == null) ? null : m.get( key );
318         if ( obj != null )
319         {
320             if ( obj instanceof Boolean JavaDoc )
321             {
322                 value = ((Boolean JavaDoc)obj).booleanValue();
323             }
324             else if ( obj instanceof String JavaDoc )
325             {
326                 value = Boolean.valueOf( (String JavaDoc)obj ).booleanValue();
327             }
328             else
329             {
330                 throw new IllegalArgumentException JavaDoc( "Illegal value for Boolean " + key );
331             }
332             
333         }
334         return( value );
335     }
336     
337         protected boolean
338     requireValidReferences( final Map JavaDoc<String JavaDoc,String JavaDoc> options )
339     {
340         return ! getBooleanOption( options, CommonConfigKeys.IGNORE_MISSING_REFERENCES_KEY );
341     }
342     
343     
344     private final static Class JavaDoc[] ATTRS_ONLY_SIG =
345         new Class JavaDoc[] { AttributeList JavaDoc.class };
346     private final static Class JavaDoc[] ATTRS_AND_PROPS_SIG =
347         new Class JavaDoc[] { AttributeList JavaDoc.class, Properties JavaDoc.class };
348         
349     
350         protected final Method JavaDoc
351     findAnyMethod( String JavaDoc methodName, final Class JavaDoc[] sig )
352     {
353         Method JavaDoc m = null;
354         try
355         {
356             m = this.getClass().getDeclaredMethod( methodName, sig );
357         }
358         catch( NoSuchMethodException JavaDoc e )
359         {
360             // ok, doesn't exist
361
}
362         
363         return( m );
364     }
365
366         protected final ObjectName JavaDoc
367     createChild( final Map JavaDoc<String JavaDoc,String JavaDoc> params )
368     {
369         return( createNamedChild( null, params ) );
370     }
371     
372     /**
373         Create an "old" child MBean of the specified name using the specified parameters,
374         and then create a corresponding AMX MBean.
375         The parameters need not include the name; it will be added.
376         <p>
377         The parameters are first translated to an AttributeList and Properties. See
378         translateParams() for details.
379         
380         @return the ObjectName of the new AMX MBean
381         
382      */

383         protected final ObjectName JavaDoc
384     createNamedChild(
385         final String JavaDoc name,
386         final Map JavaDoc<String JavaDoc,String JavaDoc> params )
387     {
388         debug( "createNamedChild: " + name + ":\n{\n" + stringify( params ) + "\n}");
389         
390         final AttributeList JavaDoc attrs = new AttributeList JavaDoc();
391         final Properties JavaDoc props = new Properties JavaDoc();
392         
393         translateParams( params, attrs, props );
394         
395         debug( "createNamedChild: translated attrs:\n{\n" + stringify( attrs ) + "\n}");
396         if ( props.keySet().size() != 0 )
397         {
398             debug( "createNamedChild: translated props:\n" + stringify( props ) );
399         }
400         
401         ObjectName JavaDoc oldObjectName = null;
402         boolean propertiesHandled = false;
403
404         if ( findAnyMethod( "createOldChildConfig", ATTRS_AND_PROPS_SIG ) != null )
405         {
406             debug( "createNamedChild: calling createOldChildConfig using attrs\n" +
407                 stringify( attrs ) + "\nand props \n" + stringify( props ) );
408                 
409             oldObjectName = createOldChildConfig( attrs, props );
410             propertiesHandled = true;
411         }
412         else if ( findAnyMethod( "createOldChildConfig", ATTRS_ONLY_SIG ) != null )
413         {
414             debug( "createNamedChild: calling createOldChildConfig using attrs\n" +
415                 stringify( attrs ));
416                 
417             oldObjectName = createOldChildConfig( attrs );
418         }
419         else
420         {
421             throw new UnsupportedOperationException JavaDoc( "createOldChildConfig" );
422         }
423         
424         return finish( oldObjectName, propertiesHandled ? null : props );
425     }
426        
427        
428          protected final ObjectName JavaDoc
429      finish(
430         final ObjectName JavaDoc oldObjectName,
431         final Properties JavaDoc props)
432      {
433         assert( oldObjectName != null );
434         debug( "createNamedChild: created: " + StringUtil.quote( oldObjectName.toString() ) );
435         
436         if ( ! getMBeanServer().isRegistered( oldObjectName ) )
437         {
438             throw new RuntimeException JavaDoc( new InstanceNotFoundException JavaDoc( oldObjectName.toString() ) );
439         }
440         
441         // need the new AMX name to set properties
442
final ObjectName JavaDoc amxName = getCallbacks().getLoader().sync( oldObjectName );
443         debug( "createNamedChild: amx object name: " + StringUtil.quote( amxName.toString() ) );
444
445         if ( props != null && props.size() > 0)
446         {
447             debug( "Setting properties: " + stringify( props ) );
448             setAllProperties( amxName, props );
449         }
450
451         getCallbacks().sendConfigCreatedNotification( amxName );
452         return( amxName );
453      }
454     
455     
456     protected static final Set JavaDoc<String JavaDoc> NO_OPTIONAL_KEYS = Collections.emptySet();
457     /**
458           By default, assume there are no optional keys.
459      */

460         protected Set JavaDoc<String JavaDoc>
461     getLegalOptionalCreateKeys()
462     {
463         return( NO_OPTIONAL_KEYS );
464     }
465     
466         protected void
467     checkLegalOptions( final Map JavaDoc<String JavaDoc,String JavaDoc> options )
468     {
469         if ( options != null )
470         {
471             final Set JavaDoc<String JavaDoc> legalKeys = getLegalOptionalCreateKeys();
472             if ( legalKeys != null )
473             {
474                 debug( "Legal optional keys: " + stringify( legalKeys ) );
475             }
476             if ( legalKeys != null )
477             {
478                 // remove all legal Attribute keys
479
final Map JavaDoc<String JavaDoc,String JavaDoc> remaining = new HashMap JavaDoc<String JavaDoc,String JavaDoc>( options );
480                 remaining.keySet().removeAll( legalKeys );
481                 
482                 final HashMap JavaDoc<String JavaDoc,String JavaDoc> illegal = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
483                 
484                 // find all non-properties; these are illegal
485
final Iterator JavaDoc iter = remaining.keySet().iterator();
486                 while ( iter.hasNext() )
487                 {
488                     final String JavaDoc key = (String JavaDoc)iter.next();
489                     if ( ! key.startsWith( PropertiesAccess.PROPERTY_PREFIX ) )
490                     {
491                         illegal.put( key, remaining.get( key ) );
492                     }
493                 }
494
495                 if ( illegal.size() != 0 )
496                 {
497                     final String JavaDoc msg = "Illegal optional keys: " +
498                         MapUtil.toString( illegal, ",");
499                 
500                     debug( msg );
501                     throw new IllegalArgumentException JavaDoc( msg );
502                 }
503             }
504         }
505         else
506         {
507             // no options, so they're legal!
508
}
509     }
510
511     /**
512         Initialize a Map of parameters consisting of attributes and properties.
513         First the optional parameters are inserted.
514         Then the name/value pairs in the Object[] are added, possibly overwriting any
515         values that were redundantly specified in the optional map.
516         
517         @param name
518         @param required name/value pairings; even ones are keys, odd ones are values
519         @param optional additional name/value pairings
520      */

521         protected final Map JavaDoc<String JavaDoc,String JavaDoc>
522     initParams(
523         final String JavaDoc name,
524         final String JavaDoc[] required,
525         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
526     {
527         checkLegalOptions( optional );
528         
529         final Map JavaDoc<String JavaDoc,String JavaDoc> m = initParams( required, optional );
530
531         if ( name == null || name.length() == 0 )
532         {
533             throw new IllegalArgumentException JavaDoc( "Illegal to have null or empty name" );
534         }
535         
536         m.put( CONFIG_NAME_KEY, name );
537         return( m );
538     }
539     
540     /**
541         Validate parameters. The params Map contains all parameters, including
542         Attributes and properties as
543         
544         @param params
545      */

546         protected final void
547     validateParams( final Map JavaDoc<String JavaDoc,?> params )
548     {
549         for( final String JavaDoc name : params.keySet() )
550         {
551             final Object JavaDoc value = params.get( name );
552             
553             validateParam( name, value );
554         }
555     }
556     
557     /**
558         Validate a parameter to a create() or createAbc() method.
559         Subclasses should verify that the parameter name is legal,
560         and optionally validate its value as well.
561         
562         @param name
563         @param value
564      */

565         protected final void
566     validateParam(
567         final String JavaDoc name,
568         final Object JavaDoc value )
569     {
570         if ( name == null || name.length() == 0 )
571         {
572             throw new IllegalArgumentException JavaDoc( "parameter name must be non-null and non-empty" );
573         }
574         
575         if ( name.startsWith( PropertiesAccess.PROPERTY_PREFIX ) )
576         {
577             if ( ! (value instanceof String JavaDoc) )
578             {
579                 throw new IllegalArgumentException JavaDoc( "Property value must be string: " +
580                     name + ", class =" + value.getClass().getName() );
581             }
582         }
583     }
584     
585     
586     /**
587         Initalize parameters, no name supplied.
588      */

589         protected final Map JavaDoc<String JavaDoc,String JavaDoc>
590     initParams(
591         final String JavaDoc[] required,
592         final Map JavaDoc<String JavaDoc,String JavaDoc> optionalIn )
593     {
594         // guarantee that all arguments are Strings;
595
// clients can be using old version of the interfaces and/or non-generic
596
// versions of Map
597
final Map JavaDoc<String JavaDoc,String JavaDoc> optional = MapUtil.toStringStringMap( optionalIn );
598         
599         final Map JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
600         
601         if ( optional != null )
602         {
603             m.putAll( optional );
604             m.remove( CommonConfigKeys.IGNORE_MISSING_REFERENCES_KEY );
605         }
606         if ( required != null )
607         {
608             m.putAll( MapUtil.newMap( required ) );
609         }
610         
611         validateParams( m );
612         
613         return( m );
614     }
615     
616     /**
617         Initalize parameters, no name supplied.
618      */

619         protected final Map JavaDoc<String JavaDoc,String JavaDoc>
620     initParams( final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
621     {
622         return( initParams( (String JavaDoc[])null, optional ) );
623     }
624     
625     
626     /**
627         Translate the Map of parameters to Attributes and Properties. AttibuteNames
628         are mapped to the underlying names. Property names are not mapped, but the
629         PROPERTY_PREFIX is stripped.
630         
631         @param paramsToTranslate
632         @param attrsOut
633         @param propsOut
634      */

635         protected final void
636     translateParams(
637         final Map JavaDoc<String JavaDoc,String JavaDoc> paramsToTranslate,
638         final AttributeList JavaDoc attrsOut,
639         final Properties JavaDoc propsOut )
640     {
641         final ParamNameMapper mapper = getParamNameMapper();
642         
643         final Iterator JavaDoc iter = paramsToTranslate.keySet().iterator();
644         final String JavaDoc propertyPrefix = PropertiesAccess.PROPERTY_PREFIX;
645         while( iter.hasNext() )
646         {
647             final String JavaDoc key = (String JavaDoc)iter.next();
648             final Object JavaDoc value = paramsToTranslate.get( key );
649             
650             if ( key.startsWith( propertyPrefix ) )
651             {
652                 final String JavaDoc name =
653                     key.substring( propertyPrefix.length(), key.length() );
654                     
655                 propsOut.put( name, value );
656             }
657             else
658             {
659                 final String JavaDoc translatedName = mapper.mangleAttributeName( key );
660                 
661                 final Attribute JavaDoc attr = new Attribute JavaDoc( translatedName, value );
662                 
663                 attrsOut.add( attr );
664             }
665         }
666     }
667
668     /**
669         Given a set of translated Attributes, create the appropriate type of child
670         and return its "old" config ObjectName
671         
672         @param translatedAttrs
673         @return ObjectName of newly-created child
674      */

675         protected ObjectName JavaDoc
676     createOldChildConfig(
677         final AttributeList JavaDoc translatedAttrs )
678     {
679         throw new UnsupportedOperationException JavaDoc( "createOldChildConfig( AttributeList )" );
680     }
681     
682     /**
683         Given a set of translated Attributes, create the appropriate type of child
684         and return its "old" config ObjectName
685         
686         @param translatedAttrs
687         @param props Properties to also use
688         @return ObjectName of newly-created child
689      */

690         protected ObjectName JavaDoc
691     createOldChildConfig(
692         final AttributeList JavaDoc translatedAttrs,
693         final Properties JavaDoc props )
694     {
695         throw new UnsupportedOperationException JavaDoc( "createOldChildConfig( AttributeList, Properties)" );
696     }
697     
698         protected final void
699     trace( Object JavaDoc o )
700     {
701         debug( o );
702     }
703     
704         protected String JavaDoc
705     stringify( Object JavaDoc o )
706     {
707         return( SmartStringifier.toString( o ) );
708     }
709     
710     /**
711         Given a set of translated Attributes, create the appropriate type of child
712         and return its "old" config ObjectName
713
714         @param oldChildType
715         @param translatedAttrs
716         @return ObjectName of newly-created child
717      */

718         protected ObjectName JavaDoc
719     createOldChildByType(
720         final String JavaDoc oldChildType,
721         final AttributeList JavaDoc translatedAttrs )
722     {
723         throw new UnsupportedOperationException JavaDoc( "createOldChildByType( String, AttributeList )" );
724     }
725     
726     /**
727         Given a set of translated Attributes, create the appropriate type of child
728         and return its "old" config ObjectName
729
730         @param oldChildType
731         @param translatedAttrs
732         @param props Properties to also use
733         @return ObjectName of newly-created child
734      */

735         protected ObjectName JavaDoc
736     createOldChildByType(
737         final String JavaDoc oldChildType,
738         final AttributeList JavaDoc translatedAttrs,
739         final Properties JavaDoc props )
740     {
741         throw new UnsupportedOperationException JavaDoc( "createOldChildByType( String, AttributeList, Properties )" );
742     }
743     
744         private static final Class JavaDoc[] TYPE_AND_ATTRS_AND_PROPS_SIG =
745         new Class JavaDoc[] { String JavaDoc.class, AttributeList JavaDoc.class, Properties JavaDoc.class };
746
747     private static final Class JavaDoc[] TYPE_AND_ATTRS_SIG =
748         new Class JavaDoc[] { String JavaDoc.class, AttributeList JavaDoc.class };
749
750     
751         protected final ObjectName JavaDoc
752     createChildByType(
753         final String JavaDoc childJ2EEType,
754         final Map JavaDoc<String JavaDoc,String JavaDoc> params )
755     {
756         //assert getChildInfos().contains (childJ2EEType) :
757
//childJ2EEType + " is not a valid child of " + getSelfJ2EEType ();
758

759         final String JavaDoc oldType = getOldTypeToJ2EETypeMapper().j2eeTypeToOldType( childJ2EEType );
760
761         assert oldType != null;
762
763         final Properties JavaDoc props = new Properties JavaDoc();
764         final AttributeList JavaDoc attrs = new AttributeList JavaDoc();
765
766         translateParams( params, attrs, props );
767
768         ObjectName JavaDoc oldObjectName = null;
769         boolean propertiesHandled = false;
770
771         if ( findAnyMethod( "createOldChildByType", TYPE_AND_ATTRS_AND_PROPS_SIG ) != null )
772         {
773             oldObjectName = createOldChildByType( oldType, attrs, props );
774             propertiesHandled = true;
775         }
776         else if ( findAnyMethod( "createOldChildByType", TYPE_AND_ATTRS_SIG ) != null )
777         {
778             oldObjectName = createOldChildByType( oldType, attrs );
779         }
780         else if ( findAnyMethod( "createOldChildByType", ATTRS_ONLY_SIG ) != null )
781         {
782             oldObjectName = createOldChildConfig( attrs );
783         }
784         else
785         {
786             throw new UnsupportedOperationException JavaDoc( "createOldChildByType" );
787         }
788         
789         assert( oldObjectName != null );
790         debug( "createChildByType: oldObjectName: " + StringUtil.quote( oldObjectName.toString() ) );
791
792         // need the new AMX name to set properties
793
final ObjectName JavaDoc amxName = getCallbacks().getLoader().sync( oldObjectName );
794         debug( "createChildByType: amx object name: " + StringUtil.quote( amxName.toString() ) );
795
796         if ( props.size() > 0 && !propertiesHandled )
797         {
798             setAllProperties( amxName, props );
799         }
800
801         getCallbacks().sendConfigCreatedNotification( amxName );
802         return( amxName );
803     }
804
805     
806
807
808         protected final void
809     setAllProperties(
810         final ObjectName JavaDoc amxObjectName,
811         final Properties JavaDoc props )
812     {
813         final PropertiesAccess proxy = PropertiesAccess.class.cast(
814             getCallbacks().getProxyFactory().getProxy( amxObjectName, AMX.class) );
815         
816         setAllProperties( proxy, props );
817     }
818     
819     /**
820         For each property in props , call setPropertyValue()
821      */

822         protected final void
823     setAllProperties(
824         final PropertiesAccess target,
825         final Properties JavaDoc props )
826     {
827         final Iterator JavaDoc iter = props.keySet().iterator();
828         
829         while ( iter.hasNext() )
830         {
831             final String JavaDoc key = (String JavaDoc)iter.next();
832             
833             target.setPropertyValue( key, (String JavaDoc)props.get( key ) );
834         }
835     }
836
837
838         protected OldTypeToJ2EETypeMapper
839     getOldTypeToJ2EETypeMapper()
840     {
841         return OldConfigTypes.getInstance();
842     }
843     
844     
845
846         
847         protected ObjectName JavaDoc
848     syncNewAMXMBeanWithOld(ObjectName JavaDoc oldObjectName)
849     {
850         final ObjectName JavaDoc amxName = getCallbacks().getLoader().sync( oldObjectName );
851         
852         getCallbacks().sendConfigCreatedNotification( amxName );
853         return amxName;
854     }
855     
856     
857     
858         final OldResourcesMBean
859     getOldResourcesMBean()
860     {
861         return( getOldConfigProxies().getOldResourcesMBean( ) );
862     }
863     
864         protected static String JavaDoc
865     quote( Object JavaDoc o )
866     {
867         return( StringUtil.quote( o.toString() ) );
868     }
869     
870     
871     
872         protected void
873     checkNonEmptyString( final String JavaDoc s, final String JavaDoc name )
874     {
875         if ( s == null || s.length() == 0 )
876         {
877             throw new IllegalArgumentException JavaDoc( "Parameter may not be null or empty: " +
878                 quote( name ) );
879         }
880     }
881         
882         protected final Object JavaDoc
883     getValue( final Map JavaDoc<String JavaDoc,String JavaDoc> m, final String JavaDoc key )
884     {
885         return (m == null) ? null : m.get( key );
886     }
887     
888         protected final String JavaDoc
889     getString( final Map JavaDoc<String JavaDoc,String JavaDoc> m, final String JavaDoc key )
890     {
891         return (String JavaDoc)getValue( m, key );
892     }
893     
894         protected final Boolean JavaDoc
895     getBoolean(
896         final Map JavaDoc<String JavaDoc,String JavaDoc> m,
897         final String JavaDoc key,
898         final Boolean JavaDoc defaultValue )
899     {
900         final Object JavaDoc value = getValue( m, key );
901         
902         return (value == null) ? defaultValue : Boolean.valueOf( "" + value );
903     }
904     
905     
906         protected boolean
907     sleepMillis( final long millis )
908     {
909         boolean interrupted = false;
910         
911         try
912         {
913             Thread.sleep( millis );
914         }
915         catch( InterruptedException JavaDoc e )
916         {
917             Thread.interrupted();
918             interrupted = true;
919         }
920         
921         return interrupted;
922     }
923     
924         protected AMX
925     requireItem(
926         final String JavaDoc j2eeType,
927         final String JavaDoc name )
928     {
929         final AMX item = getFactoryContainer().getContainee( j2eeType, name );
930         if ( item == null )
931         {
932             throw new IllegalArgumentException JavaDoc( j2eeType + "=" + name );
933         }
934         return item;
935     }
936 }
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
Popular Tags