diff --git a/src/org/apache/kandula/context/ActivityContext.java b/src/org/apache/kandula/context/ActivityContext.java
index 676fe42..290dc03 100644
--- a/src/org/apache/kandula/context/ActivityContext.java
+++ b/src/org/apache/kandula/context/ActivityContext.java
@@ -16,21 +16,21 @@
*/
package org.apache.kandula.context;
-import java.util.Iterator;
-
import org.apache.axis2.addressing.EndpointReference;
import org.apache.kandula.KandulaException;
-import org.apache.kandula.typemapping.CoordinationContext;
+import org.apache.kandula.context.coordination.CoordinationContext;
+
+import java.util.Iterator;
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
public interface ActivityContext {
-
+
public abstract EndpointReference addParticipant(EndpointReference participantEPR, String protocol) throws KandulaException;
-
+
public abstract Iterator getRegisteredParticipants(String protocol);
-
+
public abstract Iterator getAllParticipants();
public abstract int getStatus();
@@ -40,13 +40,13 @@
public abstract void lock();
public abstract void unlock();
-
+
public abstract void setProperty(Object key, Object value);
-
+
public abstract Object getProperty(Object key);
-
+
public abstract CoordinationContext getCoordinationContext();
-
+
public abstract void setCoordinationContext(CoordinationContext context);
-
+
}
\ No newline at end of file
diff --git a/src/org/apache/kandula/context/ActivityContextImpl.java b/src/org/apache/kandula/context/ActivityContextImpl.java
index 3d4fb4b..a873ea4 100644
--- a/src/org/apache/kandula/context/ActivityContextImpl.java
+++ b/src/org/apache/kandula/context/ActivityContextImpl.java
@@ -16,17 +16,16 @@
*/
package org.apache.kandula.context;
-import java.util.HashMap;
-
-import javax.xml.namespace.QName;
-
import org.apache.axis2.addressing.AnyContentType;
import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.context.coordination.CoordinationContext;
import org.apache.kandula.Status.CoordinatorStatus;
-import org.apache.kandula.typemapping.CoordinationContext;
import org.apache.kandula.utility.EndpointReferenceFactory;
import org.apache.kandula.utility.KandulaUtils;
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
@@ -48,7 +47,7 @@
public ActivityContextImpl(String coordinationType) {
propertyBag = new HashMap();
- activityID = KandulaUtils.getRandomStringOf18Characters();
+ activityID = KandulaUtils.getRandomStringOf18Characters();
coordinationContext = CoordinationContext.Factory.newInstance();
coordinationContext.setActivityID(activityID);
EndpointReference registrationEpr = EndpointReferenceFactory
@@ -70,6 +69,12 @@
this.coordinationContext = context;
}
+// public abstract EndpointReference addParticipant(EndpointReference participantEPR, String protocol) throws KandulaException;
+//
+// public abstract Iterator getRegisteredParticipants(String protocol);
+//
+// public abstract Iterator getAllParticipants();
+
public int getStatus() {
return status;
}
diff --git a/src/org/apache/kandula/context/ContextFactory.java b/src/org/apache/kandula/context/ContextFactory.java
index 03a440a..e9bc834 100644
--- a/src/org/apache/kandula/context/ContextFactory.java
+++ b/src/org/apache/kandula/context/ContextFactory.java
@@ -19,7 +19,7 @@
import org.apache.axis2.addressing.EndpointReference;
import org.apache.kandula.KandulaException;
import org.apache.kandula.context.at.ATActivityContext;
-import org.apache.kandula.typemapping.CoordinationContext;
+import org.apache.kandula.context.coordination.CoordinationContext;
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
@@ -42,7 +42,7 @@
}
public ActivityContext createActivity(String protocol,
- EndpointReference activationEPR) throws KandulaException {
+ EndpointReference activationEPR) throws KandulaException {
if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(protocol)) {
return new ATActivityContext(activationEPR);
} else {
diff --git a/src/org/apache/kandula/context/Participant.java b/src/org/apache/kandula/context/Participant.java
index d53eb09..4c4a5d8 100644
--- a/src/org/apache/kandula/context/Participant.java
+++ b/src/org/apache/kandula/context/Participant.java
@@ -1,34 +1,34 @@
- /*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
+/*
+* Copyright 2004 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
package org.apache.kandula.context;
import org.apache.axis2.addressing.EndpointReference;
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
- *
- * Used to store the details about the participant & to store the runtime status
- * of Participants
+ * <p/>
+ * Used to store the details about the participant & to store the runtime status
+ * of Participants
*/
public class Participant {
private EndpointReference epr;
private String protocol;
private int status;
-
+
/**
* @param epr
* @param protocol
@@ -39,16 +39,14 @@
this.epr = epr;
this.protocol = protocol;
}
-
- public void setStatus(int status)
- {
+
+ public void setStatus(int status) {
this.status = status;
}
-
- public int getStatus()
- {
+
+ public int getStatus() {
return status;
}
-
-
+
+
}
\ No newline at end of file
diff --git a/src/org/apache/kandula/context/at/ATActivityContext.java b/src/org/apache/kandula/context/at/ATActivityContext.java
index 74da3f6..11abba2 100644
--- a/src/org/apache/kandula/context/at/ATActivityContext.java
+++ b/src/org/apache/kandula/context/at/ATActivityContext.java
@@ -16,19 +16,20 @@
*/
package org.apache.kandula.context.at;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-
+import org.apache.axis2.addressing.EndpointReference;
import org.apache.kandula.Constants;
import org.apache.kandula.KandulaException;
import org.apache.kandula.context.ActivityContext;
import org.apache.kandula.context.ActivityContextImpl;
import org.apache.kandula.context.Participant;
-import org.apache.kandula.typemapping.CoordinationContext;
+import org.apache.kandula.context.coordination.CoordinationContext;
import org.apache.kandula.utility.EndpointReferenceFactory;
import org.apache.kandula.utility.KandulaUtils;
-import org.apache.axis2.addressing.EndpointReference;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
@@ -64,8 +65,7 @@
}
/**
- * @param context
- * To be used when coordinator is used as a sub ordinate to an another cooordinator
+ * @param context To be used when coordinator is used as a sub ordinate to an another cooordinator
*/
public ATActivityContext(CoordinationContext context) {
subOrdinate = true;
@@ -76,12 +76,11 @@
durableParticipantsTable = new Hashtable();
setCoordinationContext(context);
}
+
/**
- * @param id
- * To be used when using as the requester
+ * @param id To be used when using as the requester
*/
- public ATActivityContext(EndpointReference activationEPR)
- {
+ public ATActivityContext(EndpointReference activationEPR) {
super();
this.setProperty(REQUESTER_ID, KandulaUtils.getRandomStringOf18Characters());
this.setProperty(ACTIVATION_EPR, activationEPR);
@@ -101,13 +100,10 @@
} else if (Constants.WS_AT_DURABLE2PC.equals(protocol)) {
addDurableParticipant(participantEPR);
return EndpointReferenceFactory.getInstance().get2PCEndpoint(this.activityID);
- }else if (Constants.WS_AT_COMPLETION.equals(protocol))
- {
+ } else if (Constants.WS_AT_COMPLETION.equals(protocol)) {
//TODO keep track of requesters
return EndpointReferenceFactory.getInstance().getCompletionEndpoint(this.activityID);
- }
- else
- {
+ } else {
throw new KandulaException("UnSupported Protocol");
}
}
@@ -151,7 +147,7 @@
}
public boolean hasMorePreparing() {
- return (preparingParticipantsCount > 0);
+ return (preparingParticipantsCount > 0);
}
public boolean getSubVolatileRegistered() {
diff --git a/src/org/apache/kandula/context/coordination/CoordinationContext.java b/src/org/apache/kandula/context/coordination/CoordinationContext.java
new file mode 100644
index 0000000..98fb1fd
--- /dev/null
+++ b/src/org/apache/kandula/context/coordination/CoordinationContext.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.kandula.context.coordination;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.om.OMElement;
+import org.apache.kandula.typemapping.xmlbeansimpl.XmlBeansTypeCoordinationContext;
+import org.apache.kandula.context.coordination.simple.SimpleCoordinationContext;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public interface CoordinationContext {
+ public abstract String getActivityID();
+
+ public abstract String getCoordinationType();
+
+ public abstract EndpointReference getRegistrationService();
+
+ public abstract long getExpires();
+
+ public abstract void setActivityID(String value);
+
+ public abstract void setCoordinationType(String value);
+
+ public abstract void setRegistrationService(EndpointReference value);
+
+ public abstract void setExpires(long value);
+
+ public abstract OMElement toOM();
+
+ public abstract Object getCoordinationContextType();
+
+ public static final class Factory {
+ public static CoordinationContext newInstance() {
+ return new SimpleCoordinationContext();
+ }
+
+ public static CoordinationContext newInstance(OMElement contextElement) {
+ return new SimpleCoordinationContext(contextElement);
+ }
+
+ public static CoordinationContext newInstance(Object contextType) {
+ return new XmlBeansTypeCoordinationContext(contextType);
+ }
+
+ private Factory() {
+ } // No instance of this class allowed
+ }
+}
\ No newline at end of file
diff --git a/src/org/apache/kandula/context/coordination/simple/SimpleCoordinationContext.java b/src/org/apache/kandula/context/coordination/simple/SimpleCoordinationContext.java
new file mode 100644
index 0000000..6f529e0
--- /dev/null
+++ b/src/org/apache/kandula/context/coordination/simple/SimpleCoordinationContext.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.kandula.context.coordination.simple;
+
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.AddressingConstants.Final;
+import org.apache.axis2.addressing.AnyContentType;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.kandula.Constants;
+import org.apache.kandula.context.coordination.CoordinationContext;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class SimpleCoordinationContext implements CoordinationContext {
+ private String activityID;
+
+ private String coordinationType;
+
+ private long expires;
+
+ private EndpointReference registrationServiceEpr;
+
+ private OMElement contextElement = null;
+
+ public SimpleCoordinationContext() {
+ super();
+ }
+
+ public SimpleCoordinationContext(OMElement contextElement) {
+ super();
+ this.contextElement = contextElement;
+ activityID = contextElement.getFirstChildWithName(
+ new QName("Identifier")).getText();
+ coordinationType = contextElement.getFirstChildWithName(
+ new QName("CoordinationType")).getText();
+ OMElement registrationElement = contextElement.getFirstChildWithName(
+ new QName("RegistrationService"));
+ registrationServiceEpr = new EndpointReference(registrationElement
+ .getFirstChildWithName(new QName("Address")).getText());
+ AnyContentType referenceProperties = new AnyContentType();
+ OMElement referencePropertiesElement = registrationElement
+ .getFirstChildWithName(new QName("ReferenceProperties"));
+ Iterator propertyIter = referencePropertiesElement.getChildElements();
+ while (propertyIter.hasNext()) {
+ OMElement element = (OMElement) propertyIter.next();
+ referenceProperties.addReferenceValue(element.getQName(), element
+ .getText());
+ }
+ registrationServiceEpr.setReferenceProperties(referenceProperties);
+ }
+
+ public String getActivityID() {
+ return activityID;
+ }
+
+ public String getCoordinationType() {
+ return coordinationType;
+ }
+
+ public EndpointReference getRegistrationService() {
+ return this.registrationServiceEpr;
+ }
+
+ public long getExpires() {
+ return expires;
+ }
+
+ public void setActivityID(String value) {
+ this.activityID = value;
+
+ }
+
+ public void setCoordinationType(String value) {
+ this.coordinationType = value;
+
+ }
+
+ public void setRegistrationService(EndpointReference epr) {
+ this.registrationServiceEpr = epr;
+ }
+
+ public void setExpires(long value) {
+ this.expires = value;
+ }
+
+ public Object getCoordinationContextType() {
+ return this;
+ }
+
+ public OMElement toOM() {
+ if (contextElement != null) {
+ return contextElement;
+ } else {
+ SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
+ OMNamespace wsCoor = factory.createOMNamespace(Constants.WS_COOR,
+ "wscoor");
+ OMElement contextElement = factory.createOMElement(
+ "CoordinationContext", wsCoor);
+ if (this.expires != 0) {
+ OMElement expiresElement = factory.createOMElement("Expires",
+ wsCoor);
+ expiresElement.setText(Long.toString(this.expires));
+ contextElement.addChild(expiresElement);
+ }
+ OMElement identifierElement = factory.createOMElement("Identifier",
+ wsCoor);
+ identifierElement.setText(this.activityID);
+ contextElement.addChild(identifierElement);
+ OMElement coorTypeElement = factory.createOMElement(
+ "CoordinationType", wsCoor);
+ coorTypeElement.setText(this.coordinationType);
+ contextElement.addChild(coorTypeElement);
+ OMElement registrationServiceElement = factory.createOMElement(
+ "RegistrationService", wsCoor);
+ OMNamespace wsAddressing = factory.createOMNamespace(
+ AddressingConstants.Submission.WSA_NAMESPACE,
+ AddressingConstants.WSA_DEFAULT_PRFIX);
+ OMElement addressElement = factory.createOMElement("Address",
+ wsAddressing);
+ addressElement.setText(registrationServiceEpr.getAddress());
+ registrationServiceElement.addChild(addressElement);
+ AnyContentType referenceValues = registrationServiceEpr
+ .getReferenceProperties();
+ if (referenceValues != null) {
+ OMElement refPropertyElement = factory.createOMElement(
+ "ReferenceProperties", wsAddressing);
+ registrationServiceElement.addChild(refPropertyElement);
+ Iterator iterator = referenceValues.getKeys();
+ while (iterator.hasNext()) {
+ QName key = (QName) iterator.next();
+ String value = referenceValues.getReferenceValue(key);
+ OMElement omElement = factory.createOMElement(key,
+ refPropertyElement);
+ refPropertyElement.addChild(omElement);
+ if (Final.WSA_NAMESPACE.equals(wsAddressing)) {
+ omElement.addAttribute(
+ Final.WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE,
+ Final.WSA_TYPE_ATTRIBUTE_VALUE, wsAddressing);
+ }
+ omElement.setText(value);
+ }
+ }
+ contextElement.addChild(registrationServiceElement);
+ return contextElement;
+ }
+ }
+}
\ No newline at end of file