FileDocCategorySizeDatePackage
ConfigFactory.javaAPI DocGlassfish v2 API26543Fri May 04 22:23:18 BST 2007com.sun.enterprise.management.config

ConfigFactory

public class ConfigFactory extends Object
Factory for creating and removing configs.

Fields Summary
private final ConfigFactoryCallback
mCallbacks
private com.sun.enterprise.management.support.ParamNameMapper
mParamNameMapper
private final com.sun.appserv.management.util.misc.Output
mDebug
protected static final String
CONFIG_NAME_KEY
Whenever a name is required during creation of a new config item, this key is what is used within the Map. Usually, however, the name is passed as the first argument in createXXX().
private static final Class[]
ATTRS_ONLY_SIG
private static final Class[]
ATTRS_AND_PROPS_SIG
protected static final Set
NO_OPTIONAL_KEYS
private static final Class[]
TYPE_AND_ATTRS_AND_PROPS_SIG
private static final Class[]
TYPE_AND_ATTRS_SIG
Constructors Summary
public ConfigFactory(ConfigFactoryCallback callbacks)

    
		 
	  	 
	
		mCallbacks	= callbacks;
		
		mDebug  = AMXDebug.getInstance().getOutput( getClass().getName() );
	
Methods Summary
protected voidcheckLegalOptions(java.util.Map options)

		if ( options != null )
		{
			final Set<String>	legalKeys	= getLegalOptionalCreateKeys();
			if ( legalKeys != null )
			{
			    debug( "Legal optional keys: " + stringify( legalKeys ) );
			}
			if ( legalKeys != null )
			{
				// remove all legal Attribute keys
				final Map<String,String> remaining	= new HashMap<String,String>( options );
				remaining.keySet().removeAll( legalKeys );
				
				final HashMap<String,String>	illegal	= new HashMap<String,String>();
				
				// find all non-properties; these are illegal
				final Iterator	iter	= remaining.keySet().iterator();
				while ( iter.hasNext() )
				{
					final String	key	= (String)iter.next();
					if ( ! key.startsWith( PropertiesAccess.PROPERTY_PREFIX ) )
					{
						illegal.put( key, remaining.get( key ) );
					}
				}

				if ( illegal.size() != 0 )
				{
				    final String msg    = "Illegal optional keys: " +
						MapUtil.toString( illegal, ",");
				
				    debug( msg );
					throw new IllegalArgumentException( msg );
				}
			}
		}
		else
		{
			// no options, so they're legal!
		}
	
protected voidcheckNonEmptyString(java.lang.String s, java.lang.String name)

		if (  s == null ||  s.length() == 0 )
		{
			throw new IllegalArgumentException( "Parameter may not be null or empty: " +
				quote( name ) );
		}
	
protected final javax.management.ObjectNamecreateChild(java.util.Map params)

		return( createNamedChild( null, params ) );
	
protected final javax.management.ObjectNamecreateChildByType(java.lang.String childJ2EEType, java.util.Map params)


	
		  
	
		  
		   
	
		//assert getChildInfos().contains (childJ2EEType) : 
			//childJ2EEType + " is not a valid child of " + getSelfJ2EEType ();

		final String oldType = getOldTypeToJ2EETypeMapper().j2eeTypeToOldType( childJ2EEType );

		assert oldType != null;

		final Properties	props	= new Properties();
		final AttributeList	attrs	= new AttributeList();

		translateParams( params, attrs, props );

		ObjectName	oldObjectName		= null;
		boolean		propertiesHandled	= false;

		if ( findAnyMethod( "createOldChildByType", TYPE_AND_ATTRS_AND_PROPS_SIG ) != null )
		{
			oldObjectName	= createOldChildByType( oldType, attrs, props );
			propertiesHandled = true;
		}
		else if ( findAnyMethod( "createOldChildByType", TYPE_AND_ATTRS_SIG ) != null )
		{
			oldObjectName	= createOldChildByType( oldType, attrs );
		}
		else if ( findAnyMethod( "createOldChildByType", ATTRS_ONLY_SIG ) != null )
		{
			oldObjectName	= createOldChildConfig( attrs );
		}
		else
		{
			throw new UnsupportedOperationException( "createOldChildByType" );
		}
		
		assert( oldObjectName != null );
		debug( "createChildByType: oldObjectName: " + StringUtil.quote( oldObjectName.toString() ) );

		// need the new AMX name to set properties
		final ObjectName	amxName	= getCallbacks().getLoader().sync( oldObjectName );
		debug( "createChildByType: amx object name: " + StringUtil.quote( amxName.toString() ) );

		if ( props.size() > 0 && !propertiesHandled )
		{
			setAllProperties( amxName, props );
		}

		getCallbacks().sendConfigCreatedNotification( amxName );
		return( amxName );
	
