incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r966376 - in /incubator/aries/sandbox/linsun/mds: ./ mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/ mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/ mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/
Date Wed, 21 Jul 2010 19:30:04 GMT
Author: linsun
Date: Wed Jul 21 19:30:04 2010
New Revision: 966376

URL: http://svn.apache.org/viewvc?rev=966376&view=rev
Log:
[message driven service] add additional testing for service-properties, add transaction support
so blueprint transaction can be used to describe transaction of message-driven service

Modified:
    incubator/aries/sandbox/linsun/mds/mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/MessageDrivenParser.java
    incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/NameSpaceHandlerTest.java
    incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/aries.xml
    incubator/aries/sandbox/linsun/mds/pom.xml

Modified: incubator/aries/sandbox/linsun/mds/mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/MessageDrivenParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/MessageDrivenParser.java?rev=966376&r1=966375&r2=966376&view=diff
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/MessageDrivenParser.java
(original)
+++ incubator/aries/sandbox/linsun/mds/mds-blueprint/src/main/java/org/apache/aries/mds/blueprint/MessageDrivenParser.java
Wed Jul 21 19:30:04 2010
@@ -45,10 +45,14 @@ public class MessageDrivenParser {
     private static final String SERVICE_TAG = "service";
     private static final String SERVICE_PROPERTIES_TAG = "service-properties";
     private static final String ENTRY_TAG = "entry";
+    private static final String TRANSACTION_TAG = "transaction";
     
     private static final String ID_ATTR = "id";
     private static final String INTERFACE_ATTR = "interface";
     private static final String REF_ATTR = "ref";
+    private static final String PREFIX = "org.apache.aries.message.driven.";
+    private static final String KEY_ATTR = "key";
+    private static final String VALUE_ATTR = "value";
     
     private static final String ACTIVATION_CONFIG_TAG = "activationConfig";
     
@@ -93,16 +97,19 @@ public class MessageDrivenParser {
                             Element element = (Element) current;
                             if (element.getLocalName().equals(ENTRY_TAG)) {
                                 // create element using blueprint ns and use this instead
-                                Element entryElement = createElement(serviceElement, element);
+                                Element entryElement = createElement(serviceElement, element,
PREFIX);
                                 servicepropElement.appendChild(entryElement);
                                 
                             }
                             
                         } 
                     }
+                } else if (elem.getLocalName().equals(TRANSACTION_TAG)) {
+                    Element txElement = createTransactionElement(serviceElement, elem);
+                    servicepropElement.appendChild(txElement);
                 } else {
                     // when it is not activation config tag, such as argument, etc
-                    Element element = createElement(beanElement, elem);
+                    Element element = createElement(beanElement, elem, null);
                     beanElement.appendChild(element);
                 }
                 
@@ -132,20 +139,25 @@ public class MessageDrivenParser {
     }
     
     /**
-     * this method create an element based onoldElement passed in but using blueprint ns
instead of the message-driven ns
+     * this method create an element based on oldElement passed in but using blueprint ns
instead of the message-driven ns
      * 
      * @param serviceElement
      * @param oldElement
+     * @param prefix   - needed for service properties
      * @return
      */
