Thread: [CJ-dev] commonjava-projects/commonjava-config/src/java/org/commonjava/config/snapin SnapInContainer
Brought to you by:
johnqueso
Update of /cvsroot/commonjava/commonjava-projects/commonjava-config/src/java/org/commonjava/config/snapin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21646/src/java/org/commonjava/config/snapin Modified Files: GenericSnapInContainerLoader.java SnapInContainer.java SnapInContainerLoader.java Added Files: SnapInContainerFactory.java Log Message: added more component-ized method of loading configurations. Deprecated static getContainer() in SnapInContainerLoader. Index: GenericSnapInContainerLoader.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-config/src/java/org/commonjava/config/snapin/GenericSnapInContainerLoader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- GenericSnapInContainerLoader.java 18 Feb 2004 06:11:00 -0000 1.3 +++ GenericSnapInContainerLoader.java 23 Apr 2004 19:47:31 -0000 1.4 @@ -11,23 +11,17 @@ public final class GenericSnapInContainerLoader extends SnapInContainerLoader { - private static final String DEFAULT_LOCATION = "cprs:///configuration.xml"; - private static final SnapInContainerLoader INSTANCE = new GenericSnapInContainerLoader(); - /** - * */ - private GenericSnapInContainerLoader() + public GenericSnapInContainerLoader() { } public static SnapInContainerLoader getInstance(){ - return INSTANCE; + return new GenericSnapInContainerLoader(); } - public SnapInContainer loadSnapInContainer() throws SnapInLoaderException{ - String location = System.getProperty(SnapInContainerLoader.LOCATION_SYSPROP, DEFAULT_LOCATION); - + public SnapInContainer loadSnapInContainer(String location, boolean isDefault) throws SnapInLoaderException{ try{ DocumentDriver driver = new DocumentDriver(); GenericSnapInContainer container = Index: SnapInContainer.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-config/src/java/org/commonjava/config/snapin/SnapInContainer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SnapInContainer.java 9 Jan 2004 05:05:13 -0000 1.1 +++ SnapInContainer.java 23 Apr 2004 19:47:31 -0000 1.2 @@ -11,6 +11,15 @@ */ public interface SnapInContainer { + /** System property for specifying the location of the container's persistent state. */ + public static final String LOCATION_SYSPROP = "org.commonjava.config.snapin.file.location"; + + /** System property for specifying the loader for the container. */ + public static final String LOADER_SYSPROP = "org.commonjava.config.snapin.container.loader"; + + /** Default location of the container's persistent state. */ + public static final String DEFAULT_LOCATION = "cprs:///configuration.xml"; + /** Return the snapIn for the specified id, within this configuration instance. * @param snapInId The identifier to lookup * @return the associated snapIn, or null. Index: SnapInContainerLoader.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-config/src/java/org/commonjava/config/snapin/SnapInContainerLoader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SnapInContainerLoader.java 18 Feb 2004 06:11:00 -0000 1.3 +++ SnapInContainerLoader.java 23 Apr 2004 19:47:31 -0000 1.4 @@ -9,26 +9,30 @@ */ public abstract class SnapInContainerLoader { - public static final String LOCATION_SYSPROP = "org.commonjava.config.snapin.file.location"; - public static final String LOADER_SYSPROP = "org.commonjava.config.snapin.container.loader"; private static SnapInContainer container; - public abstract SnapInContainer loadSnapInContainer() throws SnapInLoaderException; + public abstract SnapInContainer loadSnapInContainer(String location, boolean isDefaultLocation) throws SnapInLoaderException; + /** + * @deprecated Use SnapInContainerFactory instead. + */ public static SnapInContainer getSnapInContainer() throws SnapInLoaderException{ + String location = System.getProperty(SnapInContainer.LOCATION_SYSPROP, SnapInContainer.DEFAULT_LOCATION); + + boolean isDefault = SnapInContainer.DEFAULT_LOCATION.equals(location); synchronized(SnapInContainer.class){ if(container == null){ try{ SnapInContainerLoader loader = (SnapInContainerLoader)ImplFinder.findSingletonImplementation( SnapInContainerLoader.class, - LOADER_SYSPROP, + SnapInContainer.LOADER_SYSPROP, GenericSnapInContainerLoader.class, new Object[]{} ); - container = loader.loadSnapInContainer(); + container = loader.loadSnapInContainer(location, isDefault); } catch (FinderException e){ throw new SnapInLoaderException( --- NEW FILE: SnapInContainerFactory.java --- /* * Created on Apr 23, 2004 * */ package org.commonjava.config.snapin; import java.util.Map; import java.util.TreeMap; import org.commonjava.reflection.FinderException; import org.commonjava.reflection.ImplFinder; /** Factory used to load/retain/retrieve SnapInContainer instances. * * @author John Casey * */ public final class SnapInContainerFactory { public static Map containers = new TreeMap(); /** Create a new factory for loading/retrieving SnapInContainer instances. */ public SnapInContainerFactory() { } public SnapInContainer getDefaultContainer() throws SnapInLoaderException{ String location = System.getProperty(SnapInContainer.LOCATION_SYSPROP, SnapInContainer.DEFAULT_LOCATION); return _getContainer(location, true); } public SnapInContainer getContainer(String location) throws SnapInLoaderException{ return _getContainer(location, false); } private SnapInContainer _getContainer(String location, boolean isDefault) throws SnapInLoaderException{ synchronized(SnapInContainer.class){ SnapInContainer container = (SnapInContainer)containers.get(location); if(container == null){ try{ SnapInContainerLoader loader = (SnapInContainerLoader)ImplFinder.findSingletonImplementation( SnapInContainerLoader.class, SnapInContainer.LOADER_SYSPROP, GenericSnapInContainerLoader.class, new Object[]{} ); container = loader.loadSnapInContainer(location, isDefault); } catch (FinderException e){ throw new SnapInLoaderException( "Error finding loader class for snap-in configuration container.", e ); } } return container; } } } |