FileDocCategorySizeDatePackage
PersistenceStrategyBuilderFactory.javaAPI DocGlassfish v2 API8319Fri May 04 22:32:56 BST 2007com.sun.ejb.base.sfsb.initialization

PersistenceStrategyBuilderFactory

public class PersistenceStrategyBuilderFactory extends Object
author
lwhite

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 final Logger
_logger
The logger to use for logging ALL ejb container related messages.
Constructors Summary
public PersistenceStrategyBuilderFactory()
Creates a new instance of PersistenceStrategyBuilderFactory

        
    
           
              
    
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)
returns an appropriately camel-cased String that is a candidate class name for a builder if persistenceType is "file" this returns the correct class name and package name for these classes i.e. com.sun.ejb.spi.?? FIXME:figure this out where the file builder will reside otherwise they are in com.sun.appserv.ee.web.initialization

param
persistenceType

        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("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));
        sb.append("StrategyBuilder");
        String classname = sb.toString();
        return classname;
    
public com.sun.ejb.spi.sfsb.initialization.PersistenceStrategyBuildercreatePersistenceStrategyBuilder(java.lang.String persistenceType)
creates the correct implementation of PersistenceStrategyBuilder if an invalid combination is input; an error is logged and MemoryStrategyBuilder is returned

param
persistenceType
param
container
param
descriptor

        /* FIXME replace after testing
        PersistenceTypeResolver persistenceTypeResolver 
            = this.getPersistenceTypeResolver();
        String resolvedPersistenceType 
            = persistenceTypeResolver.resolvePersistenceType(persistenceType);
        debug("resolvedPersistenceType = " + resolvedPersistenceType);
         */
        String passedInPersistenceType = persistenceType;        
        PersistenceStrategyBuilder builder = new FileStrategyBuilder();
        String className = createClassNameFrom(persistenceType);
        if(_logger.isLoggable(Level.FINEST)) {
            _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: "
                + "CandidateBuilderClassName = " + className); 
        }
	boolean requestedBuilderCreated = false;
        try {
            builder = 
                (PersistenceStrategyBuilder) (Class.forName(className)).newInstance();
	    requestedBuilderCreated = true;
        } catch (ClassNotFoundException clnfEx) {
	    _logger.log(Level.WARNING, "Couldn't find class: "
		    + className + " for persistenceType: "
		    + persistenceType);
            if(_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Exception while creating Builder", clnfEx);
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "Exception while creating Builder", ex);
        }    
	if (! requestedBuilderCreated) {
            _logger.log(Level.WARNING, "Couldn't create builder for "
		    + "persistence type: " + persistenceType
		    +". Instead created FileStrategyBuilder....");
	}
        builder.setPassedInPersistenceType(passedInPersistenceType);
        return builder;
    
private static voiddebug(java.lang.String s)

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

        return DEFAULT_EE_BUILDER_PATH;
    
private PersistenceTypeResolvergetPersistenceTypeResolver()

        String resolverClassName 
            = "com.sun.enterprise.ee.web.sessmgmt.EEPersistenceTypeResolver";
    
        PersistenceTypeResolver persistenceTypeResolver = null;
        try {
            persistenceTypeResolver = 
                (PersistenceTypeResolver) (Class.forName(resolverClassName)).newInstance();
        } catch (Exception ex) {
            debug("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();