FileDocCategorySizeDatePackage
PersistenceStrategyBuilderFactory.javaAPI DocGlassfish v2 API13074Fri May 04 22:36:02 BST 2007com.sun.enterprise.web

PersistenceStrategyBuilderFactory

public class PersistenceStrategyBuilderFactory extends Object

Fields Summary
protected final String
DEFAULT_EE_BUILDER_PATH
The default path to the EE persistence strategy builders only used if getEEBuilderPath fails (which should only occur in unit-test
private static Logger
_logger
The logger to use for logging ALL web container related messages.
private String
_eeBuilderPath
The path where ee builders reside
Constructors Summary
public PersistenceStrategyBuilderFactory()
Creates a new instance of PersistenceStrategyBuilderFactory

        if (_logger == null) {
            _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
        }            
    
Methods Summary
private java.lang.StringcamelCase(java.lang.String inputString)
this method strips out all non-alpha characters; camelCases the result

param
inputString

        String strippedString = stripNonAlphas(inputString);
        String firstLetter = (strippedString.substring(0, 1)).toUpperCase();
        String remainingPart = 
            (strippedString.substring(1, strippedString.length())).toLowerCase();
        return firstLetter + remainingPart;
    
private java.lang.StringcreateClassNameFrom(java.lang.String persistenceType, java.lang.String frequency, java.lang.String scope)
returns an appropriately camel-cased String that is a candidate class name for a builder if persistenceType is "memory" or "file" this returns the correct class name and package name for these classes i.e. com.iplanet.ias.web otherwise they are in com.sun.appserv.ee.web.initialization

param
persistenceType
param
frequency
param
scope

        StringBuffer sb = new StringBuffer();
        //using package name will mean this will work
        //even if class is moved to another package
        String pkg = this.getClass().getPackage().getName();
        if( !(persistenceType.equalsIgnoreCase("memory") 
            | persistenceType.equalsIgnoreCase("file")) )  
        {
            //pkg is the package where EE builders MUST reside
            //this defaults to
            //"com.sun.enterprise.ee.web.initialization"
            // but is configurable via (not-well-publicized)
            //property in server.xml
            //at "/server/availability-service/persistence-store/property[@name='ee-builder-path']"
            pkg = this.getEEBuilderPath();
        }
        sb.append(pkg + ".");
        sb.append(camelCase(persistenceType));
        if(frequency != null) {
            sb.append(camelCase(frequency));
        }
        if(scope != null) {
            sb.append(camelCase(scope));
        }
        sb.append("StrategyBuilder");
        String classname = sb.toString();
        return classname;
    
PersistenceStrategyBuildercreatePersistenceStrategyBuilder(java.lang.String persistenceType, java.lang.String frequency, java.lang.String scope, org.apache.catalina.Context ctx)
creates the correct implementation of PersistenceStrategyBuilder if an invalid combination is input; an error is logged and MemoryStrategyBuilder is returned

param
persistenceType
param
frequency
param
scope
param
ctx

        
        String resolvedPersistenceFrequency = null;
        String resolvedPersistenceScope = null;
        PersistenceTypeResolver persistenceTypeResolver 
            = this.getPersistenceTypeResolver();
        String resolvedPersistenceType 
            = persistenceTypeResolver.resolvePersistenceType(persistenceType);
        //System.out.println("resolvedPersistenceType = " + resolvedPersistenceType);
        
        //this is only for my testing -do not check this in this way
        /*
        if(resolvedPersistenceType.equalsIgnoreCase("ha")) {
            resolvedPersistenceType = "replicated";            
        }
        System.out.println("temp resolvedPersistenceType = " + resolvedPersistenceType);
         */
        //end of temp testing part remove before checking in
        
        if( resolvedPersistenceType.equalsIgnoreCase("memory") 
            | resolvedPersistenceType.equalsIgnoreCase("file")) {
            //deliberately leaving frequency & scope null
        } else {
            resolvedPersistenceFrequency = frequency;
            resolvedPersistenceScope = scope;
        }
        _logger.finest("resolvedPersistenceType = " + resolvedPersistenceType);
        _logger.finest("resolvedPersistenceFrequency = " + resolvedPersistenceFrequency);
        _logger.finest("resolvedPersistenceScope = " + resolvedPersistenceScope);
        
        //testPersistenceTypeResolver();
        String passedInPersistenceType = persistenceType;
        PersistenceStrategyBuilder builder = new MemoryStrategyBuilder();
        //String className = createClassNameFrom(persistenceType, frequency, scope);
        String className = createClassNameFrom(resolvedPersistenceType, resolvedPersistenceFrequency, resolvedPersistenceScope);
        //begin temp code for testing
        // for testing - remove after testing complete
        /*
        if(persistenceType.equalsIgnoreCase("ha")) {
            passedInPersistenceType = "replicated";
            className = "com.sun.enterprise.ee.web.initialization.ReplicatedWebmethodSessionStrategyBuilder";
        }
         */
        //System.out.println("ctx: " + ctx.getName() + "passed in persistenceType: " + persistenceType); 
        //end temp code for testing        
        _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: "
            + "CandidateBuilderClassName = " + className);      
        try {
            builder = 
                (PersistenceStrategyBuilder) (Class.forName(className)).newInstance();
        } catch (Exception ex) {
            Object[] params = { getApplicationId(ctx), persistenceType, frequency, scope };
            _logger.log(Level.WARNING,
                        "webcontainer.invalidSessionManagerConfig",
                        params);            
        }
        builder.setPersistenceFrequency(frequency);
        builder.setPersistenceScope(scope);
        //FIXME change later
        builder.setPassedInPersistenceType(passedInPersistenceType);
        //builder.setPassedInPersistenceType(persistenceType);
        return builder;
    
