01: package org.objectweb.celtix.bus.ws.rm;
02:
03: import java.math.BigInteger;
04: import java.util.Map;
05:
06: import javax.xml.namespace.QName;
07:
08: import org.objectweb.celtix.bus.configuration.wsrm.EndpointPolicyType;
09: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
10: import org.objectweb.celtix.ws.rm.Identifier;
11: import org.objectweb.celtix.ws.rm.policy.RMAssertionType;
12: import org.objectweb.celtix.ws.rm.policy.RMAssertionType.BaseRetransmissionInterval;
13: import org.objectweb.celtix.ws.rm.policy.RMAssertionType.ExponentialBackoff;
14:
15: public class RMEndpoint {
16:
17: private static final String POLICIES_PROPERTY_NAME = "policies";
18: private static final String RMASSERTION_PROPERTY_NAME = "rmAssertion";
19:
20: private RMHandler handler;
21:
22: protected RMEndpoint(RMHandler h) {
23: handler = h;
24: }
25:
26: public RMHandler getHandler() {
27: return handler;
28: }
29:
30: public RMAssertionType getRMAssertion() {
31: RMAssertionType a = getHandler().getConfiguration().getObject(
32: RMAssertionType.class, RMASSERTION_PROPERTY_NAME);
33:
34: // the following should not be necessary as the rm handler configuration metadata
35: // supplies a default value for the RMAssertion
36:
37: if (null == a) {
38: a = RMUtils.getWSRMPolicyFactory().createRMAssertionType();
39: RMUtils.getWSRMPolicyFactory().createRMAssertionType();
40: }
41:
42: if (null == a.getBaseRetransmissionInterval()) {
43: BaseRetransmissionInterval bri = RMUtils
44: .getWSRMPolicyFactory()
45: .createRMAssertionTypeBaseRetransmissionInterval();
46: bri
47: .setMilliseconds(new BigInteger(
48: RetransmissionQueue.DEFAULT_BASE_RETRANSMISSION_INTERVAL));
49: a.setBaseRetransmissionInterval(bri);
50: }
51:
52: if (null == a.getExponentialBackoff()) {
53: ExponentialBackoff eb = RMUtils.getWSRMPolicyFactory()
54: .createRMAssertionTypeExponentialBackoff();
55: a.setExponentialBackoff(eb);
56: }
57: Map<QName, String> otherAttributes = a.getExponentialBackoff()
58: .getOtherAttributes();
59: String val = otherAttributes
60: .get(RetransmissionQueue.EXPONENTIAL_BACKOFF_BASE_ATTR);
61: if (null == val) {
62: otherAttributes.put(
63: RetransmissionQueue.EXPONENTIAL_BACKOFF_BASE_ATTR,
64: RetransmissionQueue.DEFAULT_EXPONENTIAL_BACKOFF);
65: }
66:
67: return a;
68: }
69:
70: /**
71: * Generates and returns a sequence identifier.
72: *
73: * @return the sequence identifier.
74: */
75: public Identifier generateSequenceIdentifier() {
76: String sequenceID = ContextUtils.generateUUID();
77: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
78: sid.setValue(sequenceID);
79: return sid;
80: }
81:
82: public EndpointPolicyType getPolicies() {
83: return (EndpointPolicyType) handler.getConfiguration()
84: .getObject(POLICIES_PROPERTY_NAME);
85: }
86:
87: public String getEndpointId() {
88: return handler.getConfiguration().getParent().getId()
89: .toString();
90: }
91:
92: }
|