KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > examples > scandir > config > ResultRecord


1 /*
2  * ResultRecord.java
3  *
4  * Created on 16 juillet 2006, 21:33
5  *
6  * @(#)ResultRecord.java 1.3 06/08/02
7  *
8  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * -Redistribution of source code must retain the above copyright notice, this
14  * list of conditions and the following disclaimer.
15  *
16  * -Redistribution in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
21  * be used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * This software is provided "AS IS," without a warranty of any kind. ALL
25  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
26  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
27  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
28  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
29  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
30  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
31  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
32  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
33  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
34  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
35  *
36  * You acknowledge that this software is not designed, licensed or intended
37  * for use in the design, construction, operation or maintenance of any
38  * nuclear facility.
39  */

40
41 package com.sun.jmx.examples.scandir.config;
42
43 import java.util.Date JavaDoc;
44 import javax.xml.bind.annotation.XmlElement;
45 import javax.xml.bind.annotation.XmlList;
46 import javax.xml.bind.annotation.XmlRootElement;
47 import com.sun.jmx.examples.scandir.config.DirectoryScannerConfig.Action;
48 import java.io.File JavaDoc;
49 import java.util.Arrays JavaDoc;
50
51 /**
52  * The <code>ResultRecord</code> Java Bean is used to write the
53  * results of a directory scan to a result log.
54  *
55  * <p>
56  * This class is annotated for XML binding.
57  * </p>
58  *
59  * @author Sun Microsystems, 2006 - All rights reserved.
60  */

61 @XmlRootElement(name="ResultRecord",namespace=XmlConfigUtils.NAMESPACE)
62 public class ResultRecord {
63     
64     /**
65      * The name of the file for which this result record is built.
66      */

67     private String JavaDoc filename;
68
69     /**
70      * The Date at which this result was obtained.
71      */

72     private Date JavaDoc date;
73
74     /**
75      * The short name of the directory scanner which performed the operation.
76      * @see DirectoryScannerConfig#getName()
77      */

78     private String JavaDoc directoryScanner;
79
80     /**
81      * The list of actions that were successfully carried out.
82      */

83     private Action[] actions;
84
85     /**
86      * Creates a new empty instance of ResultRecord.
87      */

88     public ResultRecord() {
89     }
90     
91     /**
92      * Creates a new instance of ResultRecord.
93      * @param scan The DirectoryScannerConfig for which this result was
94      * obtained.
95      * @param actions The list of actions that were successfully carried out.
96      * @param f The file for which these actions were successfully carried out.
97      */

98     public ResultRecord(DirectoryScannerConfig scan, Action[] actions,
99                      File JavaDoc f) {
100         directoryScanner = scan.getName();
101         this.actions = actions;
102         date = new Date JavaDoc();
103         filename = f.getAbsolutePath();
104     }
105
106     /**
107      * Gets the name of the file for which this result record is built.
108      * @return The name of the file for which this result record is built.
109      */

110     @XmlElement(name="Filename",namespace=XmlConfigUtils.NAMESPACE)
111     public String JavaDoc getFilename() {
112         return this.filename;
113     }
114
115     /**
116      * Sets the name of the file for which this result record is being built.
117      * @param filename the name of the file for which this result record is
118      * being built.
119      */

120     public void setFilename(String JavaDoc filename) {
121         this.filename = filename;
122     }
123
124     /**
125      * Gets the Date at which this result was obtained.
126      * @return the Date at which this result was obtained.
127      */

128     @XmlElement(name="Date",namespace=XmlConfigUtils.NAMESPACE)
129     public Date JavaDoc getDate() {
130         synchronized(this) {
131             return (date==null)?null:(new Date JavaDoc(date.getTime()));
132         }
133     }
134
135     /**
136      * Sets the Date at which this result was obtained.
137      * @param date the Date at which this result was obtained.
138      */

139     public void setDate(Date JavaDoc date) {
140         synchronized (this) {
141             this.date = (date==null)?null:(new Date JavaDoc(date.getTime()));
142         }
143     }
144
145     /**
146      * Gets the short name of the directory scanner which performed the
147      * operation.
148      * @see DirectoryScannerConfig#getName()
149      * @return the short name of the directory scanner which performed the
150      * operation.
151      */

152     @XmlElement(name="DirectoryScanner",namespace=XmlConfigUtils.NAMESPACE)
153     public String JavaDoc getDirectoryScanner() {
154         return this.directoryScanner;
155     }
156
157     /**
158      * Sets the short name of the directory scanner which performed the
159      * operation.
160      * @see DirectoryScannerConfig#getName()
161      * @param directoryScanner the short name of the directory scanner which
162      * performed the operation.
163      */

164     public void setDirectoryScanner(String JavaDoc directoryScanner) {
165         this.directoryScanner = directoryScanner;
166     }
167
168     /**
169      * Gets the list of actions that were successfully carried out.
170      * @return the list of actions that were successfully carried out.
171      */

172     @XmlElement(name="Actions",namespace=XmlConfigUtils.NAMESPACE)
173     @XmlList
174     public Action[] getActions() {
175         return (actions == null)?null:actions.clone();
176     }
177
178     /**
179      * Sets the list of actions that were successfully carried out.
180      * @param actions the list of actions that were successfully carried out.
181      */

182     public void setActions(Action[] actions) {
183         this.actions = (actions == null)?null:actions.clone();
184     }
185     
186     // Used for equality
187
private Object JavaDoc[] toArray() {
188         final Object JavaDoc[] thisconfig = {
189             filename, date, directoryScanner, actions
190         };
191         return thisconfig;
192     }
193     
194     @Override JavaDoc
195     public boolean equals(Object JavaDoc o) {
196         if (this == o) return true;
197         if (!(o instanceof ResultRecord)) return false;
198         return Arrays.deepEquals(toArray(),((ResultRecord)o).toArray());
199     }
200     
201     @Override JavaDoc
202     public int hashCode() {
203         return Arrays.deepHashCode(toArray());
204     }
205 }
206
Popular Tags