Revision: 837
http://stripes.svn.sourceforge.net/stripes/?rev=837&view=rev
Author: bengunter
Date: 2008-02-05 09:26:10 -0800 (Tue, 05 Feb 2008)
Log Message:
-----------
STS-436. Added a new @DontAutoLoad annotation. When the annotation is present
on an extension class, BootstrapPropertyResolver's autodiscovery code will
ignore it.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
Added Paths:
-----------
trunk/stripes/src/net/sourceforge/stripes/config/DontAutoLoad.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
2008-02-05 16:58:08 UTC (rev 836)
+++
trunk/stripes/src/net/sourceforge/stripes/config/BootstrapPropertyResolver.java
2008-02-05 17:26:10 UTC (rev 837)
@@ -15,6 +15,8 @@
package net.sourceforge.stripes.config;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.FilterConfig;
@@ -118,6 +120,7 @@
String[] packages =
StringUtil.standardSplit(getProperty(PACKAGES));
resolver.findImplementations(targetType, packages);
Set<Class<? extends T>> classes = resolver.getClasses();
+ removeDontAutoloadClasses((Collection<Class>) classes);
if (classes.size() == 1) {
clazz = classes.iterator().next();
className = clazz.getName();
@@ -172,16 +175,15 @@
* @param targetType the type that we're looking for
* @return a List of classes found
*/
+ @SuppressWarnings("unchecked")
public <T> List<Class<? extends T>> getClassPropertyList(Class<T>
targetType)
{
- List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
-
ResolverUtil<T> resolver = new ResolverUtil<T>();
String[] packages = StringUtil.standardSplit(getProperty(PACKAGES));
resolver.findImplementations(targetType, packages);
- classes.addAll(resolver.getClasses());
-
- return classes;
+ Set<Class<? extends T>> classes = resolver.getClasses();
+ removeDontAutoloadClasses((Collection<Class>) classes);
+ return new ArrayList<Class<? extends T>>(classes);
}
/**
@@ -206,4 +208,17 @@
return classes;
}
+
+ /** Removes any classes from the collection that are marked with [EMAIL
PROTECTED] DontAutoLoad}. */
+ @SuppressWarnings("unchecked")
+ protected void removeDontAutoloadClasses(Collection<Class> classes) {
+ Iterator<Class> iterator = classes.iterator();
+ while (iterator.hasNext()) {
+ Class clazz = iterator.next();
+ if (clazz.isAnnotationPresent(DontAutoLoad.class)) {
+ log.debug("Ignoring ", clazz, " because @DontAutoLoad is
present.");
+ iterator.remove();
+ }
+ }
+ }
}
Added: trunk/stripes/src/net/sourceforge/stripes/config/DontAutoLoad.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/config/DontAutoLoad.java
(rev 0)
+++ trunk/stripes/src/net/sourceforge/stripes/config/DontAutoLoad.java
2008-02-05 17:26:10 UTC (rev 837)
@@ -0,0 +1,42 @@
+/* Copyright 2008 Ben Gunter
+ *
+ * Licensed 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 net.sourceforge.stripes.config;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import net.sourceforge.stripes.exception.AutoExceptionHandler;
+import net.sourceforge.stripes.format.Formatter;
+import net.sourceforge.stripes.validation.TypeConverter;
+import net.sourceforge.stripes.validation.Validate;
+
+/**
+ * When applied to a Stripes extension class (e.g., one that implements [EMAIL
PROTECTED] Formatter},
+ * [EMAIL PROTECTED] TypeConverter}, [EMAIL PROTECTED] AutoExceptionHandler},
etc.), this annotation indicates that the
+ * class should <em>not</em> be loaded via autodiscovery. This is useful, for
example, when you
+ * have a [EMAIL PROTECTED] TypeConverter} that is applied in special cases
via [EMAIL PROTECTED] Validate#converter()}
+ * but should not be used for all the type conversions to which it applies.
+ *
+ * @author Ben Gunter
+ * @since Stripes 1.5
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]( { ElementType.TYPE })
[EMAIL PROTECTED]
+public @interface DontAutoLoad {
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development