[webbeans-commits] Webbeans SVN: r1264 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bean and 7 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Jan 28 11:13:09 EST 2009
Author: pete.muir at jboss.org
Date: 2009-01-28 11:13:08 -0500 (Wed, 28 Jan 2009)
New Revision: 1264
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exception/NotAScopeException.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/lookup/
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Beans.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/context/PassivatingContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/definition/StereotypesTest.java
Log:
tidy up
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -40,6 +40,7 @@
import org.jboss.webbeans.bean.NewSimpleBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.ListComparator;
import org.jboss.webbeans.util.Proxies;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -63,11 +63,12 @@
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
+import org.jboss.webbeans.injection.Resolver;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
-import org.jboss.webbeans.lookup.Resolver;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.util.Beans;
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,142 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans;
-
-import java.lang.annotation.Annotation;
-import java.util.concurrent.Callable;
-
-import org.jboss.webbeans.model.BindingTypeModel;
-import org.jboss.webbeans.model.ScopeModel;
-import org.jboss.webbeans.model.StereotypeModel;
-import org.jboss.webbeans.util.ConcurrentCache;
-
-/**
- * Metadata singleton for holding EJB metadata, scope models etc.
- *
- * @author Pete Muir
- *
- */
-public class MetaDataCache
-{
- // The singleton instance
- private static MetaDataCache instance;
-
- /**
- * Gets the singleton
- *
- * @return The instance
- */
- public static MetaDataCache instance()
- {
- return instance;
- }
-
- static
- {
- instance = new MetaDataCache();
- }
-
- // The stereotype models
- private ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>>();
- // The scope models
- private ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>> scopes = new ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>>();
- // The binding type models
- private ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>> bindingTypes = new ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>>();
-
- /**
- * Gets a stereotype model
- *
- * Adds the model if it is not present.
- *
- * @param <T> The type
- * @param stereotype The stereotype
- * @return The stereotype model
- */
- public <T extends Annotation> StereotypeModel<T> getStereotype(final Class<T> stereotype)
- {
- return stereotypes.putIfAbsent(stereotype, new Callable<StereotypeModel<T>>()
- {
-
- public StereotypeModel<T> call() throws Exception
- {
- return new StereotypeModel<T>(stereotype);
- }
- });
- }
-
- /**
- * Gets a scope model
- *
- * Adds the model if it is not present.
- *
- * @param <T> The type
- * @param scopeType The scope type
- * @return The scope type model
- */
- public <T extends Annotation> ScopeModel<T> getScopeModel(final Class<T> scopeType)
- {
- return scopes.putIfAbsent(scopeType, new Callable<ScopeModel<T>>()
- {
-
- public ScopeModel<T> call() throws Exception
- {
- return new ScopeModel<T>(scopeType);
- }
-
- });
- }
-
- /**
- * Gets a binding type model.
- *
- * Adds the model if it is not present.
- *
- * @param <T> The type
- * @param bindingType The binding type
- * @return The binding type model
- */
- public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(final Class<T> bindingType)
- {
- return bindingTypes.putIfAbsent(bindingType, new Callable<BindingTypeModel<T>>()
- {
-
- public BindingTypeModel<T> call() throws Exception
- {
- return new BindingTypeModel<T>(bindingType);
- }
-
- });
- }
-
- /**
- * Gets a string representation
- *
- * @return A string representation
- */
- @Override
- public String toString()
- {
- StringBuilder buffer = new StringBuilder();
- buffer.append("Metadata cache\n");
- buffer.append("Registered binding type models: " + bindingTypes.size() + "\n");
- buffer.append("Registered scope type models: " + scopes.size() + "\n");
- buffer.append("Registered stereotype models: " + stereotypes.size() + "\n");
- return buffer.toString();
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -42,7 +42,7 @@
import org.jboss.webbeans.literal.CurrentLiteral;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.model.MergedStereotypes;
+import org.jboss.webbeans.metadata.MergedStereotypes;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Reflections;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -37,10 +37,10 @@
import javax.inject.manager.InjectionPoint;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -27,12 +27,12 @@
import javax.inject.Disposes;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.util.Names;
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -32,7 +32,6 @@
import javax.persistence.PersistenceContextType;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.injection.ConstructorInjectionPoint;
@@ -47,6 +46,7 @@
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Reflections;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -25,7 +25,7 @@
import javax.inject.Current;
import javax.inject.DuplicateBindingTypeException;
-import org.jboss.webbeans.MetaDataCache;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exception/NotAScopeException.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exception/NotAScopeException.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exception/NotAScopeException.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.exception;
-
-import javax.inject.DefinitionException;
-
-/**
- * Exception for incorrect scope usage
- *
- * @author Pete Muir
- */
-public class NotAScopeException extends DefinitionException
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * Constructor
- */
- public NotAScopeException()
- {
- super();
- }
-
- /**
- * Constructor
- *
- * @param message The exception message
- * @param throwable The root exception
- */
- public NotAScopeException(String message, Throwable throwable)
- {
- super(message, throwable);
- }
-
- /**
- * Constructor
- *
- * @param message The exception message
- */
- public NotAScopeException(String message)
- {
- super(message);
- }
-
- /**
- * Constructor
- *
- * @param throwable The root exception
- */
- public NotAScopeException(Throwable throwable)
- {
- super(throwable);
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/Resolver.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/lookup/Resolver.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/Resolver.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/Resolver.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,380 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.injection;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.Callable;
+
+import javax.inject.TypeLiteral;
+import javax.inject.manager.Bean;
+import javax.inject.manager.Decorator;
+import javax.inject.manager.InterceptionType;
+import javax.inject.manager.Interceptor;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.ForwardingAnnotatedItem;
+import org.jboss.webbeans.metadata.BindingTypeModel;
+import org.jboss.webbeans.metadata.MetaDataCache;
+import org.jboss.webbeans.util.ConcurrentCache;
+import org.jboss.webbeans.util.ListComparator;
+
+/**
+ * Implementation of Web Beans type safe and name based bean resolution
+ *
+ * @author Pete Muir
+ */
+public class Resolver
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Class<AnnotatedItem<Object, Object>> ANNOTATED_ITEM_GENERIFIED_WITH_OBJECT_OBJECT = new TypeLiteral<AnnotatedItem<Object, Object>>(){}.getRawType();
+ private static final Class<Set<Bean<Object>>> BEAN_SET_GENERIFIED_WITH_OBJECT = new TypeLiteral<Set<Bean<Object>>>(){}.getRawType();
+ private static final Class<Set<Bean<?>>> BEAN_SET_GENERIFIED_WITH_WILDCARD = new TypeLiteral<Set<Bean<?>>>(){}.getRawType();
+
+ /**
+ * Extension of an element which bases equality not only on type, but also on
+ * binding type
+ */
+ private abstract class ResolvableAnnotatedItem<T, S> extends ForwardingAnnotatedItem<T, S>
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other instanceof AnnotatedItem)
+ {
+ AnnotatedItem<?, ?> that = (AnnotatedItem<?, ?>) other;
+ return delegate().isAssignableFrom(that) && that.getBindingTypes().equals(this.getBindingTypes());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Resolvable annotated item for " + delegate();
+ }
+
+ }
+
+ // The resolved injection points
+ private ConcurrentCache<ResolvableAnnotatedItem<?, ?>, Set<Bean<?>>> resolvedInjectionPoints;
+ // The registerd injection points
+ private Set<AnnotatedItem<?, ?>> injectionPoints;
+ // The resolved names
+ private ConcurrentCache<String, Set<Bean<?>>> resolvedNames;
+ // The Web Beans manager
+ private ManagerImpl manager;
+
+ /**
+ * Constructor
+ *
+ * @param manager The Web Beans manager
+ */
+ public Resolver(ManagerImpl manager)
+ {
+ this.injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
+ this.resolvedInjectionPoints = new ConcurrentCache<ResolvableAnnotatedItem<?, ?>, Set<Bean<?>>>();
+ this.resolvedNames = new ConcurrentCache<String, Set<Bean<?>>>();
+ this.manager = manager;
+ }
+
+ /**
+ * Add multiple injection points for later resolving using
+ * {@link #registerInjectionPoint(AnnotatedItem)}. Useful during bootstrap.
+ *
+ * @param elements The injection points to add
+ */
+ public void addInjectionPoints(Collection<? extends AnnotatedItem<?, ?>> elements)
+ {
+ injectionPoints.addAll(elements);
+ }
+
+ /**
+ * Registers an injection point
+ *
+ * @param <T>
+ * @param <S>
+ * @param element The injection point to add
+ * @return A set of matching beans for the injection point
+ */
+ private <T, S> Set<Bean<T>> registerInjectionPoint(final ResolvableAnnotatedItem<T, S> element)
+ {
+ Callable<Set<Bean<T>>> callable = new Callable<Set<Bean<T>>>()
+ {
+
+ public Set<Bean<T>> call() throws Exception
+ {
+ return retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans()), manager.getEnabledDeploymentTypes());
+ }
+
+ };
+ return resolvedInjectionPoints.putIfAbsent(element, callable);
+ }
+
+ /**
+ * Reset all cached injection points. You must reset all cached injection
+ * points when you add a bean to the manager
+ */
+ public void clear()
+ {
+ this.resolvedInjectionPoints = new ConcurrentCache<ResolvableAnnotatedItem<?, ?>, Set<Bean<?>>>();
+ resolvedNames = new ConcurrentCache<String, Set<Bean<?>>>();
+ }
+
+ /**
+ * Resolve all injection points added using
+ * {@link #addInjectionPoints(Collection)}
+ */
+ public void resolveInjectionPoints()
+ {
+ for (final AnnotatedItem<? extends Object, ? extends Object> injectable : injectionPoints)
+ {
+
+ registerInjectionPoint(new ResolvableAnnotatedItem<Object, Object>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public AnnotatedItem<Object, Object> delegate()
+ {
+ return ANNOTATED_ITEM_GENERIFIED_WITH_OBJECT_OBJECT.cast(injectable);
+ }
+ });
+ }
+ }
+
+ /**
+ * Get the possible beans for the given element
+ *
+ * @param key The resolving criteria
+ * @return An unmodifiable set of matching beans
+ */
+ public <T, S> Set<Bean<T>> get(final AnnotatedItem<T, S> key)
+ {
+ Set<Bean<T>> beans = new HashSet<Bean<T>>();
+
+ final ResolvableAnnotatedItem<T, S> element = new ResolvableAnnotatedItem<T, S>()
+ {
+
+ @Override
+ public AnnotatedItem<T, S> delegate()
+ {
+ return key;
+ }
+
+ };
+ beans = registerInjectionPoint(element);
+ return Collections.unmodifiableSet(beans);
+ }
+
+ /**
+ * Get the possible beans for the given name
+ *
+ * @param name The name to match
+ * @return The set of matching beans
+ */
+ public Set<Bean<? extends Object>> get(final String name)
+ {
+ return resolvedNames.putIfAbsent(name, new Callable<Set<Bean<?>>>()
+ {
+
+ public Set<Bean<? extends Object>> call() throws Exception
+ {
+
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
+ {
+ beans.add(bean);
+ }
+ }
+ return retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
+ }
+
+ // Helper method to deal with dynamic casts being needed
+ private Set<Bean<?>> retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
+ {
+ return BEAN_SET_GENERIFIED_WITH_WILDCARD.cast(Resolver.retainHighestPrecedenceBeans(BEAN_SET_GENERIFIED_WITH_OBJECT.cast(beans), enabledDeploymentTypes));
+ }
+
+ });
+ }
+
+
+
+ /**
+ * Filters out the beans with the highest enabled deployment type
+ *
+ * @param <T>
+ * @param beans The beans to filter
+ * @param enabledDeploymentTypes The enabled deployment types
+ * @return The filtered beans
+ */
+ private static <T> Set<Bean<T>> retainHighestPrecedenceBeans(Set<Bean<T>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
+ {
+ if (beans.size() > 0)
+ {
+ SortedSet<Class<? extends Annotation>> possibleDeploymentTypes = new TreeSet<Class<? extends Annotation>>(new ListComparator<Class<? extends Annotation>>(enabledDeploymentTypes));
+ for (Bean<?> bean : beans)
+ {
+ possibleDeploymentTypes.add(bean.getDeploymentType());
+ }
+ possibleDeploymentTypes.retainAll(enabledDeploymentTypes);
+ Set<Bean<T>> trimmed = new HashSet<Bean<T>>();
+ if (possibleDeploymentTypes.size() > 0)
+ {
+ Class<? extends Annotation> highestPrecedencePossibleDeploymentType = possibleDeploymentTypes.last();
+
+ for (Bean<T> bean : beans)
+ {
+ if (bean.getDeploymentType().equals(highestPrecedencePossibleDeploymentType))
+ {
+ trimmed.add(bean);
+ }
+ }
+ }
+ return trimmed;
+ }
+ else
+ {
+ return beans;
+ }
+ }
+
+ /**
+ * Gets the matching beans for binding criteria from a list of beans
+ *
+ * @param <T> The type of the beans
+ * @param element The binding criteria
+ * @param beans The beans to filter
+ * @return A set of filtered beans
+ */
+ private <T> Set<Bean<T>> getMatchingBeans(AnnotatedItem<T, ?> element, List<Bean<?>> beans)
+ {
+ Set<Bean<T>> resolvedBeans = new HashSet<Bean<T>>();
+ for (Bean<?> bean : beans)
+ {
+ if (element.isAssignableFrom(bean.getTypes()) && containsAllBindingBindingTypes(element, bean.getBindings()))
+ {
+ @SuppressWarnings("unchecked")
+ Bean<T> b = (Bean<T>) bean;
+ resolvedBeans.add(b);
+ }
+ }
+ return resolvedBeans;
+ }
+
+ /**
+ * Checks if binding criteria fulfill all binding types
+ *
+ * @param element The binding criteria to check
+ * @param bindingTypes The binding types to check
+ * @return True if all matches, false otherwise
+ */
+ private boolean containsAllBindingBindingTypes(AnnotatedItem<?, ?> element, Set<Annotation> bindingTypes)
+ {
+ for (Annotation bindingType : element.getBindingTypes())
+ {
+ BindingTypeModel<?> bindingTypeModel = MetaDataCache.instance().getBindingTypeModel(bindingType.annotationType());
+ if (bindingTypeModel.getNonBindingTypes().size() > 0)
+ {
+ boolean matchFound = false;
+ for (Annotation otherBindingType : bindingTypes)
+ {
+ if (bindingTypeModel.isEqual(bindingType, otherBindingType))
+ {
+ matchFound = true;
+ }
+ }
+ if (!matchFound)
+ {
+ return false;
+ }
+ }
+ else if (!bindingTypes.contains(bindingType))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Resolves decorators according to binding criteria
+ *
+ * @param types The set of API types to match
+ * @param bindingTypes The binding types to match
+ * @return The set of matching decorators
+ */
+ public List<Decorator> resolveDecorators(Set<Type> types, Annotation[] bindingTypes)
+ {
+ // TODO Implement decorators
+ return Collections.emptyList();
+ }
+
+ /**
+ * Resolves interceptors according to binding criteria
+ *
+ * @param types The set of API types to match
+ * @param bindingTypes The binding types to match
+ * @return The set of matching interceptors
+ */
+ public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation[] interceptorBindings)
+ {
+ // TODO Implement interceptors
+ return null;
+ }
+
+ /**
+ * Gets a string representation
+ *
+ * @return A string representation
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Resolver\n");
+ buffer.append("Injection points: " + injectionPoints.size() + "\n");
+ buffer.append("Resolved injection points: " + resolvedInjectionPoints.size() + "\n");
+ buffer.append("Resolved names points: " + resolvedNames.size() + "\n");
+ return buffer.toString();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/Resolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata (from rev 1259, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model)
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2009-01-28 09:00:59 UTC (rev 1259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-
-import javax.inject.DefinitionException;
-
-import org.jboss.webbeans.introspector.AnnotatedAnnotation;
-import org.jboss.webbeans.introspector.jlr.AnnotatedAnnotationImpl;
-
-/**
- * Abstract representation of an annotation model
- *
- * @author Pete Muir
- */
-public abstract class AnnotationModel<T extends Annotation>
-{
- // The underlying annotation
- private AnnotatedAnnotation<T> annotatedAnnotation;
- // Is the data valid?
- private boolean valid;
-
- /**
- * Constructor
- *
- * @param type The annotation type
- */
- public AnnotationModel(Class<T> type)
- {
- this.annotatedAnnotation = new AnnotatedAnnotationImpl<T>(type);
- init();
- }
-
- /**
- * Initializes the type and validates it
- */
- protected void init()
- {
- initType();
- initValid();
- }
-
- /**
- * Initializes the type
- */
- protected void initType()
- {
- if (!Annotation.class.isAssignableFrom(getType()))
- {
- throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getType());
- }
- }
-
- /**
- * Validates the data for correct annotation
- */
- protected void initValid()
- {
- this.valid = annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
- }
-
- /**
- * Gets the type of the annotation
- *
- * @return The type
- */
- public Class<T> getType()
- {
- return annotatedAnnotation.getType();
- }
-
- /**
- * Gets the meta-annotation that should be present
- *
- * @return
- */
- protected abstract Class<? extends Annotation> getMetaAnnotation();
-
- /**
- * Indicates if the annotation is valid
- *
- * @return True if valid, false otherwise
- */
- public boolean isValid()
- {
- return valid;
- }
-
- /**
- * Gets the annotated annotation
- *
- * @return The annotation
- */
- protected AnnotatedAnnotation<T> getAnnotatedAnnotation()
- {
- return annotatedAnnotation;
- }
-
- /**
- * Gets a string representation of the annotation model
- *
- * @return The string representation
- */
- @Override
- public String toString()
- {
- return (isValid() ? "Valid" : "Invalid") + " annotation model for " + getType();
- }
-
-}
\ No newline at end of file
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/AnnotationModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+
+import javax.inject.DefinitionException;
+
+import org.jboss.webbeans.introspector.AnnotatedAnnotation;
+import org.jboss.webbeans.introspector.jlr.AnnotatedAnnotationImpl;
+
+/**
+ * Abstract representation of an annotation model
+ *
+ * @author Pete Muir
+ */
+public abstract class AnnotationModel<T extends Annotation>
+{
+ // The underlying annotation
+ private AnnotatedAnnotation<T> annotatedAnnotation;
+ // Is the data valid?
+ private boolean valid;
+
+ /**
+ * Constructor
+ *
+ * @param type The annotation type
+ */
+ public AnnotationModel(Class<T> type)
+ {
+ this.annotatedAnnotation = new AnnotatedAnnotationImpl<T>(type);
+ init();
+ }
+
+ /**
+ * Initializes the type and validates it
+ */
+ protected void init()
+ {
+ initType();
+ initValid();
+ }
+
+ /**
+ * Initializes the type
+ */
+ protected void initType()
+ {
+ if (!Annotation.class.isAssignableFrom(getType()))
+ {
+ throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getType());
+ }
+ }
+
+ /**
+ * Validates the data for correct annotation
+ */
+ protected void initValid()
+ {
+ this.valid = annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
+ }
+
+ /**
+ * Gets the type of the annotation
+ *
+ * @return The type
+ */
+ public Class<T> getType()
+ {
+ return annotatedAnnotation.getType();
+ }
+
+ /**
+ * Gets the meta-annotation that should be present
+ *
+ * @return
+ */
+ protected abstract Class<? extends Annotation> getMetaAnnotation();
+
+ /**
+ * Indicates if the annotation is valid
+ *
+ * @return True if valid, false otherwise
+ */
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ /**
+ * Gets the annotated annotation
+ *
+ * @return The annotation
+ */
+ protected AnnotatedAnnotation<T> getAnnotatedAnnotation()
+ {
+ return annotatedAnnotation;
+ }
+
+ /**
+ * Gets a string representation of the annotation model
+ *
+ * @return The string representation
+ */
+ @Override
+ public String toString()
+ {
+ return (isValid() ? "Valid" : "Invalid") + " annotation model for " + getType();
+ }
+
+}
\ No newline at end of file
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2009-01-28 09:00:59 UTC (rev 1259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,157 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-import java.util.Set;
-
-import javax.annotation.NonBinding;
-import javax.inject.BindingType;
-import javax.inject.DefinitionException;
-
-import org.jboss.webbeans.introspector.AnnotatedMethod;
-import org.jboss.webbeans.util.Reflections;
-
-/**
- *
- * Model of a binding type
- *
- * @author Pete Muir
- *
- */
-public class BindingTypeModel<T extends Annotation> extends AnnotationModel<T>
-{
- // The non-binding types
- private Set<AnnotatedMethod<?>> nonBindingTypes;
-
- /**
- * Constructor
- *
- * @param type The type
- */
- public BindingTypeModel(Class<T> type)
- {
- super(type);
- }
-
- /**
- * Initializes the non-binding types and validates the members
- */
- @Override
- protected void init()
- {
- super.init();
- initNonBindingTypes();
- checkArrayAndAnnotationValuedMembers();
- }
-
- /**
- * Validates the members
- */
- private void checkArrayAndAnnotationValuedMembers()
- {
- for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
- {
- if ((Reflections.isArrayType(annotatedMethod.getType()) || Annotation.class.isAssignableFrom(annotatedMethod.getType())) && !nonBindingTypes.contains(annotatedMethod))
- {
- throw new DefinitionException("Member of array type or annotation type must be annotated @NonBinding " + annotatedMethod);
- }
- }
-
- }
-
- /**
- * Gets the meta-annotation type
- *
- * @return The BindingType class
- */
- @Override
- protected Class<? extends Annotation> getMetaAnnotation()
- {
- return BindingType.class;
- }
-
- /**
- * Indicates if there are non-binding types present
- *
- * @return True if present, false otherwise
- */
- public boolean hasNonBindingTypes()
- {
- return nonBindingTypes.size() > 0;
- }
-
- /**
- * Gets the non-binding types
- *
- * @return A set of non-binding types, or an empty set if there are none
- * present
- */
- public Set<AnnotatedMethod<?>> getNonBindingTypes()
- {
- return nonBindingTypes;
- }
-
- /**
- * Initializes the non-binding types
- */
- protected void initNonBindingTypes()
- {
- nonBindingTypes = getAnnotatedAnnotation().getAnnotatedMembers(NonBinding.class);
- }
-
- /**
- * Comparator for checking equality
- *
- * @param instance The instance to check against
- * @param other The other binding type
- * @return True if equal, false otherwise
- */
- public boolean isEqual(Annotation instance, Annotation other)
- {
- if (instance.annotationType().equals(getType()) && other.annotationType().equals(getType()))
- {
- for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
- {
- if (!nonBindingTypes.contains(annotatedMethod))
- {
- Object thisValue = annotatedMethod.invoke(instance);
- Object thatValue = annotatedMethod.invoke(other);
- if (!thisValue.equals(thatValue))
- {
- return false;
- }
- }
- }
- return true;
- }
- return false;
- }
-
- /**
- * Gets a string representation of the binding type model
- *
- * @return The string representation
- */
- @Override
- public String toString()
- {
- return (isValid() ? "Valid" : "Invalid") + " binding type model for " + getType() + " with non-binding types " + getNonBindingTypes();
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/BindingTypeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.annotation.NonBinding;
+import javax.inject.BindingType;
+import javax.inject.DefinitionException;
+
+import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ *
+ * Model of a binding type
+ *
+ * @author Pete Muir
+ *
+ */
+public class BindingTypeModel<T extends Annotation> extends AnnotationModel<T>
+{
+ // The non-binding types
+ private Set<AnnotatedMethod<?>> nonBindingTypes;
+
+ /**
+ * Constructor
+ *
+ * @param type The type
+ */
+ public BindingTypeModel(Class<T> type)
+ {
+ super(type);
+ }
+
+ /**
+ * Initializes the non-binding types and validates the members
+ */
+ @Override
+ protected void init()
+ {
+ super.init();
+ initNonBindingTypes();
+ checkArrayAndAnnotationValuedMembers();
+ }
+
+ /**
+ * Validates the members
+ */
+ private void checkArrayAndAnnotationValuedMembers()
+ {
+ for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
+ {
+ if ((Reflections.isArrayType(annotatedMethod.getType()) || Annotation.class.isAssignableFrom(annotatedMethod.getType())) && !nonBindingTypes.contains(annotatedMethod))
+ {
+ throw new DefinitionException("Member of array type or annotation type must be annotated @NonBinding " + annotatedMethod);
+ }
+ }
+
+ }
+
+ /**
+ * Gets the meta-annotation type
+ *
+ * @return The BindingType class
+ */
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
+ {
+ return BindingType.class;
+ }
+
+ /**
+ * Indicates if there are non-binding types present
+ *
+ * @return True if present, false otherwise
+ */
+ public boolean hasNonBindingTypes()
+ {
+ return nonBindingTypes.size() > 0;
+ }
+
+ /**
+ * Gets the non-binding types
+ *
+ * @return A set of non-binding types, or an empty set if there are none
+ * present
+ */
+ public Set<AnnotatedMethod<?>> getNonBindingTypes()
+ {
+ return nonBindingTypes;
+ }
+
+ /**
+ * Initializes the non-binding types
+ */
+ protected void initNonBindingTypes()
+ {
+ nonBindingTypes = getAnnotatedAnnotation().getAnnotatedMembers(NonBinding.class);
+ }
+
+ /**
+ * Comparator for checking equality
+ *
+ * @param instance The instance to check against
+ * @param other The other binding type
+ * @return True if equal, false otherwise
+ */
+ public boolean isEqual(Annotation instance, Annotation other)
+ {
+ if (instance.annotationType().equals(getType()) && other.annotationType().equals(getType()))
+ {
+ for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
+ {
+ if (!nonBindingTypes.contains(annotatedMethod))
+ {
+ Object thisValue = annotatedMethod.invoke(instance);
+ Object thatValue = annotatedMethod.invoke(other);
+ if (!thisValue.equals(thatValue))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets a string representation of the binding type model
+ *
+ * @return The string representation
+ */
+ @Override
+ public String toString()
+ {
+ return (isValid() ? "Valid" : "Invalid") + " binding type model for " + getType() + " with non-binding types " + getNonBindingTypes();
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypes.java 2009-01-28 09:00:59 UTC (rev 1259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,164 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.webbeans.MetaDataCache;
-import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;
-
-/**
- * Meta model for the merged stereotype for a bean
- *
- * @author Pete Muir
- */
-public class MergedStereotypes<T, E>
-{
- // The possible deployment types
- private AnnotationMap possibleDeploymentTypes;
- // The possible scope types
- private Set<Annotation> possibleScopeTypes;
- // Is the bean name defaulted?
- private boolean beanNameDefaulted;
- // The required types
- private Set<Class<?>> requiredTypes;
- // The supported scopes
- private Set<Class<? extends Annotation>> supportedScopes;
-
- /**
- * Constructor
- *
- * @param stereotypeAnnotations The stereotypes to merge
- */
- public MergedStereotypes(Set<Annotation> stereotypeAnnotations)
- {
- possibleDeploymentTypes = new AnnotationMap();
- possibleScopeTypes = new HashSet<Annotation>();
- requiredTypes = new HashSet<Class<?>>();
- supportedScopes = new HashSet<Class<? extends Annotation>>();
- merge(stereotypeAnnotations);
- }
-
- /**
- * Perform the merge
- *
- * @param stereotypeAnnotations The stereotype annotations
- */
- protected void merge(Set<Annotation> stereotypeAnnotations)
- {
- for (Annotation stereotypeAnnotation : stereotypeAnnotations)
- {
- // Retrieve and merge all metadata from stereotypes
- StereotypeModel<?> stereotype = MetaDataCache.instance().getStereotype(stereotypeAnnotation.annotationType());
- if (stereotype == null)
- {
- throw new IllegalStateException("Stereotype " + stereotypeAnnotation + " not registered with container");
- }
- if (stereotype.getDefaultDeploymentType() != null)
- {
- possibleDeploymentTypes.put(stereotype.getDefaultDeploymentType().annotationType(), stereotype.getDefaultDeploymentType());
- }
- if (stereotype.getDefaultScopeType() != null)
- {
- possibleScopeTypes.add(stereotype.getDefaultScopeType());
- }
- requiredTypes.addAll(stereotype.getRequiredTypes());
- supportedScopes.addAll(stereotype.getSupportedScopes());
- if (stereotype.isBeanNameDefaulted())
- {
- beanNameDefaulted = true;
- }
- }
- }
-
- /**
- * Returns the possible deployment typess
- *
- * @return The deployment types
- */
- public AnnotationMap getPossibleDeploymentTypes()
- {
- return possibleDeploymentTypes;
- }
-
- /**
- * Returns the possible scope types
- *
- * @return The scope types
- */
- public Set<Annotation> getPossibleScopeTypes()
- {
- return possibleScopeTypes;
- }
-
- /**
- * Indicates if the name i defaulted
- *
- * @return True if defaulted, false if not
- */
- public boolean isBeanNameDefaulted()
- {
- return beanNameDefaulted;
- }
-
- /**
- * Returns the required types
- *
- * @return The required types
- */
- public Set<Class<?>> getRequiredTypes()
- {
- return requiredTypes;
- }
-
- /**
- * Returns the supported scopes
- *
- * @return The supported scopes
- */
- public Set<Class<? extends Annotation>> getSupportedScopes()
- {
- return supportedScopes;
- }
-
- /**
- * Indicates if the bean was declared in XML
- *
- * @return True if declared in XML, else false
- */
- public boolean isDeclaredInXml()
- {
- return false;
- }
-
- /**
- * Gets a string representation of the merged stereotypes
- *
- * @return The string representation
- */
- @Override
- public String toString()
- {
- return "Merged stereotype model with possible deployment types " +
- possibleDeploymentTypes + ", required types " + requiredTypes +
- ", possible scopes " + possibleScopeTypes + " and supported scopes " + supportedScopes;
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypes.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MergedStereotypes.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;
+
+/**
+ * Meta model for the merged stereotype for a bean
+ *
+ * @author Pete Muir
+ */
+public class MergedStereotypes<T, E>
+{
+ // The possible deployment types
+ private AnnotationMap possibleDeploymentTypes;
+ // The possible scope types
+ private Set<Annotation> possibleScopeTypes;
+ // Is the bean name defaulted?
+ private boolean beanNameDefaulted;
+ // The required types
+ private Set<Class<?>> requiredTypes;
+ // The supported scopes
+ private Set<Class<? extends Annotation>> supportedScopes;
+
+ /**
+ * Constructor
+ *
+ * @param stereotypeAnnotations The stereotypes to merge
+ */
+ public MergedStereotypes(Set<Annotation> stereotypeAnnotations)
+ {
+ possibleDeploymentTypes = new AnnotationMap();
+ possibleScopeTypes = new HashSet<Annotation>();
+ requiredTypes = new HashSet<Class<?>>();
+ supportedScopes = new HashSet<Class<? extends Annotation>>();
+ merge(stereotypeAnnotations);
+ }
+
+ /**
+ * Perform the merge
+ *
+ * @param stereotypeAnnotations The stereotype annotations
+ */
+ protected void merge(Set<Annotation> stereotypeAnnotations)
+ {
+ for (Annotation stereotypeAnnotation : stereotypeAnnotations)
+ {
+ // Retrieve and merge all metadata from stereotypes
+ StereotypeModel<?> stereotype = MetaDataCache.instance().getStereotype(stereotypeAnnotation.annotationType());
+ if (stereotype == null)
+ {
+ throw new IllegalStateException("Stereotype " + stereotypeAnnotation + " not registered with container");
+ }
+ if (stereotype.getDefaultDeploymentType() != null)
+ {
+ possibleDeploymentTypes.put(stereotype.getDefaultDeploymentType().annotationType(), stereotype.getDefaultDeploymentType());
+ }
+ if (stereotype.getDefaultScopeType() != null)
+ {
+ possibleScopeTypes.add(stereotype.getDefaultScopeType());
+ }
+ requiredTypes.addAll(stereotype.getRequiredTypes());
+ supportedScopes.addAll(stereotype.getSupportedScopes());
+ if (stereotype.isBeanNameDefaulted())
+ {
+ beanNameDefaulted = true;
+ }
+ }
+ }
+
+ /**
+ * Returns the possible deployment typess
+ *
+ * @return The deployment types
+ */
+ public AnnotationMap getPossibleDeploymentTypes()
+ {
+ return possibleDeploymentTypes;
+ }
+
+ /**
+ * Returns the possible scope types
+ *
+ * @return The scope types
+ */
+ public Set<Annotation> getPossibleScopeTypes()
+ {
+ return possibleScopeTypes;
+ }
+
+ /**
+ * Indicates if the name i defaulted
+ *
+ * @return True if defaulted, false if not
+ */
+ public boolean isBeanNameDefaulted()
+ {
+ return beanNameDefaulted;
+ }
+
+ /**
+ * Returns the required types
+ *
+ * @return The required types
+ */
+ public Set<Class<?>> getRequiredTypes()
+ {
+ return requiredTypes;
+ }
+
+ /**
+ * Returns the supported scopes
+ *
+ * @return The supported scopes
+ */
+ public Set<Class<? extends Annotation>> getSupportedScopes()
+ {
+ return supportedScopes;
+ }
+
+ /**
+ * Indicates if the bean was declared in XML
+ *
+ * @return True if declared in XML, else false
+ */
+ public boolean isDeclaredInXml()
+ {
+ return false;
+ }
+
+ /**
+ * Gets a string representation of the merged stereotypes
+ *
+ * @return The string representation
+ */
+ @Override
+ public String toString()
+ {
+ return "Merged stereotype model with possible deployment types " +
+ possibleDeploymentTypes + ", required types " + requiredTypes +
+ ", possible scopes " + possibleScopeTypes + " and supported scopes " + supportedScopes;
+ }
+
+}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MetaDataCache.java (from rev 1259, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MetaDataCache.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/MetaDataCache.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.concurrent.Callable;
+
+import org.jboss.webbeans.util.ConcurrentCache;
+
+/**
+ * Metadata singleton for holding EJB metadata, scope models etc.
+ *
+ * @author Pete Muir
+ *
+ */
+public class MetaDataCache
+{
+ // The singleton instance
+ private static MetaDataCache instance;
+
+ /**
+ * Gets the singleton
+ *
+ * @return The instance
+ */
+ public static MetaDataCache instance()
+ {
+ return instance;
+ }
+
+ static
+ {
+ instance = new MetaDataCache();
+ }
+
+ // The stereotype models
+ private ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>>();
+ // The scope models
+ private ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>> scopes = new ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>>();
+ // The binding type models
+ private ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>> bindingTypes = new ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>>();
+
+ /**
+ * Gets a stereotype model
+ *
+ * Adds the model if it is not present.
+ *
+ * @param <T> The type
+ * @param stereotype The stereotype
+ * @return The stereotype model
+ */
+ public <T extends Annotation> StereotypeModel<T> getStereotype(final Class<T> stereotype)
+ {
+ return stereotypes.putIfAbsent(stereotype, new Callable<StereotypeModel<T>>()
+ {
+
+ public StereotypeModel<T> call() throws Exception
+ {
+ return new StereotypeModel<T>(stereotype);
+ }
+ });
+ }
+
+ /**
+ * Gets a scope model
+ *
+ * Adds the model if it is not present.
+ *
+ * @param <T> The type
+ * @param scopeType The scope type
+ * @return The scope type model
+ */
+ public <T extends Annotation> ScopeModel<T> getScopeModel(final Class<T> scopeType)
+ {
+ return scopes.putIfAbsent(scopeType, new Callable<ScopeModel<T>>()
+ {
+
+ public ScopeModel<T> call() throws Exception
+ {
+ return new ScopeModel<T>(scopeType);
+ }
+
+ });
+ }
+
+ /**
+ * Gets a binding type model.
+ *
+ * Adds the model if it is not present.
+ *
+ * @param <T> The type
+ * @param bindingType The binding type
+ * @return The binding type model
+ */
+ public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(final Class<T> bindingType)
+ {
+ return bindingTypes.putIfAbsent(bindingType, new Callable<BindingTypeModel<T>>()
+ {
+
+ public BindingTypeModel<T> call() throws Exception
+ {
+ return new BindingTypeModel<T>(bindingType);
+ }
+
+ });
+ }
+
+ /**
+ * Gets a string representation
+ *
+ * @return A string representation
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Metadata cache\n");
+ buffer.append("Registered binding type models: " + bindingTypes.size() + "\n");
+ buffer.append("Registered scope type models: " + scopes.size() + "\n");
+ buffer.append("Registered stereotype models: " + stereotypes.size() + "\n");
+ return buffer.toString();
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2009-01-28 09:00:59 UTC (rev 1259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,88 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-
-import javax.context.ScopeType;
-
-/**
- *
- * Model of a scope
- *
- * @author Pete Muir
- *
- */
-public class ScopeModel<T extends Annotation> extends AnnotationModel<T>
-{
- /**
- * Constrctor
- *
- * @param scope The scope type
- */
- public ScopeModel(Class<T> scope)
- {
- super(scope);
- }
-
- /**
- * Indicates if the scope is "normal"
- *
- * @return True if normal, false otherwise
- */
- public boolean isNormal()
- {
- return getAnnotatedAnnotation().getAnnotation(ScopeType.class).normal();
- }
-
- /**
- * Indicates if the scope is "passivating"
- *
- * @return True if passivating, false otherwise
- */
- public boolean isPassivating()
- {
- return getAnnotatedAnnotation().getAnnotation(ScopeType.class).passivating();
- }
-
- /**
- * Gets the corresponding meta-annotation type class
- *
- * @return The ScopeType class
- */
- @Override
- protected Class<? extends Annotation> getMetaAnnotation()
- {
- return ScopeType.class;
- }
-
- /**
- * Gets a string representation of the scope model
- *
- * @return The string representation
- */
- @Override
- public String toString()
- {
- String valid = isValid() ? "Valid " : "Invalid";
- String normal = isNormal() ? "normal " : "non-normal ";
- String passivating = isPassivating() ? "passivating " : "pon-passivating ";
- return valid + normal + passivating + " scope model for " + getType();
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/ScopeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+
+import javax.context.ScopeType;
+
+/**
+ *
+ * Model of a scope
+ *
+ * @author Pete Muir
+ *
+ */
+public class ScopeModel<T extends Annotation> extends AnnotationModel<T>
+{
+ /**
+ * Constrctor
+ *
+ * @param scope The scope type
+ */
+ public ScopeModel(Class<T> scope)
+ {
+ super(scope);
+ }
+
+ /**
+ * Indicates if the scope is "normal"
+ *
+ * @return True if normal, false otherwise
+ */
+ public boolean isNormal()
+ {
+ return getAnnotatedAnnotation().getAnnotation(ScopeType.class).normal();
+ }
+
+ /**
+ * Indicates if the scope is "passivating"
+ *
+ * @return True if passivating, false otherwise
+ */
+ public boolean isPassivating()
+ {
+ return getAnnotatedAnnotation().getAnnotation(ScopeType.class).passivating();
+ }
+
+ /**
+ * Gets the corresponding meta-annotation type class
+ *
+ * @return The ScopeType class
+ */
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
+ {
+ return ScopeType.class;
+ }
+
+ /**
+ * Gets a string representation of the scope model
+ *
+ * @return The string representation
+ */
+ @Override
+ public String toString()
+ {
+ String valid = isValid() ? "Valid " : "Invalid";
+ String normal = isNormal() ? "normal " : "non-normal ";
+ String passivating = isPassivating() ? "passivating " : "pon-passivating ";
+ return valid + normal + passivating + " scope model for " + getType();
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2009-01-28 09:00:59 UTC (rev 1259)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -1,258 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.annotation.Named;
-import javax.annotation.Stereotype;
-import javax.context.ScopeType;
-import javax.inject.BindingType;
-import javax.inject.DefinitionException;
-import javax.inject.DeploymentType;
-import javax.interceptor.InterceptorBindingType;
-
-/**
- * A meta model for a stereotype, allows us to cache a stereotype and to
- * validate it
- *
- * @author Pete Muir
- *
- */
-public class StereotypeModel<T extends Annotation> extends AnnotationModel<T>
-{
- // The default deployment type
- private Annotation defaultDeploymentType;
- // The default scope type
- private Annotation defaultScopeType;
- // Is the bean name defaulted
- private boolean beanNameDefaulted;
- // The supported scopes
- private Set<Class<? extends Annotation>> supportedScopes;
- // The required types
- private Set<Class<?>> requiredTypes;
- // The interceptor bindings
- private Set<Annotation> interceptorBindings;
-
- /**
- * Constructor
- *
- * @param sterotype The stereotype
- */
- public StereotypeModel(Class<T> sterotype)
- {
- super(sterotype);
- initDefaultDeploymentType();
- initDefaultScopeType();
- initBeanNameDefaulted();
- initSupportedScopes();
- initRequiredTypes();
- initInterceptorBindings();
- checkBindingTypes();
- }
-
- /**
- * Validates the binding types
- */
- private void checkBindingTypes()
- {
- Set<Annotation> bindingTypes = getAnnotatedAnnotation().getMetaAnnotations(BindingType.class);
- if (bindingTypes.size() > 0)
- {
- throw new DefinitionException("Cannot declare binding types on a stereotype " + getAnnotatedAnnotation());
- }
- }
-
- /**
- * Initializes the interceptor bindings
- */
- private void initInterceptorBindings()
- {
- interceptorBindings = getAnnotatedAnnotation().getMetaAnnotations(InterceptorBindingType.class);
- }
-
- /**
- * Initializes the supported scopes
- */
- private void initSupportedScopes()
- {
- this.supportedScopes = new HashSet<Class<? extends Annotation>>();
- Class<? extends Annotation>[] supportedScopes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).supportedScopes();
- if (supportedScopes.length > 0)
- {
- this.supportedScopes.addAll(Arrays.asList(supportedScopes));
- }
- }
-
- /**
- * Initializes the required types
- */
- private void initRequiredTypes()
- {
- this.requiredTypes = new HashSet<Class<?>>();
- Class<?>[] requiredTypes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).requiredTypes();
- if (requiredTypes.length > 0)
- {
- this.requiredTypes.addAll(Arrays.asList(requiredTypes));
- }
- }
-
- /**
- * Initializes the bean name defaulted
- */
- private void initBeanNameDefaulted()
- {
- if (getAnnotatedAnnotation().isAnnotationPresent(Named.class))
- {
- if (!"".equals(getAnnotatedAnnotation().getAnnotation(Named.class).value()))
- {
- throw new DefinitionException("Cannot specify a value for a @Named stereotype " + getAnnotatedAnnotation());
- }
- beanNameDefaulted = true;
- }
- }
-
- /**
- * Initializes the default scope type
- */
- private void initDefaultScopeType()
- {
- Set<Annotation> scopeTypes = getAnnotatedAnnotation().getMetaAnnotations(ScopeType.class);
- if (scopeTypes.size() > 1)
- {
- throw new DefinitionException("At most one scope type may be specified for " + getAnnotatedAnnotation());
- }
- else if (scopeTypes.size() == 1)
- {
- this.defaultScopeType = scopeTypes.iterator().next();
- }
- }
-
- /**
- * Initializes the default deployment type
- */
- private void initDefaultDeploymentType()
- {
- Set<Annotation> deploymentTypes = getAnnotatedAnnotation().getMetaAnnotations(DeploymentType.class);
- if (deploymentTypes.size() > 1)
- {
- throw new DefinitionException("At most one deployment type may be specified on " + getAnnotatedAnnotation());
- }
- else if (deploymentTypes.size() == 1)
- {
- this.defaultDeploymentType = deploymentTypes.iterator().next();
- }
- }
-
- /**
- * Get the default deployment type the stereotype specifies
- *
- * @return The default deployment type, or null if none is specified
- */
- public Annotation getDefaultDeploymentType()
- {
- return defaultDeploymentType;
- }
-
- /**
- * Get the default scope type the stereotype specifies
- *
- * @return The default scope type, or null if none is specified
- */
- public Annotation getDefaultScopeType()
- {
- return defaultScopeType;
- }
-
- /**
- * Get any interceptor bindings the the stereotype specifies
- *
- * @return The interceptor bindings, or an empty set if none are specified.
- */
- public Set<Annotation> getInterceptorBindings()
- {
- return interceptorBindings;
- }
-
- /**
- * Indicates if the bean name is defaulted
- *
- * @return True if defaulted, false otherwise
- */
- public boolean isBeanNameDefaulted()
- {
- return beanNameDefaulted;
- }
-
- /**
- * Gets the supported scopes
- *
- * @return A set of supported scopes, or an empty set if none are specified
- */
- public Set<Class<? extends Annotation>> getSupportedScopes()
- {
- return supportedScopes;
- }
-
- /**
- * Gets the required types
- *
- * @return A set of required types, or an empty set if none are specified
- */
- public Set<Class<?>> getRequiredTypes()
- {
- return requiredTypes;
- }
-
- /**
- * Gets the type
- *
- * @return The type
- */
- @Deprecated
- public Class<? extends Annotation> getStereotypeClass()
- {
- return getType();
- }
-
- /**
- * Gets a string representation of the stereotype
- *
- * @return The string representation
- */
- @Override
- public String toString()
- {
- return "Stereotype model with required types " + requiredTypes + " and supported scopes " + supportedScopes;
- }
-
- /**
- * Gets the meta-annotation type
- *
- * @return The Stereotype class
- */
- @Override
- protected Class<? extends Annotation> getMetaAnnotation()
- {
- return Stereotype.class;
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java (from rev 1263, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/metadata/StereotypeModel.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.Named;
+import javax.annotation.Stereotype;
+import javax.context.ScopeType;
+import javax.inject.BindingType;
+import javax.inject.DefinitionException;
+import javax.inject.DeploymentType;
+import javax.interceptor.InterceptorBindingType;
+
+/**
+ * A meta model for a stereotype, allows us to cache a stereotype and to
+ * validate it
+ *
+ * @author Pete Muir
+ *
+ */
+public class StereotypeModel<T extends Annotation> extends AnnotationModel<T>
+{
+ // The default deployment type
+ private Annotation defaultDeploymentType;
+ // The default scope type
+ private Annotation defaultScopeType;
+ // Is the bean name defaulted
+ private boolean beanNameDefaulted;
+ // The supported scopes
+ private Set<Class<? extends Annotation>> supportedScopes;
+ // The required types
+ private Set<Class<?>> requiredTypes;
+ // The interceptor bindings
+ private Set<Annotation> interceptorBindings;
+
+ /**
+ * Constructor
+ *
+ * @param sterotype The stereotype
+ */
+ public StereotypeModel(Class<T> sterotype)
+ {
+ super(sterotype);
+ initDefaultDeploymentType();
+ initDefaultScopeType();
+ initBeanNameDefaulted();
+ initSupportedScopes();
+ initRequiredTypes();
+ initInterceptorBindings();
+ checkBindingTypes();
+ }
+
+ /**
+ * Validates the binding types
+ */
+ private void checkBindingTypes()
+ {
+ Set<Annotation> bindingTypes = getAnnotatedAnnotation().getMetaAnnotations(BindingType.class);
+ if (bindingTypes.size() > 0)
+ {
+ throw new DefinitionException("Cannot declare binding types on a stereotype " + getAnnotatedAnnotation());
+ }
+ }
+
+ /**
+ * Initializes the interceptor bindings
+ */
+ private void initInterceptorBindings()
+ {
+ interceptorBindings = getAnnotatedAnnotation().getMetaAnnotations(InterceptorBindingType.class);
+ }
+
+ /**
+ * Initializes the supported scopes
+ */
+ private void initSupportedScopes()
+ {
+ this.supportedScopes = new HashSet<Class<? extends Annotation>>();
+ Class<? extends Annotation>[] supportedScopes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).supportedScopes();
+ if (supportedScopes.length > 0)
+ {
+ this.supportedScopes.addAll(Arrays.asList(supportedScopes));
+ }
+ }
+
+ /**
+ * Initializes the required types
+ */
+ private void initRequiredTypes()
+ {
+ this.requiredTypes = new HashSet<Class<?>>();
+ Class<?>[] requiredTypes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).requiredTypes();
+ if (requiredTypes.length > 0)
+ {
+ this.requiredTypes.addAll(Arrays.asList(requiredTypes));
+ }
+ }
+
+ /**
+ * Initializes the bean name defaulted
+ */
+ private void initBeanNameDefaulted()
+ {
+ if (getAnnotatedAnnotation().isAnnotationPresent(Named.class))
+ {
+ if (!"".equals(getAnnotatedAnnotation().getAnnotation(Named.class).value()))
+ {
+ throw new DefinitionException("Cannot specify a value for a @Named stereotype " + getAnnotatedAnnotation());
+ }
+ beanNameDefaulted = true;
+ }
+ }
+
+ /**
+ * Initializes the default scope type
+ */
+ private void initDefaultScopeType()
+ {
+ Set<Annotation> scopeTypes = getAnnotatedAnnotation().getMetaAnnotations(ScopeType.class);
+ if (scopeTypes.size() > 1)
+ {
+ throw new DefinitionException("At most one scope type may be specified for " + getAnnotatedAnnotation());
+ }
+ else if (scopeTypes.size() == 1)
+ {
+ this.defaultScopeType = scopeTypes.iterator().next();
+ }
+ }
+
+ /**
+ * Initializes the default deployment type
+ */
+ private void initDefaultDeploymentType()
+ {
+ Set<Annotation> deploymentTypes = getAnnotatedAnnotation().getMetaAnnotations(DeploymentType.class);
+ if (deploymentTypes.size() > 1)
+ {
+ throw new DefinitionException("At most one deployment type may be specified on " + getAnnotatedAnnotation());
+ }
+ else if (deploymentTypes.size() == 1)
+ {
+ this.defaultDeploymentType = deploymentTypes.iterator().next();
+ }
+ }
+
+ /**
+ * Get the default deployment type the stereotype specifies
+ *
+ * @return The default deployment type, or null if none is specified
+ */
+ public Annotation getDefaultDeploymentType()
+ {
+ return defaultDeploymentType;
+ }
+
+ /**
+ * Get the default scope type the stereotype specifies
+ *
+ * @return The default scope type, or null if none is specified
+ */
+ public Annotation getDefaultScopeType()
+ {
+ return defaultScopeType;
+ }
+
+ /**
+ * Get any interceptor bindings the the stereotype specifies
+ *
+ * @return The interceptor bindings, or an empty set if none are specified.
+ */
+ public Set<Annotation> getInterceptorBindings()
+ {
+ return interceptorBindings;
+ }
+
+ /**
+ * Indicates if the bean name is defaulted
+ *
+ * @return True if defaulted, false otherwise
+ */
+ public boolean isBeanNameDefaulted()
+ {
+ return beanNameDefaulted;
+ }
+
+ /**
+ * Gets the supported scopes
+ *
+ * @return A set of supported scopes, or an empty set if none are specified
+ */
+ public Set<Class<? extends Annotation>> getSupportedScopes()
+ {
+ return supportedScopes;
+ }
+
+ /**
+ * Gets the required types
+ *
+ * @return A set of required types, or an empty set if none are specified
+ */
+ public Set<Class<?>> getRequiredTypes()
+ {
+ return requiredTypes;
+ }
+
+ /**
+ * Gets the type
+ *
+ * @return The type
+ */
+ @Deprecated
+ public Class<? extends Annotation> getStereotypeClass()
+ {
+ return getType();
+ }
+
+ /**
+ * Gets a string representation of the stereotype
+ *
+ * @return The string representation
+ */
+ @Override
+ public String toString()
+ {
+ return "Stereotype model with required types " + requiredTypes + " and supported scopes " + supportedScopes;
+ }
+
+ /**
+ * Gets the meta-annotation type
+ *
+ * @return The Stereotype class
+ */
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
+ {
+ return Stereotype.class;
+ }
+
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Beans.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Beans.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Beans.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -21,9 +21,9 @@
import javax.inject.manager.Bean;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.metadata.MetaDataCache;
/**
* Helper class for bean inspection
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/context/PassivatingContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/context/PassivatingContextTest.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/context/PassivatingContextTest.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -5,7 +5,7 @@
import javax.context.RequestScoped;
import javax.context.SessionScoped;
-import org.jboss.webbeans.MetaDataCache;
+import org.jboss.webbeans.metadata.MetaDataCache;
import org.testng.annotations.Test;
public class PassivatingContextTest extends org.jboss.webbeans.test.unit.AbstractTest
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/definition/StereotypesTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/definition/StereotypesTest.java 2009-01-28 15:49:28 UTC (rev 1263)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/definition/StereotypesTest.java 2009-01-28 16:13:08 UTC (rev 1264)
@@ -4,7 +4,7 @@
import javax.context.RequestScoped;
-import org.jboss.webbeans.model.StereotypeModel;
+import org.jboss.webbeans.metadata.StereotypeModel;
import org.jboss.webbeans.test.unit.AbstractTest;
import org.testng.annotations.Test;
More information about the weld-commits
mailing list