Author: remy.maucherat(a)jboss.com
Date: 2009-02-13 10:21:15 -0500 (Fri, 13 Feb 2009)
New Revision: 930
Added:
trunk/java/org/apache/catalina/AnnotationScanner.java
trunk/java/org/apache/catalina/ClassLoadingAnnotationScanner.java
trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java
trunk/java/org/apache/catalina/core/ClassLoadingAnnotationScanner.java
trunk/java/org/apache/catalina/core/JavassistAnnotationScanner.java
Removed:
trunk/java/org/apache/catalina/core/AnnotationScanner.java
Modified:
trunk/webapps/docs/changelog.xml
Log:
- Repackage using a class hierarchy (I am told JBoss developers get fired if their class
hierarchy is not at least 10 deep,
so not there yet).
Added: trunk/java/org/apache/catalina/AnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/AnnotationScanner.java (rev 0)
+++ trunk/java/org/apache/catalina/AnnotationScanner.java 2009-02-13 15:21:15 UTC (rev
930)
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina;
+
+import java.util.List;
+
+public interface AnnotationScanner {
+
+ /**
+ * Scan the given context's default locations for annotations.
+ *
+ * @param context
+ */
+ public List<Class<?>> scan(Context context);
+
+
+}
Added: trunk/java/org/apache/catalina/ClassLoadingAnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/ClassLoadingAnnotationScanner.java
(rev 0)
+++ trunk/java/org/apache/catalina/ClassLoadingAnnotationScanner.java 2009-02-13 15:21:15
UTC (rev 930)
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina;
+
+import java.util.List;
+
+public interface ClassLoadingAnnotationScanner {
+
+ /**
+ * Scan the given context's default locations for annotations.
+ *
+ * @param context
+ */
+ public List<Class<?>> scan(Context context);
+
+
+}
Deleted: trunk/java/org/apache/catalina/core/AnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/core/AnnotationScanner.java 2009-02-13 15:19:22 UTC
(rev 929)
+++ trunk/java/org/apache/catalina/core/AnnotationScanner.java 2009-02-13 15:21:15 UTC
(rev 930)
@@ -1,250 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.catalina.core;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import javax.naming.directory.DirContext;
-import javax.servlet.annotation.InitParam;
-import javax.servlet.annotation.ServletFilter;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.annotation.WebServletContextListener;
-
-import org.apache.catalina.Context;
-
-public class AnnotationScanner {
-
- public static final boolean USE_JAVASSIST =
-
Boolean.valueOf(System.getProperty("org.apache.catalina.core.AnnotationScanner.USE_JAVASSIST",
"false")).booleanValue();
-
- /**
- * Scan the given context's default locations for annotations.
- *
- * @param context
- */
- public List<Class<?>> scan(Context context) {
- ArrayList<Class<?>> result = new ArrayList<Class<?>>();
-
- if (context.getLoader().findLoaderRepositories() != null) {
- String[] repositories = context.getLoader().findLoaderRepositories();
- for (int i = 0; i < repositories.length; i++) {
- if (repositories[i].endsWith(".jar")) {
- try {
- scanJar(result, context, new JarFile(repositories[i]));
- } catch (IOException e) {
- // Ignore
- }
- } else {
- scanClasses(result, context, new File(repositories[i]),
"");
- }
- }
- }
-
- return result;
- /*
- DirContext resources = context.getResources();
- DirContext webInfClasses = null;
- DirContext webInfLib = null;
-
- try {
- webInfClasses = (DirContext) resources.lookup("/WEB-INF/classes");
- } catch (Exception e) {
- // Ignore, /WEB-INF/classes not found, or not a folder
- }
- if (webInfClasses != null) {
- scanClasses(context, webInfClasses, "");
- }
-
- try {
- webInfLib = (DirContext) resources.lookup("/WEB-INF/lib");
- } catch (Exception e) {
- // Ignore, /WEB-INF/classes not found, or not a folder
- }
- if (webInfLib != null) {
- scanJars(context, webInfLib);
- }*/
-
- }
-
-
- /**
- * Scan folder containing class files.
- */
- public void scanClasses(List<Class<?>> result, Context context, File
folder, String path) {
- String[] files = folder.list();
- for (int i = 0; i < files.length; i++) {
- File file = new File(folder, files[i]);
- if (file.isDirectory()) {
- scanClasses(result, context, file, path + "/" + files[i]);
- } else if (files[i].endsWith(".class")) {
- String className = getClassName(path + "/" + files[i]);
- Class<?> annotated = scanClass(context, className, file, null);
- if (annotated != null) {
- result.add(annotated);
- }
- }
- }
- }
-
-
- /**
- * Scan folder containing class files.
- */
- /*
- public static void scanClasses(Context context, DirContext folder, String path) {
- try {
- NamingEnumeration<Binding> enumeration = folder.listBindings(path);
- while (enumeration.hasMore()) {
- Binding binding = enumeration.next();
- Object object = binding.getObject();
-
- if (object instanceof Resource) {
- // This is a class, so we should load it
- String className = getClassName(path + "/" +
binding.getName());
- scanClass(context, className, (Resource) object, null, null);
- } else if (object instanceof DirContext) {
- scanClasses(context, folder, path + "/" +
binding.getName());
- }
-
- }
- } catch (NamingException e) {
- // Ignore for now
- e.printStackTrace();
- }
- }*/
-
-
- /**
- * Scan folder containing JAR files.
- */
- public void scanJars(List<Class<?>> result, Context context, DirContext
folder) {
- if (context.getLoader().findLoaderRepositories() != null) {
- String[] repositories = context.getLoader().findLoaderRepositories();
- for (int i = 0; i < repositories.length; i++) {
- if (repositories[i].endsWith(".jar")) {
- try {
- scanJar(result, context, new JarFile(repositories[i]));
- } catch (IOException e) {
- // Ignore
- }
- }
- }
- }
- /*else {
- try {
- NamingEnumeration<Binding> enumeration =
folder.listBindings("");
- while (enumeration.hasMore()) {
- Binding binding = enumeration.next();
- Object object = binding.getObject();
-
- if (object instanceof Resource &&
binding.getName().endsWith(".jar")) {
- // This is normally a JAR, put it in the work folder
- File destDir = null;
- File workDir =
- (File)
context.getServletContext().getAttribute(Globals.WORK_DIR_ATTR);
- destDir = new File(workDir, "WEB-INF/lib");
- destDir.mkdirs();
- File destFile = new File(destDir, binding.getName());
-
- scanJar(context, (Resource) object);
- }
-
- }
- } catch (NamingException e) {
- // Ignore for now
- e.printStackTrace();
- }
- }*/
- }
-
-
- /**
- * Scan all class files in the given JAR.
- */
- public void scanJar(List<Class<?>> result, Context context, JarFile file)
{
- Enumeration<JarEntry> entries = file.entries();
- while (entries.hasMoreElements()) {
- JarEntry entry = entries.nextElement();
- if (entry.getName().endsWith(".class")) {
- Class<?> annotated = scanClass(context,
getClassName(entry.getName()), null, entry);
- if (annotated != null) {
- result.add(annotated);
- }
- }
- }
- try {
- file.close();
- } catch (IOException e) {
- // Ignore
- }
- }
-
-
- /**
- * Get class name given a path to a classfile.
- * /my/class/MyClass.class -> my.class.MyClass
- */
- public String getClassName(String filePath) {
- if (filePath.startsWith("/")) {
- filePath = filePath.substring(1);
- }
- if (filePath.endsWith(".class")) {
- filePath = filePath.substring(0, filePath.length() -
".class".length());
- }
- return filePath.replace('/', '.');
- }
-
-
- /**
- * Scan class for interesting annotations.
- */
- public Class<?> scanClass(Context context, String className, File file,
JarEntry entry) {
- if (USE_JAVASSIST) {
- // FIXME: Javassist implementation
- try {
-
- return context.getLoader().getClassLoader().loadClass(className);
- } catch (Throwable t) {
- // Ignore classloading errors here
- }
- } else {
- // Load the class using the classloader, and see if it implements one of the
web annotations
- try {
- Class<?> clazz =
context.getLoader().getClassLoader().loadClass(className);
- if (clazz.isAnnotationPresent(InitParam.class)
- || clazz.isAnnotationPresent(ServletFilter.class)
- || clazz.isAnnotationPresent(WebServlet.class)
- || clazz.isAnnotationPresent(WebServletContextListener.class)) {
- return clazz;
- }
- } catch (Throwable t) {
- // Ignore classloading errors here
- }
- }
- return null;
- }
-
-
-}
Copied: trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java (from rev 925,
trunk/java/org/apache/catalina/core/AnnotationScanner.java)
===================================================================
--- trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java
(rev 0)
+++ trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java 2009-02-13 15:21:15 UTC
(rev 930)
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import javax.naming.directory.DirContext;
+
+import org.apache.catalina.AnnotationScanner;
+import org.apache.catalina.Context;
+
+public abstract class BaseAnnotationScanner
+ implements AnnotationScanner {
+
+ /**
+ * Scan the given context's default locations for annotations.
+ *
+ * @param context
+ */
+ public List<Class<?>> scan(Context context) {
+ ArrayList<Class<?>> result = new ArrayList<Class<?>>();
+
+ if (context.getLoader().findLoaderRepositories() != null) {
+ String[] repositories = context.getLoader().findLoaderRepositories();
+ for (int i = 0; i < repositories.length; i++) {
+ if (repositories[i].endsWith(".jar")) {
+ try {
+ scanJar(result, context, new JarFile(repositories[i]));
+ } catch (IOException e) {
+ // Ignore
+ }
+ } else {
+ scanClasses(result, context, new File(repositories[i]),
"");
+ }
+ }
+ }
+
+ return result;
+ /*
+ DirContext resources = context.getResources();
+ DirContext webInfClasses = null;
+ DirContext webInfLib = null;
+
+ try {
+ webInfClasses = (DirContext) resources.lookup("/WEB-INF/classes");
+ } catch (Exception e) {
+ // Ignore, /WEB-INF/classes not found, or not a folder
+ }
+ if (webInfClasses != null) {
+ scanClasses(context, webInfClasses, "");
+ }
+
+ try {
+ webInfLib = (DirContext) resources.lookup("/WEB-INF/lib");
+ } catch (Exception e) {
+ // Ignore, /WEB-INF/classes not found, or not a folder
+ }
+ if (webInfLib != null) {
+ scanJars(context, webInfLib);
+ }*/
+
+ }
+
+
+ /**
+ * Scan folder containing class files.
+ */
+ public void scanClasses(List<Class<?>> result, Context context, File
folder, String path) {
+ String[] files = folder.list();
+ for (int i = 0; i < files.length; i++) {
+ File file = new File(folder, files[i]);
+ if (file.isDirectory()) {
+ scanClasses(result, context, file, path + "/" + files[i]);
+ } else if (files[i].endsWith(".class")) {
+ String className = getClassName(path + "/" + files[i]);
+ Class<?> annotated = scanClass(context, className, file, null);
+ if (annotated != null) {
+ result.add(annotated);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Scan folder containing class files.
+ */
+ /*
+ public static void scanClasses(Context context, DirContext folder, String path) {
+ try {
+ NamingEnumeration<Binding> enumeration = folder.listBindings(path);
+ while (enumeration.hasMore()) {
+ Binding binding = enumeration.next();
+ Object object = binding.getObject();
+
+ if (object instanceof Resource) {
+ // This is a class, so we should load it
+ String className = getClassName(path + "/" +
binding.getName());
+ scanClass(context, className, (Resource) object, null, null);
+ } else if (object instanceof DirContext) {
+ scanClasses(context, folder, path + "/" +
binding.getName());
+ }
+
+ }
+ } catch (NamingException e) {
+ // Ignore for now
+ e.printStackTrace();
+ }
+ }*/
+
+
+ /**
+ * Scan folder containing JAR files.
+ */
+ public void scanJars(List<Class<?>> result, Context context, DirContext
folder) {
+ if (context.getLoader().findLoaderRepositories() != null) {
+ String[] repositories = context.getLoader().findLoaderRepositories();
+ for (int i = 0; i < repositories.length; i++) {
+ if (repositories[i].endsWith(".jar")) {
+ try {
+ scanJar(result, context, new JarFile(repositories[i]));
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ /*else {
+ try {
+ NamingEnumeration<Binding> enumeration =
folder.listBindings("");
+ while (enumeration.hasMore()) {
+ Binding binding = enumeration.next();
+ Object object = binding.getObject();
+
+ if (object instanceof Resource &&
binding.getName().endsWith(".jar")) {
+ // This is normally a JAR, put it in the work folder
+ File destDir = null;
+ File workDir =
+ (File)
context.getServletContext().getAttribute(Globals.WORK_DIR_ATTR);
+ destDir = new File(workDir, "WEB-INF/lib");
+ destDir.mkdirs();
+ File destFile = new File(destDir, binding.getName());
+
+ scanJar(context, (Resource) object);
+ }
+
+ }
+ } catch (NamingException e) {
+ // Ignore for now
+ e.printStackTrace();
+ }
+ }*/
+ }
+
+
+ /**
+ * Scan all class files in the given JAR.
+ */
+ public void scanJar(List<Class<?>> result, Context context, JarFile file)
{
+ Enumeration<JarEntry> entries = file.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry entry = entries.nextElement();
+ if (entry.getName().endsWith(".class")) {
+ Class<?> annotated = scanClass(context,
getClassName(entry.getName()), null, entry);
+ if (annotated != null) {
+ result.add(annotated);
+ }
+ }
+ }
+ try {
+ file.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+
+
+ /**
+ * Get class name given a path to a classfile.
+ * /my/class/MyClass.class -> my.class.MyClass
+ */
+ public String getClassName(String filePath) {
+ if (filePath.startsWith("/")) {
+ filePath = filePath.substring(1);
+ }
+ if (filePath.endsWith(".class")) {
+ filePath = filePath.substring(0, filePath.length() -
".class".length());
+ }
+ return filePath.replace('/', '.');
+ }
+
+
+ /**
+ * Scan class for interesting annotations.
+ */
+ public abstract Class<?> scanClass(Context context, String className, File
file, JarEntry entry);
+
+
+}
Property changes on: trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/java/org/apache/catalina/core/ClassLoadingAnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/core/ClassLoadingAnnotationScanner.java
(rev 0)
+++ trunk/java/org/apache/catalina/core/ClassLoadingAnnotationScanner.java 2009-02-13
15:21:15 UTC (rev 930)
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.core;
+
+import java.io.File;
+import java.util.jar.JarEntry;
+
+import javax.servlet.annotation.InitParam;
+import javax.servlet.annotation.ServletFilter;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.annotation.WebServletContextListener;
+
+import org.apache.catalina.Context;
+
+public class ClassLoadingAnnotationScanner
+ extends BaseAnnotationScanner {
+
+ /**
+ * Scan class for interesting annotations.
+ */
+ public Class<?> scanClass(Context context, String className, File file,
JarEntry entry) {
+ // Load the class using the classloader, and see if it implements one of the web
annotations
+ try {
+ Class<?> clazz =
context.getLoader().getClassLoader().loadClass(className);
+ if (clazz.isAnnotationPresent(InitParam.class)
+ || clazz.isAnnotationPresent(ServletFilter.class)
+ || clazz.isAnnotationPresent(WebServlet.class)
+ || clazz.isAnnotationPresent(WebServletContextListener.class)) {
+ return clazz;
+ }
+ } catch (Throwable t) {
+ // Ignore classloading errors here
+ }
+ return null;
+ }
+
+
+}
Added: trunk/java/org/apache/catalina/core/JavassistAnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/core/JavassistAnnotationScanner.java
(rev 0)
+++ trunk/java/org/apache/catalina/core/JavassistAnnotationScanner.java 2009-02-13
15:21:15 UTC (rev 930)
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.core;
+
+import java.io.File;
+import java.util.jar.JarEntry;
+
+import org.apache.catalina.Context;
+
+public class JavassistAnnotationScanner
+ extends BaseAnnotationScanner {
+
+ /**
+ * Scan class for interesting annotations.
+ */
+ public Class<?> scanClass(Context context, String className, File file,
JarEntry entry) {
+ // FIXME: Javassist impl
+ return null;
+ }
+
+
+}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2009-02-13 15:19:22 UTC (rev 929)
+++ trunk/webapps/docs/changelog.xml 2009-02-13 15:21:15 UTC (rev 930)
@@ -60,6 +60,9 @@
<fix>
<bug>39013</bug>: Fix appBase test when deleting resources. (markt)
</fix>
+ <fix>
+ Status code for redirect rule in rewrite valve. (jfclere)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">