[jboss-svn-commits] JBL Code SVN: r13090 - in labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba: aspect and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 4 15:30:41 EDT 2007


Author: maciej.machulak
Date: 2007-07-04 15:30:41 -0400 (Wed, 04 Jul 2007)
New Revision: 13090

Added:
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/TaskDescription.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/CompensationManagement.java
Modified:
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/BATransactionManager.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/SingleTransactionManager.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/aspect/JaxWSBAProcessingAspect.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/compensation/CompensationManagerImpl.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/CompensationData.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescription.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescriptionImpl.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/BAServiceVisitor.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/old/JaxWSBusinessActivityHandler.java
   labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/participant/Participant.java
Log:
Important changes in the BATransactionManager class. Encapsulation of implementation specific code. Redesign of service description and compensation data. Added Task Description and CompensationManagement for injection of a relevant CompensationManager during method invocation.

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/BATransactionManager.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/BATransactionManager.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/BATransactionManager.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -3,11 +3,14 @@
 import org.apache.log4j.Logger;
 import org.jboss.txbridge.ba.data.MethodInformation;
 import org.jboss.txbridge.ba.data.ServiceDescription;
+import org.jboss.txbridge.ba.data.TaskDescription;
+import org.jboss.txbridge.ba.data.IdentificationType;
 import org.jboss.txbridge.ba.compensation.CompensationService;
 import org.jboss.txbridge.ba.id.IdentifierFactory;
 import org.jboss.txbridge.ba.id.UidIdentifierFactory;
 import org.jboss.txbridge.ba.helper.BAServiceVisitor;
 import org.jboss.txbridge.ba.helper.ServiceInformationManager;
+import org.jboss.txbridge.ba.participant.Participant;
 import com.arjuna.mw.wst.BusinessActivityManager;
 import com.arjuna.wsc.AlreadyRegisteredException;
 import com.arjuna.wst.SystemException;
@@ -91,7 +94,7 @@
      * @param method is the method which is being invoked.
      * @return the task identifier for this method.
      */
-    public synchronized String handleTransaction(Method method)
+    public synchronized TaskDescription handleTransaction(Method method)
     {
         log.info("handleTransaction()");
         String txId = null;
@@ -123,6 +126,11 @@
             String serviceId = serviceManager.getServiceId(className+methodName);
             log.info("Service ID: " + serviceId);
 
+            log.info("Getting new task identifier...");
+            IdentifierFactory idf = new UidIdentifierFactory();
+            String taskId = idf.getIdentifier();
+            log.info("Task ID: " + taskId);
+
             // Get a reference to a single transaction manager. If there is none - create a new one.
             SingleTransactionManager stm = singleTransactionManagers.get(txId);
             if (stm == null)
@@ -140,20 +148,11 @@
                 log.info("Transaction already known...");
             }
 
-            // Process invocation of this service
-
-            // 1) Get a unique task identifier
-            log.info("Getting new task identifier...");
-            IdentifierFactory idf = new UidIdentifierFactory();
-            String taskId = idf.getIdentifier();
-            log.info("Task ID: " + taskId);
-
-            // 2) Delegate transaction management to the single transaction manager
+            // Delegate transaction management to the single transaction manager
             log.info("Delegating transaction management.");
-            stm.processInvocation(taskId,serviceId);
+            Participant participant = stm.processInvocation(taskId,serviceId);
+            return new TaskDescription(txId,taskId,serviceId,participant);
 
-            // Return the task identifier
-            return taskId;
         }
         catch (Exception se)
         {
@@ -280,9 +279,42 @@
         }
     }
 