protected final javax.management.ObjectNamecreateNamedChild(java.lang.String name, java.util.Map params)
Create an "old" child MBean of the specified name using the specified parameters, and then create a corresponding AMX MBean. The parameters need not include the name; it will be added.

The parameters are first translated to an AttributeList and Properties. See translateParams() for details.

return
the ObjectName of the new AMX MBean

		debug( "createNamedChild: " + name + ":\n{\n" + stringify( params ) + "\n}");
		
		final AttributeList		attrs	= new AttributeList();
		final Properties		props	= new Properties();
		
		translateParams( params, attrs, props );
		
		debug( "createNamedChild: translated attrs:\n{\n" + stringify( attrs ) + "\n}");
		if ( props.keySet().size() != 0 )
		{
		    debug( "createNamedChild: translated props:\n" + stringify( props ) );
		}
		
		ObjectName	oldObjectName		= null;
		boolean		propertiesHandled	= false;

		if ( findAnyMethod( "createOldChildConfig", ATTRS_AND_PROPS_SIG ) != null )
		{
		    debug( "createNamedChild: calling createOldChildConfig using attrs\n" +
		        stringify( attrs ) + "\nand props \n" + stringify( props ) );
		        
			oldObjectName	= createOldChildConfig( attrs, props );
			propertiesHandled = true;
		}
		else if ( findAnyMethod( "createOldChildConfig", ATTRS_ONLY_SIG ) != null )
		{
		    debug( "createNamedChild: calling createOldChildConfig using attrs\n" +
		        stringify( attrs ));
		        
			oldObjectName	= createOldChildConfig( attrs );
		}
		else
		{
			throw new UnsupportedOperationException( "createOldChildConfig" );
		}
		
		return finish( oldObjectName, propertiesHandled ? null : props );
	
protected javax.management.ObjectNamecreateOldChildByType(java.lang.String oldChildType, javax.management.AttributeList translatedAttrs)
Given a set of translated Attributes, create the appropriate type of child and return its "old" config ObjectName

param
oldChildType
param
translatedAttrs
return
ObjectName of newly-created child

		throw new UnsupportedOperationException( "createOldChildByType( String, AttributeList )" );
	
protected javax.management.ObjectNamecreateOldChildByType(java.lang.String oldChildType, javax.management.AttributeList translatedAttrs, java.util.Properties props)
Given a set of translated Attributes, create the appropriate type of child and return its "old" config ObjectName

param
oldChildType
param
translatedAttrs
param
props Properties to also use
return
ObjectName of newly-created child

		throw new UnsupportedOperationException( "createOldChildByType( String, AttributeList, Properties )" );
	
protected javax.management.ObjectNamecreateOldChildConfig(javax.management.AttributeList translatedAttrs)
Given a set of translated Attributes, create the appropriate type of child and return its "old" config ObjectName

param
translatedAttrs
return
ObjectName of newly-created child

		throw new UnsupportedOperationException( "createOldChildConfig( AttributeList )" );
	
protected javax.management.ObjectNamecreateOldChildConfig(javax.management.AttributeList translatedAttrs, java.util.Properties props)
Given a set of translated Attributes, create the appropriate type of child and return its "old" config ObjectName

param
translatedAttrs
param
props Properties to also use
return
ObjectName of newly-created child

		throw new UnsupportedOperationException( "createOldChildConfig( AttributeList, Properties)" );
	
