Author: struberg
Date: Mon Feb 28 22:22:38 2011
New Revision: 1075564
URL: http://svn.apache.org/viewvc?rev=1075564&view=rev
Log:
OWB-539 lazily fill our AnnotatedTypeImpl
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java?rev=1075564&r1=1075563&r2=1075564&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
Mon Feb 28 22:22:38 2011
@@ -33,7 +33,6 @@ import org.apache.webbeans.config.OWBLog
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.SecurityUtil;
/**
* Factory for {@link javax.enterprise.inject.spi.Annotated} elements.
@@ -97,27 +96,6 @@ public final class AnnotatedElementFacto
{
annotatedType = new AnnotatedTypeImpl<X>(annotatedClass);
- Field[] fields =
SecurityUtil.doPrivilegedGetDeclaredFields(annotatedClass);
- Method[] methods =
SecurityUtil.doPrivilegedGetDeclaredMethods(annotatedClass);
- Constructor<X>[] ctxs =
(Constructor<X>[])SecurityUtil.doPrivilegedGetDeclaredConstructors(annotatedClass);
- for(Field f : fields)
- {
- AnnotatedField<X> af = new AnnotatedFieldImpl<X>(f,
annotatedType);
- annotatedType.addAnnotatedField(af);
- }
-
- for(Method m : methods)
- {
- AnnotatedMethod<X> am = new
AnnotatedMethodImpl<X>(m,annotatedType);
- annotatedType.addAnnotatedMethod(am);
- }
-
- for(Constructor<X> ct : ctxs)
- {
- AnnotatedConstructor<X> ac = new
AnnotatedConstructorImpl<X>(ct,annotatedType);
- annotatedType.addAnnotatedConstructor(ac);
- }
-
AnnotatedTypeImpl<X> oldType =
(AnnotatedTypeImpl<X>)annotatedTypeCache.putIfAbsent(annotatedClass,
annotatedType);
if(oldType != null)
{
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java?rev=1075564&r1=1075563&r2=1075564&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedTypeImpl.java
Mon Feb 28 22:22:38 2011
@@ -18,6 +18,11 @@
*/
package org.apache.webbeans.portable;
+import org.apache.webbeans.util.SecurityUtil;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -40,13 +45,13 @@ class AnnotatedTypeImpl<X> extends Abstr
private final Class<X> annotatedClass;
/**Constructors*/
- private Set<AnnotatedConstructor<X>> constructors = new
HashSet<AnnotatedConstructor<X>>();
+ private Set<AnnotatedConstructor<X>> constructors = null;
/**Fields*/
- private Set<AnnotatedField<? super X>> fields = new
HashSet<AnnotatedField<? super X>>();
+ private Set<AnnotatedField<? super X>> fields = null;
/**Methods*/
- private Set<AnnotatedMethod<? super X>> methods = new
HashSet<AnnotatedMethod<? super X>>();
+ private Set<AnnotatedMethod<? super X>> methods = null;
/**
* Creates a new instance.
@@ -60,7 +65,48 @@ class AnnotatedTypeImpl<X> extends Abstr
setAnnotations(annotatedClass.getDeclaredAnnotations());
}
-
+
+ private synchronized void init()
+ {
+ if (constructors == null)
+ {
+ constructors = new HashSet<AnnotatedConstructor<X>>();
+ fields = new HashSet<AnnotatedField<? super X>>();
+ methods = new HashSet<AnnotatedMethod<? super X>>();
+
+ Field[] decFields =
SecurityUtil.doPrivilegedGetDeclaredFields(annotatedClass);
+ Method[] decMethods =
SecurityUtil.doPrivilegedGetDeclaredMethods(annotatedClass);
+ Constructor<X>[] decCtxs =
SecurityUtil.doPrivilegedGetDeclaredConstructors(annotatedClass);
+ for(Field f : decFields)
+ {
+ AnnotatedField<X> af = new AnnotatedFieldImpl<X>(f, this);
+ fields.add(af);
+ }
+
+ for(Method m : decMethods)
+ {
+ AnnotatedMethod<X> am = new AnnotatedMethodImpl<X>(m,this);
+ methods.add(am);
+ }
+
+ for(Constructor<X> ct : decCtxs)
+ {
+ AnnotatedConstructor<X> ac = new
AnnotatedConstructorImpl<X>(ct,this);
+ constructors.add(ac);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Class<X> getJavaClass()
+ {
+ return this.annotatedClass;
+ }
+
+
/**
* Adds new annotated constructor.
*
@@ -68,26 +114,38 @@ class AnnotatedTypeImpl<X> extends Abstr
*/
void addAnnotatedConstructor(AnnotatedConstructor<X> constructor)
{
+ if (constructors == null)
+ {
+ init();
+ }
this.constructors.add(constructor);
}
/**
* Adds new annotated field.
*
- * @param constructor new field
+ * @param field new field
*/
void addAnnotatedField(AnnotatedField<? super X> field)
{
+ if (constructors == null)
+ {
+ init();
+ }
this.fields.add(field);
}
/**
* Adds new annotated method.
*
- * @param constructor new method
+ * @param method new method
*/
void addAnnotatedMethod(AnnotatedMethod<? super X> method)
{
+ if (constructors == null)
+ {
+ init();
+ }
this.methods.add(method);
}
@@ -97,6 +155,11 @@ class AnnotatedTypeImpl<X> extends Abstr
@Override
public Set<AnnotatedConstructor<X>> getConstructors()
{
+ if (constructors == null)
+ {
+ init();
+ }
+
return Collections.unmodifiableSet(this.constructors);
}
@@ -106,16 +169,12 @@ class AnnotatedTypeImpl<X> extends Abstr
@Override
public Set<AnnotatedField<? super X>> getFields()
{
- return Collections.unmodifiableSet(this.fields);
- }
+ if (constructors == null)
+ {
+ init();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public Class<X> getJavaClass()
- {
- return this.annotatedClass;
+ return Collections.unmodifiableSet(this.fields);
}
/**
@@ -124,6 +183,11 @@ class AnnotatedTypeImpl<X> extends Abstr
@Override
public Set<AnnotatedMethod<? super X>> getMethods()
{
+ if (constructors == null)
+ {
+ init();
+ }
+
return Collections.unmodifiableSet(this.methods);
}