-    public synchronized void completeTransaction()
+    public synchronized void completeTransaction(TaskDescription taskDesc, Object[] arguments, Object returnObject)
     {
         log.info("completeTransaction()");
+
+        // Get the service description
+        ServiceDescription sd = serviceManager.getServiceById(taskDesc.getServiceId());
+
+        // Remember necessary additional data (annotated with @BAParam and @BAResult)
+
+        // 1) Get reference to the participant
+        String taskId = taskDesc.getTaskId();
+        Participant participant = taskDesc.getParticipant();
+
+        // 2) Get the annotation values
+        Object[] annotations = sd.getOriginalParameterAnnotation();
+
+        // 3) Remember parameters
+        for (int i = 0; i < annotations.length ; i++)
+        {
+            if (annotations[i] != null)
+            {
+                participant.put(taskId,annotations[i],arguments[i]);
+            }
+        }
+
+        // 4) Remember the return object if necessary
+        Object returnId = sd.getOriginalReturnId();
+        if (returnId != null)
+        {
+            participant.put(taskId,returnId,returnObject);
+        }
+    }
+
+    public synchronized void completeTheTransaction()
+    {
+        log.info("completeTheTransaction()");
         String txId = null;
         try
         {

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/SingleTransactionManager.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/SingleTransactionManager.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/SingleTransactionManager.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -11,6 +11,7 @@
 
 import org.jboss.txbridge.ba.data.MethodInformation;
 import org.jboss.txbridge.ba.data.CompensationDataReturn;
+import org.jboss.txbridge.ba.data.TaskDescription;
 import org.jboss.txbridge.ba.participant.ParticipantCompletionParticipantBA;
 import org.jboss.txbridge.ba.participant.CoordinatorCompletionParticipantBA;
 import org.jboss.txbridge.ba.participant.Participant;
@@ -101,6 +102,9 @@
         // Initialise (participant , participant manager mapping)
         participantManagerMapping = new ConcurrentHashMap<Participant,BAParticipantManager>();
 
+
+
+        
         methodIdList = new HashMap<String,String>();
         methodList = new HashMap<String, MethodInformation>();
         participant2List = new HashMap<String, ParticipantCompletionParticipantBA>();
@@ -126,8 +130,9 @@
      *
      * @param taskId is the task identifier.
      * @param serviceId is the service identifier.
+     * @return the participant associated with the invocation.
      */
-    public void processInvocation(String taskId, String serviceId)
+    public Participant processInvocation(String taskId, String serviceId)
     {
         log.info("processInvocation()");
 
@@ -135,7 +140,7 @@
         if (taskList.contains(taskId) || taskServiceMapping.containsKey(taskId))
         {
             log.info("Task is already known. Exiting...");
-            return;
+            return null;
         }
 
         // Remember the task and its service
@@ -179,6 +184,8 @@
         {
             e.printStackTrace();
         }
+        
+        return participant;
 
     }
 

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/aspect/JaxWSBAProcessingAspect.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/aspect/JaxWSBAProcessingAspect.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/aspect/JaxWSBAProcessingAspect.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -1,26 +1,15 @@
 package org.jboss.txbridge.ba.aspect;
 
+import org.apache.log4j.Logger;
 import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.txbridge.ba.data.ClassInformation;
-import org.jboss.txbridge.ba.data.MethodInformation;
-import org.jboss.txbridge.ba.data.ServiceDescription;
 import org.jboss.txbridge.ba.BATransactionManager;
-import org.jboss.txbridge.ba.id.IdentifierFactory;
-import org.jboss.txbridge.ba.id.UidIdentifierFactory;
-import org.jboss.txbridge.ba.annotation.BAParam;
-import org.jboss.txbridge.ba.annotation.BACompensationManagement;
-import org.jboss.txbridge.ba.helper.ClassInformationManager;
-import org.jboss.txbridge.ba.helper.ClassBAVisitor;
+import org.jboss.txbridge.ba.annotation.BAAgreementType;
+import org.jboss.txbridge.ba.data.ServiceDescription;
+import org.jboss.txbridge.ba.data.TaskDescription;
 import org.jboss.txbridge.ba.helper.ServiceInformationManager;
-import org.jboss.txbridge.ba.helper.BAServiceVisitor;
-import org.jboss.txbridge.ba.compensation.CompensationManager2Impl;
-import org.apache.log4j.Logger;
+import org.jboss.txbridge.ba.helper.CompensationManagement;
 
 import java.lang.reflect.Method;
-import java.lang.reflect.Field;
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.HashMap;
 
 /**
  * Author: Maciej Machulak
@@ -30,269 +19,51 @@
     // Logger
     private static Logger log = Logger.getLogger(JaxWSBAProcessingAspect.class);
 
-    // Holds information about classes that are used
-    private static ClassInformationManager classInfoManager = ClassInformationManager.getSingletonInstance();
+    // BA Transaction Manager
+    private static BATransactionManager baTransactionManager = BATransactionManager.getSingletonInstance();
 
     // Service information manager
     private static ServiceInformationManager serviceManager = ServiceInformationManager.getSingletonInstance();
 
     public Object process(MethodInvocation invocation) throws Throwable
     {
+
         log.info("process()");
 
-        // Process this service if necessary
+        // #### IMPLEMENTATION SPECIFIC PART - BEGIN
+        // 1) Method
+        // 2) Arguments
+        // 3) Target Object
         Method method = invocation.getMethod();
-        String methodName = method.getName();
-        String className = method.getDeclaringClass().getName();
-        log.info("Class: " + className);
-        log.info("Method: " + methodName);
-        log.info("Checking if the service is known...");
-        if (!serviceManager.knowsAboutByName(className+methodName))
-        {
-            log.info("Service unknown... processing...");
-            ServiceDescription sd = BAServiceVisitor.processMethod(method);
-            serviceManager.storeServiceDescription(sd);
-        }
-        else
-        {
-            log.info("Service already known...");
-        }
-        log.info("Getting service ID.");
-        String serviceId = serviceManager.getServiceId(className+methodName);
-        log.info("Service ID: " + serviceId);
-
-        // Get a new unique task for this invocation
-        log.info("Getting new task identifier...");
-        IdentifierFactory idf = new UidIdentifierFactory();
-        String taskId = idf.getIdentifier();
-        log.info("Task ID: " + taskId);
-
-        
-
-        // Inject the transaction identifier
+        Object[] arguments = invocation.getArguments();
         Object targetObject = invocation.getTargetObject();
-        Class clazzz = targetObject.getClass();
-        log.info("Injecting task identifier...");
-        Field[] fields = clazzz.getDeclaredFields();
-        for (Field singleField : fields)
-        {
-            BACompensationManagement cm = singleField.getAnnotation(BACompensationManagement.class);
-            if (cm != null)
-            {
-                log.info("CompensationManager2 found...");
-                log.info("Creating new one...");
-                log.info("taskId: " + taskId);
-                singleField.setAccessible(true);
-                singleField.set(targetObject,new CompensationManager2Impl("",taskId));
-            }
-        }
-        invocation.setTargetObject(targetObject);
+        // #### IMPLEMENTATION SPECIFIC PART - END
 
-        // Get method
-        Method theMethod = invocation.getMethod();
 
-        // Get class
-        Class clazz = theMethod.getDeclaringClass();
 
-        // Process the class
-        ClassInformation classInfo = classInfoManager.getClassInformation(clazz.getName());
+        // Handle the transaction
+        TaskDescription taskDesc = baTransactionManager.handleTransaction(method,arguments);
 
-        // Get original method name
-        methodName = theMethod.getName();
+        // Inject the compensation manager
+        targetObject = CompensationManagement.injectCompensationManager(targetObject,taskDesc);
 
-        // Get method information
-        MethodInformation methodInfo = classInfo.getMethodInformation(methodName);
 
-        // Display for logging purposes
-        log.info("Business Activity...");
-        log.info("BAService: " + methodInfo.getServiceType());
-        log.info("BAAgreement: " + methodInfo.getTransactionAttribute());
-        log.info("BACompensatedBy: " + methodInfo.getCompensationMethod());
-        log.info("Return Type: " + methodInfo.getReturnType().getName());
-        log.info("Compensation Type: " + methodInfo.getCompensationType());
 
-        // Remember necessary parameters
-        boolean rememberReturn = true;
-        boolean rememberParameters = false;
-        Object[] parameterObjects = null;
-        Map<String,Object> arguments = new HashMap<String,Object>();
-        String compensationType = methodInfo.getCompensationType();
-        log.info("Processing according to the compensation type...");
-        // If the compensation is by return value we do not have to remember any parameters
-        if (!compensationType.equals("RETURN_VALUE"))
-        {
-            log.info("Must check what parameters we need.");
-            // If the compensation is by parameters that match we just remember the arguments
-            if (compensationType.equals("PARAMETERS_MATCH"))
-            {
-                log.info("Parameters match. Remember all arguments.");
-                // ...and we don't want to remember the return value
-                rememberReturn = false;
-                rememberParameters = true;
-                parameterObjects = invocation.getArguments();
-            }
-            // ...but if the compensation type is custom than we must remember mappings
-            // between identifiers and objects (possibly the return value as well)
-            else if ( compensationType.equals("CUSTOM"))
-            {
-                log.info("Parameters do not match. Checking parameter annotations.");
-                Annotation[][] parameterAnnotations = theMethod.getParameterAnnotations();
-                Object[] parameters = invocation.getArguments();
-                // Check each parameter if it has the @BAParam annotation
-                int i = 0;
-                for (Annotation[] annotationArray : parameterAnnotations)
-                {
-                    int j = 0;
-                    log.info("Annotation array length: " + annotationArray.length);
-                    for (Annotation annotation : annotationArray)
-                    {
-                        if (annotation instanceof BAParam)
-                        {
-                            log.info("BAParam annotation present at position: (" + i + "," + j + ")");
-                            String value = ((BAParam)annotation).value();
-                            log.info("Value: " + value);
-                            arguments.put(value,parameters[i]);
-                        }
-                        j++;
-                    }
 
-                    i++;
-                }
-            }
-        }
-        else
-        {
-            log.info("Doing nothing with parameters.");
-        }
-
-        // Check the type of transaction
-        if (methodInfo.getTransactionAttribute() == null)
-        {
-
-        }
-        else if (methodInfo.getTransactionAttribute().equals("COORDINATOR_COMPLETION"))
-        {
-
-        }
-        else if (methodInfo.getTransactionAttribute().equals("PARTICIPANT_COMPLETION"))
-        {
-            // Get reference to the BATransactionManager
-            log.info("Getting reference to the BA Bridge Manager");
-            BATransactionManager babridgeManager = BATransactionManager.getSingletonInstance();
-
-            // Starting transaction management
-            log.info("Starting transaction managemenet");
-            babridgeManager.handleTheTransaction(methodInfo,taskId);
-
-        }
-
+        // #### IMPLEMENTATION SPECIFIC PART - BEGIN
         // Invoke the service
+        invocation.setTargetObject(targetObject);
         Object returnObject = invocation.invokeNext();
-        log.info("No exception... proceeding...");
+        // #### IMPLEMENTATION SPECIFIC PART - END
 
-        // Check the type of transaction
-        if (methodInfo.getTransactionAttribute() == null)
-        {
 
-        }
-        else if (methodInfo.getTransactionAttribute().equals("COORDINATOR_COMPLETION"))
-        {
 
-        }
-        else if (methodInfo.getTransactionAttribute().equals("PARTICIPANT_COMPLETION"))
-        {
-            log.info("Getting reference to the bridge manager");
-            BATransactionManager babridgeManager = BATransactionManager.getSingletonInstance();
+        log.info("No exception... proceeding...");
 
-            // Get the return object if necessary
-            if (rememberReturn)
-            {
-                log.info("Checking return type...");
-                Class returnType = methodInfo.getReturnType();
-                String returnName = methodInfo.getReturnName();
-                log.info("Return type: " + returnType.getName());
-                if (!methodInfo.getReturnType().getName().equals("void"))
-                {
-                    log.info("Getting return object");
-                    log.info("Return object: " + returnObject.toString());
-                    log.info("Return name: " + returnName);
+        // Complete the execution within this transaction
+        baTransactionManager.completeTransaction(taskDesc,returnObject);
 
-                    // Set return object
-                    log.info("Remembering return object");
-                    babridgeManager.manageReturnObject(returnName,returnObject,taskId);
-                }
-            }
-            if (rememberParameters)
-            {
-                babridgeManager.manageParameterObjects(parameterObjects,taskId);
-            }
-            babridgeManager.manageCustomObjects(arguments,taskId);
-            // Complete the transaction
-            babridgeManager.completeTransaction();
-        }
-
         return returnObject;
     }
 
-    public Object specify(MethodInvocation invocation) throws Throwable
-    {
-        log.info("specify()");
-
-        // Get method
-        Method theMethod = invocation.getMethod();
-        log.info("Executing method: " + theMethod.getName());
-
-        // Get class
-        Class clazz = theMethod.getDeclaringClass();
-
-        // Get reference to the class manager
-        ClassInformationManager classInfoManager = ClassInformationManager.getSingletonInstance();
-
-        // Obtain information about the class
-        // - first check if the classInfoManager knows about this class
-        ClassInformation classInfo = classInfoManager.getClassInformation(clazz.getName());
-        // - if not than process this class
-        if (classInfo == null)
-        {
-            // Process class and obtain info
-            classInfo = ClassBAVisitor.processClass(clazz);
-
-            // Remember info about the class
-            classInfoManager.storeClassInformation(classInfo);
-
-        }
-
-        // Get the real name of the method
-        String methodName = theMethod.getName();
-
-        // Display for logging purposes
-        MethodInformation methodInfo = classInfo.getMethodInformation(methodName);
-        String transactionType =  methodInfo.getTransactionAttribute();
-        log.info("Mapping: (" + methodName + "," + transactionType + ")");
-        String serviceType =  methodInfo.getServiceType();
-        log.info("Mapping: (" + methodName + "," + serviceType + ")");
-        String compensationMethod = methodInfo.getCompensationMethod();
-        log.info("Link: (" + methodName + "," + compensationMethod + ")");
-        Class returnType = methodInfo.getReturnType();
-        log.info("Return type: (" + methodName + "," + returnType.getName() + ")");
-        String compensationType = methodInfo.getCompensationType();
-        log.info("Compensation type: (" + methodName + "," + compensationType + ")");
-
-        return invocation.invokeNext();
-
-    }
-
-    /*
-    public Object access(FieldReadInvocation invocation) throws Throwable
-    {
-        log.info("Reading compensation manager");
-        return compensationManager;
-    }
-
-    public Object access(FieldWriteInvocation invocation) throws Throwable
-    {
-        throw new RuntimeException("Setting an @BACompensationManagement variable is illegal");
-    }
-    */
-
 }

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/compensation/CompensationManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/compensation/CompensationManagerImpl.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/compensation/CompensationManagerImpl.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -2,6 +2,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.txbridge.ba.participant.Participant;
+import org.jboss.txbridge.ba.data.TaskDescription;
 
 /**
  * @author: Maciej P. Machulak
@@ -23,10 +24,10 @@
     // Participant
     private Participant participant;
 
-    CompensationManagerImpl(String taskId, Participant participant)
+    public CompensationManagerImpl(TaskDescription td)
     {
-        this.taskId = taskId;
-        this.participant = participant;
+        this.taskId = td.getTaskId();
+        this.participant = td.getParticipant();
     }
 
     /**
@@ -36,10 +37,9 @@
      * @param objectId is the ID of the object.
      * @param object is the object itself :)
      */
-    public void put(String objectId, Object object)
+    public void put(Object objectId, Object object)
     {
         participant.put(taskId,objectId,object);
-
     }
 
     /**
@@ -49,7 +49,7 @@
      * @param objectId is the ID of the object.
      * @return the object.
      */
-    public Object get(String objectId)
+    public Object get(Object objectId)
     {
         return participant.get(taskId,objectId);
     }

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/CompensationData.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/CompensationData.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/CompensationData.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -1,7 +1,30 @@
 package org.jboss.txbridge.ba.data;
 
+import org.jboss.txbridge.ba.compensation.ServiceExecutor;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+
 /**
  * Author: Maciej Machulak
  */
-public abstract class CompensationData {
+public abstract class CompensationData
+{
+    ConcurrentMap<Object,Object> compensationData;
+
+    protected CompensationData()
+    {
+        compensationData = new ConcurrentHashMap<Object,Object>();
+    }
+
+    public Object get(Object key) 
+    {
+        return compensationData.get(key);
+    }
+
+    public Object put(Object key, Object value)
+    {
+        return compensationData.put(key, value);
+    }
 }

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescription.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescription.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescription.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -10,7 +10,7 @@
 /**
  * Author: Maciej Machulak
  */
-public interface ServiceDescription extends Serializable 
+public interface ServiceDescription extends Serializable
 {
     BAServiceType getServiceType();
 
@@ -64,14 +64,6 @@
 
     public void setCompensationParameterTypes(Class[] compensationParameterTypes);
 
-    public Map<String, Integer> getOriginalParameterAnnotations();
-
-    public void setOriginalParameterAnnotations(Map<String, Integer> originalParameterAnnotations);
-
-    public Map<Integer, Integer> getOriginalParameterAnnotations2();
-
-    public void setOriginalParameterAnnotations2(Map<Integer, Integer> originalParameterAnnotations2);
-
     public Map<String, Integer> getCompensationParameterAnnotations();
 
     public void setCompensationParameterAnnotations(Map<String, Integer> compensationParameterAnnotations);
@@ -80,12 +72,12 @@
 
     public void setIdentificationType(IdentificationType identificationType);
 
-    public String getOriginalReturnName();
+    public Object getOriginalReturnId();
 
-    public void setOriginalReturnName(String originalReturnName);
+    public void setOriginalReturnId(Object originalReturnId);
 
-    public Integer getOriginalReturnId();
+    public Object[] getOriginalParameterAnnotation();
 
-    public void setOriginalReturnId(Integer originalReturnId);
+    public void setOriginalParameterAnnotation(Object[] originalParameterAnnotation);
 
 }

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescriptionImpl.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescriptionImpl.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/ServiceDescriptionImpl.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -22,8 +22,6 @@
 
     public ServiceDescriptionImpl()
     {
-        originalParameterAnnotations = new HashMap<String,Integer>();
-        originalParameterAnnotations2 = new HashMap<Integer,Integer>();
         compensationParameterAnnotations = new HashMap<String,Integer>();
     }
 
@@ -42,10 +40,8 @@
     private String originalMethodName;
     private String originalWebMethodName;
     private Class[] originalParameterTypes;
-    private Map<String,Integer> originalParameterAnnotations;
-    private Map<Integer,Integer> originalParameterAnnotations2;
-    private String originalReturnName;
-    private Integer originalReturnId;
+    private Object[] originalParameterAnnotation;
+    private Object originalReturnId;
     private Class originalReturnType;
 
     /**
@@ -190,27 +186,6 @@
         this.compensationParameterTypes = compensationParameterTypes;
     }
 
-
-    public Map<String, Integer> getOriginalParameterAnnotations()
-    {
-        return originalParameterAnnotations;
-    }
-
-    public void setOriginalParameterAnnotations(Map<String, Integer> originalParameterAnnotations)
-    {
-        this.originalParameterAnnotations = originalParameterAnnotations;
-    }
-
-    public Map<Integer, Integer> getOriginalParameterAnnotations2()
-    {
-        return originalParameterAnnotations2;
-    }
-
-    public void setOriginalParameterAnnotations2(Map<Integer, Integer> originalParameterAnnotations2)
-    {
-        this.originalParameterAnnotations2 = originalParameterAnnotations2;
-    }
-
     public Map<String, Integer> getCompensationParameterAnnotations()
     {
         return compensationParameterAnnotations;
@@ -232,23 +207,23 @@
         this.identificationType = identificationType;
     }
 
-    public String getOriginalReturnName()
+    public Object getOriginalReturnId()
     {
-        return originalReturnName;
+        return originalReturnId;
     }
 
-    public void setOriginalReturnName(String originalReturnName)
+    public void setOriginalReturnId(Object originalReturnId)
     {
-        this.originalReturnName = originalReturnName;
+        this.originalReturnId = originalReturnId;
     }
 
-    public Integer getOriginalReturnId()
+    public Object[] getOriginalParameterAnnotation()
     {
-        return originalReturnId;
+        return originalParameterAnnotation;
     }
 
-    public void setOriginalReturnId(Integer originalReturnId)
+    public void setOriginalParameterAnnotation(Object[] originalParameterAnnotation)
     {
-        this.originalReturnId = originalReturnId;
+        this.originalParameterAnnotation = originalParameterAnnotation;
     }
 }
\ No newline at end of file

Added: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/TaskDescription.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/TaskDescription.java	                        (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/data/TaskDescription.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -0,0 +1,73 @@
+package org.jboss.txbridge.ba.data;
+
+import org.jboss.txbridge.ba.participant.Participant;
+
+/**
+ * @author: Maciej P. Machulak
+ * @date: Jul 4, 2007
+ */
+public class TaskDescription
+{
+    private String txId;
+    private String taskId;
+    private String serviceId;
+    private Participant participant;
+
+
+    public TaskDescription(String txId, String taskId, String serviceId, Participant participant)
+    {
+        this.txId = txId;
+        this.taskId = taskId;
+        this.serviceId = serviceId;
+        this.participant = participant;
+    }
+
+
+    public String getTxId()
+    {
+        return txId;
+    }
+
+    public String getTaskId()
+    {
+        return taskId;
+    }
+
+    public String getServiceId()
+    {
+        return serviceId;
+    }
+
+    public Participant getParticipant()
+    {
+        return participant;
+    }
+
+
+    public boolean equals(Object o)
+    {
+        if (this == o)
+        {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass())
+        {
+            return false;
+        }
+
+        TaskDescription that = (TaskDescription) o;
+
+        return participant.equals(that.participant) && serviceId.equals(that.serviceId) && taskId.equals(that.taskId) && txId.equals(that.txId);
+
+    }
+
+    public int hashCode()
+    {
+        int result;
+        result = txId.hashCode();
+        result = 31 * result + taskId.hashCode();
+        result = 31 * result + serviceId.hashCode();
+        result = 31 * result + participant.hashCode();
+        return result;
+    }
+}

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/BAServiceVisitor.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/BAServiceVisitor.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/BAServiceVisitor.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -10,7 +10,10 @@
 import javax.jws.WebMethod;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
+import java.util.HashMap;
 import java.lang.reflect.Method;
+import java.lang.annotation.Annotation;
 
 /**
  * @author: Maciej P. Machulak
@@ -216,8 +219,42 @@
 
 
         // Remember @BAParam annotation values
+        Object[] parameterAnnotation = new Object[method.getParameterTypes().length];
+        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+        int i = 0;
+        for (Annotation[] annotationArray : parameterAnnotations)
+        {
+            for (Annotation annotation : annotationArray)
+            {
+                if (annotation instanceof BAParam)
+                {
+                    log.info("BAParam annotation present for parameter: " + i);
+                    String valueS = ((BAParam)annotation).value();
+                    try
+                    {
+                        Integer valueI = new Integer(valueS);
+                        if (serviceDescription.getIdentificationType() == IdentificationType.BY_NAME)
+                        {
+                            throw new MethodIncorrectlyAnnotatedException("BAParam annotation uses numerical identifier.");
+                        }
+                        parameterAnnotation[i] = valueI;
+                        serviceDescription.setIdentificationType(IdentificationType.BY_NUMBER);
+                    }
+                    catch (NumberFormatException nfe)
+                    {
+                        if (serviceDescription.getIdentificationType() == IdentificationType.BY_NUMBER)
+                        {
+                            throw new MethodIncorrectlyAnnotatedException("BAParam annotation uses text identifier.");
+                        }
+                        parameterAnnotation[i] = valueS;
+                        serviceDescription.setIdentificationType(IdentificationType.BY_NAME);
+                    }
+                }
+            }
+            i++;
+        }
+        serviceDescription.setOriginalParameterAnnotation(parameterAnnotation);
 
-
         // Remember @BAResult annotation value
         BAResult baResult = method.getAnnotation(BAResult.class);
         String returnName = "";

Added: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/CompensationManagement.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/CompensationManagement.java	                        (rev 0)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/helper/CompensationManagement.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -0,0 +1,48 @@
+package org.jboss.txbridge.ba.helper;
+
+import org.jboss.txbridge.ba.annotation.BACompensationManagement;
+import org.jboss.txbridge.ba.compensation.CompensationManagerImpl;
+import org.jboss.txbridge.ba.data.TaskDescription;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.Field;
+
+/**
+ * @author: Maciej P. Machulak
+ * @date: Jul 4, 2007
+ */
+public class CompensationManagement
+{
+    // Logger
+    private static Logger log = Logger.getLogger(CompensationManagement.class);
+
+    public static synchronized Object injectCompensationManager(Object targetObject, TaskDescription taskDesc)
+    {
+        // Inject the transaction identifier
+        try
+        {
+            Class clazz = targetObject.getClass();
+            log.info("Injecting task identifier...");
+            Field[] fields = clazz.getDeclaredFields();
+            for (Field singleField : fields)
+            {
+                BACompensationManagement cm = singleField.getAnnotation(BACompensationManagement.class);
+                if (cm != null)
+                {
+                    log.info("CompensationManager found...");
+                    log.info("Creating new one...");
+                    log.info("taskId: " + taskDesc.getTaskId());
+                    singleField.setAccessible(true);
+                    singleField.set(targetObject,new CompensationManagerImpl(taskDesc));
+                    return targetObject;
+                }
+            }
+        }
+        catch (IllegalAccessException iae)
+        {
+            iae.printStackTrace();
+            return null;
+        }
+        return null;
+    }
+}

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/old/JaxWSBusinessActivityHandler.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/old/JaxWSBusinessActivityHandler.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/old/JaxWSBusinessActivityHandler.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -166,7 +166,7 @@
                     //babridgeManager.manageReturnObject(methodInfo,returnObject,"");
                 }
 
-                babridgeManager.completeTransaction();
+                babridgeManager.completeTheTransaction();
             }
 
 