protected final voiddebug(java.lang.Object o)

        mDebug.println( o );
	
protected final java.lang.reflect.MethodfindAnyMethod(java.lang.String methodName, java.lang.Class[] sig)

		
	
		  
	      
	
		Method	m	= null;
		try
		{
			m	= this.getClass().getDeclaredMethod( methodName, sig );
		}
		catch( NoSuchMethodException e )
		{
			// ok, doesn't exist
		}
		
		return( m );
	
protected final javax.management.ObjectNamefinish(javax.management.ObjectName oldObjectName, java.util.Properties props)

		assert( oldObjectName != null );
		debug( "createNamedChild: created: " + StringUtil.quote( oldObjectName.toString() ) );
		
		if ( ! getMBeanServer().isRegistered( oldObjectName ) )
		{
			throw new RuntimeException( new InstanceNotFoundException( oldObjectName.toString() ) );
		}
		
		// need the new AMX name to set properties
		final ObjectName	amxName	= getCallbacks().getLoader().sync( oldObjectName );
		debug( "createNamedChild: amx object name: " + StringUtil.quote( amxName.toString() ) );

		if ( props != null && props.size() > 0)
		{
		    debug( "Setting properties: " + stringify( props ) );
			setAllProperties( amxName, props );
		}

        // ensure that all sub-elements are also present
        getCallbacks().getLoader().waitAll();
        
		getCallbacks().sendConfigCreatedNotification( amxName );
		return( amxName );
	 
protected final java.lang.BooleangetBoolean(java.util.Map m, java.lang.String key, java.lang.Boolean defaultValue)

	    final Object    value   = getValue( m, key );
	    
	    return (value == null) ? defaultValue : Boolean.valueOf( "" + value );
	
protected booleangetBooleanOption(java.util.Map m, java.lang.String key)

		boolean	value	= false;
		final Object	obj	= (m == null) ? null : m.get( key );
		if ( obj != null )
		{
			if ( obj instanceof Boolean )
			{
				value	= ((Boolean)obj).booleanValue();
			}
			else if ( obj instanceof String )
			{
				value	= Boolean.valueOf( (String)obj ).booleanValue();
			}
			else
			{
				throw new IllegalArgumentException( "Illegal value for Boolean " + key );
			}
			
		}
		return( value );
	
protected final ConfigFactoryCallbackgetCallbacks()

		return( mCallbacks );
	
protected final java.lang.StringgetConfigName()

		return( getCallbacks().getConfigName() );
	
protected final java.lang.StringgetContainerName()

        final String name   = getFactoryContainer().getName();
        if ( name == null )
        {
            throw new IllegalArgumentException();
        }
        return name;
    
protected final com.sun.appserv.management.config.DomainConfiggetDomainConfig()

		return( getDomainRoot().getDomainConfig() );
	
protected final com.sun.appserv.management.DomainRootgetDomainRoot()

		return( getCallbacks().getDomainRoot() );
	
protected final com.sun.appserv.management.base.ContainergetFactoryContainer()

		return( getCallbacks().getFactoryContainer() );
	
protected java.util.SetgetLegalOptionalCreateKeys()
By default, assume there are no optional keys.

			         	 
	     
	
	
		return( NO_OPTIONAL_KEYS );
	
protected final java.util.logging.LoggergetLogger()

		return( getCallbacks().getLogger() );
	
protected final javax.management.MBeanServergetMBeanServer()

	    return getCallbacks().getMBeanServer();
	 
protected final com.sun.enterprise.management.support.oldconfig.OldConfigProxiesgetOldConfigProxies()

		return( getCallbacks().getOldConfigProxies() );
	
final com.sun.enterprise.management.support.oldconfig.OldResourcesMBeangetOldResourcesMBean()

		return( getOldConfigProxies().getOldResourcesMBean( ) );
	
protected com.sun.enterprise.management.support.OldTypeToJ2EETypeMappergetOldTypeToJ2EETypeMapper()

		return OldConfigTypes.getInstance();
	
