FileDocCategorySizeDatePackage
BackingStoreRegistry.javaAPI DocGlassfish v2 API7474Fri May 04 22:35:26 BST 2007com.sun.appserv.ha.spi

BackingStoreRegistry

public final class BackingStoreRegistry extends Object
A class for storing BackingStore implementation. This is a singleton and contains a mapping between persistence-type and BackingStoreFactory. An instance of this class can be obtained using getInstance() method.
see
BackingStore

Fields Summary
private static BackingStoreRegistry
_instance
private Map
type2BackingStoreInfo
Constructors Summary
private BackingStoreRegistry()


    // Private constructor
      
    
Methods Summary
public java.util.PropertiesgetFactoryClassEnv(java.lang.String type)
Get the registered factory for the type specified in the parameter

param
type the type
return
The BackingStoreFactory env (Properties) or null

        BackingStoreInfo info = type2BackingStoreInfo.get(type);
        return (info == null) ? null : info.props;
    
public java.lang.StringgetFactoryClassName(java.lang.String type)
Get the registered factory for the type specified in the parameter

param
type the type
return
The BackingStoreFactory class name or null

        BackingStoreInfo info = type2BackingStoreInfo.get(type);
        return (info == null) ? null : info.className;
    
public BackingStoreFactorygetFactoryInstance(java.lang.String type)
Return an instance of BackingStoreFactory for the specified type. If a factory instance for this persistence type has not yet been instantiated then an instance is created using the public no-arg constructor. Then {@link BackingStore#initialize(String, Properties)} will be called to properly initialize the BsackingStore.

param
type the persistence type for which a factory is required
return
an instance of BackingStoreFactory for the specified type
throws
BackingStoreException if the store cannot be initialized properly.
throws
ClassNotFoundException If the BackingStore class cannot be found.
throws
InstantiationException If the BackingStore class cannot be instantiated.
throws
IllegalAccessException If the BackingStore class doen't provide a public no-arg constructor
see
BackingStore.initialize(String, Properties)

        BackingStoreFactory factory = null;
        BackingStoreInfo info = type2BackingStoreInfo.get(type);
        if (info != null) {
            if (info.factory == null) {
                synchronized (info) {
                    Class clazz = Class.forName(info.className);
                    info.factory = (BackingStoreFactory) clazz.newInstance();
                }
            }

            factory = info.factory;
        }

        return factory;
    
public static com.sun.appserv.ha.spi.BackingStoreRegistrygetInstance()
Return the (singleton) instance of BackingStoreRegistry

return
BackingStoreRegistry

        return _instance;
    
public java.util.CollectiongetRegisteredTypes()
Get a list of all registered store type

return
Collection where each entry in the collection is the type

        return type2BackingStoreInfo.keySet();
    
public synchronized voidregister(java.lang.String type, java.lang.String factoryClassName, java.util.Properties props)
Register a BackingStoreFactory class name and any associated Properties for the given persistence type. The properties must contain any additional configuration paramters to properly initialize and use the store.

param
type The persistence-type
param
factoryClassName The factory class name for this type. This class must extend BackingStore.
param
props Properties that contain additional configration paramters.
throws
DuplicateFactoryRegistrationException If this type is already registered.
see
BackingStoreFactory#createBackingStore(Class, String, Properties)

        if (type2BackingStoreInfo.get(type) != null) {
            throw new DuplicateFactoryRegistrationException(
                    "Duplicate factory class (" + factoryClassName
                            + ") for type: " + type);
        } else {
            type2BackingStoreInfo.put(type, new BackingStoreInfo(
                    factoryClassName, props));
        }
    
public booleanremove(java.lang.String type)
Unregister the factory

param
type the type

        return (type2BackingStoreInfo.remove(type) != null);