PersistenceStrategyBuildercreatePersistenceStrategyBuilder(java.lang.String persistenceType, java.lang.String frequency, java.lang.String scope)
creates the correct implementation of PersistenceStrategyBuilder if an invalid combination is input; an error is logged and MemoryStrategyBuilder is returned

param
persistenceType
param
frequency
param
scope

        String passedInPersistenceType = persistenceType;
        PersistenceStrategyBuilder builder = new MemoryStrategyBuilder();
        String className = createClassNameFrom(persistenceType, frequency, scope);
        _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: "
            + "CandidateBuilderClassName = " + className);      
        try {
            builder = 
                (PersistenceStrategyBuilder) (Class.forName(className)).newInstance();
        } catch (Exception ex) {
            Object[] params = { persistenceType, frequency, scope };
            _logger.log(Level.WARNING,
                        "webcontainer.invalidSessionManagerConfig",
                        params);            
        }
        builder.setPersistenceFrequency(frequency);
        builder.setPersistenceScope(scope);
        //FIXME change later
        builder.setPassedInPersistenceType(passedInPersistenceType);
        //builder.setPassedInPersistenceType(persistenceType);        
        return builder;
    
public java.lang.StringgetApplicationId(org.apache.catalina.Context ctx)
returns the application id for the module

param
ctx the context

        com.sun.enterprise.web.WebModule wm =
        (com.sun.enterprise.web.WebModule)ctx;
        return wm.getID();
    
private java.lang.StringgetEEBuilderPath()
return the path where the ee builders reside although this method allows this to be configurable via an property in server.xml we do not expose it and it should not be re-configured

    

                                             
       
        if(_eeBuilderPath == null) {
            ServerConfigLookup lookup = new ServerConfigLookup();
            _eeBuilderPath = lookup.getEEBuilderPathFromConfig();
        }
        _logger.finest("_eeBuilderPath = " + _eeBuilderPath);    
        return _eeBuilderPath;
    
private PersistenceTypeResolvergetPersistenceTypeResolver()

        String resolverClassName 
            = "com.sun.enterprise.ee.web.sessmgmt.EEPersistenceTypeResolver";
    
        PersistenceTypeResolver persistenceTypeResolver = null;
        try {
            persistenceTypeResolver = 
                (PersistenceTypeResolver) (Class.forName(resolverClassName)).newInstance();
        } catch (Exception ex) {
            _logger.finest("unable to create persistence type resolver");
        } 
        return persistenceTypeResolver;
    
private java.lang.StringstripNonAlphas(java.lang.String inputString)
this method strips out all non-alpha characters

param
inputString

        StringBuffer sb = new StringBuffer(50);
        for(int i=0; i<inputString.length(); i++) {
            char nextChar = inputString.charAt(i);
            if(Character.isLetter(nextChar)) {
                sb.append(nextChar);
            }
        }
        return sb.toString();
    
public PersistenceStrategyBuildertestCreatePersistenceStategyBuilder(java.lang.String persistenceType, java.lang.String frequency, java.lang.String scope)

        return this.createPersistenceStrategyBuilder(persistenceType, frequency, scope);
    
private voidtestPersistenceTypeResolver()

        PersistenceTypeResolver persistenceTypeResolver 
            = this.getPersistenceTypeResolver();
        List testTypes = Arrays.asList("memory", "file", "ha", "replicated", "registered_foo", "non-registered_foo");
        for(int i=0; i<testTypes.size(); i++) {
            String nextType = (String)testTypes.get(i);
            String nextResolvedPersistenceType 
                = persistenceTypeResolver.resolvePersistenceType(nextType);
            System.out.println("nextType=" + nextType + "::nextResolvedPersistenceType = " + nextResolvedPersistenceType + "\n");
        }