aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1072948 - in /aries/trunk/transaction/transaction-blueprint/src: main/java/org/apache/aries/transaction/parsing/ main/resources/OSGI-INF/blueprint/ test/java/org/apache/aries/transaction/
Date Mon, 21 Feb 2011 12:37:41 GMT
Author: mahrwald
Date: Mon Feb 21 12:37:41 2011
New Revision: 1072948

URL: http://svn.apache.org/viewvc?rev=1072948&view=rev
Log:
ARIES-578: More lifecycle fixes for component level metadata. Also, one fix for registering
interceptors correctly for bundle wide transaction configuration.

Modified:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxBlueprintListener.java
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
    aries/trunk/transaction/transaction-blueprint/src/main/resources/OSGI-INF/blueprint/transaction.xml
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxBlueprintListener.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxBlueprintListener.java?rev=1072948&r1=1072947&r2=1072948&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxBlueprintListener.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxBlueprintListener.java
Mon Feb 21 12:37:41 2011
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.transaction.parsing;
 
-import org.apache.aries.transaction.TxComponentMetaDataHelper;
 import org.osgi.service.blueprint.container.BlueprintEvent;
 import org.osgi.service.blueprint.container.BlueprintListener;
 
@@ -29,11 +28,9 @@ import org.osgi.service.blueprint.contai
 public class TxBlueprintListener implements BlueprintListener {
     
     private final TxElementHandler handler;
-    private final TxComponentMetaDataHelper helper;
     
-    public TxBlueprintListener(TxElementHandler handler, TxComponentMetaDataHelper helper)
{
+    public TxBlueprintListener(TxElementHandler handler) {
         this.handler = handler;
-        this.helper = helper;
     }
     
     public void blueprintEvent(BlueprintEvent event) {

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java?rev=1072948&r1=1072947&r2=1072948&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
Mon Feb 21 12:37:41 2011
@@ -35,6 +35,7 @@ import org.apache.aries.blueprint.Interc
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.PassThroughMetadata;
+import org.apache.aries.transaction.BundleWideTxData;
 import org.apache.aries.transaction.Constants;
 import org.apache.aries.transaction.TxComponentMetaDataHelper;
 import org.osgi.framework.Bundle;
@@ -85,6 +86,14 @@ public class TxElementHandler implements
                 metaDataHelper.setComponentTransactionData(cdr, cm, elt.getAttribute(Constants.VALUE),
elt
                         .getAttribute(Constants.METHOD));
             }
+            
+            ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle");
+            Bundle blueprintBundle = null;
+            if (meta instanceof PassThroughMetadata) {
+                blueprintBundle = (Bundle) ((PassThroughMetadata) meta).getObject();
+            }
+
+            registered.put(cdr, blueprintBundle);
         }
         
         if (LOGGER.isDebugEnabled())
@@ -167,36 +176,29 @@ public class TxElementHandler implements
         }
     }
     