Modified: labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/participant/Participant.java
===================================================================
--- labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/participant/Participant.java	2007-07-04 18:41:53 UTC (rev 13089)
+++ labs/jbosstm/workspace/maciej.machulak/code/bridge/org/jboss/txbridge/ba/participant/Participant.java	2007-07-04 19:30:41 UTC (rev 13090)
@@ -89,10 +89,19 @@
      * @param objectId is the ID of the object.
      * @param object is the object to be stored.
      */
-    public void put(String taskId,String objectId,Object object)
+    public void put(String taskId,Object objectId,Object object)
     {
-        // TODO: Implementation...
-
+        // Get the correct compensation data
+        CompensationData cd = compensationData.get(taskId);
+        if (cd == null)
+        {
+            return;
+        }
+        // Put the data
+        if (objectId instanceof Integer || objectId instanceof String)
+        {
+            cd.put(objectId,object);
+        }
     }
 
     /**
@@ -103,9 +112,18 @@
      * @param objectId is the ID of the object.
      * @return the object with a given ID.
      */
-    public Object get(String taskId,String objectId)
+    public Object get(String taskId,Object objectId)
     {
-        // TODO: Implementation...
+        // Get the correct compensation data
+        CompensationData cd = compensationData.get(taskId);
+        if (cd == null)
+        {
+            return null;
+        }
+        if (objectId instanceof Integer || objectId instanceof String)
+        {
+            return cd.get(objectId);
+        }
         return null;
     }
 




More information about the jboss-svn-commits mailing list