-    private Element createElement(Element ele, Element oldElement) {
+    private Element createElement(Element ele, Element oldElement, String prefix) {
         Element element = ele.getOwnerDocument().createElementNS(BLUEPRINT_NS, oldElement.getLocalName());
         NamedNodeMap attrs = oldElement.getAttributes();
         for (int i = 0; i < attrs.getLength(); i++) {
             Node cur = attrs.item(i);
             if (cur.getNodeType() == Node.ATTRIBUTE_NODE) {
               Attr a = (Attr) cur;
-              element.setAttribute(a.getName(), a.getValue());
+              if (prefix != null && oldElement.getLocalName().equals(ENTRY_TAG) &&
a.getLocalName().equals(KEY_ATTR)) {
+                  element.setAttribute(a.getName(), prefix + a.getValue());
+              } else {
+                  element.setAttribute(a.getName(), a.getValue());
+              }
             }            
         }
             
@@ -153,5 +165,38 @@ public class MessageDrivenParser {
     }
     
 
-
+    /**
+     * this method create an element based on the old transaction element passed in but using
blueprint ns instead of the transaction ns
+     * for example, we want to convert 
+     *     <tx:transaction method="*" value="Required"/>
+     *      to
+     *     <entry key="org.apache.aries.message.driven.transactionAttribute" value="Required"/>
in service properties
+     *TODO: it doesn't handle method level transaction yet.   transaction is decorated on
class level.      
+     * 
+     * @param serviceElement
+     * @param txElement
+     * @return
+     */
+    private Element createTransactionElement(Element ele, Element txElement) {
+        Element element = ele.getOwnerDocument().createElementNS(BLUEPRINT_NS, ENTRY_TAG);
+        NamedNodeMap attrs = txElement.getAttributes();
+        for (int i = 0; i < attrs.getLength(); i++) {
+            Node cur = attrs.item(i);
+            if (cur.getNodeType() == Node.ATTRIBUTE_NODE) {
+                Attr a = (Attr) cur;
+                
+                if (a.getName().equals(VALUE_ATTR)) {
+                    if (a.getValue().equals("Required") || a.getValue().equals("NotSupported"))
{
+                        element.setAttribute(KEY_ATTR, PREFIX + "transactionAttribute");
+                        element.setAttribute(VALUE_ATTR, a.getValue());
+                        break;
+                    } else {
+                        LOGGER.warn("Unexpected transaction attribute detected - " + a.getValue());

+                    }
+                }
+            }            
+        }
+            
+        return element;
+    }
 }

Modified: incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/NameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/NameSpaceHandlerTest.java?rev=966376&r1=966375&r2=966376&view=diff
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/NameSpaceHandlerTest.java
(original)
+++ incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/java/org/apache/aries/mds/blueprint/NameSpaceHandlerTest.java
Wed Jul 21 19:30:04 2010
@@ -40,6 +40,9 @@ import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.MapEntry;
+import org.osgi.service.blueprint.reflect.ServiceMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
 
 public class NameSpaceHandlerTest {
     
@@ -75,7 +78,32 @@ public class NameSpaceHandlerTest {
       assertEquals("destory", comp.getDestroyMethod());
       assertEquals("singleton", comp.getScope());
       
+      // we don't know the service id for the message-driven service since it is auto generated
by the container
+      Set<String> names = cdr.getComponentDefinitionNames();
+      int verify = 0;
+      for (String name : names) {
+          if (cdr.getComponentDefinition(name) instanceof ServiceMetadata) {
+              ServiceMetadata sm = (ServiceMetadata)cdr.getComponentDefinition(name);
+              List<MapEntry> entries = sm.getServiceProperties();
+              for (MapEntry entry : entries) {
+                  if (entry.getKey() instanceof ValueMetadata) {
+                      ValueMetadata vmkey = (ValueMetadata)entry.getKey();
+                      if (vmkey.getStringValue().equals("org.apache.aries.message.driven.destination"))
{
+                          ValueMetadata vmvalue = (ValueMetadata)entry.getValue();
+                          assertEquals("Hello.Queue", vmvalue.getStringValue());
+                          verify++;
+                      }
+                      if (vmkey.getStringValue().equals("org.apache.aries.message.driven.destinationType"))
{
+                          ValueMetadata vmvalue = (ValueMetadata)entry.getValue();
+                          assertEquals("javax.jms.Queue", vmvalue.getStringValue());
+                          verify++;
+                      }
+                  }
+              }
+          }
+      }
       
+      assertEquals(2, verify);
 
 
 

Modified: incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/aries.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/aries.xml?rev=966376&r1=966375&r2=966376&view=diff
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/aries.xml
(original)
+++ incubator/aries/sandbox/linsun/mds/mds-blueprint/src/test/resources/org/apache/aries/mds/blueprint/aries.xml
Wed Jul 21 19:30:04 2010
@@ -20,11 +20,12 @@
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-            xmlns:md="http://aries.apache.org/xmlns/messagedriven" 
+            xmlns:md="http://aries.apache.org/xmlns/messagedriven"
             default-activation="lazy">
             
 <md:message-driven id="myMessageDrivenBean" class="org.apache.aries.mds.sample.MyMessageDrivenBean"
destroy-method="destory" 
 		    scope="singleton" interface="javax.jms.MessageListener">
+	<!-- <tx:transaction method="*" value="Required"/>	  -->   
 	<md:activationConfig>
         <md:entry key="destination" value="Hello.Queue" />
 		<md:entry key="destinationType" value="javax.jms.Queue" />

Modified: incubator/aries/sandbox/linsun/mds/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/pom.xml?rev=966376&r1=966375&r2=966376&view=diff
==============================================================================
--- incubator/aries/sandbox/linsun/mds/pom.xml (original)
+++ incubator/aries/sandbox/linsun/mds/pom.xml Wed Jul 21 19:30:04 2010
@@ -358,6 +358,7 @@
 		<module>mds-ra</module>
 		<module>mds-impl</module>
 		<module>mds-ra-activemq</module>
+                <module>mds-blueprint</module>
 		<module>mds-sample</module>
 		<module>mds-itest</module>
 	</modules>



Mime
View raw message