Author: pete.muir(a)jboss.org
Date: 2008-12-07 07:13:21 -0500 (Sun, 07 Dec 2008)
New Revision: 431
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/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
Log:
Make metadatacache a static singleton
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-12-07
12:07:38 UTC (rev 430)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -73,7 +73,6 @@
public static final String JNDI_KEY = "java:comp/Manager";
private List<Class<? extends Annotation>> enabledDeploymentTypes;
- private MetaDataCache metaDataCache;
private EventManager eventManager;
private Resolver resolver;
private ContextMap contextMap;
@@ -85,7 +84,6 @@
@SuppressWarnings("unchecked")
public ManagerImpl()
{
- this.metaDataCache = new MetaDataCache();
this.beans = new CopyOnWriteArrayList<Bean<?>>();
this.eventManager = new EventManager(this);
this.resolver = new Resolver(this);
@@ -191,18 +189,6 @@
}
/**
- * Returns the metadata cache
- *
- * @return The cache
- *
- * @see org.jboss.webbeans.MetaDataCache
- */
- public MetaDataCache getMetaDataCache()
- {
- return this.metaDataCache;
- }
-
- /**
* Resolves beans by API type and binding types
*
* @param type The API type to match
@@ -244,7 +230,7 @@
{
for (Annotation annotation : element.getAnnotations())
{
- if (!metaDataCache.getBindingTypeModel(annotation.annotationType()).isValid())
+ if
(!MetaDataCache.instance().getBindingTypeModel(annotation.annotationType()).isValid())
{
throw new IllegalArgumentException("Not a binding type " +
annotation);
}
@@ -446,7 +432,7 @@
try
{
contextMap.getBuiltInContext(Dependent.class).setActive(true);
- if (getMetaDataCache().getScopeModel(bean.getScopeType()).isNormal())
+ if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
return (T) proxyPool.getClientProxy(bean);
}
@@ -545,7 +531,7 @@
else
{
Bean<T> bean = beans.iterator().next();
- if (getMetaDataCache().getScopeModel(bean.getScopeType()).isNormal() &&
!element.isProxyable())
+ if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal()
&& !element.isProxyable())
{
throw new UnproxyableDependencyException(element + "Unable to
proxy");
}
@@ -651,7 +637,7 @@
StringBuilder buffer = new StringBuilder();
buffer.append(Strings.collectionToString("Enabled deployment types: ",
getEnabledDeploymentTypes()));
buffer.append(eventManager.toString() + "\n");
- buffer.append(metaDataCache.toString() + "\n");
+ buffer.append(MetaDataCache.instance().toString() + "\n");
buffer.append(resolver.toString() + "\n");
buffer.append(contextMap.toString() + "\n");
buffer.append(proxyPool.toString() + "\n");
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-12-07
12:07:38 UTC (rev 430)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -30,6 +30,18 @@
public class MetaDataCache
{
+ private static MetaDataCache instance;
+
+ public static MetaDataCache instance()
+ {
+ return instance;
+ }
+
+ static
+ {
+ instance = new MetaDataCache();
+ }
+
private ConcurrentCache<Class<? extends Annotation>,
StereotypeModel<?>> stereotypes = new ConcurrentCache<Class<? extends
Annotation>, StereotypeModel<?>>();
private ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>>
scopes = new ConcurrentCache<Class<? extends Annotation>,
ScopeModel<?>>();
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-12-07
12:07:38 UTC (rev 430)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -270,10 +270,9 @@
private boolean containsAllBindingBindingTypes(AnnotatedItem<?, ?> element,
Set<Annotation> bindingTypes)
{
- MetaDataCache metaDataCache = manager.getMetaDataCache();
for (Annotation bindingType : element.getBindingTypes())
{
- BindingTypeModel<?> bindingTypeModel =
metaDataCache.getBindingTypeModel(bindingType.annotationType());
+ BindingTypeModel<?> bindingTypeModel =
MetaDataCache.instance().getBindingTypeModel(bindingType.annotationType());
if (bindingTypeModel.getNonBindingTypes().size() > 0)
{
boolean matchFound = false;
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 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -121,7 +121,7 @@
*/
protected void init()
{
- mergedStereotypes = new MergedStereotypes<T,
E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class),
manager.getMetaDataCache());
+ mergedStereotypes = new MergedStereotypes<T,
E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class));
initType();
initPrimitive();
log.debug("Building Web Bean bean metadata for " + getType());
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -32,6 +32,7 @@
import javax.webbeans.manager.Manager;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.ejb.EJB;
import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.introspector.AnnotatedField;
@@ -71,7 +72,7 @@
protected void init()
{
super.init();
- ejbMetaData = manager.getMetaDataCache().getEjbMetaData(getType());
+ ejbMetaData = MetaDataCache.instance().getEjbMetaData(getType());
initRemoveMethod();
initInjectionPoints();
checkEnterpriseBeanTypeAllowed();
@@ -139,14 +140,14 @@
}
if (!isDefinedInXml())
{
- if
(!manager.getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
+ if
(!MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("Annotation defined specializing EJB must
have EJB superclass");
}
}
else
{
- if
(manager.getMetaDataCache().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
+ if
(MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("XML defined specializing EJB must have
annotation defined EJB implementation");
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -49,13 +49,13 @@
*
* @param stereotypeAnnotations The stereotypes to merge
*/
- public MergedStereotypes(Set<Annotation> stereotypeAnnotations, MetaDataCache
metaDataCache)
+ public MergedStereotypes(Set<Annotation> stereotypeAnnotations)
{
possibleDeploymentTypes = new AnnotationMap();
possibleScopeTypes = new HashSet<Annotation>();
requiredTypes = new HashSet<Class<?>>();
supportedScopes = new HashSet<Class<? extends Annotation>>();
- merge(stereotypeAnnotations, metaDataCache);
+ merge(stereotypeAnnotations);
}
/**
@@ -63,12 +63,12 @@
*
* @param stereotypeAnnotations The stereotype annotations
*/
- protected void merge(Set<Annotation> stereotypeAnnotations, MetaDataCache
metaDataCache)
+ protected void merge(Set<Annotation> stereotypeAnnotations)
{
for (Annotation stereotypeAnnotation : stereotypeAnnotations)
{
// Retrieve and merge all metadata from stereotypes
- StereotypeModel<?> stereotype =
metaDataCache.getStereotype(stereotypeAnnotation.annotationType());
+ StereotypeModel<?> stereotype =
MetaDataCache.instance().getStereotype(stereotypeAnnotation.annotationType());
if (stereotype == null)
{
throw new IllegalStateException("Stereotype " +
stereotypeAnnotation + " not registered with container");
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -28,6 +28,7 @@
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.EventBean;
@@ -115,7 +116,7 @@
for (Class<?> clazz : classes)
{
AbstractClassBean<?> bean;
- if
(CurrentManager.rootManager().getMetaDataCache().getEjbMetaData(clazz).isEjb())
+ if (MetaDataCache.instance().getEjbMetaData(clazz).isEjb())
{
bean = createEnterpriseBean(clazz);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -159,7 +159,7 @@
*/
public <T> void addObserver(Observer<T> observer, Class<T>
eventType, Annotation... bindings)
{
- EventObserver<T> eventObserver = new
EventObserver<T>(manager.getMetaDataCache(), observer, eventType, bindings);
+ EventObserver<T> eventObserver = new EventObserver<T>(observer,
eventType, bindings);
registeredObservers.put(eventType, eventObserver);
}
@@ -252,7 +252,7 @@
public <T> void removeObserver(Observer<T> observer, Class<T>
eventType, Annotation... bindings)
{
List<EventObserver<?>> observers = registeredObservers.get(eventType);
- EventObserver<T> eventObserver = new
EventObserver<T>(manager.getMetaDataCache(), observer, eventType, bindings);
+ EventObserver<T> eventObserver = new EventObserver<T>(observer,
eventType, bindings);
observers.remove(eventObserver);
}
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 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -44,7 +44,6 @@
private final Class<T> eventType;
private final List<Annotation> eventBindings;
private final Observer<T> observer;
- private final MetaDataCache metaDataCache;
/**
* Constructs a new wrapper for an observer.
@@ -53,12 +52,11 @@
* @param eventType The class of event being observed
* @param eventBindings The array of annotation event bindings, if any
*/
- public EventObserver(MetaDataCache metaDataCache, final Observer<T> observer,
final Class<T> eventType, final Annotation... eventBindings)
+ public EventObserver(final Observer<T> observer, final Class<T> eventType,
final Annotation... eventBindings)
{
this.observer = observer;
this.eventType = eventType;
this.eventBindings = Arrays.asList(eventBindings);
- this.metaDataCache = metaDataCache;
}
/**
@@ -108,7 +106,7 @@
boolean found = false;
for (Annotation y: bindings)
{
- if ( metaDataCache.getBindingTypeModel(x.annotationType()).isEqual(x, y) ) {
+ if ( MetaDataCache.instance().getBindingTypeModel(x.annotationType()).isEqual(x,
y) ) {
found = true;
}
}
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-12-07
12:07:38 UTC (rev 430)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-12-07
12:13:21 UTC (rev 431)
@@ -2,7 +2,6 @@
import javax.webbeans.Observer;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.event.EventObserver;
import org.jboss.webbeans.test.beans.DangerCall;
import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
@@ -38,7 +37,7 @@
public void testIsObserverInterested()
{
Observer<DangerCall> observer = new AnObserver<DangerCall>();
- EventObserver<DangerCall> wrappedObserver = new
EventObserver<DangerCall>(new MetaDataCache(), observer, DangerCall.class, new
TameAnnotationLiteral());
+ EventObserver<DangerCall> wrappedObserver = new
EventObserver<DangerCall>(observer, DangerCall.class, new TameAnnotationLiteral());
assert wrappedObserver.getEventBindings().size() == 1;
assert wrappedObserver.isObserverInterested(new TameAnnotationLiteral());
assert !wrappedObserver.isObserverInterested(new
AnimalStereotypeAnnotationLiteral());
@@ -46,7 +45,7 @@
assert wrappedObserver.isObserverInterested(new TameAnnotationLiteral(), new
RoleBinding("Admin"));
// Perform some tests with binding values (7.7.1)
- wrappedObserver = new EventObserver<DangerCall>(new MetaDataCache(),
observer, DangerCall.class, new RoleBinding("Admin"));
+ wrappedObserver = new EventObserver<DangerCall>(observer, DangerCall.class,
new RoleBinding("Admin"));
assert wrappedObserver.getEventBindings().size() == 1;
assert wrappedObserver.isObserverInterested(new RoleBinding("Admin"));
assert !wrappedObserver.isObserverInterested(new RoleBinding("User"));