1 /* 2 * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * - Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * - Neither the name of Oracle nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * This source code is provided to illustrate the usage of a given feature 34 * or technique and has been deliberately simplified. Additional steps 35 * required for a production-quality application, such as security checks, 36 * input validation and proper error handling, might not be present in 37 * this sample code. 38 */ 39 40 41 package com.sun.jmx.examples.scandir.config; 42 43 import java.util.Date; 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; 49 import java.util.Arrays; 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 filename; 68 69 /** 70 * The Date at which this result was obtained. 71 */ 72 private Date date; 73 74 /** 75 * The short name of the directory scanner which performed the operation. 76 * @see DirectoryScannerConfig#getName() 77 */ 78 private String 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 f) { 100 directoryScanner = scan.getName(); 101 this.actions = actions; 102 date = new Date(); 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 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 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 getDate() { 130 synchronized(this) { 131 return (date==null)?null:(new Date(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 date) { 140 synchronized (this) { 141 this.date = (date==null)?null:(new Date(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 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 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[] toArray() { 188 final Object[] thisconfig = { 189 filename, date, directoryScanner, actions 190 }; 191 return thisconfig; 192 } 193 194 @Override 195 public boolean equals(Object 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 202 public int hashCode() { 203 return Arrays.deepHashCode(toArray()); 204 } 205 } 206