1 /***
2 * ***************************************************************
3 * JADE - Java Agent DEvelopment Framework is a framework to develop
4 * multi-agent systems in compliance with the FIPA specifications.
5 * Copyright (C) 2000 CSELT S.p.A.
6 *
7 * GNU Lesser General Public License
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation,
12 * version 2.1 of the License.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 * **************************************************************
24 */
25 package JADE_SL;
26
27 import java.util.List;
28 import java.util.Iterator;
29 import JADE_SL.abs.*;
30 import JADE_SL.onto.*;
31
32 /***
33 * @author Giovanni Caire - TILAB
34 */
35 public class OntoACLMessage extends ACLMessage implements AgentAction {
36
37 /***
38 * Constructs an ontological ACL message whose performative
39 * is ACLMessage.NOT_UNDERSTOOD
40 */
41 public OntoACLMessage() {
42 super(ACLMessage.NOT_UNDERSTOOD);
43 }
44
45 /***
46 * Constructor for an ontological ACL message with a given
47 * performative
48 * @param performative the performative of this ACL message.
49 * @see ACLMessage#ACLMessage(int)
50 */
51 public OntoACLMessage(int performative) {
52 super(performative);
53 }
54
55 /***
56 * Create an ontological ACL message that wraps an existing
57 * <code>ACLMessage</code>.
58 * @param msg the <code>ACLMessage</code>to be wrapped. If
59 * <code>msg</code>
60 * is already an ontological ACL message no new object is
61 * created and <code>msg</code> is returned with the sender
62 * and receivers properly wrapped if necessary.
63 */
64 public static OntoACLMessage wrap(ACLMessage msg) {
65 OntoACLMessage wrapper = null;
66 if (msg instanceof OntoACLMessage) {
67 wrapper = (OntoACLMessage) msg;
68 }
69 else {
70 wrapper = new OntoACLMessage(msg.getPerformative());
71
72 wrapper.setSender(msg.getSender());
73 Iterator it = msg.getAllReceiver();
74 while (it.hasNext()) {
75
76 wrapper.addReceiver((AID) it.next());
77 }
78
79 it = msg.getAllReplyTo();
80 while (it.hasNext()) {
81
82 wrapper.addReplyTo((AID) it.next());
83 }
84
85 wrapper.setLanguage(msg.getLanguage());
86 wrapper.setOntology(msg.getOntology());
87 wrapper.setProtocol(msg.getProtocol());
88 wrapper.setInReplyTo(msg.getInReplyTo());
89 wrapper.setReplyWith(msg.getReplyWith());
90 wrapper.setConversationId(msg.getConversationId());
91 wrapper.setReplyByDate(msg.getReplyByDate());
92 if (msg.hasByteSequenceContent()) {
93 wrapper.setByteSequenceContent(msg.getByteSequenceContent());
94 }
95 else {
96 wrapper.setContent(msg.getContent());
97 }
98 wrapper.setEncoding(msg.getEncoding());
99
100
101 }
102
103 return wrapper;
104 }
105
106 /***
107 * This method is redefined so that the sender AID is automatically
108 * wrapped into an OntoAID
109 */
110 public void setSender(AID aid) {
111 super.setSender(OntoAID.wrap(aid));
112 }
113
114 /***
115 * This method is redefined so that the receiver AID is automatically
116 * wrapped into an OntoAID
117 */
118 public void addReceiver(AID aid) {
119 super.addReceiver(OntoAID.wrap(aid));
120 }
121
122 /***
123 * This method is redefined so that the replyTo AID is automatically
124 * wrapped into an OntoAID
125 */
126 public void addReplyTo(AID aid) {
127 super.addReplyTo(OntoAID.wrap(aid));
128 }
129
130
131
132 }
133