[jboss-cvs] JBossAS SVN: r95769 - in projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann: repository and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 29 12:58:22 EDT 2009
Author: alesj
Date: 2009-10-29 12:58:22 -0400 (Thu, 29 Oct 2009)
New Revision: 95769
Added:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
Modified:
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationRepository.java
projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java
Log:
Introduce grouping.
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationRepository.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationRepository.java 2009-10-29 16:41:16 UTC (rev 95768)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationRepository.java 2009-10-29 16:58:22 UTC (rev 95769)
@@ -56,6 +56,14 @@
void merge(AnnotationRepository repository);
/**
+ * Group according to strategy.
+ *
+ * @param strategy the grouping strategy
+ * @return grouping result
+ */
+ <T> T group(GroupingStrategy<T> strategy);
+
+ /**
* Does this annotation environment contain a class
* which is annotated with annotation parameter.
* This only applies to annotations for ElementType.TYPE level.
Copied: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java (from rev 95278, projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/AnnotationRepository.java)
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/GroupingStrategy.java 2009-10-29 16:58:22 UTC (rev 95769)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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;
+
+/**
+ * Group default annotation repository.
+ *
+ * @param <T> exact result type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface GroupingStrategy<T>
+{
+ /**
+ * Group current repository
+ *
+ * @param repository the repository
+ * @return grouped result
+ */
+ T group(AnnotationRepository repository);
+
+ /**
+ * Should we used cached results.
+ *
+ * @return true if we should used cached results
+ */
+ boolean useCache();
+
+ /**
+ * Put result to cache.
+ *
+ * @return true if we should put result to cache
+ */
+ boolean putToCache();
+
+ /**
+ * Wrap to right type.
+ *
+ * @param result the existing result
+ * @return wrapped result
+ */
+ T wrap(Object result);
+}
\ No newline at end of file
Modified: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java 2009-10-29 16:41:16 UTC (rev 95768)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java 2009-10-29 16:58:22 UTC (rev 95769)
@@ -21,11 +21,6 @@
*/
package org.jboss.mcann.repository;
-import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.mcann.AnnotationRepository;
-import org.jboss.mcann.Element;
-import org.jboss.util.collection.CollectionsFactory;
-
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
@@ -39,6 +34,13 @@
import java.util.Map;
import java.util.Set;
+import org.jboss.mcann.AnnotationRepository;
+import org.jboss.mcann.Element;
+import org.jboss.mcann.GroupingStrategy;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.util.collection.CollectionsFactory;
+import org.jboss.util.collection.ConcurrentReferenceHashMap;
+
/**
* DefaultAnnotationEnvironment.
*
@@ -54,6 +56,8 @@
private transient Set<String> checkedClassNames;
/** Should we keep the annotation */
private boolean keepAnnotations;
+ /** The grouping cache */
+ private Map<Class<?>, Object> grouping = new ConcurrentReferenceHashMap<Class<?>, Object>();
public DefaultAnnotationRepository(ClassLoader classLoader)
{
@@ -98,24 +102,27 @@
public void merge(AnnotationRepository repository)
{
- if (repository instanceof DefaultAnnotationRepository == false)
- log.info("Cannot merge with non DefaultAnnotationRepository repo.");
+ group(new MergeGroupingStrategy(repository));
+ }
- // FIXME -- restrictions, filtering, ...
+ public <T> T group(GroupingStrategy<T> strategy)
+ {
+ if (strategy == null)
+ throw new IllegalArgumentException("Null strategy.");
- DefaultAnnotationRepository oldRepo = DefaultAnnotationRepository.class.cast(repository);
- Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = oldRepo.getEnv();
- for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ if (strategy.useCache())
{
- Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
- for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
- {
- for (ClassSignaturePair csp : et.getValue())
- {
- putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
- }
- }
+ Object cached = grouping.get(strategy.getClass());
+ if (cached != null)
+ return strategy.wrap(cached);
}
+
+ T result = strategy.group(this);
+
+ if (result != null && strategy.putToCache())
+ grouping.put(strategy.getClass(), result);
+
+ return result;
}
/**
Copied: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java (from rev 95215, projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/DefaultAnnotationRepository.java)
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/MergeGroupingStrategy.java 2009-10-29 16:58:22 UTC (rev 95769)
@@ -0,0 +1,87 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.util.Set;
+import java.util.Map;
+
+import org.jboss.mcann.AnnotationRepository;
+import org.jboss.mcann.GroupingStrategy;
+
+/**
+ * Merge repositories.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MergeGroupingStrategy implements GroupingStrategy<Void>
+{
+ private DefaultAnnotationRepository repository;
+
+ public MergeGroupingStrategy(AnnotationRepository repository)
+ {
+ if (repository == null || repository instanceof DefaultAnnotationRepository == false)
+ throw new IllegalArgumentException("Illegal repository: " + repository);
+
+ this.repository = DefaultAnnotationRepository.class.cast(repository);
+ }
+
+ public Void group(AnnotationRepository current)
+ {
+ // TODO - restrictions
+
+ if (current instanceof DefaultAnnotationRepository)
+ {
+ DefaultAnnotationRepository dar = DefaultAnnotationRepository.class.cast(current);
+
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = repository.getEnv();
+ for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ {
+ Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ {
+ for (ClassSignaturePair csp : et.getValue())
+ {
+ dar.putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean useCache()
+ {
+ return false;
+ }
+
+ public boolean putToCache()
+ {
+ return false;
+ }
+
+ public Void wrap(Object result)
+ {
+ return null;
+ }
+}
\ No newline at end of file
Added: projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java
===================================================================
--- projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java (rev 0)
+++ projects/mc-ann/trunk/core/src/main/java/org/jboss/mcann/repository/SourceLocationGroupingStrategy.java 2009-10-29 16:58:22 UTC (rev 95769)
@@ -0,0 +1,91 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+
+import org.jboss.mcann.AnnotationRepository;
+import org.jboss.mcann.GroupingStrategy;
+
+/**
+ * Group per source location.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SourceLocationGroupingStrategy implements GroupingStrategy<Map<URL, AnnotationRepository>>
+{
+ private boolean useCache;
+ private boolean putToCache;
+
+ public SourceLocationGroupingStrategy()
+ {
+ }
+
+ public SourceLocationGroupingStrategy(boolean useCache, boolean putToCache)
+ {
+ this.useCache = useCache;
+ this.putToCache = putToCache;
+ }
+
+ public Map<URL, AnnotationRepository> group(AnnotationRepository current)
+ {
+ Map<URL, AnnotationRepository> map = new HashMap<URL, AnnotationRepository>();
+ if (current instanceof DefaultAnnotationRepository)
+ {
+ DefaultAnnotationRepository repository = DefaultAnnotationRepository.class.cast(current);
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = repository.getEnv();
+ for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ {
+ Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ {
+ for (ClassSignaturePair csp : et.getValue())
+ {
+ // TODO - group per source location
+ }
+ }
+ }
+ }
+ return map;
+ }
+
+ public boolean useCache()
+ {
+ return useCache;
+ }
+
+ public boolean putToCache()
+ {
+ return putToCache;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<URL, AnnotationRepository> wrap(Object result)
+ {
+ return (Map<URL, AnnotationRepository>)result;
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list