Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/cerberus/component/descriptor/ComponentMessage.java


1   /*
2    * ComponentMessage.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.cerberus.component.descriptor;
11  
12  import java.util.HashMap;
13  import java.util.Collection;
14  
15  /**
16   * <p>Describes a {@link com.aendvari.hermes.broker.Message} that a component either
17   * sends or receives.</p>
18   *
19   * <p>A message is referenced by a simple name. The simple name is mapped
20   * to a message topic. Typically, the implementation of the component will
21   * refer to the message by the simple name.</p>
22   *
23   * <p>The topic is built from a series of literals and attributes. Attributes
24   * allow portions of the topic to be specified during component instantiation.</p>
25   *
26   * <p>Messages may also be mapped to a message of a parent component. This copies
27   * the topic assigned to the parent message to the child message.</p>
28   *
29   * <p>A message may also describe it's signature, the set of properties describing
30   * the payload of the message. This provides an explict description of the
31   * component's message interface.</p>
32   *
33   * @author  Trevor Milne
34   *
35   */
36  
37  public class ComponentMessage extends ComponentProperty
38  {
39    /** The type of this message. See {@link Type Type} for possible values. */
40    protected int type;
41  
42    /** Specifies whether the message is required. */
43    protected boolean required;
44  
45    /** The topic of this message. */
46    protected MultiPartValue topic;
47  
48    /** Specifies whether the topic contains a mapping to another message. */
49    protected boolean mapped;
50  
51    /** The signature of the message. */
52    protected MessageSignature signature;
53  
54  
55    /* Constants. */
56  
57  
58    /** Constants for the type of the message. */
59    public interface Type
60    {
61      /** The type of this message is undefined. */
62      public static int Undefined  = 0;
63  
64      /** This message is sent. */
65      public static int Send     = 1;
66  
67      /** This message is received (listened for). */
68      public static int Receive  = 2;
69    }
70  
71  
72    /* Constructors. */
73  
74  
75    /**
76     * Constructs a <code>ComponentMessage</code> instance.
77     *
78     */
79  
80    public ComponentMessage()
81    {
82      super();
83  
84      type = Type.Undefined;
85      required = false;
86      topic = new MultiPartValue();
87      mapped = false;
88      signature = new MessageSignature();
89    }
90  
91    /**
92     * Constructs a <code>ComponentMessage</code> instance as a copy of the one supplied.
93     *
94     * @param    message            The <code>ComponentMessage</code> to copy.
95     *
96     */
97  
98    public ComponentMessage(ComponentMessage message)
99    {
100     super(message);
101 
102     type = message.getType();
103     required = message.getRequired();
104     topic = new MultiPartValue(message.getTopic());
105     mapped = message.isMapped();
106     signature = new MessageSignature(message.getSignature());
107   }
108 
109 
110   /* Accessors. */
111 
112 
113   /* Type. */
114 
115   /**
116    * Sets the type of this message.
117    *
118    * @param    setType            The type of this message. See {@link Type Type}.
119    *
120    */
121 
122   public void setType(int setType)
123   {
124     type = setType;
125   }
126 
127   /**
128    * Returns the type of this message.
129    *
130    * @return                  The type of this message. See {@link Type Type}.
131    *
132    */
133 
134   public int getType()
135   {
136     return type;
137   }
138 
139   /* Required. */
140 
141   /**
142    * Sets the required state of this message.
143    *
144    * @param    setRequired          The message's required state.
145    *
146    */
147 
148   public void setRequired(boolean setRequired)
149   {
150     required = setRequired;
151   }
152 
153   /**
154    * Returns the required state of this message.
155    *
156    * @return                  True if required, false otherwise.
157    *
158    */
159 
160   public boolean getRequired()
161   {
162     return required;
163   }
164 
165   /* Topic. */
166 
167   /**
168    * Returns the topic of this message. The {@link MultiPartValue}
169    * returned may be manipulated to modify the topic of this message.
170    *
171    * @return                  The topic of this message.
172    *
173    */
174 
175   public MultiPartValue getTopic()
176   {
177     return topic;
178   }
179 
180   /* Mapped. */
181 
182   /**
183    * Sets the mapped status of this message.
184    *
185    * @param    setMapped          True if this is a mapped message.
186    *
187    */
188 
189   public void setMapped(boolean setMapped)
190   {
191     mapped = setMapped;
192   }
193 
194   /**
195    * Returns the mapped status of this message.
196    *
197    * @return                  True if this is a mapped message.
198    *
199    */
200 
201   public boolean isMapped()
202   {
203     return mapped;
204   }
205 
206   /* Signature. */
207 
208   /**
209    * Returns the signature of this message.
210    *
211    * @return                  The {@link MessageSignature} of this message.
212    *
213    */
214 
215   public MessageSignature getSignature()
216   {
217     return signature;
218   }
219 }
220