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.Iterator;
28
29 /***
30 * @author Giovanni Caire - TILAB
31 */
32 public class OntoAID extends AID implements Concept {
33
34 /***
35 * Constructs an ontological Agent-Identifier whose slot name is
36 * set to an empty string
37 * @see AID#AID()
38 */
39 public OntoAID() {
40 super();
41 }
42
43 /***
44 * Constructor for an ontological Agent-identifier
45 * @param name is the value for the slot name for the agent.
46 * @param isGUID indicates if the passed <code>name</code>
47 * is already a globally unique identifier or not. Two
48 * constants <code>ISGUID</code>, <code>ISLOCALNAME</code>
49 * have also been defined for setting a value for this parameter.
50 * If the name is a local name, then the HAP (Home Agent Platform)
51 * is concatenated to the name, separated by "@".
52 * @see AID#AID(String, boolean)
53 */
54 public OntoAID(String name, boolean isGUID) {
55 super(name, isGUID);
56 }
57
58 /***
59 * Create an ontological Agent identifier that wraps an existing
60 * <code>AID</code>.
61 * @param id the <code>AID</code>to be wrapped. If <code>id</code>
62 * is already an ontological agent identifier no new object is
63 * created and <code>id</code> is returned with the resolvers
64 * (if any) properly wrapped.
65 */
66 public static OntoAID wrap(AID id) {
67 OntoAID wrapper = null;
68 if (id instanceof OntoAID) {
69 wrapper = (OntoAID) id;
70 }
71 else {
72 wrapper = new OntoAID(id.getName(), ISGUID);
73 Iterator it = id.getAllAddresses();
74 while (it.hasNext()) {
75 wrapper.addAddresses((String) it.next());
76 }
77
78 it = id.getAllResolvers();
79 while (it.hasNext()) {
80
81 wrapper.addResolvers((AID) it.next());
82 }
83 }
84
85 return wrapper;
86 }
87
88 /***
89 * This method is redefined so that resolvers AID are automatically
90 * wrapped into OntoAIDs
91 */
92 public void addResolvers(AID aid) {
93 super.addResolvers(wrap(aid));
94 }
95
96
97 }
98