001: package com.sun.jbi.messaging;
002:
003: import java.net.URI;
004:
005: import javax.jbi.messaging.NormalizedMessage;
006:
007: /**
008: *
009: * Used to pass copied Message Exchanges to all known Observers of
010: * the NMR.
011: *
012: */
013: public class Observer extends MessageExchangeProxy {
014: /** Simple state machine for the SOURCE side of the pattern */
015: private static final int[][] SOURCE = {
016: { DO_ACCEPT | SET_PROPERTY, -1, 1, 0, 0 },
017: { MARK_DONE, -1, -1, -1, -1 }, };
018:
019: /** Simple state machine for the TARGET side of the pattern */
020: private static final int[][] TARGET = {
021: { DO_ACCEPT, -1, -1, -1, -1 },
022: { MARK_DONE, -1, -1, -1, -1 }, };
023:
024: private Role mRole;
025: private URI mPattern;
026:
027: /**
028: * Default Constructor
029: *
030: */
031: public Observer(MessageExchangeProxy me) {
032: this (SOURCE);
033: mRole = me.getRole();
034: mPattern = me.getPattern();
035: }
036:
037: /**
038: * Create a new Observer in the forward or reverse direction
039: * @param state
040: */
041: Observer(int[][] state) {
042: super (state);
043: }
044:
045: public Role getRole() {
046: return (mRole);
047: }
048:
049: /**
050: * Return a new instance of ourselves in the target role
051: */
052: public MessageExchangeProxy newTwin() {
053: return (new Observer(TARGET));
054: }
055:
056: /**
057: * Get the pattern
058: */
059: public URI getPattern() {
060: return mPattern;
061: }
062:
063: /**
064: * Retrieve the message with reference id "in" from this exchange.
065: * @return the in message, or null if it is not present in the exchange
066: */
067: public NormalizedMessage getInMessage() {
068: return getMessage(IN_MSG);
069: }
070:
071: /**
072: * Retrieve the message with the reference id "out" from this exchange.
073: * @return the out message, or null if it is not present in the exchange
074: */
075: public NormalizedMessage getOutMessage() {
076: return getMessage(OUT_MSG);
077: }
078:
079: /**
080: * Specifies the "in" message reference for this exchange
081: * @param msg in message
082: * @throws javax.jbi.messaging.MessagingException invalid message or the
083: * curent state of the exchange does not permit this operation.
084: */
085: public void setInMessage(NormalizedMessage msg)
086: throws javax.jbi.messaging.MessagingException {
087: setMessage(msg, IN_MSG);
088: }
089:
090: /**
091: * Specifies the "out" message reference for this exchange
092: * @param msg out message
093: * @throws javax.jbi.messaging.MessagingException nvalid message or the
094: * curent state of the exchange does not permit this operation.
095: */
096: public void setOutMessage(NormalizedMessage msg)
097: throws javax.jbi.messaging.MessagingException {
098: setMessage(msg, OUT_MSG);
099: }
100: }
|