1 | package desmoj.core.report; |
2 | |
3 | import desmoj.core.simulator.Model; |
4 | import desmoj.core.simulator.TimeInstant; |
5 | |
6 | /** |
7 | * Base class for all message types used in the DESMO-J framework. Provides the |
8 | * basic functionality and information common to all messages. Other Messages |
9 | * must be derived from this class and extend the attributes to transport the |
10 | * desired information. This allows for adding custom message bearing specific |
11 | * information. Given the references to the objects to be displayed in a |
12 | * message, the constructor extracts their names if possible. In case of |
13 | * <code>null</code> references given as parameters, the String "----" is taken |
14 | * instead. |
15 | * |
16 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
17 | * @author Tim Lechler |
18 | * @author modified by Ruth Meyer |
19 | * |
20 | * Licensed under the Apache License, Version 2.0 (the "License"); |
21 | * you may not use this file except in compliance with the License. You |
22 | * may obtain a copy of the License at |
23 | * http://www.apache.org/licenses/LICENSE-2.0 |
24 | * |
25 | * Unless required by applicable law or agreed to in writing, software |
26 | * distributed under the License is distributed on an "AS IS" |
27 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
28 | * or implied. See the License for the specific language governing |
29 | * permissions and limitations under the License. |
30 | * |
31 | */ |
32 | public class Message { |
33 | |
34 | /** |
35 | * The name of the model that produced this message. |
36 | */ |
37 | private String _modName; |
38 | |
39 | /** |
40 | * The textual message to be published by a messagereceiver. |
41 | */ |
42 | private String _msgDescription; |
43 | |
44 | /** |
45 | * The point of simulation time that this message was created. |
46 | */ |
47 | private desmoj.core.simulator.TimeInstant _msgTime; |
48 | |
49 | private String _expName; |
50 | |
51 | /** |
52 | * Constructs a message with the given parameters. |
53 | * |
54 | * @param origin |
55 | * Model : The model that produced this message |
56 | * @param description |
57 | * java.lang.String : The actual message text |
58 | * @param time |
59 | * TimeInstant : The point in simulation time this message was |
60 | * created |
61 | */ |
62 | // TODO: |
63 | public Message(Model origin, String description, TimeInstant time) { |
64 | |
65 | // fill in the attributes, checking vor void parameters |
66 | // |
67 | // @modified by Nick Denz on 18.9.07 |
68 | // Reason: Some clients (e.g. SimTime) use this constructor |
69 | // (indirectly) without passing an origin model. In this case, |
70 | // querying the experiment name also fails. I have therefore |
71 | // added an empty experiment name similar to the empty model name. |
72 | if (origin == null) { |
73 | _modName = "----"; |
74 | _expName = "----"; |
75 | } else { |
76 | _modName = origin.getName(); |
77 | _expName = origin.getExperiment().getName(); |
78 | } |
79 | |
80 | if (description == null) |
81 | _msgDescription = "----"; |
82 | else |
83 | _msgDescription = description; |
84 | |
85 | // save the simulation time the message was created at |
86 | _msgTime = time; |
87 | |
88 | } |
89 | |
90 | /** |
91 | * Returns the textual description of this message as a String. |
92 | * |
93 | * @return java.lang.String : The message's description |
94 | */ |
95 | public String getDescription() { |
96 | |
97 | return _msgDescription; |
98 | |
99 | } |
100 | |
101 | /** |
102 | * Returns the name of the model that produced this message. |
103 | * |
104 | * @return java.lang.String : The the name of the model that produced this |
105 | * message |
106 | */ |
107 | public String getModelName() { |
108 | |
109 | return _modName; |
110 | |
111 | } |
112 | |
113 | public String getExperimentName() { |
114 | return _expName; |
115 | } |
116 | |
117 | /** |
118 | * Returns the time the message was (created) sent as a TimeInstant object. |
119 | * |
120 | * @return desmoj.core.simulator.TimeInstant : The time the message was sent |
121 | * as a TimeInstant object. |
122 | */ |
123 | public TimeInstant getSendTime() { |
124 | |
125 | return _msgTime; |
126 | } |
127 | |
128 | /** |
129 | * Returns the point of simulation time that this message was created as a |
130 | * String. |
131 | * |
132 | * @return java.lang.String : the point of simulation time this message was |
133 | * created |
134 | */ |
135 | public String getTime() { |
136 | |
137 | if (_msgTime == null) |
138 | return "----"; |
139 | else |
140 | return _msgTime.toString(); |
141 | |
142 | } |
143 | |
144 | /** |
145 | * Overrides the Object's <code>toString()</code> method to return the |
146 | * message's description when this object is used as a String. |
147 | * |
148 | * @return java.lang.String : The message's description |
149 | */ |
150 | public String toString() { |
151 | |
152 | return _msgDescription; |
153 | |
154 | } |
155 | } |