[webbeans-commits] Webbeans SVN: r336 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: contexts and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Nov 20 04:58:12 EST 2008
Author: nickarls
Date: 2008-11-20 04:58:12 -0500 (Thu, 20 Nov 2008)
New Revision: 336
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PrivateContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SharedContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
Log:
javadoc, comment, toStrings
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 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,3 +1,20 @@
+/*
+ * 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;
@@ -45,11 +62,11 @@
/**
* Implementation of the Web Beans Manager.
*
- * Essentially a singleton for registering Beans, Contexts, Observers,
+ * Essentially a singleton for registering Beans, Contexts, Observers,
* Interceptors etc. as well as providing resolution
*
* @author Pete Muir
- *
+ *
*/
public class ManagerImpl implements Manager
{
@@ -63,6 +80,7 @@
private Set<Decorator> decorators;
private Set<Interceptor> interceptors;
+ @SuppressWarnings("unchecked")
public ManagerImpl()
{
this.metaDataCache = new MetaDataCache();
@@ -76,20 +94,23 @@
initContexts();
initStandardBeans();
}
-
+
/**
* Add any beans provided by the Web Beans RI to the registry
*/
protected void initStandardBeans()
{
- addBean( new SimpleBean<DefaultEnterpriseBeanLookup>( DefaultEnterpriseBeanLookup.class, this ) );
+ addBean(new SimpleBean<DefaultEnterpriseBeanLookup>(DefaultEnterpriseBeanLookup.class, this));
}
/**
* Set up the enabled deployment types, if none are specified by the user,
* the default @Production and @Standard are used
+ *
+ * @param enabledDeploymentTypes The enabled deployment types from
+ * web-beans.xml
*/
- protected void initEnabledDeploymentTypes(Class<? extends Annotation> ... enabledDeploymentTypes)
+ protected void initEnabledDeploymentTypes(Class<? extends Annotation>... enabledDeploymentTypes)
{
this.enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
if (enabledDeploymentTypes.length == 0)
@@ -112,8 +133,10 @@
/**
* Set up the contexts. By default, the built in contexts are set up, but a
- * mock ManagerImpl may override this method to allow tests to set up
- * other contexts
+ * mock ManagerImpl may override this method to allow tests to set up other
+ * contexts
+ *
+ * @param contexts Non-built-in contexts to add
*/
protected void initContexts(Context... contexts)
{
@@ -135,6 +158,11 @@
}
/**
+ * Registers a bean with the manager
+ *
+ * @param bean The bean to register
+ * @return A reference to manager
+ *
* @see javax.webbeans.manager.Manager#addBean(javax.webbeans.manager.Bean)
*/
public Manager addBean(Bean<?> bean)
@@ -150,10 +178,10 @@
/**
* Resolve the disposal method for the given producer method
- * @param <T>
- * @param apiType
- * @param bindingTypes
- * @return
+ *
+ * @param apiType The API type to match
+ * @param bindingTypes The binding types to match
+ * @return The set of matching disposal methods
*/
public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
{
@@ -161,28 +189,52 @@
}
/**
- * @see javax.webbeans.manager.Manager#resolveObservers(java.lang.Object, java.lang.annotation.Annotation[])
+ * Resolves observers for given event and bindings
+ *
+ * @param event The event to match
+ * @param bindings The binding types to match
+ * @return The set of matching observers
+ *
+ * @see javax.webbeans.manager.Manager#resolveObservers(java.lang.Object,
+ * java.lang.annotation.Annotation[])
*/
public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
{
- return (Set<Observer<T>>) eventBus.getObservers(event, bindings);
+ return eventBus.getObservers(event, bindings);
}
/**
* A strongly ordered list of enabled deployment types
+ *
+ * @return The ordered enabled deployment types known to the manager
*/
public List<Class<? extends Annotation>> getEnabledDeploymentTypes()
{
return enabledDeploymentTypes;
}
+
+ /**
+ * Returns the metadata cache
+ *
+ * @return The cache
+ *
+ * @see org.jboss.webbeans.MetaDataCache
+ */
public MetaDataCache getMetaDataCache()
{
return this.metaDataCache;
}
/**
- * @see javax.webbeans.manager.Manager#resolveByType(java.lang.Class, java.lang.annotation.Annotation[])
+ * Resolves beans by API type and binding types
+ *
+ * @param type The API type to match
+ * @param bindingTypes The binding types to match
+ * @return The set of matching beans
+ *
+ * @see javax.webbeans.manager.Manager#resolveByType(java.lang.Class,
+ * java.lang.annotation.Annotation[])
*/
public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindingTypes)
{
@@ -190,16 +242,27 @@
}
/**
- * @see javax.webbeans.manager.Manager#resolveByType(javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
+ * Resolves beans by API type literal and binding types
+ *
+ * @param type The API type literal to match
+ * @param bindingTypes The binding types to match
+ * @return The set of matching beans
+ *
+ * @see javax.webbeans.manager.Manager#resolveByType(javax.webbeans.TypeLiteral,
+ * java.lang.annotation.Annotation[])
*/
public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> type, Annotation... bindingTypes)
{
return resolveByType(new AnnotatedClassImpl<T>(type.getRawType(), type.getType(), bindingTypes), bindingTypes);
}
-
+
/**
- * Check the resolution request is valid, and then ask the resolver to
+ * Check the resolution request is valid, and then ask the resolver to
* perform the resolution
+ *
+ * @param element The item to resolve
+ * @param bindingTypes The binding types to match
+ * @return The set of matching beans
*/
public <T> Set<Bean<T>> resolveByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
{
@@ -218,20 +281,25 @@
}
/**
- * Wraps a collection of beans into a thread safe list.
- * Since this overwrites any existing list of beans in the manager,
- * this should only be done on startup and other controlled situations.
+ * Wraps a collection of beans into a thread safe list. Since this overwrites
+ * any existing list of beans in the manager, this should only be done on
+ * startup and other controlled situations.
*
+ * @param beans The set of beans to add
+ * @return A reference to the manager
*/
- public Manager setBeans(Set<AbstractBean<?, ?>> beans) {
+ public Manager setBeans(Set<AbstractBean<?, ?>> beans)
+ {
this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
resolver.clear();
initStandardBeans();
return this;
}
-
+
/**
* The beans registered with the Web Bean manager
+ *
+ * @return The list of known beans
*/
public List<Bean<?>> getBeans()
{
@@ -239,6 +307,11 @@
}
/**
+ * Adds a context
+ *
+ * @param context The context to add
+ * @return A reference to the manager
+ *
* @see javax.webbeans.manager.Manager#addContext(javax.webbeans.manager.Context)
*/
public Manager addContext(Context context)
@@ -254,6 +327,11 @@
}
/**
+ * Adds a decorator
+ *
+ * @param decorator The decorator to add
+ * @return A reference to the manager
+ *
* @see javax.webbeans.manager.Manager#addDecorator(javax.webbeans.manager.Decorator)
*/
public Manager addDecorator(Decorator decorator)
@@ -263,6 +341,11 @@
}
/**
+ * Adds an interceptor
+ *
+ * @param interceptor The interceptor to add
+ * @return A reference to the manager
+ *
* @see javax.webbeans.manager.Manager#addInterceptor(javax.webbeans.manager.Interceptor)
*/
public Manager addInterceptor(Interceptor interceptor)
@@ -272,7 +355,15 @@
}
/**
- * @see javax.webbeans.manager.Manager#addObserver(javax.webbeans.Observer, java.lang.Class, java.lang.annotation.Annotation[])
+ * Adds an observer for a given event type and binding types
+ *
+ * @param observer The observer to add
+ * @param eventType The event type to match
+ * @param bindings The bindings to match
+ * @return A reference to the manager
+ *
+ * @see javax.webbeans.manager.Manager#addObserver(javax.webbeans.Observer,
+ * java.lang.Class, java.lang.annotation.Annotation[])
*/
public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
@@ -281,8 +372,17 @@
}
/**
- * @see javax.webbeans.manager.Manager#addObserver(javax.webbeans.Observer, javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
+ * Adds an observer for a given event type literal and binding types
+ *
+ * @param observer The observer to add
+ * @param eventType The event type literal to match
+ * @param bindings The bindings to match
+ * @return A reference to the manager
+ *
+ * @see javax.webbeans.manager.Manager#addObserver(javax.webbeans.Observer,
+ * javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
*/
+ @SuppressWarnings("unchecked")
public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
// TODO Using the eventType TypeLiteral<T>, the Class<T> object must be
@@ -292,7 +392,13 @@
}
/**
- * @see javax.webbeans.manager.Manager#fireEvent(java.lang.Object, java.lang.annotation.Annotation[])
+ * Fires an event object with given event object for given bindings
+ *
+ * @param event The event object to pass along
+ * @param bindings The binding types to match
+ *
+ * @see javax.webbeans.manager.Manager#fireEvent(java.lang.Object,
+ * java.lang.annotation.Annotation[])
*/
public void fireEvent(Object event, Annotation... bindings)
{
@@ -310,6 +416,12 @@
}
/**
+ * Gets an active context of the given scope. Throws an exception if there
+ * are no active contexts found or if there are too many matches
+ *
+ * @param scopeType The scope to match
+ * @return A single active context of the given scope
+ *
* @see javax.webbeans.manager.Manager#getContext(java.lang.Class)
*/
public Context getContext(Class<? extends Annotation> scopeType)
@@ -335,12 +447,18 @@
{
throw new IllegalArgumentException("More than one context active for scope type " + scopeType.getName());
}
- return activeContexts.get(0);
+ return activeContexts.iterator().next();
}
/**
+ * Returns an instance of a bean
+ *
+ * @param bean The bean to instantiate
+ * @return An instance of the bean
+ *
* @see javax.webbeans.manager.Manager#getInstance(javax.webbeans.manager.Bean)
*/
+ @SuppressWarnings("unchecked")
public <T> T getInstance(Bean<T> bean)
{
try
@@ -362,6 +480,12 @@
}
/**
+ * Gets an instance by name, returning null if none is found and throwing an
+ * exception if too many beans match
+ *
+ * @param name The name to match
+ * @return An instance of the bean
+ *
* @see javax.webbeans.manager.Manager#getInstanceByName(java.lang.String)
*/
public Object getInstanceByName(String name)
@@ -382,7 +506,14 @@
}
/**
- * @see javax.webbeans.manager.Manager#getInstanceByType(java.lang.Class, java.lang.annotation.Annotation[])
+ * Returns an instance by API type and binding types
+ *
+ * @param type The API type to match
+ * @param bindingTypes The binding types to match
+ * @return An instance of the bean
+ *
+ * @see javax.webbeans.manager.Manager#getInstanceByType(java.lang.Class,
+ * java.lang.annotation.Annotation[])
*/
public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
{
@@ -390,7 +521,14 @@
}
/**
- * @see javax.webbeans.manager.Manager#getInstanceByType(javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
+ * Returns an instance by type literal and binding types
+ *
+ * @param type The type to match
+ * @param bindingTypes The binding types to match
+ * @return An instance of the bean
+ *
+ * @see javax.webbeans.manager.Manager#getInstanceByType(javax.webbeans.TypeLiteral,
+ * java.lang.annotation.Annotation[])
*/
public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
{
@@ -401,6 +539,9 @@
* Resolve an instance, verify that the resolved bean can be instantiated,
* and return
*
+ * @param element The annotated item to match
+ * @param bindingTypes The binding types to match
+ * @return An instance of the bean
*/
public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation... bindingTypes)
{
@@ -428,7 +569,15 @@
}
/**
- * @see javax.webbeans.manager.Manager#removeObserver(javax.webbeans.Observer, java.lang.Class, java.lang.annotation.Annotation[])
+ * Removes an observer
+ *
+ * @param observer The observer to remove
+ * @param eventType The event type to match
+ * @param bindings the binding types to match
+ * @return A reference to the manager
+ *
+ * @see javax.webbeans.manager.Manager#removeObserver(javax.webbeans.Observer,
+ * java.lang.Class, java.lang.annotation.Annotation[])
*/
public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
@@ -437,8 +586,17 @@
}
/**
- * @see javax.webbeans.manager.Manager#removeObserver(javax.webbeans.Observer, javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
+ * Removes an observer
+ *
+ * @param observer The observer to remove
+ * @param eventType The event type to match
+ * @param bindings the binding types to match
+ * @return A reference to the manager
+ *
+ * @see javax.webbeans.manager.Manager#removeObserver(javax.webbeans.Observer,
+ * javax.webbeans.TypeLiteral, java.lang.annotation.Annotation[])
*/
+ @SuppressWarnings("unchecked")
public <T> Manager removeObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
// TODO The Class<T> for the event type must be retrieved from the
@@ -448,6 +606,11 @@
}
/**
+ * Resolves a set of beans based on their name
+ *
+ * @param The name to match
+ * @return The set of matching beans
+ *
* @see javax.webbeans.manager.Manager#resolveByName(java.lang.String)
*/
public Set<Bean<?>> resolveByName(String name)
@@ -456,26 +619,40 @@
}
/**
- * @see javax.webbeans.manager.Manager#resolveDecorators(java.util.Set, java.lang.annotation.Annotation[])
+ * Resolves a list of decorators based on API types and binding types
+ *
+ * @param types The set of API types to match
+ * @param bindingTypes The binding types to match
+ * @return A list of matching decorators
+ *
+ * @see javax.webbeans.manager.Manager#resolveDecorators(java.util.Set,
+ * java.lang.annotation.Annotation[])
*/
public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindingTypes)
{
- // TODO Auto-generated method stub
- return null;
+ return resolver.resolveDecorators(types, bindingTypes);
}
/**
- * @see javax.webbeans.manager.Manager#resolveInterceptors(javax.webbeans.manager.InterceptionType, java.lang.annotation.Annotation[])
+ * Resolves a list of interceptors based on interception type and interceptor
+ * bindings
+ *
+ * @param type The interception type to resolve
+ * @param interceptorBindings The binding types to match
+ * @return A list of matching interceptors
+ *
+ * @see javax.webbeans.manager.Manager#resolveInterceptors(javax.webbeans.manager.InterceptionType,
+ * java.lang.annotation.Annotation[])
*/
public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
{
- // TODO Auto-generated method stub
- return null;
+ return resolver.resolveInterceptors(type, interceptorBindings);
}
-
+
/**
* Get the web bean resolver
- * @return
+ *
+ * @return The resolver
*/
public Resolver getResolver()
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,3 +1,20 @@
+/*
+ * 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;
@@ -14,18 +31,17 @@
public class MetaDataCache
{
-
- @SuppressWarnings("unchecked")
+
private abstract class AnnotationModelMap<T extends AnnotationModel<?>> extends ForwardingMap<Class<? extends Annotation>, T>
{
Map<Class<? extends Annotation>, T> delegate;
-
+
public AnnotationModelMap()
{
delegate = new HashMap<Class<? extends Annotation>, T>();
}
-
+
public <S extends Annotation> T putIfAbsent(Class<S> key)
{
if (!containsKey(key))
@@ -36,111 +52,111 @@
}
return (T) super.get(key);
}
-
- protected abstract <S extends Annotation> T createAnnotationModel(Class<S> type);
-
+
+ protected abstract <S extends Annotation> T createAnnotationModel(Class<S> type);
+
@Override
protected Map<Class<? extends Annotation>, T> delegate()
{
return delegate;
}
-
+
}
-
+
@SuppressWarnings("unchecked")
private class ScopeModelMap extends AnnotationModelMap<ScopeModel<?>>
{
-
+
@Override
public <S extends Annotation> ScopeModel<S> putIfAbsent(Class<S> key)
{
return (ScopeModel<S>) super.putIfAbsent(key);
}
-
+
@Override
protected <S extends Annotation> ScopeModel<?> createAnnotationModel(Class<S> type)
{
return new ScopeModel<S>(type);
}
-
+
}
-
+
@SuppressWarnings("unchecked")
private class BindingTypeModelMap extends AnnotationModelMap<BindingTypeModel<?>>
{
-
+
@Override
public <S extends Annotation> BindingTypeModel<S> putIfAbsent(Class<S> key)
{
return (BindingTypeModel<S>) super.putIfAbsent(key);
}
-
+
@Override
protected <S extends Annotation> BindingTypeModel<?> createAnnotationModel(Class<S> type)
{
return new BindingTypeModel<S>(type);
}
-
+
}
-
+
private class EjbMetaDataMap extends ForwardingMap<Class<?>, EjbMetaData<?>>
{
-
+
private Map<Class<?>, EjbMetaData<?>> delegate;
public EjbMetaDataMap()
{
delegate = new HashMap<Class<?>, EjbMetaData<?>>();
}
-
+
@Override
protected Map<Class<?>, EjbMetaData<?>> delegate()
{
return delegate;
}
-
+
+ @SuppressWarnings("unchecked")
public <T> EjbMetaData<T> putIfAbsent(Class<T> key)
{
if (!containsKey(key))
{
- EjbMetaData<T> ejbMetaData = new EjbMetaData<T>(key);
+ EjbMetaData<T> ejbMetaData = new EjbMetaData<T>(key);
super.put(key, ejbMetaData);
return ejbMetaData;
}
return (EjbMetaData<T>) super.get(key);
}
-
+
}
-
+
private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
-
+
private ScopeModelMap scopes = new ScopeModelMap();
-
+
private BindingTypeModelMap bindingTypes = new BindingTypeModelMap();
-
+
private EjbMetaDataMap ejbMetaDataMap = new EjbMetaDataMap();
-
public void addStereotype(StereotypeModel<?> stereotype)
{
stereotypes.put(stereotype.getType(), stereotype);
}
-
+
public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
{
return stereotypes.get(annotationType);
}
-
+
public <T extends Annotation> ScopeModel<T> getScopeModel(Class<T> scopeType)
{
return scopes.putIfAbsent(scopeType);
}
-
+
public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(Class<T> bindingType)
{
return bindingTypes.putIfAbsent(bindingType);
}
-
+
public <T> EjbMetaData<T> getEjbMetaData(Class<T> clazz)
{
return ejbMetaDataMap.putIfAbsent(clazz);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,3 +1,20 @@
+/*
+ * 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;
@@ -13,6 +30,9 @@
import javax.webbeans.NullableDependencyException;
import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Decorator;
+import javax.webbeans.manager.InterceptionType;
+import javax.webbeans.manager.Interceptor;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.ForwardingAnnotatedItem;
@@ -23,20 +43,19 @@
/**
* Implementation of Web Beans type safe and name based bean resolution
+ *
* @author Pete Muir
- *
*/
public class Resolver
{
/**
- * Extension of an element which bases equality not only on type, but also
- * on binding type
- *
+ * 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>
{
-
+
@Override
public boolean equals(Object other)
{
@@ -44,25 +63,24 @@
if (other instanceof AnnotatedItem)
{
AnnotatedItem<?, ?> that = (AnnotatedItem<?, ?>) other;
- return delegate().isAssignableFrom(that) &&
- that.getBindingTypes().equals(this.getBindingTypes());
+ return delegate().isAssignableFrom(that) && that.getBindingTypes().equals(this.getBindingTypes());
}
else
{
return false;
}
}
-
+
@Override
public int hashCode()
{
return delegate().hashCode();
}
-
+
}
-
+
// TODO Why can't we generify Set?
-
+
/**
* Type safe map for caching annotation metadata
*/
@@ -71,18 +89,17 @@
{
private Map<AnnotatedItem<?, ?>, Set> delegate;
-
+
public AnnotatedItemMap()
{
delegate = new HashMap<AnnotatedItem<?, ?>, Set>();
}
-
- @SuppressWarnings("unchecked")
+
public <T> Set<Bean<T>> get(AnnotatedItem<T, ?> key)
{
return (Set<Bean<T>>) super.get(key);
}
-
+
@Override
protected Map<AnnotatedItem<?, ?>, Set> delegate()
{
@@ -93,27 +110,27 @@
private AnnotatedItemMap resolvedInjectionPoints;
private Set<AnnotatedItem<?, ?>> injectionPoints;
-
+
private Map<String, Set<Bean<?>>> resolvedNames;
-
+
private ManagerImpl manager;
-
+
public Resolver(ManagerImpl manager)
{
this.manager = manager;
- this.injectionPoints = new HashSet<AnnotatedItem<?,?>>();
+ this.injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
this.resolvedInjectionPoints = new AnnotatedItemMap();
}
-
+
/**
- * Add multiple injection points for later resolving using
+ * Add multiple injection points for later resolving using
* {@link #registerInjectionPoint(AnnotatedItem)}. Useful during bootstrap.
*/
public void addInjectionPoints(Collection<AnnotatedItem<?, ?>> elements)
{
injectionPoints.addAll(elements);
}
-
+
private <T, S> void registerInjectionPoint(final AnnotatedItem<T, S> element)
{
Set<Bean<?>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans(), manager.getMetaDataCache()), manager.getEnabledDeploymentTypes());
@@ -127,18 +144,18 @@
}
}
}
- resolvedInjectionPoints.put(new ResolvableAnnotatedItem<T, S>()
- {
+ resolvedInjectionPoints.put(new ResolvableAnnotatedItem<T, S>()
+ {
@Override
public AnnotatedItem<T, S> delegate()
{
return element;
}
-
+
}, beans);
}
-
+
/**
* Reset all cached injection points. You must reset all cached injection
* points when you add a bean to the manager
@@ -148,9 +165,10 @@
resolvedInjectionPoints = new AnnotatedItemMap();
resolvedNames = new HashMap<String, Set<Bean<?>>>();
}
-
+
/**
- * Resolve all injection points added using {@link #addInjectionPoints(Collection)}
+ * Resolve all injection points added using
+ * {@link #addInjectionPoints(Collection)}
*/
public void resolveInjectionPoints()
{
@@ -159,10 +177,11 @@
registerInjectionPoint(injectable);
}
}
-
+
/**
* Get the possible beans for the given element
*/
+ @SuppressWarnings("unchecked")
public <T, S> Set<Bean<T>> get(final AnnotatedItem<T, S> key)
{
Set<Bean<T>> beans = new HashSet<Bean<T>>();
@@ -175,9 +194,9 @@
{
return key;
}
-
+
};
-
+
// TODO We don't need this I think
if (element.getType().equals(Object.class))
{
@@ -194,7 +213,7 @@
}
return Collections.unmodifiableSet(beans);
}
-
+
/**
* Get the possible beans for the given name
*/
@@ -210,18 +229,18 @@
beans = new HashSet<Bean<?>>();
for (Bean<?> bean : manager.getBeans())
{
- if ( (bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
+ if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
{
beans.add(bean);
}
}
beans = retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
resolvedNames.put(name, beans);
-
+
}
return Collections.unmodifiableSet(beans);
}
-
+
private static Set<Bean<?>> retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
{
if (beans.size() > 0)
@@ -236,7 +255,7 @@
if (possibleDeploymentTypes.size() > 0)
{
Class<? extends Annotation> highestPrecedencePossibleDeploymentType = possibleDeploymentTypes.last();
-
+
for (Bean<?> bean : beans)
{
if (bean.getDeploymentType().equals(highestPrecedencePossibleDeploymentType))
@@ -252,7 +271,7 @@
return beans;
}
}
-
+
private static Set<Bean<?>> getMatchingBeans(AnnotatedItem<?, ?> element, List<Bean<?>> beans, MetaDataCache metaDataCache)
{
Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
@@ -265,7 +284,7 @@
}
return resolvedBeans;
}
-
+
private static boolean containsAllBindingBindingTypes(AnnotatedItem<?, ?> element, Set<Annotation> bindingTypes, MetaDataCache metaDataCache)
{
for (Annotation bindingType : element.getBindingTypes())
@@ -294,4 +313,16 @@
return true;
}
+ public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation[] bindingTypes)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation[] interceptorBindings)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -26,7 +26,9 @@
import javax.webbeans.manager.Manager;
/**
- * Base for the Context implementations
+ * Base for the Context implementations. Delegates calls to the abstract
+ * getBeanMap and getActive to allow for different implementations (storage
+ * types and ThreadLocal vs. shared)
*
* @author Nicklas Karlsson
* @author Pete Muir
@@ -36,7 +38,7 @@
*/
public abstract class AbstractContext implements Context
{
-
+
private Class<? extends Annotation> scopeType;
public AbstractContext(Class<? extends Annotation> scopeType)
@@ -48,10 +50,9 @@
* Get the bean if it exists in the contexts.
*
* @param create If true, a new instance of the bean will be created if none
- * exists
- *
+ * exists
+ * @return An instance of the bean
* @throws ContextNotActiveException if the context is not active
- *
*/
public <T> T get(Bean<T> bean, boolean create)
{
@@ -77,6 +78,8 @@
/**
* Get the scope the context is for
+ *
+ * @return The scope type
*/
public Class<? extends Annotation> getScopeType()
{
@@ -85,21 +88,24 @@
/**
* Return true if the context is active
+ *
+ * @return The active state
*/
public boolean isActive()
{
return getActive().get();
}
-
- /**
+
+ /**
* Set the context active, internal API for WBRI
*
* @param active The new state
*/
- public void setActive(boolean active) {
+ public void setActive(boolean active)
+ {
getActive().set(active);
}
-
+
// TODO Do we need this
private <T> void destroy(Manager manager, Bean<T> bean)
{
@@ -114,9 +120,29 @@
destroy(manager, bean);
}
getBeanMap().clear();
- }
+ }
+
+ /**
+ * A method that should return the actual bean map implementation
+ *
+ * @return The actual bean map
+ */
+ protected abstract BeanMap getBeanMap();
- protected abstract BeanMap getBeanMap();
+ /**
+ * A method that should return the actual atomic boolean instance
+ *
+ * @return The active boolean
+ */
protected abstract AtomicBoolean getActive();
+ @Override
+ public String toString()
+ {
+ return
+ "Context type: " + getScopeType().getName() +
+ "\nActive: " + getActive().toString() +
+ "\nBeans: " + getBeanMap().toString();
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -23,20 +23,15 @@
* The Application context
*
* @author Nicklas Karlsson
- *
+ *
* @see org.jboss.webbeans.contexts.ApplicationContext
*/
-public class ApplicationContext extends SharedContext {
+public class ApplicationContext extends SharedContext
+{
public ApplicationContext()
{
super(ApplicationScoped.class);
}
-
- @Override
- public String toString()
- {
- return "Application context";
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,27 +1,27 @@
/*
-* 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.
-*/
+ * 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.contexts;
import javax.webbeans.manager.Bean;
/**
- * Interface for different implementations of Bean to Bean instance
- * storage. Used primarily by the contexts.
+ * Interface for different implementations of Bean to Bean instance storage.
+ * Used primarily by the contexts.
*
* @author Nicklas Karlsson
*
@@ -31,19 +31,17 @@
public interface BeanMap
{
/**
- * Gets an instance of a bean from the storage.
+ * Gets an instance of a bean from the storage.
*
* @param bean The bean whose instance to return
- *
* @return The instance. Null if not found
*/
public abstract <T extends Object> T get(Bean<? extends T> bean);
-
+
/**
* Removes an instance of a bean from the storage
- *
- * @param bean The bean whose instance to remove
*
+ * @param bean The bean whose instance to remove
* @return The removed instance. Null if not found in storage.
*/
public abstract <T extends Object> T remove(Bean<? extends T> bean);
@@ -52,21 +50,19 @@
* Clears the storage of any bean instances
*/
public abstract void clear();
-
+
/**
* Returns an Iterable over the current keys in the storage
*
* @return An Iterable over the keys in the storage
*/
public abstract Iterable<Bean<? extends Object>> keySet();
-
+
/**
* Adds a bean instance to the storage
*
* @param bean The bean type. Used as key
- *
* @param instance The instance to add
- *
* @return The instance added
*/
public abstract <T> void put(Bean<? extends T> bean, T instance);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,3 +1,20 @@
+/*
+ * 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.contexts;
import java.lang.annotation.Annotation;
@@ -4,15 +21,21 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.webbeans.manager.Context;
import com.google.common.collect.ForwardingMap;
-public class ContextMap extends
- ForwardingMap<Class<? extends Annotation>, List<Context>>
+/**
+ * A map from a scope to a list of contexts
+ *
+ * @author Nicklas Karlsson
+ * @author Pete Muir
+ *
+ */
+public class ContextMap extends ForwardingMap<Class<? extends Annotation>, List<Context>>
{
-
private Map<Class<? extends Annotation>, List<Context>> delegate;
public ContextMap()
@@ -20,19 +43,52 @@
delegate = new HashMap<Class<? extends Annotation>, List<Context>>();
}
+ /**
+ * Gets a list of contexts for a give scope type
+ *
+ * @param key The scope type class
+ * @return The list of contexts (null if none found)
+ */
public List<Context> get(Class<? extends Annotation> key)
{
return (List<Context>) super.get(key);
}
+ /**
+ * Gets the dependent context
+ *
+ * @param scopeType The scope type to get
+ * @return The dependent context
+ */
public DependentContext getBuiltInContext(Class<? extends Annotation> scopeType)
{
+ // TODO Why can we request any scopetype and the cast it to dependent?
return (DependentContext) get(scopeType).iterator().next();
}
+ /**
+ * Returns the delegate of the forwarding map
+ *
+ * @return the delegate
+ */
@Override
protected Map<Class<? extends Annotation>, List<Context>> delegate()
{
return delegate;
}
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Known scope types: " + delegate.size());
+ for (Entry<Class<? extends Annotation>, List<Context>> entry : delegate.entrySet())
+ {
+ for (Context context : entry.getValue())
+ {
+ buffer.append(context.toString());
+ }
+ }
+ return buffer.toString();
+ }
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -24,17 +24,12 @@
*
* @author Nicklas Karlsson
*/
-public class ConversationContext extends PrivateContext {
+public class ConversationContext extends PrivateContext
+{
public ConversationContext()
{
super(ConversationScoped.class);
}
-
- @Override
- public String toString()
- {
- return "Conversation context";
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -36,6 +36,12 @@
setActive(false);
}
+ /**
+ * Overriden method always creating a new instance
+ *
+ * @param bean The bean to create
+ * @param create Should a new one be created
+ */
@Override
public <T> T get(Bean<T> bean, boolean create)
{
@@ -45,11 +51,6 @@
}
// Dependent contexts don't really use any BeanMap storage
return create == false ? null : bean.create();
- }
-
- @Override
- public String toString()
- {
- return "Dependent context";
- }
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PrivateContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PrivateContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PrivateContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -45,12 +45,18 @@
active.set(new AtomicBoolean(true));
}
+ /**
+ * Delegates to a ThreadLocal instance
+ */
@Override
protected AtomicBoolean getActive()
{
return active.get();
}
+ /**
+ * Delegates to a ThreadLocal instance
+ */
@Override
protected BeanMap getBeanMap()
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -32,9 +32,4 @@
super(RequestScoped.class);
}
- @Override
- public String toString()
- {
- return "Request context";
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -38,7 +38,7 @@
public class SessionBeanMap implements BeanMap
{
private static LogProvider log = Logging.getLogProvider(SessionBeanMap.class);
-
+
private HttpSession session;
private ManagerImpl manager;
private String keyPrefix;
@@ -80,7 +80,6 @@
* the Bean in the Manager bean list.
*
* @param bean The bean to generate a key for.
- *
* @return A unique key;
*/
private String getBeanKey(Bean<?> bean)
@@ -96,6 +95,7 @@
* (null if not found in the session).
*
* @param bean The bean to get from the session
+ * @return An instance of the bean
*/
@SuppressWarnings("unchecked")
public <T> T get(Bean<? extends T> bean)
@@ -115,6 +115,7 @@
* in the first place or not.
*
* @param bean The bean whose instance to remove.
+ * @return The instance removed
*/
public <T> T remove(Bean<? extends T> bean)
{
@@ -185,7 +186,6 @@
* the instance in the session under that key.
*
* @param bean The bean to use as key
- *
* @param instance The bean instance to add
*/
public <T> void put(Bean<? extends T> bean, T instance)
@@ -195,16 +195,18 @@
session.setAttribute(key, instance);
log.trace("Stored bean " + bean + " under key " + key + " in session");
}
-
+
@SuppressWarnings("unchecked")
@Override
- public String toString() {
+ public String toString()
+ {
StringBuffer buffer = new StringBuffer();
List<Bean<?>> beans = (List) keySet();
buffer.append(beans.size() + " found in session");
- for (Bean<?> bean : beans) {
+ for (Bean<?> bean : beans)
+ {
Object instance = get(bean);
- buffer.append(getBeanKey(bean) + ": " + instance);
+ buffer.append(getBeanKey(bean) + ": " + instance + "\n");
}
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,29 +1,26 @@
/*
-* 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.
-*/
+ * 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.contexts;
import javax.servlet.http.HttpSession;
import javax.webbeans.SessionScoped;
-import org.apache.log4j.Logger;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.bootstrap.Bootstrap;
-import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -32,10 +29,11 @@
*
* @author Nicklas Karlsson
*/
-public class SessionContext extends PrivateContext {
+public class SessionContext extends PrivateContext
+{
private static LogProvider log = Logging.getLogProvider(SessionContext.class);
-
+
public SessionContext(ManagerImpl manager)
{
super(SessionScoped.class);
@@ -43,24 +41,15 @@
beans.set(new SessionBeanMap(manager, getScopeType().getName() + "#"));
log.trace("Created session context");
}
-
+
/**
* Sets the session in the session bean map
*
* @param session The session to set
*/
- public void setSession(HttpSession session) {
- ((SessionBeanMap)getBeanMap()).setSession(session);
- }
-
- @Override
- public String toString()
+ public void setSession(HttpSession session)
{
- return
- "Session context:\n" +
- "Active: " + getActive().toString() +
- "Beans: " + getBeanMap().toString();
- }
-
+ ((SessionBeanMap) getBeanMap()).setSession(session);
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SharedContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SharedContext.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SharedContext.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,19 +1,19 @@
/*
-* 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.
-*/
+ * 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.contexts;
@@ -21,9 +21,9 @@
import java.util.concurrent.atomic.AtomicBoolean;
/**
- * The abstraction of a shared context with common beans but
- * with a private active state
- *
+ * The abstraction of a shared context with common beans but with a private
+ * active state
+ *
* @author Nicklas Karlsson
*
* @see org.jboss.webbeans.contexts.ApplicationContext
@@ -41,12 +41,18 @@
active.set(new AtomicBoolean(true));
}
+ /**
+ * Delegates to the ThreadLocal
+ */
@Override
protected AtomicBoolean getActive()
{
return active.get();
}
+ /**
+ * Delegates to the map implementation
+ */
@Override
protected BeanMap getBeanMap()
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java 2008-11-20 09:37:12 UTC (rev 335)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java 2008-11-20 09:58:12 UTC (rev 336)
@@ -1,24 +1,26 @@
/*
-* 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.
-*/
+ * 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.contexts;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.webbeans.manager.Bean;
@@ -32,7 +34,6 @@
*/
public class SimpleBeanMap extends ForwardingMap<Bean<? extends Object>, Object> implements BeanMap
{
-
protected Map<Bean<? extends Object>, Object> delegate;
public SimpleBeanMap()
@@ -40,35 +41,80 @@
delegate = new ConcurrentHashMap<Bean<? extends Object>, Object>();
}
+ /**
+ * Gets an instance from the map
+ *
+ * @param The bean to look for
+ * @return An instance, if found
+ */
@SuppressWarnings("unchecked")
public <T extends Object> T get(Bean<? extends T> bean)
{
return (T) super.get(bean);
}
+ /**
+ * Gets the delegate for the map
+ *
+ * @return The delegate
+ */
@Override
public Map<Bean<? extends Object>, Object> delegate()
{
return delegate;
}
+ /**
+ * Removed a instance from the map
+ *
+ * @param bean the bean to remove
+ * @return The instance removed
+ */
@SuppressWarnings("unchecked")
public <T extends Object> T remove(Bean<? extends T> bean)
{
return (T) super.remove(bean);
}
-
- public void clear() {
+
+ /**
+ * Clears the map
+ */
+ public void clear()
+ {
delegate.clear();
}
-
- public Set<Bean<? extends Object>> keySet() {
+
+ /**
+ * Returns the beans contained in the map
+ *
+ * @return The beans present
+ */
+ public Set<Bean<? extends Object>> keySet()
+ {
return delegate.keySet();
}
-
+
+ /**
+ * Puts a bean instance under the bean key in the map
+ *
+ * @param bean The bean
+ * @param instance the instance
+ */
public <T> void put(Bean<? extends T> bean, T instance)
{
delegate.put(bean, instance);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(delegate.size() + " found in session\n");
+ for (Entry<Bean<? extends Object>, Object> entry : delegate.entrySet()) {
+ buffer.append(entry.getKey().toString() + ": " + entry.getValue().toString() + "\n");
+ }
+ return buffer.toString();
+ }
+
}
\ No newline at end of file
More information about the weld-commits
mailing list