1 40 41 package com.sun.jmx.examples.scandir.config; 42 43 import java.util.Arrays ; 44 import java.util.LinkedHashMap ; 45 import java.util.Map ; 46 import javax.xml.bind.annotation.XmlAttribute; 47 import javax.xml.bind.annotation.XmlElement; 48 import javax.xml.bind.annotation.XmlElementRef; 49 import javax.xml.bind.annotation.XmlElementWrapper; 50 import javax.xml.bind.annotation.XmlRootElement; 51 52 53 70 @XmlRootElement(name="ScanManager", 71 namespace="jmx:com.sun.jmx.examples.scandir.config") 72 public class ScanManagerConfig { 73 74 79 82 private final Map <String , DirectoryScannerConfig> directoryScanners; 83 84 87 private ResultLogConfig initialResultLogConfig; 88 89 97 private String name; 98 99 111 public ScanManagerConfig() { 112 this(null,true); 113 } 114 115 123 public ScanManagerConfig(String name) { 124 this(name,false); 125 } 126 127 private ScanManagerConfig(String name, boolean allowsNull) { 129 if (name == null && allowsNull==false) 130 throw new IllegalArgumentException ("name=null"); 131 this.name = name; 132 directoryScanners = new LinkedHashMap <String ,DirectoryScannerConfig>(); 133 this.initialResultLogConfig = new ResultLogConfig(); 134 this.initialResultLogConfig.setMemoryMaxRecords(1024); 135 } 136 137 private Object [] toArray() { 139 final Object [] thisconfig = { 140 name,directoryScanners,initialResultLogConfig 141 }; 142 return thisconfig; 143 } 144 145 @Override 147 public boolean equals(Object o) { 148 if (o == this) return true; 149 if (!(o instanceof ScanManagerConfig)) return false; 150 final ScanManagerConfig other = (ScanManagerConfig)o; 151 if (this.directoryScanners.size() != other.directoryScanners.size()) 152 return false; 153 return Arrays.deepEquals(toArray(),other.toArray()); 154 } 155 156 @Override 157 public int hashCode() { 158 final String key = name; 159 if (key == null) return 0; 160 else return key.hashCode(); 161 } 162 163 172 @XmlAttribute(name="name",required=true) 173 public String getName() { 174 return this.name; 175 } 176 177 187 public void setName(String name) { 188 if (this.name == null) 189 this.name = name; 190 else if (name == null) 191 throw new IllegalArgumentException ("name=null"); 192 else if (!name.equals(this.name)) 193 throw new IllegalArgumentException ("name="+name); 194 } 195 196 204 @XmlElementWrapper(name="DirectoryScannerList", 205 namespace=XmlConfigUtils.NAMESPACE) 206 @XmlElementRef 207 public DirectoryScannerConfig[] getScanList() { 208 return directoryScanners.values().toArray(new DirectoryScannerConfig[0]); 209 } 210 211 219 public void setScanList(DirectoryScannerConfig[] scans) { 220 directoryScanners.clear(); 221 for (DirectoryScannerConfig scan : scans) 222 directoryScanners.put(scan.getName(),scan); 223 } 224 225 233 public DirectoryScannerConfig getScan(String name) { 234 return directoryScanners.get(name); 235 } 236 237 248 public DirectoryScannerConfig putScan(DirectoryScannerConfig scan) { 249 return this.directoryScanners.put(scan.getName(),scan); 250 } 251 252 public String toString() { 254 return XmlConfigUtils.toString(this); 255 } 256 257 266 public DirectoryScannerConfig removeScan(String name) { 267 return this.directoryScanners.remove(name); 268 } 269 270 274 @XmlElement(name="InitialResultLogConfig",namespace=XmlConfigUtils.NAMESPACE) 275 public ResultLogConfig getInitialResultLogConfig() { 276 return this.initialResultLogConfig; 277 } 278 279 283 public void setInitialResultLogConfig(ResultLogConfig initialLogConfig) { 284 this.initialResultLogConfig = initialLogConfig; 285 } 286 287 292 public ScanManagerConfig copy(String newname) { 293 return copy(newname,this); 294 } 295 296 private static ScanManagerConfig 299 copy(String newname, ScanManagerConfig other) { 300 ScanManagerConfig newbean = XmlConfigUtils.xmlClone(other); 301 newbean.name = newname; 302 return newbean; 303 } 304 } 305 | Popular Tags |