1 | package genius.core.repository;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import javax.xml.bind.annotation.XmlElement;
|
---|
7 | import javax.xml.bind.annotation.XmlElementWrapper;
|
---|
8 | import javax.xml.bind.annotation.XmlSeeAlso;
|
---|
9 | import javax.xml.bind.annotation.XmlType;
|
---|
10 |
|
---|
11 | import genius.core.exceptions.InstantiateException;
|
---|
12 | import genius.core.parties.NegotiationParty;
|
---|
13 | import genius.core.repository.boa.BoaPartyRepItem;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Abstract superclass for RepItems that can generate Participants.
|
---|
17 | *
|
---|
18 | */
|
---|
19 | @SuppressWarnings("serial")
|
---|
20 | @XmlSeeAlso({ BoaPartyRepItem.class, PartyRepItem.class })
|
---|
21 | @XmlType
|
---|
22 | public abstract class ParticipantRepItem implements RepItem {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * true iff the cached elemenents have been initialized. Only
|
---|
26 | * the @XmlElement objects are set hard, the others are set when needed.
|
---|
27 | */
|
---|
28 | private boolean initialized = false;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unused but still in some XML files. Maybe needed in future?
|
---|
32 | */
|
---|
33 | @XmlElementWrapper(name = "properties")
|
---|
34 | @XmlElement(name = "property")
|
---|
35 | private List<String> properties = new ArrayList<String>();
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * The protocol that this item supports. file path including the class name.
|
---|
39 | * cached.
|
---|
40 | */
|
---|
41 | private String protocolClassPath = null;
|
---|
42 |
|
---|
43 | // deserialization support
|
---|
44 | protected ParticipantRepItem() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * @return the actual {@link NegotiationParty} that this refers to.
|
---|
49 | * @throws InstantiateException
|
---|
50 | * if party can't be loaded
|
---|
51 | *
|
---|
52 | */
|
---|
53 | public abstract NegotiationParty load() throws InstantiateException;
|
---|
54 |
|
---|
55 | public Boolean isMediator() {
|
---|
56 | return false;
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public int hashCode() {
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | *
|
---|
66 | * @return a unique name that identifies this participant. Used e.g. to
|
---|
67 | * create a storage space. Can be derived from the class name or
|
---|
68 | * other settings in the participant. Notice that {@link #getName()}
|
---|
69 | * may not be unique.
|
---|
70 | */
|
---|
71 | public abstract String getUniqueName();
|
---|
72 |
|
---|
73 | public String getProtocolClassPath() {
|
---|
74 | try {
|
---|
75 | initSilent();
|
---|
76 | } catch (InstantiateException e) {
|
---|
77 | return e.toString();
|
---|
78 | }
|
---|
79 | return protocolClassPath;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Init our fields to cache the party information. party must have been set
|
---|
84 | * before getting here.
|
---|
85 | *
|
---|
86 | * @param party
|
---|
87 | * @throws InstantiateException
|
---|
88 | */
|
---|
89 | protected NegotiationParty init() throws InstantiateException {
|
---|
90 | NegotiationParty party1 = load();
|
---|
91 | protocolClassPath = party1.getProtocol().getCanonicalName();
|
---|
92 | initialized = true;
|
---|
93 | return party1;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * call init but suppress any exceptions and print just a stacktrace.
|
---|
98 | *
|
---|
99 | * @throws InstantiateException
|
---|
100 | */
|
---|
101 | final protected void initSilent() throws InstantiateException {
|
---|
102 | if (initialized)
|
---|
103 | return;
|
---|
104 | init();
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * @return a descriptor that is unique for this rep item class. Typically a
|
---|
109 | * full.class.path but may be a composite.
|
---|
110 | */
|
---|
111 | abstract public String getClassDescriptor();
|
---|
112 | }
|
---|