[jboss-cvs] JBossAS SVN: r105415 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/hierarchy/plugins and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 31 11:17:05 EDT 2010
Author: alesj
Date: 2010-05-31 11:17:04 -0400 (Mon, 31 May 2010)
New Revision: 105415
Added:
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ErrorHandler.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IgnoreSetErrorHandler.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/LogErrorHandler.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPluginFactory.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/annotations/support/FilteredAnnotationScanningPluginFactory.java
Log:
Add error handler.
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -24,10 +24,10 @@
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
-import org.jboss.classloading.spi.visitor.ResourceVisitor;
import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.plugins.helpers.ClassResourceOwnerFinder;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.IntrospectionReflectProvider;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.helpers.AbstractClassLoadingScanningPlugin;
@@ -42,17 +42,19 @@
/** The repository */
private final DefaultAnnotationRepository repository;
/** The visitor */
- private final ResourceVisitor visitor;
+ private final GenericAnnotationVisitor visitor;
public AnnotationsScanningPlugin(ClassLoader cl)
{
- this(IntrospectionReflectProvider.INSTANCE, ClassResourceOwnerFinder.INSTANCE, cl);
+ this(IntrospectionReflectProvider.INSTANCE, ClassResourceOwnerFinder.INSTANCE, cl, null);
}
- public AnnotationsScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl)
+ public AnnotationsScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl, ErrorHandler handler)
{
repository = new DefaultAnnotationRepository(cl);
+ // setup visitor
visitor = new GenericAnnotationVisitor(provider, finder, repository);
+ visitor.setErrorHandler(handler);
}
protected DefaultAnnotationRepository doCreateHandle()
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -27,6 +27,7 @@
import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.ScanningPlugin;
@@ -48,6 +49,7 @@
{
ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
ResourceOwnerFinder finder = DeploymentUtilsFactory.getFinder(unit);
- return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader());
+ ErrorHandler handler = DeploymentUtilsFactory.getHandler(unit);
+ return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader(), handler);
}
}
\ No newline at end of file
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPlugin.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPlugin.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -25,10 +25,10 @@
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.scanning.hierarchy.spi.HierarchyIndex;
import org.jboss.scanning.plugins.helpers.ClassResourceOwnerFinder;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.IntrospectionReflectProvider;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.helpers.AbstractClassLoadingScanningPlugin;
@@ -43,17 +43,19 @@
/** The reosurces */
private final HierarchyIndexImpl hierarchy;
/** The visitor */
- private final ResourceVisitor visitor;
+ private final HierarchyTypeVisitor visitor;
public HierarchyIndexScanningPlugin(ClassLoader cl)
{
- this(IntrospectionReflectProvider.INSTANCE, ClassResourceOwnerFinder.INSTANCE, cl);
+ this(IntrospectionReflectProvider.INSTANCE, ClassResourceOwnerFinder.INSTANCE, cl, null);
}
- public HierarchyIndexScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl)
+ public HierarchyIndexScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl, ErrorHandler handler)
{
hierarchy = new HierarchyIndexImpl(cl);
+ // setup the visitor
visitor = new HierarchyTypeVisitor(provider, finder, hierarchy);
+ visitor.setErrorHandler(handler);
}
protected HierarchyIndexImpl doCreateHandle()
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPluginFactory.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexScanningPluginFactory.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -27,6 +27,7 @@
import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.ScanningPlugin;
import org.jboss.util.JBossObject;
@@ -58,7 +59,8 @@
{
ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
ResourceOwnerFinder finder = DeploymentUtilsFactory.getFinder(unit);
- return new HierarchyIndexScanningPlugin(provider, finder, unit.getClassLoader());
+ ErrorHandler handler = DeploymentUtilsFactory.getHandler(unit);
+ return new HierarchyIndexScanningPlugin(provider, finder, unit.getClassLoader(), handler);
}
@Override
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -28,6 +28,7 @@
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
/**
@@ -77,13 +78,26 @@
*/
public static <T> T getUtil(DeploymentUnit unit, Class<T> utilType)
{
+ return getUtil(unit, utilType, false);
+ }
+
+ /**
+ * Get util.
+ *
+ * @param unit the deployment unit
+ * @param utilType the util type
+ * @param allowNull do we allow null util
+ * @return util instance
+ */
+ public static <T> T getUtil(DeploymentUnit unit, Class<T> utilType, boolean allowNull)
+ {
if (utilType == null)
throw new IllegalArgumentException("Null util type");
DeploymentUnit moduleUnit = getModuleUnit(unit);
T util = moduleUnit.getAttachment(utilType);
- if (util == null)
+ if (util == null && allowNull == false)
{
UtilFactory factory = defaults.get(utilType);
if (factory == null)
@@ -157,6 +171,17 @@
}
/**
+ * Get error handler.
+ *
+ * @param unit the depoyment unit
+ * @return the error handler
+ */
+ public static ErrorHandler getHandler(DeploymentUnit unit)
+ {
+ return getUtil(unit, ErrorHandler.class, true);
+ }
+
+ /**
* Cleanup the util.
*
* @param util the util to cleanup
Copied: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ErrorHandler.java (from rev 104079, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectProvider.java)
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ErrorHandler.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ErrorHandler.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.plugins.visitor;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * Handle visitor error.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ErrorHandler
+{
+ /**
+ * Handle error.
+ *
+ * @param visitor the visitor
+ * @param resource the resource
+ * @param t the throwable
+ */
+ void handleError(ResourceVisitor visitor, ResourceContext resource, Throwable t);
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IgnoreSetErrorHandler.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IgnoreSetErrorHandler.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/IgnoreSetErrorHandler.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.plugins.visitor;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.logging.Logger;
+
+/**
+ * Set of ignored errors.
+ * If it's not ignored, it's thrown fwd wrapped as RuntimeException.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class IgnoreSetErrorHandler implements ErrorHandler
+{
+ private static final Logger log = Logger.getLogger(IgnoreSetErrorHandler.class);
+
+ @SuppressWarnings({"unchecked"})
+ private Set<Class<Throwable>> ignore = new HashSet<Class<Throwable>>();
+
+ public void handleError(ResourceVisitor visitor, ResourceContext resource, Throwable t)
+ {
+ for (Class<Throwable> i : ignore)
+ {
+ if (i.isInstance(t))
+ {
+ if (log.isTraceEnabled())
+ log.trace("Ignoring resource (" + resource + ") visitor (" + visitor + ") error: " + t);
+
+ return;
+ }
+ }
+ throw new RuntimeException(t);
+ }
+
+ public void addIgnored(Class<Throwable> t)
+ {
+ if (t == null)
+ throw new IllegalArgumentException("Null class");
+
+ ignore.add(t);
+ }
+
+ public void removeIgnored(Class<Throwable> t)
+ {
+ if (t == null)
+ throw new IllegalArgumentException("Null class");
+
+ ignore.remove(t);
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/LogErrorHandler.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/LogErrorHandler.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/LogErrorHandler.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.plugins.visitor;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.logging.Logger;
+
+/**
+ * Simple log error handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class LogErrorHandler implements ErrorHandler
+{
+ private Logger log = Logger.getLogger(LogErrorHandler.class);
+
+ public void handleError(ResourceVisitor visitor, ResourceContext resource, Throwable t)
+ {
+ log.debug("Error visiting resource: " + resource + ", error: " + t);
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -38,7 +38,8 @@
protected final Logger log = Logger.getLogger(getClass());
private ReflectProvider provider;
- protected boolean ignoreError;
+ private ErrorHandler errorHandler;
+ protected boolean ignoreError = true;
protected ReflectResourceVisitor(ReflectProvider provider)
{
@@ -86,7 +87,9 @@
}
catch (Throwable t)
{
- if (ignoreError)
+ if (errorHandler != null)
+ errorHandler.handleError(this, resource, t);
+ else if (ignoreError)
logThrowable(resource, t);
else
throw new RuntimeException(t);
@@ -143,7 +146,6 @@
*/
protected void logThrowable(ResourceContext resource, Throwable t)
{
- t.printStackTrace();
if (log.isTraceEnabled())
log.trace("Exception reading resource: " + resource.getResourceName(), t);
}
@@ -152,4 +154,9 @@
{
this.ignoreError = ignoreError;
}
+
+ public void setErrorHandler(ErrorHandler errorHandler)
+ {
+ this.errorHandler = errorHandler;
+ }
}
Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/annotations/support/FilteredAnnotationScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/annotations/support/FilteredAnnotationScanningPluginFactory.java 2010-05-31 15:02:23 UTC (rev 105414)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/annotations/support/FilteredAnnotationScanningPluginFactory.java 2010-05-31 15:17:04 UTC (rev 105415)
@@ -30,6 +30,7 @@
import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ErrorHandler;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.ScanningPlugin;
@@ -58,7 +59,8 @@
{
ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
ResourceOwnerFinder finder = DeploymentUtilsFactory.getFinder(unit);
- return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader())
+ ErrorHandler handler = DeploymentUtilsFactory.getHandler(unit);
+ return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader(), handler)
{
@Override
public ResourceFilter getRecurseFilter()
More information about the jboss-cvs-commits
mailing list