src/core/net/sf/basedb/util/fileset/ValidatingFileSetMember.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.FileSetMember;
5623 06 May 11 nicklas 25
5623 06 May 11 nicklas 26 /**
5623 06 May 11 nicklas 27   This class is a proxy used for holding information about 
5623 06 May 11 nicklas 28   a file set member that is currently undergoing validation.
5623 06 May 11 nicklas 29
5623 06 May 11 nicklas 30   @author Nicklas
5623 06 May 11 nicklas 31   @since 3.0
5623 06 May 11 nicklas 32   @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 44      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 54     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 62     Has this member been accepted for validation by at
5623 06 May 11 nicklas 63     least one validator? When the validation has ended,
5623 06 May 11 nicklas 64     the core will update the validation status only for
5623 06 May 11 nicklas 65     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 73     Is the member considered valid so far in the validation process?
5623 06 May 11 nicklas 74     Members that has been marked as invalid by a validator will not 
5623 06 May 11 nicklas 75     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 83     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 91     Check if the member is accepted by the given validator.
5623 06 May 11 nicklas 92     Members that have already been validated and marked as
5623 06 May 11 nicklas 93     invalid will never be accepted by other actions.
5623 06 May 11 nicklas 94     
5623 06 May 11 nicklas 95     @param action The next validation action
5623 06 May 11 nicklas 96     @return An {@link Accept} value or null if the file
5623 06 May 11 nicklas 97       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 111     Set the result of the validation for this file.
5623 06 May 11 nicklas 112     
5623 06 May 11 nicklas 113     @param isValid TRUE if the file passed validation
5623 06 May 11 nicklas 114     @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 }