[jboss-cvs] JBossAS SVN: r95382 - in projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann: repository and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 22 02:54:16 EDT 2009
Author: alesj
Date: 2009-10-22 02:54:15 -0400 (Thu, 22 Oct 2009)
New Revision: 95382
Added:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/Configuration.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java
Modified:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java
Log:
Extract configuration.
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java 2009-10-22 06:50:14 UTC (rev 95381)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationScannerFactory.java 2009-10-22 06:54:15 UTC (rev 95382)
@@ -21,8 +21,9 @@
*/
package org.jboss.mcann;
+import org.jboss.mcann.repository.DefaultConfiguration;
+import org.jboss.mcann.repository.javassist.JavassistTypeInfoProvider;
import org.jboss.mcann.scanner.DefaultAnnotationScanner;
-import org.jboss.mcann.repository.javassist.JavassistTypeInfoProvider;
/**
* An annotation scanner factory
@@ -51,6 +52,11 @@
*/
static boolean haveJavassist = false;
+ /**
+ * Javassist configuration
+ */
+ private static DefaultConfiguration configuration;
+
static
{
try
@@ -71,6 +77,10 @@
{
defaultStrategy = JAVA_LANG_REFLECT;
}
+
+ // javassist type info
+ configuration = new DefaultConfiguration();
+ configuration.setTypeInfoProvider(new JavassistTypeInfoProvider());
}
/**
@@ -103,7 +113,7 @@
DefaultAnnotationScanner scanner = new DefaultAnnotationScanner();
if (strategy == JAVASSIST)
- scanner.setTypeInfoProvider(new JavassistTypeInfoProvider());
+ scanner.setConfiguration(configuration);
return scanner;
}
Added: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/Configuration.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/Configuration.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/Configuration.java 2009-10-22 06:54:15 UTC (rev 95382)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mcann.repository;
+
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+
+/**
+ * Scan configuration.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface Configuration
+{
+ ResourceFilter resourceFilter();
+
+ boolean forceAnnotations();
+
+ boolean keepAnnotations();
+
+ boolean checkSuper();
+
+ boolean checkInterfaces();
+
+ TypeInfoProvider typeInfoProvider();
+}
Added: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultConfiguration.java 2009-10-22 06:54:15 UTC (rev 95382)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mcann.repository;
+
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ClassFilter;
+
+/**
+ * Default scan configuration.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultConfiguration implements Configuration
+{
+ private ResourceFilter resourceFilter = ClassFilter.INSTANCE;
+ private boolean forceAnnotations;
+ private boolean keepAnnotations;
+ private boolean checkSuper;
+ private boolean checkInterfaces;
+ private TypeInfoProvider typeInfoProvider = new IntrospectionTypeInfoProvider();
+
+ public ResourceFilter resourceFilter()
+ {
+ return resourceFilter;
+ }
+
+ public boolean forceAnnotations()
+ {
+ return forceAnnotations;
+ }
+
+ public boolean keepAnnotations()
+ {
+ return keepAnnotations;
+ }
+
+ public boolean checkSuper()
+ {
+ return checkSuper;
+ }
+
+ public boolean checkInterfaces()
+ {
+ return checkInterfaces;
+ }
+
+ public TypeInfoProvider typeInfoProvider()
+ {
+ return typeInfoProvider;
+ }
+
+ /**
+ * Set the resource filter.
+ *
+ * @param resourceFilter the resource filter
+ */
+ public void setResourceFilter(ResourceFilter resourceFilter)
+ {
+ this.resourceFilter = resourceFilter;
+ }
+
+ /**
+ * Should we force all annotations to be available.
+ *
+ * @param forceAnnotations the force annotations flag
+ */
+ public void setForceAnnotations(boolean forceAnnotations)
+ {
+ this.forceAnnotations = forceAnnotations;
+ }
+
+ /**
+ * Set the keep annotations flag.
+ *
+ * @param keepAnnotations the keep annotations flag
+ */
+ public void setKeepAnnotations(boolean keepAnnotations)
+ {
+ this.keepAnnotations = keepAnnotations;
+ }
+
+ /**
+ * Should we check super class for annotations as well.
+ *
+ * @param checkSuper the check super flag
+ */
+ public void setCheckSuper(boolean checkSuper)
+ {
+ this.checkSuper = checkSuper;
+ }
+
+ /**
+ * Should we check interfaces for annotations as well.
+ *
+ * @param checkInterfaces the check interfaces flag
+ */
+ public void setCheckInterfaces(boolean checkInterfaces)
+ {
+ this.checkInterfaces = checkInterfaces;
+ }
+
+ /**
+ * Set type info provider.
+ *
+ * @param typeInfoProvider the type info factory
+ */
+ public void setTypeInfoProvider(TypeInfoProvider typeInfoProvider)
+ {
+ if (typeInfoProvider == null)
+ throw new IllegalArgumentException("Null type info provider.");
+
+ this.typeInfoProvider = typeInfoProvider;
+ }
+}
\ No newline at end of file
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java 2009-10-22 06:50:14 UTC (rev 95381)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/GenericAnnotationResourceVisitor.java 2009-10-22 06:54:15 UTC (rev 95382)
@@ -26,14 +26,13 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.classloading.spi.visitor.ClassFilter;
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.classloading.spi.visitor.ResourceVisitor;
import org.jboss.logging.Logger;
-import org.jboss.metadata.spi.signature.Signature;
import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.Signature;
import org.jboss.reflect.spi.AnnotatedInfo;
import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.ConstructorInfo;
@@ -51,18 +50,22 @@
{
private static final Logger log = Logger.getLogger(GenericAnnotationResourceVisitor.class);
- private ResourceFilter resourceFilter = ClassFilter.INSTANCE;
- private boolean forceAnnotations;
- private boolean checkSuper;
- private boolean checkInterfaces;
private DefaultAnnotationRepository repository;
- private TypeInfoProvider typeInfoProvider = new IntrospectionTypeInfoProvider();
+ private Configuration configuration;
public GenericAnnotationResourceVisitor(DefaultAnnotationRepository repository)
{
this.repository = repository;
}
+ protected synchronized Configuration configuration()
+ {
+ if (configuration == null)
+ configuration = new DefaultConfiguration();
+
+ return configuration;
+ }
+
@SuppressWarnings("deprecation")
protected boolean isRelevant(ClassInfo ci)
{
@@ -71,6 +74,7 @@
protected ClassInfo createClassInfo(ResourceContext context) throws Exception
{
+ TypeInfoProvider typeInfoProvider = configuration().typeInfoProvider();
TypeInfo typeInfo = typeInfoProvider.createTypeInfo(context);
if (typeInfo instanceof ClassInfo == false)
throw new IllegalArgumentException("Can only handle class info: " + typeInfo);
@@ -80,7 +84,7 @@
public ResourceFilter getFilter()
{
- return resourceFilter;
+ return configuration().resourceFilter();
}
public void visit(ResourceContext resource)
@@ -100,7 +104,7 @@
}
catch (ClassNotFoundException e)
{
- if (forceAnnotations)
+ if (configuration().forceAnnotations())
throw new RuntimeException(e);
logThrowable(resource, e);
@@ -118,7 +122,7 @@
*/
protected List<CommitElement> createCommitList()
{
- return forceAnnotations ? new RepositoryPutList(repository) : new ArrayList<CommitElement>();
+ return configuration().forceAnnotations() ? new RepositoryPutList(repository) : new ArrayList<CommitElement>();
}
/**
@@ -153,7 +157,7 @@
return;
}
- if (checkInterfaces == false && classInfo.isInterface())
+ if (configuration().checkInterfaces() == false && classInfo.isInterface())
{
if (log.isTraceEnabled())
log.trace("Skipping interface: " + className);
@@ -170,9 +174,9 @@
handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className, commit);
handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className, commit);
- if (checkSuper)
+ if (configuration().checkSuper())
{
- if (checkInterfaces)
+ if (configuration().checkInterfaces())
{
// interfaces
ClassInfo[] interfaces = classInfo.getInterfaces();
@@ -311,65 +315,12 @@
}
/**
- * Set the resource filter.
- *
- * @param resourceFilter the resource filter
+ * Set configuration().
+ *
+ * @param configuration the configuration
*/
- public void setResourceFilter(ResourceFilter resourceFilter)
+ public synchronized void setConfiguration(Configuration configuration)
{
- this.resourceFilter = resourceFilter;
+ this.configuration = configuration;
}
-
- /**
- * Should we force all annotations to be available.
- *
- * @param forceAnnotations the force annotations flag
- */
- public void setForceAnnotations(boolean forceAnnotations)
- {
- this.forceAnnotations = forceAnnotations;
- }
-
- /**
- * Set the keep annotations flag.
- *
- * @param keepAnnotations the keep annotations flag
- */
- public void setKeepAnnotations(boolean keepAnnotations)
- {
- repository.setKeepAnnotations(keepAnnotations);
- }
-
- /**
- * Should we check super class for annotations as well.
- *
- * @param checkSuper the check super flag
- */
- public void setCheckSuper(boolean checkSuper)
- {
- this.checkSuper = checkSuper;
- }
-
- /**
- * Should we check interfaces for annotations as well.
- *
- * @param checkInterfaces the check interfaces flag
- */
- public void setCheckInterfaces(boolean checkInterfaces)
- {
- this.checkInterfaces = checkInterfaces;
- }
-
- /**
- * Set type info provider.
- *
- * @param typeInfoProvider the type info factory
- */
- public void setTypeInfoProvider(TypeInfoProvider typeInfoProvider)
- {
- if (typeInfoProvider == null)
- throw new IllegalArgumentException("Null type info provider.");
-
- this.typeInfoProvider = typeInfoProvider;
- }
}
\ No newline at end of file
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java 2009-10-22 06:50:14 UTC (rev 95381)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/scanner/DefaultAnnotationScanner.java 2009-10-22 06:54:15 UTC (rev 95382)
@@ -24,12 +24,12 @@
import java.net.URL;
import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.classloading.spi.visitor.ResourceVisitor;
-import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
+import org.jboss.mcann.repository.Configuration;
import org.jboss.mcann.repository.DefaultAnnotationRepository;
import org.jboss.mcann.repository.GenericAnnotationResourceVisitor;
-import org.jboss.mcann.repository.TypeInfoProvider;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
@@ -40,16 +40,11 @@
*/
public class DefaultAnnotationScanner extends AbstractAnnotationScanner<DefaultAnnotationRepository>
{
- protected boolean forceAnnotations;
- protected boolean keepAnnotations;
- protected boolean checkSuper;
- protected boolean checkInterfaces;
+ protected Configuration configuration;
protected VirtualFile[] excludedRoots;
protected ClassFilter included;
protected ClassFilter excluded;
- protected ResourceFilter resourceFilter;
protected ResourceFilter recurseFilter;
- protected TypeInfoProvider typeInfoProvider;
protected DefaultAnnotationRepository createAnnotationRepository(ClassLoader classLoader)
{
@@ -59,7 +54,7 @@
protected void rescan(DefaultAnnotationRepository repo, URL[] urls, ClassLoader classLoader) throws Exception
{
ResourceVisitor visitor = createResourceVisitor(repo);
- ResourceFilter filter = resourceFilter;
+ ResourceFilter filter = (configuration != null) ? configuration.resourceFilter() : null;
if (filter == null)
filter = visitor.getFilter();
@@ -80,55 +75,15 @@
protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository)
{
GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(repository);
- visitor.setForceAnnotations(forceAnnotations);
- visitor.setKeepAnnotations(keepAnnotations);
- visitor.setCheckSuper(checkSuper);
- visitor.setCheckInterfaces(checkInterfaces);
- if (typeInfoProvider != null)
- visitor.setTypeInfoProvider(typeInfoProvider);
+ visitor.setConfiguration(configuration);
return visitor;
}
- /**
- * Should we force all annotations to be available.
- *
- * @param forceAnnotations the force annotations flag
- */
- public void setForceAnnotations(boolean forceAnnotations)
+ public void setConfiguration(Configuration configuration)
{
- this.forceAnnotations = forceAnnotations;
+ this.configuration = configuration;
}
- /**
- * Set the keep annotations flag.
- *
- * @param keepAnnotations the keep annotations flag
- */
- public void setKeepAnnotations(boolean keepAnnotations)
- {
- this.keepAnnotations = keepAnnotations;
- }
-
- /**
- * Should we check super class for annotations as well.
- *
- * @param checkSuper the check super flag
- */
- public void setCheckSuper(boolean checkSuper)
- {
- this.checkSuper = checkSuper;
- }
-
- /**
- * Should we check interfaces for annotations as well.
- *
- * @param checkInterfaces the check interfaces flag
- */
- public void setCheckInterfaces(boolean checkInterfaces)
- {
- this.checkInterfaces = checkInterfaces;
- }
-
public void setExcludedRoots(VirtualFile[] excludedRoots)
{
this.excludedRoots = excludedRoots;
@@ -144,18 +99,8 @@
this.excluded = excluded;
}
- public void setResourceFilter(ResourceFilter resourceFilter)
- {
- this.resourceFilter = resourceFilter;
- }
-
public void setRecurseFilter(ResourceFilter recurseFilter)
{
this.recurseFilter = recurseFilter;
}
-
- public void setTypeInfoProvider(TypeInfoProvider typeInfoProvider)
- {
- this.typeInfoProvider = typeInfoProvider;
- }
}
More information about the jboss-cvs-commits
mailing list