Source code: org/biomage/AuditAndSecurity/Audit.java
1 /***************************************************************************
2 * *
3 * C O P Y R I G H T N O T I C E *
4 * Copyright (c) 2001 by: *
5 * * The MicroArray Gene Expression Database group (MGED) *
6 * * Rosetta Inpharmatics *
7 * *
8 * All Rights Reserved. *
9 * *
10 * Permission is hereby granted, free of charge, to any person *
11 * obtaining a copy of this software and associated documentation files *
12 * (the "Software"), to deal in the Software without restriction, *
13 * including without limitation the rights to use, copy, modify, merge, *
14 * publish, distribute, sublicense, and/or sell copies of the Software, *
15 * and to permit persons to whom the Software is furnished to do so, *
16 * subject to the following conditions: *
17 * *
18 * The above copyright notice and this permission notice shall be *
19 * included in all copies or substantial portions of the Software. *
20 * *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS *
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN *
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN *
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
28 * SOFTWARE. *
29 ***************************************************************************
30 * *
31 * Created by the create_mage_java_classes java program based on the *
32 * information in the xmi file created from the MAGE-OM UML model, *
33 * copyright European Bioinformatics Institute (EBI) for MGED and Rosetta *
34 * Informatics. *
35 * *
36 * The ideas and work are built on the previous work in perl of Jason *
37 * Stewart, Open Informatics, and Robert M. Hubley, Institute for Systems *
38 * Biology *
39 * *
40 * @author Michael Miller, Rosetta Inpharmatics *
41 * @version Revision: 1.0 *
42 * @date Thu, Feb 21, 2002 10:46:16 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.AuditAndSecurity
49 *
50 */
51 package org.biomage.AuditAndSecurity;
52
53 /**
54 * Import list for Audit
55 *
56 */
57 import java.io.Serializable;
58 import java.util.*;
59 import java.util.Date;
60 import org.xml.sax.Attributes;
61 import java.io.Writer;
62 import java.io.IOException;
63 import org.biomage.Interface.HasPerformer;
64 import org.biomage.Common.Describable;
65
66 /**
67 * Tracks information on the contact that creates or modifies an object.
68 *
69 */
70 public
71 class Audit
72 extends Describable
73 implements Serializable,
74 HasPerformer
75 {
76 /**
77 * The date of a change.
78 *
79 */
80 Date date;
81
82 /**
83 * Inner class for the enumeration values that the attribute action
84 * can assume.
85 *
86 */
87 public
88 class
89 Action
90 {
91 int value = -1;
92 private HashMap nameToValue = new HashMap(2);
93
94 final public int CREATION = 0;
95 final public int MODIFICATION = 1;
96
97 Action(){
98 nameToValue.put("CREATION",new Integer(0));
99 nameToValue.put("MODIFICATION",new Integer(1));
100 }
101
102 public int setValueByName(String name) {
103 value = ((Integer)nameToValue.get(name)).intValue();
104 return value;
105 }
106 }
107
108 /**
109 * Indicates whether an action is a creation or a modification.
110 *
111 */
112 Action action = new Action();
113
114 /**
115 * The contact for creating or changing the instance referred to by
116 * the Audit.
117 *
118 */
119 private Contact performer;
120
121
122 /**
123 * Default constructor.
124 *
125 */
126 public
127 Audit()
128 {
129 super();
130 }
131
132 /**
133 * Attribute constructor.
134 *
135 * Looks up the attributes in the parameter and casts them from strings
136 * appropriately
137 * @param atts: the attribute list.
138 *
139 */
140 // TODO Work in progress (attribute constructor).
141 public
142 Audit(Attributes atts)
143 {
144 super(atts);
145
146 {
147 int nIndex = atts.getIndex("", "date");
148 if (nIndex != -1)
149 {
150 date = new Date(atts.getValue(nIndex));
151 }
152 }
153
154 {
155 int nIndex = atts.getIndex("", "action");
156 if (nIndex != -1)
157 {
158 action.setValueByName(atts.getValue(nIndex).toUpperCase());
159 }
160 }
161
162 }
163
164 /**
165 * writeMAGEML
166 * <p>
167 * This method is responsible for assembling the attribute and
168 * association data into XML. It creates the object tag and then calls
169 * the writeAttributes and writeAssociation methods.
170 * <p>
171 *
172 */
173 public
174 void
175 writeMAGEML(Writer out)
176 throws IOException
177 {
178 out.write("<Audit");
179 writeAttributes(out);
180 out.write(">");
181 writeAssociations(out);
182 out.write("</Audit>");
183 }
184
185 /**
186 * writeAttributes
187 * <p>
188 * This method is responsible for assembling the attribute data into
189 * XML. It calls the super method to write out all attributes of this
190 * class and it's ancestors.
191 * <p>
192 *
193 */
194 public
195 void
196 writeAttributes(Writer out)
197 throws IOException
198 {
199 super.writeAttributes(out);
200 out.write(" date=\"" + date + "\"");
201 out.write(" action=\"" + action + "\"");
202 }
203
204 /**
205 * writeAssociations
206 * <p>
207 * This method is responsible for assembling the association data
208 * into XML. It calls the super method to write out all associations of
209 * this class's ancestors.
210 * <p>
211 *
212 */
213 public
214 void
215 writeAssociations(Writer out)
216 throws IOException
217 {
218 super.writeAssociations(out);
219 if ( performer != null ){
220 out.write("<Performer_assnref>");
221 out.write("<Contact_ref identifier=\"" + performer.getIdentifier() + "\"/>");
222 out.write("</Performer_assnref>");
223 }
224 }
225
226 /**
227 * Set method for date
228 * <p>
229 * @param value to set
230 * <p>
231 *
232 */
233 public
234 void
235 setDate(
236 Date date
237 )
238 {
239 this.date = date;
240 }
241
242 /**
243 * Get method for date
244 * <p>
245 * @return value of the attribute
246 * <p>
247 *
248 */
249 public
250 Date
251 getDate()
252 {
253 return date;
254 }
255
256 /**
257 * Set method for action
258 * <p>
259 * @param value to set
260 * <p>
261 *
262 */
263 public
264 void
265 setAction(
266 Action action
267 )
268 {
269 this.action = action;
270 }
271
272 /**
273 * Get method for action
274 * <p>
275 * @return value of the attribute
276 * <p>
277 *
278 */
279 public
280 Action
281 getAction()
282 {
283 return action;
284 }
285
286 /**
287 * Set method for performer
288 * <p>
289 * @param value to set
290 * <p>
291 *
292 */
293 public
294 void
295 setPerformer(
296 Contact performer
297 )
298 {
299 this.performer = performer;
300 }
301
302 /**
303 * Get method for performer
304 * <p>
305 * @return value of the attribute
306 * <p>
307 *
308 */
309 public
310 Contact
311 getPerformer()
312 {
313 return performer;
314 }
315
316 }