5603 |
08 Apr 11 |
nicklas |
1 |
/** |
5603 |
08 Apr 11 |
nicklas |
$Id$ |
5603 |
08 Apr 11 |
nicklas |
3 |
|
5603 |
08 Apr 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5603 |
08 Apr 11 |
nicklas |
5 |
|
5603 |
08 Apr 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5603 |
08 Apr 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5603 |
08 Apr 11 |
nicklas |
8 |
|
5603 |
08 Apr 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5603 |
08 Apr 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5603 |
08 Apr 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5603 |
08 Apr 11 |
nicklas |
of the License, or (at your option) any later version. |
5603 |
08 Apr 11 |
nicklas |
13 |
|
5603 |
08 Apr 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5603 |
08 Apr 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5603 |
08 Apr 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5603 |
08 Apr 11 |
nicklas |
GNU General Public License for more details. |
5603 |
08 Apr 11 |
nicklas |
18 |
|
5603 |
08 Apr 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5603 |
08 Apr 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5603 |
08 Apr 11 |
nicklas |
21 |
*/ |
5603 |
08 Apr 11 |
nicklas |
22 |
package net.sf.basedb.util.extensions.manager.filter; |
5603 |
08 Apr 11 |
nicklas |
23 |
|
5603 |
08 Apr 11 |
nicklas |
24 |
import net.sf.basedb.util.extensions.manager.ExtensionsFile; |
5603 |
08 Apr 11 |
nicklas |
25 |
import net.sf.basedb.util.filter.Filter; |
5603 |
08 Apr 11 |
nicklas |
26 |
|
5603 |
08 Apr 11 |
nicklas |
27 |
/** |
5603 |
08 Apr 11 |
nicklas |
Filter implementation for extension files that |
5603 |
08 Apr 11 |
nicklas |
allow valid and new or modified files to pass. |
5605 |
12 Apr 11 |
nicklas |
The allowUnmodified parameter can be set to also |
5603 |
08 Apr 11 |
nicklas |
allow unmodified files to pass. |
5603 |
08 Apr 11 |
nicklas |
32 |
|
5603 |
08 Apr 11 |
nicklas |
@author Nicklas |
5603 |
08 Apr 11 |
nicklas |
@since 3.0 |
5603 |
08 Apr 11 |
nicklas |
@base.modified $Date$ |
5603 |
08 Apr 11 |
nicklas |
36 |
*/ |
5603 |
08 Apr 11 |
nicklas |
37 |
public class ValidAndNewOrModifiedFilter |
5603 |
08 Apr 11 |
nicklas |
38 |
implements Filter<ExtensionsFile> |
5603 |
08 Apr 11 |
nicklas |
39 |
{ |
5603 |
08 Apr 11 |
nicklas |
40 |
|
6444 |
09 Apr 14 |
nicklas |
41 |
private static final org.slf4j.Logger log = |
6444 |
09 Apr 14 |
nicklas |
42 |
org.slf4j.LoggerFactory.getLogger(ValidAndNewOrModifiedFilter.class); |
5603 |
08 Apr 11 |
nicklas |
43 |
|
5603 |
08 Apr 11 |
nicklas |
44 |
private final boolean allowUnmodified; |
5616 |
27 Apr 11 |
nicklas |
45 |
private final Filter<ExtensionsFile> parent; |
5603 |
08 Apr 11 |
nicklas |
46 |
|
5603 |
08 Apr 11 |
nicklas |
47 |
/** |
5603 |
08 Apr 11 |
nicklas |
Create a new filter. |
5603 |
08 Apr 11 |
nicklas |
49 |
|
5603 |
08 Apr 11 |
nicklas |
@param allowUnmodified TRUE to allow unmodified files to |
5603 |
08 Apr 11 |
nicklas |
pass the filter, FALSE to block them |
5603 |
08 Apr 11 |
nicklas |
52 |
*/ |
5603 |
08 Apr 11 |
nicklas |
53 |
public ValidAndNewOrModifiedFilter(boolean allowUnmodified) |
5603 |
08 Apr 11 |
nicklas |
54 |
{ |
5616 |
27 Apr 11 |
nicklas |
55 |
this(allowUnmodified, null); |
5616 |
27 Apr 11 |
nicklas |
56 |
} |
5616 |
27 Apr 11 |
nicklas |
57 |
|
5616 |
27 Apr 11 |
nicklas |
58 |
/** |
5616 |
27 Apr 11 |
nicklas |
Create a new filter. |
5616 |
27 Apr 11 |
nicklas |
60 |
|
5616 |
27 Apr 11 |
nicklas |
@param allowUnmodified TRUE to allow unmodified files to |
5616 |
27 Apr 11 |
nicklas |
pass the filter, FALSE to block them |
5616 |
27 Apr 11 |
nicklas |
@param parent An optional parent filter that will also be checked |
5616 |
27 Apr 11 |
nicklas |
64 |
*/ |
5616 |
27 Apr 11 |
nicklas |
65 |
public ValidAndNewOrModifiedFilter(boolean allowUnmodified, Filter<ExtensionsFile> parent) |
5616 |
27 Apr 11 |
nicklas |
66 |
{ |
5603 |
08 Apr 11 |
nicklas |
67 |
this.allowUnmodified = allowUnmodified; |
5616 |
27 Apr 11 |
nicklas |
68 |
this.parent = parent; |
5603 |
08 Apr 11 |
nicklas |
69 |
} |
5603 |
08 Apr 11 |
nicklas |
70 |
|
5603 |
08 Apr 11 |
nicklas |
71 |
/* |
5603 |
08 Apr 11 |
nicklas |
From the Filter interface |
5603 |
08 Apr 11 |
nicklas |
73 |
------------------------- |
5603 |
08 Apr 11 |
nicklas |
74 |
*/ |
5603 |
08 Apr 11 |
nicklas |
75 |
@Override |
5603 |
08 Apr 11 |
nicklas |
76 |
public boolean evaluate(ExtensionsFile xtFile) |
5603 |
08 Apr 11 |
nicklas |
77 |
{ |
5616 |
27 Apr 11 |
nicklas |
78 |
if (parent != null && !parent.evaluate(xtFile)) |
5616 |
27 Apr 11 |
nicklas |
79 |
{ |
5616 |
27 Apr 11 |
nicklas |
80 |
return false; |
5616 |
27 Apr 11 |
nicklas |
81 |
} |
5616 |
27 Apr 11 |
nicklas |
82 |
|
5607 |
15 Apr 11 |
nicklas |
83 |
if (!xtFile.isValid() || (xtFile.hasError() && !allowUnmodified)) |
5603 |
08 Apr 11 |
nicklas |
84 |
{ |
5603 |
08 Apr 11 |
nicklas |
85 |
log.info("File has errors (skipping): " + xtFile); |
5603 |
08 Apr 11 |
nicklas |
86 |
return false; |
5603 |
08 Apr 11 |
nicklas |
87 |
} |
5603 |
08 Apr 11 |
nicklas |
88 |
|
5603 |
08 Apr 11 |
nicklas |
89 |
if (!xtFile.wasModified() && !allowUnmodified) |
5603 |
08 Apr 11 |
nicklas |
90 |
{ |
5603 |
08 Apr 11 |
nicklas |
91 |
log.info("File is not modified (skipping): " + xtFile); |
5603 |
08 Apr 11 |
nicklas |
92 |
return false; |
5603 |
08 Apr 11 |
nicklas |
93 |
} |
5603 |
08 Apr 11 |
nicklas |
94 |
|
5603 |
08 Apr 11 |
nicklas |
95 |
return true; |
5603 |
08 Apr 11 |
nicklas |
96 |
} |
5603 |
08 Apr 11 |
nicklas |
97 |
// ------------------------- |
5603 |
08 Apr 11 |
nicklas |
98 |
|
5603 |
08 Apr 11 |
nicklas |
99 |
|
5603 |
08 Apr 11 |
nicklas |
100 |
} |