-    private void registerComponentsWithInterceptor(ComponentDefinitionRegistry cdr, String
bean) {
-        ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle");
-        Bundle blueprintBundle = null;
-        if (meta instanceof PassThroughMetadata) {
-            blueprintBundle = (Bundle) ((PassThroughMetadata) meta).getObject();
-        }
-        
-        // if it is already registered all components in the component definition registry,
do nothing
-        if (registered.putIfAbsent(cdr, blueprintBundle) == null) {
-            Set<String> ids = cdr.getComponentDefinitionNames();
-            
-            if (bean == null || bean.isEmpty()) {
-                // in this case, let's attempt to register all components
-                // if the component has already been registered with this interceptor,
-                // the registration will be ignored.
-                for (String id : ids) {
-                    ComponentMetadata componentMetadata = cdr.getComponentDefinition(id);
-                    cdr.registerInterceptorWithComponent(componentMetadata, interceptor);
-                }
-            } else {
-                // register the beans specified
-                Pattern p = Pattern.compile(bean);
-                for (String id : ids) {
-                    Matcher m = p.matcher(id);
-                    if (m.matches()) {
-                        ComponentMetadata componentMetadata = cdr.getComponentDefinition(id);
-                        cdr.registerInterceptorWithComponent(componentMetadata, interceptor);
-                    }
-                }
+    private void registerComponentsWithInterceptor(ComponentDefinitionRegistry cdr, String
bean) {        
+        Set<String> ids = cdr.getComponentDefinitionNames();
+
+        if (bean == null || bean.isEmpty()) {
+            // in this case, let's attempt to register all components
+            // if the component has already been registered with this interceptor,
+            // the registration will be ignored.
+            for (String id : ids) {
+                ComponentMetadata componentMetadata = cdr.getComponentDefinition(id);
+                cdr.registerInterceptorWithComponent(componentMetadata, interceptor);
+            }
+        } else {
+            //create a dummy bundle wide tx data, so we can get the bean patterns from it
+            BundleWideTxData data = new BundleWideTxData(null, "*", bean);
+            for (Pattern p : data.getBean()) {
+              for (String id : ids) {
+                  Matcher m = p.matcher(id);
+                  if (m.matches()) {
+                      ComponentMetadata componentMetadata = cdr.getComponentDefinition(id);
+                      cdr.registerInterceptorWithComponent(componentMetadata, interceptor);
+                  }
+              }
             }
-        }        
+        }
     }
 }

Modified: aries/trunk/transaction/transaction-blueprint/src/main/resources/OSGI-INF/blueprint/transaction.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/resources/OSGI-INF/blueprint/transaction.xml?rev=1072948&r1=1072947&r2=1072948&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/resources/OSGI-INF/blueprint/transaction.xml
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/resources/OSGI-INF/blueprint/transaction.xml
Mon Feb 21 12:37:41 2011
@@ -48,9 +48,8 @@
   <reference id="tm" interface="javax.transaction.TransactionManager"/>
   
   <service interface="org.osgi.service.blueprint.container.BlueprintListener">
-  	<bean class="org.apache.aries.transaction.parsing.TxElementHandler">
+  	<bean class="org.apache.aries.transaction.parsing.TxBlueprintListener">
   	  <argument ref="nsHandler" />
-  	  <argument ref="txenhancer" />
   	</bean>
   </service>
   

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java?rev=1072948&r1=1072947&r2=1072948&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
Mon Feb 21 12:37:41 2011
@@ -38,6 +38,9 @@ public class BundleWideNameSpaceHandlerT
       assertNotNull(compTop);
       assertNotNull(compDown);
       
+      assertEquals(1, cdr.getInterceptors(compTop).size());
+      assertEquals(1, cdr.getInterceptors(compDown).size());
+      
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
       assertEquals("Never", txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
         
@@ -56,6 +59,10 @@ public class BundleWideNameSpaceHandlerT
       assertNotNull(compDown);
       assertNotNull(compMiddle);
       
+      assertEquals(1, cdr.getInterceptors(compTop).size());
+      assertEquals(1, cdr.getInterceptors(compDown).size());
+      assertEquals(0, cdr.getInterceptors(compMiddle).size());
+      
       assertEquals("RequiresNew", txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(compTop, "update"));
       assertEquals("NotSupported", txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
@@ -80,6 +87,10 @@ public class BundleWideNameSpaceHandlerT
       assertNotNull(compDown);
       assertNotNull(compMiddle);
       
+      assertEquals(1, cdr.getInterceptors(compTop).size());
+      assertEquals(1, cdr.getInterceptors(compDown).size());
+      assertEquals(1, cdr.getInterceptors(compMiddle).size());
+      
       assertEquals("RequiresNew", txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(compTop, "update"));
       assertEquals("NotSupported", txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java?rev=1072948&r1=1072947&r2=1072948&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/NameSpaceHandlerTest.java
Mon Feb 21 12:37:41 2011
@@ -41,8 +41,7 @@ public class NameSpaceHandlerTest extend
       BeanMetadata anonToo = (BeanMetadata) (comp.getProperties().get(1)).getValue();
 
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(anon, "doSomething"));
-      assertEquals("Never", txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
-        
+      assertEquals("Never", txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
       
     }
     
     @Test
@@ -139,7 +138,29 @@ public class NameSpaceHandlerTest extend
     }
     
     @Test
-    public void testLifecycle() throws Exception
+    public void testLifecycleOld() throws Exception
+    {
+        ComponentDefinitionRegistry cdr = parseCDR("aries.xml");
+
+        BeanMetadata comp = (BeanMetadata) cdr.getComponentDefinition("top");
+
+        BeanMetadata anon = (BeanMetadata) (comp.getProperties().get(0)).getValue();
+        BeanMetadata anonToo = (BeanMetadata) (comp.getProperties().get(1)).getValue();
+
+        assertEquals("Required", txenhancer.getComponentMethodTxAttribute(anon, "doSomething"));
+        assertEquals("Never", txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
+        
+        assertTrue(namespaceHandler.isRegistered(cdr));
+        
+        new TxBlueprintListener(namespaceHandler).blueprintEvent(
+                new BlueprintEvent(BlueprintEvent.DESTROYED, b, Skeleton.newMock(Bundle.class)));
+
+        assertNull(txenhancer.getComponentMethodTxAttribute(anon, "doSomething"));
+        assertNull(txenhancer.getComponentMethodTxAttribute(anonToo, "doSomething"));
+    }
+    
+    @Test
+    public void testLifecycleMixed() throws Exception
     {
         ComponentDefinitionRegistry cdr = parseCDR("mixed-aries.xml");
         
@@ -159,7 +180,7 @@ public class NameSpaceHandlerTest extend
         
         assertTrue(namespaceHandler.isRegistered(cdr));
         
-        new TxBlueprintListener(namespaceHandler, txenhancer).blueprintEvent(
+        new TxBlueprintListener(namespaceHandler).blueprintEvent(
                 new BlueprintEvent(BlueprintEvent.DESTROYED, b, Skeleton.newMock(Bundle.class)));
         
         assertFalse(namespaceHandler.isRegistered(cdr));



Mime
View raw message