Author: dasarath
Date: Mon Jun 18 13:07:55 2007
New Revision: 548468

URL: http://svn.apache.org/viewvc?view=rev&rev=548468
Log:
Hannes Erven, Georg Hicker

Modified:
    
webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java

Modified: 
webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java?view=diff&rev=548468&r1=548467&r2=548468
==============================================================================
--- 
webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java
 (original)
+++ 
webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java
 Mon Jun 18 13:07:55 2007
@@ -7,11 +7,13 @@
 import java.net.MalformedURLException;
 import java.rmi.RemoteException;
 
+import javax.xml.namespace.QName;
 import javax.xml.rpc.ServiceException;
 
 import org.apache.axis.AxisFault;
 import org.apache.axis.components.uuid.UUIDGen;
 import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.MessageElement;
 import org.apache.axis.message.addressing.EndpointReference;
 import org.apache.axis.types.URI.MalformedURIException;
 import org.apache.kandula.utils.SoapFaultSender;
@@ -19,51 +21,107 @@
 import org.apache.kandula.wscoor.RegisterType;
 
 /**
- * @author Dasarath Weeratunge
+ * An abstract implementation of the Coordinator interface.
+ * 
+ * @author Dasarath Weeratunge, Hannes Erven, Georg Hicker
  *  
  */
 public abstract class CoordinatorImpl extends Coordinator {
 
-       private String id;
-
+       /**
+        * 
+        * This header element is set to a value the initiator chose for the
+        * participant before forwarding the registration service endpoint.
+        */
+       public final static QName INITIATOR_MATCHCODE = new QName(
+                       "http://ws.apache.org/kandula/ws-ba--extension";, 
"matchcode"
+       );
+       
+       /**
+        * T
+        */
        private CoordinationContext ctx;
 
        protected CoordinatorImpl(String coordinationType)
-                       throws MalformedURIException {
+                       throws MalformedURIException 
+       {
                UUIDGen gen = UUIDGenFactory.getUUIDGen();
-               id = "uuid:" + gen.nextUUID();
+               final String id = "uuid:" + gen.nextUUID();
+               
                CoordinationService cs = CoordinationService.getInstance();
-               EndpointReference epr = 
cs.getRegistrationCoordinatorService(this);
-               ctx = new CoordinationContext(id, coordinationType, epr);
+               EndpointReference epr = 
cs.getRegistrationCoordinatorService(this, id);
+
+               this.ctx = new CoordinationContext(id, coordinationType, epr);
        }
 
        public String getID() {
+               final String id = 
this.ctx.getIdentifier().get_value().toString();
                return id;
        }
 
        public CoordinationContext getCoordinationContext() {
-               return ctx;
+               return this.ctx;
        }
 
-       public abstract EndpointReference register(String prot,
-                       EndpointReference pps) throws 
InvalidCoordinationProtocolException;
+       /**
+        * Welcome a new participant in a transaction context.
+        * @param prot The protocol the participant wishes to register for
+        * @param pps The participant's protocol service endpoint
+        * @param referenceCode The reference code the initiator provided to 
the participant
+        * @return The coordinator's endpoint reference for this participant
+        * @throws InvalidCoordinationProtocolException
+        */
+       public abstract EndpointReference register(
+                       final String prot,
+                       final EndpointReference pps,
+                       final String referenceCode
+       ) throws InvalidCoordinationProtocolException;
+
+       
+       /**
+        * Add a participant matchcode to the default registration service.
+        * ATTENTION: at this point there are no checks!
+        * @param participantMATCHCODE The matchcode
+        * @return The service.
+        */
+       protected CoordinationContext getCoordinationContext(final String 
participantMATCHCODE) {
+               final CoordinationContext ctx = this.getCoordinationContext();
+               
+               // Duplicate the coordination context!
+               final CoordinationContext r = 
+                       new CoordinationContext(
+                                       ctx.getIdentifier(), 
+                                       ctx.getCoordinationType(), 
+                                       new 
EndpointReference(ctx.getRegistrationService())
+                       );
+
+               final MessageElement participantIDMessageElement = 
+                       new MessageElement(INITIATOR_MATCHCODE, 
participantMATCHCODE);
+               
r.getRegistrationService().getProperties().add(participantIDMessageElement);
+
+               return r;
+       }
 
        public synchronized RegisterResponseType registerOperation(
                        RegisterType params) throws RemoteException {
 
                EndpointReference epr = null;
                try {
-                       epr = 
register(params.getProtocolIdentifier().toString(),
-                               new 
EndpointReference(params.getParticipantProtocolService()));
-
+                       epr = register(
+                               params.getProtocolIdentifier().toString(),
+                               new 
EndpointReference(params.getParticipantProtocolService()),
+                               CallbackRegistry.getRef(INITIATOR_MATCHCODE)
+                       );
                } catch (InvalidCoordinationProtocolException e) {
                        throw INVALID_PROTOCOL_SOAP_FAULT();
 
                } catch (IllegalStateException e) {
                        throw INVALID_STATE_SOAP_FAULT();
 
+
                } catch (IllegalArgumentException e) {
                        throw INVALID_PARAMETERS_SOAP_FAULT();
+
                }
 
                RegisterResponseType r = new RegisterResponseType();
@@ -85,4 +143,4 @@
                }
        }
 
-}
\ No newline at end of file
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to