[jboss-cvs] JBossAS SVN: r102980 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/hibernate and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 25 17:16:41 EDT 2010
Author: alesj
Date: 2010-03-25 17:16:39 -0400 (Thu, 25 Mar 2010)
New Revision: 102980
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/HierarchyTypeVisitor.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPluginFactory.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java
Removed:
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentResourceOwnerFinderFactory.java
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/hibernate/HibernateScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
Log:
Web plugins, better deployment utils handling.
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-03-25 21:10:23 UTC (rev 102979)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -25,9 +25,8 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
-import org.jboss.scanning.plugins.helpers.DeploymentResourceOwnerFinderFactory;
+import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
-import org.jboss.scanning.plugins.visitor.JavassistReflectProvider;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.ScanningPlugin;
@@ -47,11 +46,8 @@
public ScanningPlugin<DefaultAnnotationRepository, AnnotationIndex> create(DeploymentUnit unit)
{
- ReflectProvider provider = unit.getAttachment(ReflectProvider.class);
- if (provider == null)
- provider = new JavassistReflectProvider();
-
- ResourceOwnerFinder finder = DeploymentResourceOwnerFinderFactory.getFinder(unit);
+ ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
+ ResourceOwnerFinder finder = DeploymentUtilsFactory.getFinder(unit);
return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader());
}
}
\ No newline at end of file
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java 2010-03-25 21:10:23 UTC (rev 102979)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -32,7 +32,7 @@
import org.jboss.classloading.spi.visitor.ResourceVisitor;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.scanning.plugins.AbstractScanningPlugin;
-import org.jboss.scanning.plugins.visitor.JavassistReflectProvider;
+import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.hibernate.ejb.packaging.Scanner;
@@ -67,9 +67,7 @@
visitors.add(rv);
}
// handle classes
- ReflectProvider provider = unit.getAttachment(ReflectProvider.class);
- if (provider == null)
- provider = new JavassistReflectProvider();
+ ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
for (Class<? extends Annotation> annotation : factory.getAnnotations())
{
ResourceVisitor rv = new SingleAnnotationVisitor(provider, annotation, scanner);
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-03-25 21:10:23 UTC (rev 102979)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -35,7 +35,7 @@
import org.jboss.classloading.spi.visitor.ResourceVisitor;
import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.scanning.plugins.helpers.DeploymentResourceOwnerFinderFactory;
+import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.plugins.helpers.WeakClassLoaderHolder;
import org.jboss.scanning.spi.ScanningHandle;
@@ -82,7 +82,7 @@
{
super(check(unit).getClassLoader());
this.unit = unit;
- this.finder = DeploymentResourceOwnerFinderFactory.getFinder(unit);
+ this.finder = DeploymentUtilsFactory.getFinder(unit);
}
/**
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java 2010-03-25 21:10:23 UTC (rev 102979)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -30,7 +30,7 @@
import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.annotations.spi.Element;
-import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.spi.ScanningHandle;
import org.jboss.scanning.web.spi.ResourcesIndex;
import org.jboss.vfs.VirtualFile;
@@ -39,7 +39,7 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class DefaultResourcesIndex implements ResourcesIndex
+public class DefaultResourcesIndex implements ResourcesIndex, ScanningHandle<DefaultResourcesIndex>
{
/** The annotation index */
private AnnotationIndex index;
@@ -51,6 +51,11 @@
this.index = index;
}
+ public void merge(DefaultResourcesIndex subHandle)
+ {
+ // TODO
+ }
+
public <A extends Annotation> Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<A> annotationToLookFor)
{
if (cpEntry == null)
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/HierarchyTypeVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/HierarchyTypeVisitor.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/HierarchyTypeVisitor.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -0,0 +1,63 @@
+/*
+ * 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.web.plugins;
+
+import java.net.URL;
+
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.plugins.visitor.ReflectResourceVisitor;
+
+/**
+ * Hierarchy type visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class HierarchyTypeVisitor extends ReflectResourceVisitor
+{
+ private ResourceOwnerFinder finder;
+
+ public HierarchyTypeVisitor(ReflectProvider provider, ResourceOwnerFinder finder)
+ {
+ super(provider);
+ if (finder == null)
+ throw new IllegalArgumentException("Null finder");
+ this.finder = finder;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ @Override
+ protected void handleClass(ResourceContext resource, ClassInfo classInfo) throws Exception
+ {
+ URL ownerURL = finder.findOwnerURL(resource);
+ // TODO -- handle hierarchy
+ }
+}
\ No newline at end of file
Copied: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java (from rev 102976, projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java)
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -0,0 +1,73 @@
+/*
+ * 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.web.plugins;
+
+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.annotations.spi.AnnotationIndex;
+import org.jboss.scanning.plugins.AbstractScanningPlugin;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.web.spi.ResourcesIndex;
+
+/**
+ * Default resource index.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ResourcesIndexScanningPlugin extends AbstractScanningPlugin<DefaultResourcesIndex, ResourcesIndex>
+{
+ /** The reosurces */
+ private final DefaultResourcesIndex resources;
+ /** The visitor */
+ private final ResourceVisitor visitor;
+
+ public ResourcesIndexScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, AnnotationIndex index)
+ {
+ visitor = new HierarchyTypeVisitor(provider, finder);
+ resources = new DefaultResourcesIndex(index);
+ }
+
+ @Override
+ protected DefaultResourcesIndex doCreateHandle()
+ {
+ return resources;
+ }
+
+ public Class<ResourcesIndex> getHandleInterface()
+ {
+ return ResourcesIndex.class;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ visitor.visit(resource);
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPluginFactory.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPluginFactory.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -0,0 +1,53 @@
+/*
+ * 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.web.plugins;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
+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.ReflectProvider;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.scanning.web.spi.ResourcesIndex;
+
+/**
+ * Default resource index.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ResourcesIndexScanningPluginFactory implements DeploymentScanningPluginFactory<DefaultResourcesIndex, ResourcesIndex>
+{
+ public boolean isRelevant(DeploymentUnit unit)
+ {
+ return unit.isAttachmentPresent("org.jboss.metadata.web.X.JBossWebMetaData");
+ }
+
+ public ScanningPlugin<DefaultResourcesIndex, ResourcesIndex> create(DeploymentUnit unit)
+ {
+ ReflectProvider provider = DeploymentUtilsFactory.getProvider(unit);
+ ResourceOwnerFinder finder = DeploymentUtilsFactory.getFinder(unit);
+ AnnotationIndex index = null; // TODO -- lazy
+ return new ResourcesIndexScanningPlugin(provider, finder, index);
+ }
+}
\ No newline at end of file
Deleted: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentResourceOwnerFinderFactory.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentResourceOwnerFinderFactory.java 2010-03-25 21:10:23 UTC (rev 102979)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentResourceOwnerFinderFactory.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -1,52 +0,0 @@
-package org.jboss.scanning.plugins.helpers;
-
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-
-/**
- * Find the resource owner for deployment.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class DeploymentResourceOwnerFinderFactory
-{
- /**
- * Get finder.
- *
- * @param unit the depoyment unit
- * @return the finder
- */
- public static ResourceOwnerFinder getFinder(DeploymentUnit unit)
- {
- if (unit == null)
- throw new IllegalArgumentException("Null unit");
-
- ResourceOwnerFinder rof = AttachmentLocator.searchAncestors(unit, ResourceOwnerFinder.class);
- if (rof == null)
- rof = new CachingResourceOwnerFinder();
-
- DeploymentUnit moduleUnit = unit;
- while(moduleUnit != null && moduleUnit.isAttachmentPresent(Module.class) == false)
- moduleUnit = moduleUnit.getParent();
-
- if (moduleUnit == null)
- throw new IllegalArgumentException("No module in unit: " + unit);
-
- // group rof per module
- moduleUnit.addAttachment(ResourceOwnerFinder.class, rof);
-
- return rof;
- }
-
- /**
- * Cleanup the finder.
- *
- * @param finder the finder to cleanup
- */
- public static void cleanup(ResourceOwnerFinder finder)
- {
- if (finder instanceof CachingResourceOwnerFinder)
- CachingResourceOwnerFinder.class.cast(finder).cleanup();
- }
-}
\ No newline at end of file
Copied: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java (from rev 102928, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentResourceOwnerFinderFactory.java)
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentUtilsFactory.java 2010-03-25 21:16:39 UTC (rev 102980)
@@ -0,0 +1,126 @@
+package org.jboss.scanning.plugins.helpers;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+import org.jboss.scanning.plugins.visitor.JavassistReflectProvider;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+
+/**
+ * Find the util for deployment.
+ * Newly created utils are grouped per module.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeploymentUtilsFactory
+{
+ /** The default impls */
+ private static Map<Class<?>, Class<?>> defaults = new WeakHashMap<Class<?>, Class<?>>();
+
+ static
+ {
+ addImplementation(ReflectProvider.class, JavassistReflectProvider.class);
+ addImplementation(ResourceOwnerFinder.class, CachingResourceOwnerFinder.class);
+ }
+
+ /**
+ * Add the util impl.
+ *
+ * @param iface the interface
+ * @param implementation the impl
+ */
+ public static <T> void addImplementation(Class<T> iface, Class<? extends T> implementation)
+ {
+ defaults.put(iface, implementation);
+ }
+
+ /**
+ * Remove the util impl.
+ *
+ * @param iface the interface
+ */
+ public static <T> void removeImplementation(Class<T> iface)
+ {
+ defaults.remove(iface);
+ }
+
+ /**
+ * Get util.
+ *
+ * @param unit the deployment unit
+ * @param utilType the util type
+ * @return util instance
+ */
+ protected static <T> T getUtil(DeploymentUnit unit, Class<T> utilType)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+
+ T util = AttachmentLocator.searchAncestors(unit, utilType);
+ if (util == null)
+ {
+ Class<?> defUtilClass = defaults.get(utilType);
+ if (defUtilClass == null)
+ throw new IllegalArgumentException("No default impl defined for " + utilType);
+
+ try
+ {
+ Object instance = ReflectionUtils.newInstance(defUtilClass);
+ util = utilType.cast(instance);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+
+ DeploymentUnit moduleUnit = unit;
+ while(moduleUnit != null && moduleUnit.isAttachmentPresent(Module.class) == false)
+ moduleUnit = moduleUnit.getParent();
+
+ if (moduleUnit == null)
+ throw new IllegalArgumentException("No module in unit: " + unit);
+
+ // group util per module
+ moduleUnit.addAttachment(utilType, util);
+
+ return util;
+ }
+
+ /**
+ * Get reflect provider.
+ *
+ * @param unit the depoyment unit
+ * @return the provider
+ */
+ public static ReflectProvider getProvider(DeploymentUnit unit)
+ {
+ return getUtil(unit, ReflectProvider.class);
+ }
+
+ /**
+ * Get finder.
+ *
+ * @param unit the depoyment unit
+ * @return the finder
+ */
+ public static ResourceOwnerFinder getFinder(DeploymentUnit unit)
+ {
+ return getUtil(unit, ResourceOwnerFinder.class);
+ }
+
+ /**
+ * Cleanup the util.
+ *
+ * @param util the util to cleanup
+ */
+ public static void cleanup(Object util)
+ {
+ if (util instanceof CachingResourceOwnerFinder)
+ CachingResourceOwnerFinder.class.cast(util).cleanup();
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list