src/core/net/sf/basedb/util/fileset/SingleFileValidationAction.java

Code
Comments
Other
Rev Date Author Line
5623 06 May 11 nicklas 1 /**
5623 06 May 11 nicklas 2   $Id$
5623 06 May 11 nicklas 3
5623 06 May 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5623 06 May 11 nicklas 5
5623 06 May 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5623 06 May 11 nicklas 7   Available at http://base.thep.lu.se/
5623 06 May 11 nicklas 8
5623 06 May 11 nicklas 9   BASE is free software; you can redistribute it and/or
5623 06 May 11 nicklas 10   modify it under the terms of the GNU General Public License
5623 06 May 11 nicklas 11   as published by the Free Software Foundation; either version 3
5623 06 May 11 nicklas 12   of the License, or (at your option) any later version.
5623 06 May 11 nicklas 13
5623 06 May 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5623 06 May 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5623 06 May 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5623 06 May 11 nicklas 17   GNU General Public License for more details.
5623 06 May 11 nicklas 18
5623 06 May 11 nicklas 19   You should have received a copy of the GNU General Public License
5623 06 May 11 nicklas 20   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 28   Base class for validators that works on single files
5623 06 May 11 nicklas 29   of a known data file type. The external if of the 
5623 06 May 11 nicklas 30   file type should be specified in the constructor.
5623 06 May 11 nicklas 31
5623 06 May 11 nicklas 32   @author Nicklas
5623 06 May 11 nicklas 33   @since 3.0
5623 06 May 11 nicklas 34   @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 44     Create a new instance.
5623 06 May 11 nicklas 45     
5623 06 May 11 nicklas 46     @param fileTypeId The external if of the {@link DataFileType}
5623 06 May 11 nicklas 47       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 55     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 59     If the file has a file type matching the id given in the constructor
5623 06 May 11 nicklas 60     it is accepted for immediate validation. 
5623 06 May 11 nicklas 61     @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 78     Get the file that was last accepted by the {@link #acceptFile(FileSetMember)}
5623 06 May 11 nicklas 79     method.
5623 06 May 11 nicklas 80     @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 }