FileDocCategorySizeDatePackage
ConfigContextFactory.javaAPI DocGlassfish v2 API8151Fri May 04 22:31:18 BST 2007com.sun.enterprise.config

ConfigContextFactory

public class ConfigContextFactory extends Object
A factory to create ConfigContext

Fields Summary
private static Hashtable
_ctxCache
Constructors Summary
Methods Summary
private static voidaddConfigContextToCache(java.lang.String url, ConfigContext ctx)

        _ctxCache.put(url, ctx);
    
public ConfigContextcreateConfigContext(java.lang.String url, java.lang.String rootClass)
Returns a ConfigContext object that was either previously created (and stored in the cache) or created anew. If cache is true then the factory looks up its cache of previously created ConfigContext objects and if a matching one is found then that is returned. If the cache lookup failed, then a new ConfigContext is created and inserted into the cache. If cache is false then the cache is not used and a new ConfigContext object is returned. This object is not inserted into the cache. TBD

    
    
                                                                                               
          
        ConfigEnvironment ce = getConfigEnvironment();
        ce.setUrl(url);
        ce.setRootClass(rootClass);
        return createConfigContext(ce);
    
public static ConfigContextcreateConfigContext(com.sun.enterprise.config.pluggable.ConfigEnvironment ce)

        
        if(!ce.isCachingEnabled()) {
            //log that a new one is created //FIXME
            return newConfigContext(ce);
        }
        
        ConfigContext context = getConfigContextFromCache(ce.getUrl());
        
        if(context == null) {
            context = newConfigContext(ce);
             addConfigContextToCache(ce.getUrl(), context);
             //log that it was created. //FIXME
        } else {
            //log that it was found in cache //FIXME
        }
        return context;
    
public static booleanenableLastModifiedCheck(ConfigContext ctx, boolean value)
This method is used to activate the lastModified checking for a configContext If activated, configbeans will carry a lastmodified timestamp in every bean. This time is also carried onto the configChangeList and also to clones. When configContext.updateFromConfigChangeList is called, the timestamp is first checked to see if the bean has not changed since the clone and then the update is made. If a modification to the bean is detected, a staleWriteConfigException is thrown.

param
ctx ConfigContext on which to enable/disable checking
param
value boolean to enable/disable
return
boolean previous value that was set (not the changed value) FIXME move this to configcontext

        return ((ConfigContextImpl)ctx).enableLastModifiedCheck(value);
    
public static ConfigContextgetConfigContextFromCache(java.lang.String url)

        return (ConfigContext) _ctxCache.get(url);
    
private static com.sun.enterprise.config.pluggable.ConfigEnvironmentgetConfigEnvironment()

        ConfigEnvironment ce = null;
        try {
            ce = EnvironmentFactory.
                    getEnvironmentFactory().
                    getConfigEnvironment();
        } catch(Exception e) {
            throw new ConfigRuntimeException
                    ("err_getting_config_env", 
                    "err_getting_config_env",
                    e); //FIXME
        }
        return ce;
    
private static voidinvalidateConfigContext(java.lang.Object obj)

        try {
            if(obj != null)
                ((ConfigContextImpl)obj).cleanup(); //FIXME
        } catch(Exception e) {
            // ignore since it is just cleanup.
            // multiple calls to remove should not fail.
        }
    
private static ConfigContextnewConfigContext(com.sun.enterprise.config.pluggable.ConfigEnvironment ce)

        return new ConfigContextImpl(ce);
    
public static voidremoveConfigContext(ConfigContext ctx)

        String url = ctx.getUrl();
        removeConfigContext(url);
    
public static synchronized voidremoveConfigContext(java.lang.String url)

        Object obj = _ctxCache.remove(url);
        invalidateConfigContext(obj);
    
public static synchronized voidreplaceConfigContext(ConfigContext oldCtx, ConfigContext newCtx)
Replaces a cached context with a new context So, next time the Url is accessed, it returns the new context Note the subtlity of this method: This method gets the url of the old context and replaces the value for that key with the new object Hence, even though there might be a configContext with the same url but a different object, it is still replaced. This behavior is desirable since we would like to have the newCtx set anyway. However, if the url was not present, then ConfigException is thrown with that message. Note that: this class is not i18n complaint. If the old context cannot be found in cache, then throw ConfigException This method is synchronized so to make it thread safe.

param
oldCtx Old ConfigContext that was cached in this class. This cannot be null.
param
newCtx New ConfigContext that will be replaced in the cache. This cannot be null.
throws
ConfigException if url for old ctx is not found in cache

        
        assert (oldCtx != null);
        assert (newCtx != null);
        
        String url = oldCtx.getUrl();
        
        if(_ctxCache.containsKey(url)) {
            _ctxCache.put(url, newCtx);
        } else {
            throw new ConfigException
            ("Old ConfigContext is not found. Cannot replace with new one");
            //FIxME
        }