protected synchronized com.sun.enterprise.management.support.ParamNameMappergetParamNameMapper()

		if ( mParamNameMapper == null )
		{
			mParamNameMapper	=
				new ParamNameMapper( getParamNameOverrides() );
		}
		
		return( mParamNameMapper );
	
protected java.util.MapgetParamNameOverrides()
Get the names of parameters that don't map via the default algorithms.

		// none, by default
		return( Collections.emptyMap() );
	
protected final com.sun.appserv.management.base.QueryMgrgetQueryMgr()

		return( getDomainRoot().getQueryMgr() );
	
protected final java.lang.StringgetString(java.util.Map m, java.lang.String key)

	    return (String)getValue( m, key );
	
protected final java.lang.ObjectgetValue(java.util.Map m, java.lang.String key)

	    return (m == null) ? null : m.get( key );
	
protected final java.util.MapinitParams(java.lang.String name, java.lang.String[] required, java.util.Map optional)
Initialize a Map of parameters consisting of attributes and properties. First the optional parameters are inserted. Then the name/value pairs in the Object[] are added, possibly overwriting any values that were redundantly specified in the optional map.

param
name
param
required name/value pairings; even ones are keys, odd ones are values
param
optional additional name/value pairings

		checkLegalOptions( optional );
		
		final Map<String,String>	m	= initParams( required, optional );

		if ( name == null || name.length() == 0 )
		{
			throw new IllegalArgumentException( "Illegal to have null or empty name" );
		}
		
		m.put( CONFIG_NAME_KEY, name );
		return( m );
	
protected final java.util.MapinitParams(java.lang.String[] required, java.util.Map optionalIn)
Initalize parameters, no name supplied.

	    // guarantee that all arguments are Strings;
	    // clients can be using old version of the interfaces and/or non-generic
	    // versions of Map
	    final Map<String,String> optional = MapUtil.toStringStringMap( optionalIn );
	    
		final Map<String,String>	m	= new HashMap<String,String>();
		
		if ( optional != null )
		{
			m.putAll( optional );
			m.remove( CommonConfigKeys.IGNORE_MISSING_REFERENCES_KEY );
		}
		if ( required != null )
		{
			m.putAll( MapUtil.newMap( required ) );
		}
		
		validateParams( m );
		
		return( m );
	
protected final java.util.MapinitParams(java.util.Map optional)
Initalize parameters, no name supplied.

		return( initParams( (String[])null, optional ) );
	
protected voidinternalRemove(javax.management.ObjectName objectName)

		removeByName( Util.getName( objectName ) );
	
protected com.sun.enterprise.management.config.ConfigFactory$WaitForUnregistrationListenernewWaitForUnregistrationListener(javax.management.ObjectName objectName)

        WaitForUnregistrationListener   listener = null;
        try
        {
            final String name =
                "WaitForUnregistrationListener for " + JMXUtil.toString(objectName);
            
            listener    = new WaitForUnregistrationListener( name, objectName );
            listener.startListening();
            return listener;
        }
        catch( Exception e )
        {
            throw new RuntimeException( e );
        }
    
protected static voidputNonNull(java.util.Map m, java.lang.String key, java.lang.Object value)

		if ( value != null )
		{
			m.put( key, "" + value );
		}
	
protected static java.lang.Stringquote(java.lang.Object o)

		return( StringUtil.quote( o.toString() ) );
	
protected final voidremove()

	    throw new RuntimeException( "form 'remove()' no longer supported" );
	
public final voidremove(javax.management.ObjectName objectName)
Remove the config represented by the AMX MBean with the specified ObjectName.

		if ( objectName == null )
		{
			throw new RuntimeException( new InstanceNotFoundException() );
		}
		
		final WaitForUnregistrationListener l  =
		    newWaitForUnregistrationListener( objectName );
		
		internalRemove( objectName );
		
		// do not return to caller until the MBean actually is unregistered!
		l.waitForUnregistration();
		
		getCallbacks().sendConfigRemovedNotification( objectName );
	
protected voidremoveByName(java.lang.String name)

		throw new UnsupportedOperationException( "removeByNameInternal" );
	
