41 package com.sun.jmx.examples.scandir.config;
44 import java.io.FileFilter;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.List;
48 import java.util.logging.Logger;
49 import javax.xml.bind.annotation.XmlAttribute;
50 import javax.xml.bind.annotation.XmlElement;
51 import javax.xml.bind.annotation.XmlElementRef;
52 import javax.xml.bind.annotation.XmlElementWrapper;
53 import javax.xml.bind.annotation.XmlList;
54 import javax.xml.bind.annotation.XmlRootElement;
65 @XmlRootElement(
name=
"DirectoryScanner",
109 private final List<FileMatch> includeFiles =
110 new ArrayList<FileMatch>();
115 private final List<FileMatch> excludeFiles =
116 new ArrayList<FileMatch>();
147 rootDirectory =
null;
155 @XmlElement(
name=
"RootDirectory",
namespace=XmlConfigUtils.NAMESPACE)
156 public String getRootDirectory() {
157 return rootDirectory;
165 public void setRootDirectory(String root) {
180 @XmlAttribute(
name=
"name",required=
true)
181 public String getName() {
192 public void setName(String
name) {
193 if (this.name ==
null)
195 else if (
name ==
null)
196 throw new IllegalArgumentException(
"name=null");
197 else if (!
name.equals(
this.name))
198 throw new IllegalArgumentException(
"name="+
name);
207 @XmlElementWrapper(
name=
"IncludeFiles",
208 namespace=XmlConfigUtils.NAMESPACE)
210 public FileMatch[] getIncludeFiles() {
211 synchronized(includeFiles) {
212 return includeFiles.toArray(
new FileMatch[0]);
221 public void addIncludeFiles(FileMatch
include) {
223 throw new IllegalArgumentException(
"null");
224 synchronized (includeFiles) {
236 public void setIncludeFiles(FileMatch[] includeFiles) {
237 synchronized (this.includeFiles) {
238 this.includeFiles.clear();
239 if (includeFiles ==
null)
return;
240 this.includeFiles.addAll(Arrays.asList(includeFiles));
250 @XmlElementWrapper(
name=
"ExcludeFiles",
251 namespace=XmlConfigUtils.NAMESPACE)
253 public FileMatch[] getExcludeFiles() {
254 synchronized(excludeFiles) {
255 return excludeFiles.toArray(
new FileMatch[0]);
266 public void setExcludeFiles(FileMatch[] excludeFiles) {
267 synchronized (this.excludeFiles) {
268 this.excludeFiles.clear();
269 if (excludeFiles ==
null)
return;
270 this.excludeFiles.addAll(Arrays.asList(excludeFiles));
279 public void addExcludeFiles(FileMatch exclude) {
281 throw new IllegalArgumentException(
"null");
282 synchronized (excludeFiles) {
283 this.excludeFiles.add(exclude);
294 @XmlElement(
name=
"Actions",
namespace=XmlConfigUtils.NAMESPACE)
296 public Action[] getActions() {
297 return (actions ==
null)?
null:actions.clone();
307 public void setActions(Action[] actions) {
308 this.actions = (actions ==
null)?
null:actions.clone();
328 public FileFilter buildFileFilter() {
329 final FileFilter[] ins = getIncludeFiles();
330 final FileFilter[] outs = getExcludeFiles();
331 final FileFilter filter =
new FileFilter() {
332 public boolean accept(File f) {
336 for (FileFilter
in: ins) {
338 if (!
in.accept(f))
continue;
345 if (
result ==
false)
return false;
351 for (FileFilter out: outs) {
353 if (!out.accept(f))
continue;
367 private Object[] toArray() {
368 final Object[] thisconfig = {
369 name,rootDirectory,actions,excludeFiles,includeFiles
375 public boolean equals(Object o) {
376 if (o ==
this)
return true;
377 if (!(o instanceof DirectoryScannerConfig))
return false;
378 final DirectoryScannerConfig other = (DirectoryScannerConfig)o;
379 final Object[] thisconfig = toArray();
380 final Object[] otherconfig = other.toArray();
381 return Arrays.deepEquals(thisconfig,otherconfig);
385 public int hashCode() {
386 final String key =
name;
387 if (key ==
null)
return 0;
388 else return key.hashCode();