[jboss-cvs] JBossAS SVN: r97277 - projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 2 01:18:27 EST 2009
Author: marius.bogoevici
Date: 2009-12-02 01:18:27 -0500 (Wed, 02 Dec 2009)
New Revision: 97277
Added:
projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/ContextClassUtil.java
projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareContextLoaderListener.java
projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareDispatcherServlet.java
Log:
Added: projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/ContextClassUtil.java
===================================================================
--- projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/ContextClassUtil.java (rev 0)
+++ projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/ContextClassUtil.java 2009-12-02 06:18:27 UTC (rev 97277)
@@ -0,0 +1,45 @@
+package org.jboss.spring.vfs.context;
+
+import org.springframework.context.ApplicationContextException;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class ContextClassUtil
+{
+ static final String VFS_APPLICATION_CONTEXT_CLASS_NAME = "org.jboss.spring.vfs.context.VFSXmlWebApplicationContext";
+
+ public static boolean isJBossAS5orHigher()
+ {
+ try
+ {
+ Class jBossVersionClass = VFSAwareContextLoaderListener.class.getClassLoader().loadClass("org.jboss.Version");
+ Object versionObject = ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getInstance"), null);
+ Integer majorVersion = (Integer) ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getMajor"), versionObject);
+ // For JBoss AS versions 5 and higher
+ if (majorVersion >= 5) {
+ return true;
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ // do nothing;
+ }
+ return false;
+ }
+
+ public static Class getVFSWebContextClass()
+ {
+ try
+ {
+ return ClassUtils.forName(VFS_APPLICATION_CONTEXT_CLASS_NAME);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new ApplicationContextException(
+ "Failed to load custom context class [" + VFS_APPLICATION_CONTEXT_CLASS_NAME + "]", ex);
+ }
+ }
+}
Added: projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareContextLoaderListener.java
===================================================================
--- projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareContextLoaderListener.java (rev 0)
+++ projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareContextLoaderListener.java 2009-12-02 06:18:27 UTC (rev 97277)
@@ -0,0 +1,44 @@
+package org.jboss.spring.vfs.context;
+
+import javax.servlet.ServletContext;
+
+import org.springframework.context.ApplicationContextException;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.ContextLoaderListener;
+
+/**
+ * A VFS-compatible {@link org.springframework.web.context.ContextLoaderListener},
+ * which works transparently in or outside JBoss AS.
+ *
+ * It detects whether the current runtime is JBoss AS in a version later than 5.0.0,
+ * and if that is the case, instantiates a {@link VFSXmlWebApplicationContext}, otherwise
+ * it instantiates a {@link org.springframework.web.context.support.XmlWebApplicationContext}.
+ *
+ * @author Marius Bogoevici
+ */
+public class VFSAwareContextLoaderListener extends ContextLoaderListener
+{
+
+ @Override
+ protected ContextLoader createContextLoader()
+ {
+ if (!ContextClassUtil.isJBossAS5orHigher())
+ {
+ return super.createContextLoader();
+ }
+ else
+ {
+ return new VFSContextLoader();
+ }
+ }
+
+ private static class VFSContextLoader extends ContextLoader
+ {
+ @Override
+ protected Class determineContextClass(ServletContext servletContext) throws ApplicationContextException
+ {
+ return ContextClassUtil.getVFSWebContextClass();
+
+ }
+ }
+}
Added: projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareDispatcherServlet.java
===================================================================
--- projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareDispatcherServlet.java (rev 0)
+++ projects/snowdrop/branches/1_0/vfs/src/main/java/org/jboss/spring/vfs/context/VFSAwareDispatcherServlet.java 2009-12-02 06:18:27 UTC (rev 97277)
@@ -0,0 +1,26 @@
+package org.jboss.spring.vfs.context;
+
+import org.springframework.web.servlet.DispatcherServlet;
+
+/**
+ * A VFS-compatible {@link org.springframework.web.servlet.DispatcherServlet},
+ * which works transparently in or outside JBoss AS.
+ *
+ * It detects whether the current runtime is JBoss AS in a version later than 5.0.0,
+ * and if that is the case, instantiates a {@link VFSXmlWebApplicationContext}, otherwise
+ * it instantiates a {@link org.springframework.web.context.support.XmlWebApplicationContext}.
+ *
+ * @author Marius Bogoevici
+ */
+public class VFSAwareDispatcherServlet extends DispatcherServlet
+{
+
+ @Override
+ public Class getContextClass()
+ {
+ if (ContextClassUtil.isJBossAS5orHigher())
+ return ContextClassUtil.getVFSWebContextClass();
+ else
+ return super.getContextClass();
+ }
+}
More information about the jboss-cvs-commits
mailing list