[jboss-cvs] JBossAS SVN: r102990 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/web/plugins and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 25 19:53:48 EDT 2010
Author: alesj
Date: 2010-03-25 19:53:47 -0400 (Thu, 25 Mar 2010)
New Revision: 102990
Added:
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/MergeUtils.java
Modified:
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:
Do proper merge.
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 23:40:04 UTC (rev 102989)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-03-25 23:53:47 UTC (rev 102990)
@@ -36,6 +36,7 @@
import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
+import org.jboss.scanning.plugins.helpers.MergeUtils;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.plugins.helpers.WeakClassLoaderHolder;
import org.jboss.scanning.spi.ScanningHandle;
@@ -176,9 +177,9 @@
public void merge(ScannerImpl subHandle)
{
- packages.putAll(subHandle.getPackages());
- classes.putAll(subHandle.getClasses());
- files.putAll(subHandle.getFiles());
+ MergeUtils.singleMerge(packages, subHandle.getPackages());
+ MergeUtils.doubleMerge(classes, subHandle.getClasses());
+ MergeUtils.doubleMerge(files, subHandle.getFiles());
}
public Set<Package> getPackagesInJar(URL jarToScan, Set<Class<? extends Annotation>> annotationsToLookFor)
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 23:40:04 UTC (rev 102989)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java 2010-03-25 23:53:47 UTC (rev 102990)
@@ -24,12 +24,13 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.annotations.spi.Element;
+import org.jboss.scanning.plugins.helpers.MergeUtils;
import org.jboss.scanning.spi.ScanningHandle;
import org.jboss.scanning.web.spi.ResourcesIndex;
import org.jboss.vfs.VirtualFile;
@@ -43,6 +44,10 @@
{
/** The annotation index */
private AnnotationIndex index;
+ /** The inherited types */
+ private Map<String, Map<TypeInfo, Set<TypeInfo>>> cache = new HashMap<String, Map<TypeInfo, Set<TypeInfo>>>();
+ /** The type info factory */
+ private TypeInfoFactory tif;
public DefaultResourcesIndex(AnnotationIndex index)
{
@@ -53,14 +58,39 @@
void cleanup()
{
- // TODO
+ cache.clear();
}
+ Map<String, Map<TypeInfo, Set<TypeInfo>>> getCache()
+ {
+ return cache;
+ }
+
public void merge(DefaultResourcesIndex subHandle)
{
- // TODO
+ MergeUtils.doubleMerge(cache, subHandle.getCache());
}
+ void putInfo(String path, TypeInfo key, TypeInfo... classes)
+ {
+ if (tif == null)
+ tif = key.getTypeInfoFactory();
+
+ Map<TypeInfo, Set<TypeInfo>> map = cache.get(path);
+ if (map == null)
+ {
+ map = new HashMap<TypeInfo, Set<TypeInfo>>();
+ cache.put(path, map);
+ }
+ Set<TypeInfo> infos = map.get(key);
+ if (infos == null)
+ {
+ infos = new HashSet<TypeInfo>();
+ map.put(key, infos);
+ }
+ infos.addAll(Arrays.asList(classes));
+ }
+
public <A extends Annotation> Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<A> annotationToLookFor)
{
if (cpEntry == null)
@@ -83,8 +113,23 @@
if (superTypeToLookFor == null)
throw new IllegalArgumentException("Null super type");
+ // we haven't added anything yet to cache
+ if (tif == null)
+ return Collections.emptySet();
+
+ Set<Class<?>> result = new HashSet<Class<?>>();
String path = cpEntry.getPathName();
- // TODO
- return Collections.emptySet();
+ Map<TypeInfo, Set<TypeInfo>> map = cache.get(path);
+ if (map != null)
+ {
+ TypeInfo key = tif.getTypeInfo(superTypeToLookFor);
+ Set<TypeInfo> infos = map.get(key);
+ if (infos != null)
+ {
+ for (TypeInfo ti : infos)
+ result.add(ti.getType());
+ }
+ }
+ return result;
}
}
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/MergeUtils.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/MergeUtils.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/MergeUtils.java 2010-03-25 23:53:47 UTC (rev 102990)
@@ -0,0 +1,89 @@
+/*
+ * 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.helpers;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Help merge handles.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MergeUtils
+{
+ /**
+ * Merge double level maps.
+ *
+ * @param dest the destination
+ * @param src the source
+ */
+ public static <T, U, V> void doubleMerge(Map<T, Map<U, Set<V>>> dest, Map<T, Map<U, Set<V>>> src)
+ {
+ if (dest == null)
+ throw new IllegalArgumentException("Null dest");
+ if (src == null)
+ return;
+
+ for (Map.Entry<T, Map<U, Set<V>>> entry : src.entrySet())
+ {
+ Map<U, Set<V>> dVal = dest.get(entry.getKey());
+ if (dVal != null)
+ {
+ Map<U, Set<V>> sVal = entry.getValue();
+ singleMerge(dVal, sVal);
+ }
+ else
+ {
+ dest.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Merge single level maps.
+ *
+ * @param dest the destination
+ * @param src the source
+ */
+ public static <U, V> void singleMerge(Map<U, Set<V>> dest, Map<U, Set<V>> src)
+ {
+ if (dest == null)
+ throw new IllegalArgumentException("Null dest");
+ if (src == null)
+ return;
+
+ for (Map.Entry<U, Set<V>> entry : src.entrySet())
+ {
+ Set<V> dSet = dest.get(entry.getKey());
+ if (dSet != null)
+ {
+ dSet.addAll(entry.getValue());
+ }
+ else
+ {
+ dest.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list