5623 |
06 May 11 |
nicklas |
1 |
/** |
5623 |
06 May 11 |
nicklas |
$Id$ |
5623 |
06 May 11 |
nicklas |
3 |
|
5623 |
06 May 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5623 |
06 May 11 |
nicklas |
5 |
|
5623 |
06 May 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5623 |
06 May 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5623 |
06 May 11 |
nicklas |
8 |
|
5623 |
06 May 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5623 |
06 May 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5623 |
06 May 11 |
nicklas |
of the License, or (at your option) any later version. |
5623 |
06 May 11 |
nicklas |
13 |
|
5623 |
06 May 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5623 |
06 May 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5623 |
06 May 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5623 |
06 May 11 |
nicklas |
GNU General Public License for more details. |
5623 |
06 May 11 |
nicklas |
18 |
|
5623 |
06 May 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5623 |
06 May 11 |
nicklas |
21 |
*/ |
5623 |
06 May 11 |
nicklas |
22 |
package net.sf.basedb.util.fileset; |
5623 |
06 May 11 |
nicklas |
23 |
|
5623 |
06 May 11 |
nicklas |
24 |
import net.sf.basedb.core.FileSetMember; |
5623 |
06 May 11 |
nicklas |
25 |
|
5623 |
06 May 11 |
nicklas |
26 |
/** |
5623 |
06 May 11 |
nicklas |
This class is a proxy used for holding information about |
5623 |
06 May 11 |
nicklas |
a file set member that is currently undergoing validation. |
5623 |
06 May 11 |
nicklas |
29 |
|
5623 |
06 May 11 |
nicklas |
@author Nicklas |
5623 |
06 May 11 |
nicklas |
@since 3.0 |
5623 |
06 May 11 |
nicklas |
@base.modified $Date$ |
5623 |
06 May 11 |
nicklas |
33 |
*/ |
5623 |
06 May 11 |
nicklas |
34 |
public class ValidatingFileSetMember |
5623 |
06 May 11 |
nicklas |
35 |
{ |
5623 |
06 May 11 |
nicklas |
36 |
|
5623 |
06 May 11 |
nicklas |
37 |
private final FileSetMember member; |
5623 |
06 May 11 |
nicklas |
38 |
|
5623 |
06 May 11 |
nicklas |
39 |
private boolean hasBeenAccepted; |
5623 |
06 May 11 |
nicklas |
40 |
private boolean isValidSoFar; |
5623 |
06 May 11 |
nicklas |
41 |
private String message; |
5623 |
06 May 11 |
nicklas |
42 |
|
5623 |
06 May 11 |
nicklas |
43 |
/** |
5623 |
06 May 11 |
nicklas |
Create a new instance for the given real member file. |
5623 |
06 May 11 |
nicklas |
45 |
*/ |
5623 |
06 May 11 |
nicklas |
46 |
public ValidatingFileSetMember(FileSetMember member) |
5623 |
06 May 11 |
nicklas |
47 |
{ |
5623 |
06 May 11 |
nicklas |
48 |
this.member = member; |
5623 |
06 May 11 |
nicklas |
49 |
this.hasBeenAccepted = false; |
5623 |
06 May 11 |
nicklas |
50 |
this.isValidSoFar = true; |
5623 |
06 May 11 |
nicklas |
51 |
} |
5623 |
06 May 11 |
nicklas |
52 |
|
5623 |
06 May 11 |
nicklas |
53 |
/** |
5623 |
06 May 11 |
nicklas |
Get the file set member that this proxy represents. |
5623 |
06 May 11 |
nicklas |
55 |
*/ |
5623 |
06 May 11 |
nicklas |
56 |
public FileSetMember getMember() |
5623 |
06 May 11 |
nicklas |
57 |
{ |
5623 |
06 May 11 |
nicklas |
58 |
return member; |
5623 |
06 May 11 |
nicklas |
59 |
} |
5623 |
06 May 11 |
nicklas |
60 |
|
5623 |
06 May 11 |
nicklas |
61 |
/** |
5623 |
06 May 11 |
nicklas |
Has this member been accepted for validation by at |
5623 |
06 May 11 |
nicklas |
least one validator? When the validation has ended, |
5623 |
06 May 11 |
nicklas |
the core will update the validation status only for |
5623 |
06 May 11 |
nicklas |
members that was accepted at least once. |
5623 |
06 May 11 |
nicklas |
66 |
*/ |
5623 |
06 May 11 |
nicklas |
67 |
public boolean hasBeenAccepted() |
5623 |
06 May 11 |
nicklas |
68 |
{ |
5623 |
06 May 11 |
nicklas |
69 |
return hasBeenAccepted; |
5623 |
06 May 11 |
nicklas |
70 |
} |
5623 |
06 May 11 |
nicklas |
71 |
|
5623 |
06 May 11 |
nicklas |
72 |
/** |
5623 |
06 May 11 |
nicklas |
Is the member considered valid so far in the validation process? |
5623 |
06 May 11 |
nicklas |
Members that has been marked as invalid by a validator will not |
5623 |
06 May 11 |
nicklas |
be processed by other validators. |
5623 |
06 May 11 |
nicklas |
76 |
*/ |
5623 |
06 May 11 |
nicklas |
77 |
public boolean isValidSoFar() |
5623 |
06 May 11 |
nicklas |
78 |
{ |
5623 |
06 May 11 |
nicklas |
79 |
return isValidSoFar; |
5623 |
06 May 11 |
nicklas |
80 |
} |
5623 |
06 May 11 |
nicklas |
81 |
|
5623 |
06 May 11 |
nicklas |
82 |
/** |
5623 |
06 May 11 |
nicklas |
Get the error message if the file failed validation. |
5623 |
06 May 11 |
nicklas |
84 |
*/ |
5623 |
06 May 11 |
nicklas |
85 |
public String getMessage() |
5623 |
06 May 11 |
nicklas |
86 |
{ |
5623 |
06 May 11 |
nicklas |
87 |
return message; |
5623 |
06 May 11 |
nicklas |
88 |
} |
5623 |
06 May 11 |
nicklas |
89 |
|
5623 |
06 May 11 |
nicklas |
90 |
/** |
5623 |
06 May 11 |
nicklas |
Check if the member is accepted by the given validator. |
5623 |
06 May 11 |
nicklas |
Members that have already been validated and marked as |
5623 |
06 May 11 |
nicklas |
invalid will never be accepted by other actions. |
5623 |
06 May 11 |
nicklas |
94 |
|
5623 |
06 May 11 |
nicklas |
@param action The next validation action |
5623 |
06 May 11 |
nicklas |
@return An {@link Accept} value or null if the file |
5623 |
06 May 11 |
nicklas |
wasn't accepted |
5623 |
06 May 11 |
nicklas |
98 |
*/ |
5623 |
06 May 11 |
nicklas |
99 |
public Accept isAcceptedByValidator(ValidationAction action) |
5623 |
06 May 11 |
nicklas |
100 |
{ |
5623 |
06 May 11 |
nicklas |
101 |
Accept accept = null; |
5623 |
06 May 11 |
nicklas |
102 |
if (!hasBeenAccepted || isValidSoFar) |
5623 |
06 May 11 |
nicklas |
103 |
{ |
5623 |
06 May 11 |
nicklas |
104 |
accept = action.acceptFile(member); |
5623 |
06 May 11 |
nicklas |
105 |
hasBeenAccepted |= (accept != null); |
5623 |
06 May 11 |
nicklas |
106 |
} |
5623 |
06 May 11 |
nicklas |
107 |
return accept; |
5623 |
06 May 11 |
nicklas |
108 |
} |
5623 |
06 May 11 |
nicklas |
109 |
|
5623 |
06 May 11 |
nicklas |
110 |
/** |
5623 |
06 May 11 |
nicklas |
Set the result of the validation for this file. |
5623 |
06 May 11 |
nicklas |
112 |
|
5623 |
06 May 11 |
nicklas |
@param isValid TRUE if the file passed validation |
5623 |
06 May 11 |
nicklas |
@param message A message about the validation |
5623 |
06 May 11 |
nicklas |
115 |
*/ |
5623 |
06 May 11 |
nicklas |
116 |
public void setResult(boolean isValid, String message) |
5623 |
06 May 11 |
nicklas |
117 |
{ |
5623 |
06 May 11 |
nicklas |
118 |
this.isValidSoFar = isValid; |
5623 |
06 May 11 |
nicklas |
119 |
this.message = message; |
5623 |
06 May 11 |
nicklas |
120 |
} |
5623 |
06 May 11 |
nicklas |
121 |
|
5623 |
06 May 11 |
nicklas |
122 |
|
5623 |
06 May 11 |
nicklas |
123 |
} |