protected com.sun.appserv.management.base.AMXrequireItem(java.lang.String j2eeType, java.lang.String name)

	    final AMX item  = getFactoryContainer().getContainee( j2eeType, name );
	    if ( item == null )
	    {
	        throw new IllegalArgumentException( j2eeType + "=" + name );
	    }
	    return item;
	
protected booleanrequireValidReferences(java.util.Map options)

		return ! getBooleanOption( options, CommonConfigKeys.IGNORE_MISSING_REFERENCES_KEY );
	
protected final voidsetAllProperties(javax.management.ObjectName amxObjectName, java.util.Properties props)

		final PropertiesAccess	proxy	= PropertiesAccess.class.cast(
		    getCallbacks().getProxyFactory().getProxy( amxObjectName, AMX.class) );
		
		setAllProperties( proxy, props );
	
protected final voidsetAllProperties(com.sun.appserv.management.config.PropertiesAccess target, java.util.Properties props)
For each property in props , call setPropertyValue()

		final Iterator	iter	= props.keySet().iterator();
		
		while ( iter.hasNext() )
		{
			final String	key	= (String)iter.next();
			
			target.setPropertyValue( key, (String)props.get( key ) );
		}
	
protected booleansleepMillis(long millis)

		boolean	interrupted	= false;
		
		try
		{
			Thread.sleep( millis );
		}
		catch( InterruptedException e )
		{
			Thread.interrupted();
			interrupted	= true;
		}
		
		return interrupted;
	
protected java.lang.Stringstringify(java.lang.Object o)

		return( SmartStringifier.toString( o ) );
	
protected javax.management.ObjectNamesyncNewAMXMBeanWithOld(javax.management.ObjectName oldObjectName)

		final ObjectName amxName = getCallbacks().getLoader().sync( oldObjectName );
		
		getCallbacks().sendConfigCreatedNotification( amxName );
		return amxName;
	
protected final voidtrace(java.lang.Object o)

	    debug( o );
	
protected final voidtranslateParams(java.util.Map paramsToTranslate, javax.management.AttributeList attrsOut, java.util.Properties propsOut)
Translate the Map of parameters to Attributes and Properties. AttibuteNames are mapped to the underlying names. Property names are not mapped, but the PROPERTY_PREFIX is stripped.

param
paramsToTranslate
param
attrsOut
param
propsOut

		final ParamNameMapper	mapper	= getParamNameMapper();
		
		final Iterator	iter	= paramsToTranslate.keySet().iterator();
		final String	propertyPrefix	= PropertiesAccess.PROPERTY_PREFIX;
		while( iter.hasNext() )
		{
			final String	key	= (String)iter.next();
			final Object	value	= paramsToTranslate.get( key );
			
			if ( key.startsWith( propertyPrefix ) )
			{
				final String	name	=
					key.substring( propertyPrefix.length(), key.length() );
					
				propsOut.put( name, value );
			}
			else
			{
				final String	translatedName	= mapper.mangleAttributeName( key );
				
				final Attribute	attr	= new Attribute( translatedName, value );
				
				attrsOut.add( attr );
			}
		}
	
protected final voidvalidateParam(java.lang.String name, java.lang.Object value)
Validate a parameter to a create() or createAbc() method. Subclasses should verify that the parameter name is legal, and optionally validate its value as well.

param
name
param
value

		if ( name == null || name.length() == 0 )
		{
			throw new IllegalArgumentException( "parameter name must be non-null and non-empty" );
		}
		
		if ( name.startsWith( PropertiesAccess.PROPERTY_PREFIX ) )
		{
			if ( ! (value instanceof String) )
			{
				throw new IllegalArgumentException( "Property value must be string: " +
					name + ", class =" + value.getClass().getName() );
			}
		}
	
protected final voidvalidateParams(java.util.Map params)
Validate parameters. The params Map contains all parameters, including Attributes and properties as

param
params

		for( final String name : params.keySet() )
		{
			final Object	value	= params.get( name );
			
			validateParam( name, value );
		}