[jboss-cvs] JBossAS SVN: r76838 - in projects/microcontainer/trunk: kernel/src/main/org/jboss/beans/metadata/plugins and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 8 12:29:39 EDT 2008
Author: adrian at jboss.org
Date: 2008-08-08 12:29:39 -0400 (Fri, 08 Aug 2008)
New Revision: 76838
Modified:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractScopeInfo.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/KernelScopeInfo.java
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase_NotAutomatic.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/TestBean.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase.java
Log:
[JBMICROCONT-334] - Remove annotations at uninstall, also fix similar issue to [JBMICROCONT-330] where it always creating component metadata contexts even if they already existed
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractScopeInfo.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractScopeInfo.java 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractScopeInfo.java 2008-08-08 16:29:39 UTC (rev 76838)
@@ -127,23 +127,10 @@
repository.addMetaDataRetrieval(mutable);
addedScopes.add(scope);
}
- else if (retrieval instanceof MutableMetaDataLoader)
+ else
{
- mutable = (MutableMetaDataLoader) retrieval;
+ mutable = getMutableMetaDataLoader(retrieval);
}
- else if (retrieval instanceof MetaDataContext)
- {
- MetaDataContext metaDataContext = (MetaDataContext) retrieval;
- List<MetaDataRetrieval> locals = metaDataContext.getLocalRetrievals();
- if (locals != null)
- {
- for (MetaDataRetrieval local : locals)
- {
- if (local instanceof MutableMetaDataLoader)
- mutable = (MutableMetaDataLoader) local;
- }
- }
- }
if (mutable == null)
{
@@ -151,23 +138,33 @@
return;
}
- addMetaData(repository, context, mutable);
+ updateMetaData(repository, context, mutable, true);
}
-
+
/**
- * Add metadata
+ * Update metadata
*
* @param repository the repository
* @param context the context
* @param mutable the mutable
+ * @param add true for add, false for remove
*/
- protected void addMetaData(MutableMetaDataRepository repository, ControllerContext context, MutableMetaDataLoader mutable)
+ protected void updateMetaData(MutableMetaDataRepository repository, ControllerContext context, MutableMetaDataLoader mutable, boolean add)
{
// nothing
}
public void removeMetaData(MutableMetaDataRepository repository, ControllerContext context)
{
+ ScopeKey mutableScope = getMutableScope();
+ MetaDataRetrieval retrieval = repository.getMetaDataRetrieval(mutableScope);
+ if (retrieval != null)
+ {
+ MutableMetaDataLoader mutable = getMutableMetaDataLoader(retrieval);
+ if (mutable != null)
+ updateMetaData(repository, context, mutable, false);
+ }
+
for (ScopeKey scope : addedScopes)
{
try
@@ -184,6 +181,31 @@
}
+ protected MutableMetaDataLoader getMutableMetaDataLoader(MetaDataRetrieval retrieval)
+ {
+ if (retrieval == null)
+ return null;
+
+ if (retrieval instanceof MutableMetaDataLoader)
+ {
+ return (MutableMetaDataLoader) retrieval;
+ }
+ else if (retrieval instanceof MetaDataContext)
+ {
+ MetaDataContext metaDataContext = (MetaDataContext) retrieval;
+ List<MetaDataRetrieval> locals = metaDataContext.getLocalRetrievals();
+ if (locals != null)
+ {
+ for (MetaDataRetrieval local : locals)
+ {
+ if (local instanceof MutableMetaDataLoader)
+ return (MutableMetaDataLoader) local;
+ }
+ }
+ }
+ return null;
+ }
+
public MutableMetaDataLoader initMutableMetaDataRetrieval(MutableMetaDataRepository repository, ControllerContext context, ScopeKey scopeKey)
{
return new MemoryMetaDataLoader(scopeKey);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractAnnotationMetaData.java 2008-08-08 16:29:39 UTC (rev 76838)
@@ -78,6 +78,7 @@
public void setAnnotation(String annotation)
{
this.annotation = annotation;
+ flushJBossObjectCache();
}
public boolean isReplace()
@@ -111,6 +112,7 @@
cl = Thread.currentThread().getContextClassLoader();
}
ann = (Annotation)AnnotationCreator.createAnnotation(annString, cl);
+ flushJBossObjectCache();
}
catch(TokenMgrError e)
{
@@ -147,12 +149,16 @@
public void toString(JBossStringBuilder buffer)
{
- buffer.append("expr=").append(ann);
+ buffer.append("expr=");
+ toShortString(buffer);
}
public void toShortString(JBossStringBuilder buffer)
{
- buffer.append(ann);
+ if (ann == null)
+ buffer.append(annotation);
+ else
+ buffer.append(ann);
}
protected int getHashCode()
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/KernelScopeInfo.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/KernelScopeInfo.java 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/KernelScopeInfo.java 2008-08-08 16:29:39 UTC (rev 76838)
@@ -21,6 +21,7 @@
*/
package org.jboss.kernel.plugins.dependency;
+import java.lang.annotation.Annotation;
import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
@@ -33,17 +34,18 @@
import org.jboss.kernel.plugins.config.Configurator;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
-import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
import org.jboss.metadata.spi.ComponentMutableMetaData;
import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
import org.jboss.metadata.spi.scope.CommonLevels;
import org.jboss.metadata.spi.scope.Scope;
import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.FieldSignature;
import org.jboss.metadata.spi.signature.MethodSignature;
-import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.reflect.spi.FieldInfo;
import org.jboss.reflect.spi.MethodInfo;
-import org.jboss.reflect.spi.FieldInfo;
/**
* KernelScopeInfo.
@@ -108,25 +110,27 @@
}
@Override
- public void addMetaData(MutableMetaDataRepository repository, ControllerContext context, MutableMetaDataLoader mutable)
+ public void updateMetaData(MutableMetaDataRepository repository, ControllerContext context, MutableMetaDataLoader mutable, boolean add)
{
if (context instanceof KernelControllerContext == false)
return;
KernelControllerContext theContext = (KernelControllerContext) context;
- addClassAnnotations(mutable, theContext);
+ updateClassAnnotations(repository, mutable, theContext, add);
if (mutable instanceof ComponentMutableMetaData)
- addPropertyAnnotations((ComponentMutableMetaData) mutable, theContext);
- else
+ updatePropertyAnnotations(repository, (ComponentMutableMetaData) mutable, theContext, add);
+ else if (add == true)
log.warn("Unable to add properties to mutable metadata that does not support components: " + mutable + " for " + context.toShortString());
}
/**
- * Add class annotations
+ * Update class annotations
*
+ * @param repository the repository
* @param mutable the mutable metadata
* @param context the context
+ * @param add true for add, false for remove
*/
- private void addClassAnnotations(MutableMetaDataLoader mutable, KernelControllerContext context)
+ private void updateClassAnnotations(MutableMetaDataRepository repository, MutableMetaDataLoader mutable, KernelControllerContext context, boolean add)
{
BeanMetaData beanMetaData = context.getBeanMetaData();
if (beanMetaData != null)
@@ -140,17 +144,19 @@
{
throw new RuntimeException("Error getting classloader for " + beanMetaData.getName(), t);
}
- addAnnotations(cl, mutable, beanMetaData.getAnnotations());
+ updateAnnotations(repository, cl, mutable, context, beanMetaData.getAnnotations(), add);
}
}
/**
- * Add property annotations
+ * Update property annotations
*
+ * @param repository the repository
* @param mutable the mutable
* @param context the kernel controller contex
+ * @param add true for add, false for remove
*/
- private void addPropertyAnnotations(ComponentMutableMetaData mutable, KernelControllerContext context)
+ private void updatePropertyAnnotations(MutableMetaDataRepository repository, ComponentMutableMetaData mutable, KernelControllerContext context, boolean add)
{
BeanMetaData beanMetaData = context.getBeanMetaData();
if (beanMetaData == null)
@@ -175,18 +181,21 @@
throw new RuntimeException("Error getting classloader for metadata");
}
for (PropertyMetaData property : properties)
- addPropertyAnnotations(cl, mutable, property, beanInfo);
+ updatePropertyAnnotations(repository, cl, mutable, context, property, beanInfo, add);
}
/**
- * Add property annotations
+ * Update property annotations
*
+ * @param repository the repository
* @param classloader the classloader
* @param mutable the mutable
+ * @param context the context
* @param propertyMetaData the property
* @param beanInfo the bean info
+ * @param add true for add, false for remove
*/
- private void addPropertyAnnotations(ClassLoader classloader, ComponentMutableMetaData mutable, PropertyMetaData propertyMetaData, BeanInfo beanInfo)
+ private void updatePropertyAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, ComponentMutableMetaData mutable, KernelControllerContext context, PropertyMetaData propertyMetaData, BeanInfo beanInfo, boolean add)
{
Set<AnnotationMetaData> propertyAnnotations = propertyMetaData.getAnnotations();
if (propertyAnnotations == null || propertyAnnotations.size() == 0)
@@ -196,61 +205,123 @@
// method annotations
MethodInfo methodInfo = propertyInfo.getGetter();
if (methodInfo != null)
- addAnnotations(classloader, mutable, methodInfo, propertyAnnotations);
+ updateAnnotations(repository, classloader, mutable, context, methodInfo, propertyAnnotations, add);
methodInfo = propertyInfo.getSetter();
if (methodInfo != null)
- addAnnotations(classloader, mutable, methodInfo, propertyAnnotations);
+ updateAnnotations(repository, classloader, mutable, context, methodInfo, propertyAnnotations, add);
// field annotations
FieldInfo fieldInfo = propertyInfo.getFieldInfo();
if (fieldInfo != null)
- addAnnotations(classloader, mutable, fieldInfo, propertyAnnotations);
+ updateAnnotations(repository, classloader, mutable, context, fieldInfo, propertyAnnotations, add);
}
/**
- * Add annotations for a method
+ * Update component annotations
*
+ * @param repository the repository
* @param classloader the classloader
- * @param mutable the mutable metadata
+ * @param component the component metadata
+ * @param context the context
+ * @param signature the signature
+ * @param scope the scope
+ * @param annotations the annotations
+ * @param add true for add, false for remove
+ */
+ private void updateAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, ComponentMutableMetaData component, KernelControllerContext context, Signature signature, ScopeKey scope, Set<AnnotationMetaData> annotations, boolean add)
+ {
+ MetaDataRetrieval retrieval = ((MetaDataRetrieval) component).getComponentMetaDataRetrieval(signature);
+ MutableMetaDataLoader mutable = null;
+ if (retrieval != null)
+ {
+ mutable = getMutableMetaDataLoader(retrieval);
+ if (mutable == null)
+ {
+ if (add)
+ log.warn("MetaData is not mutable with signature: " + signature + " for " + context.toShortString());
+ return;
+ }
+ }
+ else if (add)
+ {
+ mutable = initMutableMetaDataRetrieval(repository, context, scope);
+ component.addComponentMetaDataRetrieval(signature, mutable);
+ }
+ else
+ {
+ return;
+ }
+ updateAnnotations(repository, classloader, mutable, context, annotations, add);
+ }
+
+ /**
+ * Update annotations for a method
+ *
+ * @param repository the repository
+ * @param classloader the classloader
+ * @param component the mutable metadata
+ * @param context the context
* @param methodInfo the method info
* @param annotations the annotations
+ * @param add true for add, false for remove
*/
- private void addAnnotations(ClassLoader classloader, ComponentMutableMetaData mutable, MethodInfo methodInfo, Set<AnnotationMetaData> annotations)
+ private void updateAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, ComponentMutableMetaData component, KernelControllerContext context, MethodInfo methodInfo, Set<AnnotationMetaData> annotations, boolean add)
{
+ if (annotations == null || annotations.isEmpty())
+ return;
+ Signature signature = new MethodSignature(methodInfo);
ScopeKey scope = new ScopeKey(CommonLevels.JOINPOINT_OVERRIDE, methodInfo.getName());
- MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scope);
- addAnnotations(classloader, loader, annotations);
- mutable.addComponentMetaDataRetrieval(new MethodSignature(methodInfo), loader);
+ updateAnnotations(repository, classloader, component, context, signature, scope, annotations, add);
}
/**
* Add annotations for a field
*
+ * @param repository the repository
* @param classloader the classloader
- * @param mutable the mutable metadata
+ * @param component the mutable metadata
+ * @param context the context
* @param fieldInfo the field info
* @param annotations the annotations
+ * @param add true for add, false for remove
*/
- private void addAnnotations(ClassLoader classloader, ComponentMutableMetaData mutable, FieldInfo fieldInfo, Set<AnnotationMetaData> annotations)
+ private void updateAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, ComponentMutableMetaData component, KernelControllerContext context, FieldInfo fieldInfo, Set<AnnotationMetaData> annotations, boolean add)
{
+ if (annotations == null || annotations.isEmpty())
+ return;
+ Signature signature = new FieldSignature(fieldInfo);
ScopeKey scope = new ScopeKey(CommonLevels.JOINPOINT_OVERRIDE, fieldInfo.getName());
- MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scope);
- addAnnotations(classloader, loader, annotations);
- mutable.addComponentMetaDataRetrieval(new FieldSignature(fieldInfo), loader);
+ updateAnnotations(repository, classloader, component, context, signature, scope, annotations, add);
}
/**
* Add annotations to a mutable metadata
*
+ * @param repository the repository
* @param classloader the classloader
* @param mutable the mutable metadata
+ * @param context the context
* @param annotations the annotations
+ * @param add true for add, false for remove
*/
- private void addAnnotations(ClassLoader classloader, MutableMetaDataLoader mutable, Set<AnnotationMetaData> annotations)
+ private void updateAnnotations(MutableMetaDataRepository repository, ClassLoader classloader, MutableMetaDataLoader mutable, KernelControllerContext context, Set<AnnotationMetaData> annotations, boolean add)
{
if (annotations == null || annotations.size() == 0)
return;
-
for (AnnotationMetaData annotation : annotations)
- mutable.addAnnotation(annotation.getAnnotationInstance(classloader));
+ {
+
+ if (add)
+ {
+ Annotation annotationInstance = annotation.getAnnotationInstance(classloader);
+ mutable.addAnnotation(annotationInstance);
+ }
+ else
+ {
+ Annotation annotationInstance = annotation.getAnnotationInstance();
+ // Null means we never constructed it in the first place
+ if (annotationInstance != null)
+ mutable.removeAnnotation(annotationInstance.annotationType());
+ }
+ }
}
}
Modified: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase_NotAutomatic.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase_NotAutomatic.xml 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase_NotAutomatic.xml 2008-08-08 16:29:39 UTC (rev 76838)
@@ -4,6 +4,9 @@
<bean name="TestBean" class="org.jboss.test.kernel.deployment.support.TestBean">
<annotation>@org.jboss.test.kernel.deployment.support.TestAnnotation1</annotation>
+
+ <property name="string">10<annotation>@org.jboss.test.kernel.deployment.support.TestAnnotation1</annotation></property>
+
</bean>
</deployment>
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/TestBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/TestBean.java 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/TestBean.java 2008-08-08 16:29:39 UTC (rev 76838)
@@ -30,5 +30,13 @@
@TestAnnotation3
public class TestBean
{
+ public String getString()
+ {
+ return null;
+ }
+ @TestAnnotation3
+ public void setString(String string)
+ {
+ }
}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase.java 2008-08-08 16:00:12 UTC (rev 76837)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/MutableMetaDataTestCase.java 2008-08-08 16:29:39 UTC (rev 76838)
@@ -31,6 +31,8 @@
import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
import org.jboss.metadata.spi.scope.CommonLevels;
import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
import org.jboss.test.kernel.deployment.support.TestAnnotation1;
import org.jboss.test.kernel.deployment.support.TestAnnotation2;
import org.jboss.test.kernel.deployment.support.TestAnnotation3;
@@ -61,6 +63,11 @@
TestAnnotation2 annotation = (TestAnnotation2) AnnotationCreator.createAnnotation("@org.jboss.test.kernel.deployment.support.TestAnnotation2", TestAnnotation2.class);
loader.addAnnotation(annotation);
repository.addMetaDataRetrieval(loader);
+ ScopeKey setStringScope = new ScopeKey(CommonLevels.JOINPOINT, "setString");
+ MemoryMetaDataLoader stringProperty = new MemoryMetaDataLoader(setStringScope);
+ stringProperty.addAnnotation(annotation);
+ Signature signature = new MethodSignature("setString", String.class);
+ loader.addComponentMetaDataRetrieval(signature, stringProperty);
KernelDeployment deployment = deploy("MutableMetaDataTestCase_NotAutomatic.xml");
try
@@ -74,6 +81,11 @@
assertNotNull("TestAnnotation1 from xml", metaData.getAnnotation(TestAnnotation1.class));
assertNotNull("TestAnnotation2 preconfigured", metaData.getAnnotation(TestAnnotation2.class));
assertNotNull("TestAnnotation3 from class", metaData.getAnnotation(TestAnnotation3.class));
+
+ MetaData setStringMetaData = metaData.getComponentMetaData(signature);
+ assertNotNull("TestAnnotation1 from xml", setStringMetaData.getAnnotation(TestAnnotation1.class));
+ assertNotNull("TestAnnotation2 preconfigured", setStringMetaData.getAnnotation(TestAnnotation2.class));
+ assertNotNull("TestAnnotation3 from class", setStringMetaData.getAnnotation(TestAnnotation3.class));
}
finally
{
@@ -86,5 +98,9 @@
assertNull("TestAnnotation1 from xml", metaData.getAnnotation(TestAnnotation1.class));
assertNotNull("TestAnnotation2 preconfigured", metaData.getAnnotation(TestAnnotation2.class));
assertNull("TestAnnotation3 from class", metaData.getAnnotation(TestAnnotation3.class));
+ MetaData setStringMetaData = metaData.getComponentMetaData(signature);
+ assertNull("TestAnnotation1 from xml", setStringMetaData.getAnnotation(TestAnnotation1.class));
+ assertNotNull("TestAnnotation2 preconfigured", setStringMetaData.getAnnotation(TestAnnotation2.class));
+ assertNull("TestAnnotation3 from class", setStringMetaData.getAnnotation(TestAnnotation3.class));
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list