Revision: 1333
http://stripes.svn.sourceforge.net/stripes/?rev=1333&view=rev
Author: bengunter
Date: 2010-11-12 15:19:15 +0000 (Fri, 12 Nov 2010)
Log Message:
-----------
STS-776, STS-773 and STS-775: Made VFS pluggable through the new VFS.Classes
init-param for StripesFilter.
Modified Paths:
--------------
branches/1.5.x/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/vfs/VFS.java
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
2010-11-12 05:29:00 UTC (rev 1332)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
2010-11-12 15:19:15 UTC (rev 1333)
@@ -28,6 +28,7 @@
import net.sourceforge.stripes.util.ReflectUtil;
import net.sourceforge.stripes.util.ResolverUtil;
import net.sourceforge.stripes.util.StringUtil;
+import net.sourceforge.stripes.vfs.VFS;
/**
* <p>Resolves configuration properties that are used to bootstrap the system.
Essentially this boils
@@ -50,12 +51,16 @@
private FilterConfig filterConfig;
+ /** The Configuration Key for looking up the comma separated list of VFS
classes. */
+ public static final String VFS_CLASSES = "VFS.Classes";
+
/** The Configuration Key for looking up the comma separated list of
extension packages. */
public static final String PACKAGES = "Extension.Packages";
/** Constructs a new BootstrapPropertyResolver with the given
ServletConfig. */
public BootstrapPropertyResolver(FilterConfig filterConfig) {
setFilterConfig(filterConfig);
+ initVFS();
}
/** Stores a reference to the filter's FilterConfig object. */
@@ -68,6 +73,18 @@
return this.filterConfig;
}
+ /** Add {...@link VFS} implementations that are specified in the filter
configuration. */
+ @SuppressWarnings("unchecked")
+ protected void initVFS() {
+ List<Class<?>> vfsImpls = getClassPropertyList(VFS_CLASSES);
+ for (Class<?> clazz : vfsImpls) {
+ if (!VFS.class.isAssignableFrom(clazz))
+ log.warn("Class ", clazz.getName(), " does not extend ",
VFS.class.getName());
+ else
+ VFS.addImplClass((Class<? extends VFS>) clazz);
+ }
+ }
+
/**
* Fetches a configuration property in the manner described in the class
level javadoc for
* this class.
Modified: branches/1.5.x/stripes/src/net/sourceforge/stripes/vfs/VFS.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/vfs/VFS.java
2010-11-12 05:29:00 UTC (rev 1332)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/vfs/VFS.java
2010-11-12 15:19:15 UTC (rev 1333)
@@ -19,6 +19,7 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -32,6 +33,14 @@
*/
public abstract class VFS {
private static final Log log = Log.getInstance(VFS.class);
+
+ /** The built-in implementations. */
+ public static final Class<?>[] IMPLEMENTATIONS = { JBoss6VFS.class,
DefaultVFS.class };
+
+ /** The list to which implementations are added by {...@link
#addImplClass(String)}. */
+ public static final List<Class<? extends VFS>> USER_IMPLEMENTATIONS = new
ArrayList<Class<? extends VFS>>();
+
+ /** Singleton instance. */
private static VFS instance;
/**
@@ -40,21 +49,52 @@
*
* @return
*/
+ @SuppressWarnings("unchecked")
public static VFS getInstance() {
if (instance != null)
return instance;
- // Try JBoss 6 first
- VFS vfs = new JBoss6VFS();
+ // Try the user implementations first, then the built-ins
+ List<Class<? extends VFS>> impls = new ArrayList<Class<? extends
VFS>>();
+ impls.addAll(USER_IMPLEMENTATIONS);
+ impls.addAll(Arrays.asList((Class<? extends VFS>[]) IMPLEMENTATIONS));
- // Fall back to default
- if (!vfs.isValid())
- vfs = new DefaultVFS();
+ // Try each implementation class until a valid one is found
+ VFS vfs = null;
+ for (int i = 0; vfs == null || !vfs.isValid(); i++) {
+ Class<? extends VFS> impl = impls.get(i);
+ try {
+ vfs = impl.newInstance();
+ if (vfs == null || !vfs.isValid()) {
+ log.debug("VFS implementation ", impl.getName(),
+ " is not valid in this environment.");
+ }
+ }
+ catch (InstantiationException e) {
+ log.error(e, "Failed to instantiate ", impl);
+ return null;
+ }
+ catch (IllegalAccessException e) {
+ log.error(e, "Failed to instantiate ", impl);
+ return null;
+ }
+ }
log.info("Using VFS adapter ", vfs.getClass().getName());
return VFS.instance = vfs;
}
+ /**
+ * Adds the specified class to the list of {...@link VFS} implementations.
Classes added in this
+ * manner are tried in the order they are added and before any of the
built-in implementations.
+ *
+ * @param className The name of the {...@link VFS} implementation class to
add.
+ */
+ public static void addImplClass(Class<? extends VFS> clazz) {
+ if (clazz != null)
+ USER_IMPLEMENTATIONS.add(clazz);
+ }
+
/** Get a class by name. If the class is not found then return null. */
protected static Class<?> getClass(String className) {
try {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development