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.DataFileType; |
5623 |
06 May 11 |
nicklas |
25 |
import net.sf.basedb.core.FileSetMember; |
5623 |
06 May 11 |
nicklas |
26 |
|
5623 |
06 May 11 |
nicklas |
27 |
/** |
5623 |
06 May 11 |
nicklas |
Base class for validators that works on single files |
5623 |
06 May 11 |
nicklas |
of a known data file type. The external if of the |
5623 |
06 May 11 |
nicklas |
file type should be specified in the constructor. |
5623 |
06 May 11 |
nicklas |
31 |
|
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 |
35 |
*/ |
5623 |
06 May 11 |
nicklas |
36 |
public abstract class SingleFileValidationAction |
5623 |
06 May 11 |
nicklas |
37 |
implements ValidationAction |
5623 |
06 May 11 |
nicklas |
38 |
{ |
5623 |
06 May 11 |
nicklas |
39 |
|
5623 |
06 May 11 |
nicklas |
40 |
private final String fileTypeId; |
5623 |
06 May 11 |
nicklas |
41 |
private FileSetMember acceptedFile; |
5623 |
06 May 11 |
nicklas |
42 |
|
5623 |
06 May 11 |
nicklas |
43 |
/** |
5623 |
06 May 11 |
nicklas |
Create a new instance. |
5623 |
06 May 11 |
nicklas |
45 |
|
5623 |
06 May 11 |
nicklas |
@param fileTypeId The external if of the {@link DataFileType} |
5623 |
06 May 11 |
nicklas |
that this validator supports |
5623 |
06 May 11 |
nicklas |
48 |
*/ |
5623 |
06 May 11 |
nicklas |
49 |
protected SingleFileValidationAction(String fileTypeId) |
5623 |
06 May 11 |
nicklas |
50 |
{ |
5623 |
06 May 11 |
nicklas |
51 |
this.fileTypeId = fileTypeId; |
5623 |
06 May 11 |
nicklas |
52 |
} |
5623 |
06 May 11 |
nicklas |
53 |
|
5623 |
06 May 11 |
nicklas |
54 |
/* |
5623 |
06 May 11 |
nicklas |
From the ValidationAction interface |
5623 |
06 May 11 |
nicklas |
56 |
----------------------------------- |
5623 |
06 May 11 |
nicklas |
57 |
*/ |
5623 |
06 May 11 |
nicklas |
58 |
/** |
5623 |
06 May 11 |
nicklas |
If the file has a file type matching the id given in the constructor |
5623 |
06 May 11 |
nicklas |
it is accepted for immediate validation. |
5623 |
06 May 11 |
nicklas |
@return {@link Accept#VALIDATE_IMMEDIATELY} or null |
5623 |
06 May 11 |
nicklas |
62 |
*/ |
5623 |
06 May 11 |
nicklas |
63 |
@Override |
5623 |
06 May 11 |
nicklas |
64 |
public Accept acceptFile(FileSetMember member) |
5623 |
06 May 11 |
nicklas |
65 |
{ |
5623 |
06 May 11 |
nicklas |
66 |
DataFileType fileType = member.getDataFileType(); |
5623 |
06 May 11 |
nicklas |
67 |
if (fileType.getExternalId().equals(fileTypeId)) |
5623 |
06 May 11 |
nicklas |
68 |
{ |
5623 |
06 May 11 |
nicklas |
69 |
this.acceptedFile = member; |
5623 |
06 May 11 |
nicklas |
70 |
return Accept.VALIDATE_IMMEDIATELY; |
5623 |
06 May 11 |
nicklas |
71 |
} |
5623 |
06 May 11 |
nicklas |
72 |
this.acceptedFile = null; |
5623 |
06 May 11 |
nicklas |
73 |
return null; |
5623 |
06 May 11 |
nicklas |
74 |
} |
5623 |
06 May 11 |
nicklas |
75 |
// ----------------------------------- |
5623 |
06 May 11 |
nicklas |
76 |
|
5623 |
06 May 11 |
nicklas |
77 |
/** |
5623 |
06 May 11 |
nicklas |
Get the file that was last accepted by the {@link #acceptFile(FileSetMember)} |
5623 |
06 May 11 |
nicklas |
method. |
5623 |
06 May 11 |
nicklas |
@return A file set member object, or null if the last file was not accepted |
5623 |
06 May 11 |
nicklas |
81 |
*/ |
5623 |
06 May 11 |
nicklas |
82 |
protected FileSetMember getAcceptedFile() |
5623 |
06 May 11 |
nicklas |
83 |
{ |
5623 |
06 May 11 |
nicklas |
84 |
return acceptedFile; |
5623 |
06 May 11 |
nicklas |
85 |
} |
5623 |
06 May 11 |
nicklas |
86 |
|
5623 |
06 May 11 |
nicklas |
87 |
} |