FileDocCategorySizeDatePackage
RefHelper.javaAPI DocGlassfish v2 API13044Mon Jul 16 11:09:06 BST 2007com.sun.appserv.management.helper

RefHelper

public class RefHelper extends Object
Helper routines for references. This class should only be used in EE builds.
since
AppServer 9.0

Fields Summary
private static final Set
REFERENT_J2EE_TYPES
Constructors Summary
private RefHelper()

Methods Summary
public static java.util.SetfindAllClusterRefConfigs(com.sun.appserv.management.base.QueryMgr queryMgr)
Find all {@link ClusterRefConfig}.

return
Set of all {@link ClusterRefConfig} found.

        return
            findAllRefConfigsByJ2EEType( queryMgr, XTypes.CLUSTER_REF_CONFIG );
    
public static java.util.SetfindAllDeployedItemRefConfigs(com.sun.appserv.management.base.QueryMgr queryMgr)
Find all {@link DeployedItemRefConfig}.

return
Set of all {@link DeployedItemRefConfig} found.

        return
            findAllRefConfigsByJ2EEType( queryMgr, XTypes.DEPLOYED_ITEM_REF_CONFIG );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.RefConfigReferent referent)
Find all {@link RefConfig} that reference the specified j2eeType/name combo.

        final AMX   amx = Util.asAMX( referent );
        
        return findAllRefConfigsWithName( getQueryMgr( amx ),
                    getReferentRefJ2EEType( referent ),
                    amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.RefConfigReferent referent, java.lang.String refJ2EEType)
Find all {@link RefConfig} that reference the specified j2eeType/name combo.

        final AMX   amx = Util.asAMX( referent );
        
        return findAllRefConfigsWithName( getQueryMgr( amx ), refJ2EEType, amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.DeployedItemRefConfigReferent referent)
Find all {@link DeployedItemRefConfig} that reference the specified item.

        final AMX   amx = Util.asAMX( referent );
        
        return
            findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.DEPLOYED_ITEM_REF_CONFIG, amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.ResourceRefConfigReferent referent)
Find all {@link ResourceRefConfig} that reference the specified item.

        final AMX   amx = Util.asAMX( referent );
        
        return
            findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.RESOURCE_REF_CONFIG, amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.ServerRefConfigReferent referent)
Find all {@link ServerRefConfig} that reference the specified item.

        final AMX   amx = Util.asAMX( referent );
        
        return
            findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.SERVER_REF_CONFIG, amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.config.ClusterRefConfigReferent referent)
Find all {@link ClusterRefConfig} that reference the specified item.

        final AMX   amx = Util.asAMX( referent );
        
        return
            findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.CLUSTER_REF_CONFIG, amx.getName() );
    
public static java.util.SetfindAllRefConfigs(com.sun.appserv.management.base.QueryMgr queryMgr)
Find all ref configs of any j2EEType

return
Set of all {@link RefConfig} found.

        final Set<T>  refs    = 
            queryMgr.queryInterfaceSet( RefConfig.class.getName(), null);
        
        return refs;
    
public static java.util.SetfindAllRefConfigsByJ2EEType(com.sun.appserv.management.base.QueryMgr queryMgr, java.lang.String refJ2EEType)
Find all ref configs of the specified j2EEType

return
Set of all {@link RefConfig} found.

        final Set<T>  refs    =
            queryMgr.queryJ2EETypeSet( refJ2EEType );
        
        return refs;
    
public static java.util.SetfindAllRefConfigsWithName(com.sun.appserv.management.base.QueryMgr queryMgr, java.lang.String refJ2EEType, java.lang.String name)
Find all {@link RefConfig} of the specified j2EEType having the specified name.

return
Set of all {@link RefConfig} found with the specified name.

        final String props = Util.makeRequiredProps( refJ2EEType, name );
        
        final Set<T> refs  = queryMgr.queryPatternSet( null, props );
        
        return refs;
    
public static java.util.SetfindAllResourceRefConfigs(com.sun.appserv.management.base.QueryMgr queryMgr)
Find all {@link ResourceRefConfig}.

return
Set of all {@link ResourceRefConfig} found.

        return
            findAllRefConfigsByJ2EEType( queryMgr, XTypes.RESOURCE_REF_CONFIG );
    
public static java.util.SetfindAllServerRefConfigs(com.sun.appserv.management.base.QueryMgr queryMgr)
Find all {@link ServerRefConfig}.

return
Set of all {@link ServerRefConfig} found.

        return
            findAllRefConfigsByJ2EEType( queryMgr, XTypes.SERVER_REF_CONFIG );
    
private static com.sun.appserv.management.util.misc.OutputgetDebug()

        return AMXDebug.getInstance().getOutput( "com.sun.appserv.management.helper.RefHelper" );
    
private static com.sun.appserv.management.base.QueryMgrgetQueryMgr(com.sun.appserv.management.base.AMX amx)

        return amx.getDomainRoot().getQueryMgr();
    
public static java.util.SetgetReferentJ2EETypes()

    
          
    
    
        return REFERENT_J2EE_TYPES;
    
public static java.lang.StringgetReferentRefJ2EEType(com.sun.appserv.management.config.RefConfigReferent referent)

return
the j2eeType of the config element which can refer to this item

        String  j2eeType    = null;
        
        if ( referent instanceof ResourceRefConfigReferent )
        {
            j2eeType    = XTypes.RESOURCE_REF_CONFIG;
        }
        else if ( referent instanceof DeployedItemRefConfigReferent )
        {
            j2eeType    = XTypes.DEPLOYED_ITEM_REF_CONFIG;
        }
        else if ( referent instanceof ServerRefConfigReferent )
        {
            j2eeType    = XTypes.SERVER_REF_CONFIG;
        }
        else if ( referent instanceof ClusterRefConfigReferent )
        {
            j2eeType    = XTypes.CLUSTER_REF_CONFIG;
        }
        else
        {
            throw new IllegalArgumentException(
                "Unknown referent class: " + Util.asAMX( referent ).getJ2EEType() );
        }
        
        return j2eeType;
    
public static java.util.SetremoveAllRefsTo(com.sun.appserv.management.config.RefConfigReferent item, boolean allowSingleFailure)

        final Set<T> refs   = RefHelper.findAllRefConfigs( item );

	    final Set<T>    failures   = RefHelper.removeRefConfigs( refs );
	    if ( failures.size() != 0 )
        {
            if ( failures.size() > 1 || ! allowSingleFailure )
            {
                final Set<ObjectName>  objectNames = Util.toObjectNames( failures );
                
                throw new IllegalArgumentException( "failure removing refererences:\n{" +
                    CollectionUtil.toString( objectNames, "\n" ) + "\n}" );
            }
        }
        
        return failures;
    
public static java.util.SetremoveRefConfigs(java.util.Set refs)
Remove all specified references (that are possible).

return
any references that could not be removed

        final Set<T> failures    = new HashSet<T>();
        
        for( final T ref : refs )
        {
            /* while deleting references, certain ones, such as those contained
               within a cluster, implicitly delete other (redundant) references
               eg references by clustered servers.  Verify that a reference still
               exists before attempting to delete it.
             */
            final Extra extra = Util.getExtra( ref );
            if ( extra.checkValid() )
            {
                final ConfigRemover rrc   = ConfigRemover.class.cast( ref.getContainer() );
                
                try
                {
                    // may fail as illegal in PE or EE with one ref
                    rrc.removeConfig( ref.getJ2EEType(), ref.getName() );
                }
                catch( Exception e )
                {
                    failures.add( ref );
                }
            }
        }
        
        return failures;