src/core/net/sf/basedb/util/extensions/manager/ExtensionsFileProcessor.java

Code
Comments
Other
Rev Date Author Line
5598 30 Mar 11 nicklas 1 /**
5598 30 Mar 11 nicklas 2   $Id$
5598 30 Mar 11 nicklas 3
5598 30 Mar 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5598 30 Mar 11 nicklas 5
5598 30 Mar 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5598 30 Mar 11 nicklas 7   Available at http://base.thep.lu.se/
5598 30 Mar 11 nicklas 8
5598 30 Mar 11 nicklas 9   BASE is free software; you can redistribute it and/or
5598 30 Mar 11 nicklas 10   modify it under the terms of the GNU General Public License
5598 30 Mar 11 nicklas 11   as published by the Free Software Foundation; either version 3
5598 30 Mar 11 nicklas 12   of the License, or (at your option) any later version.
5598 30 Mar 11 nicklas 13
5598 30 Mar 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5598 30 Mar 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5598 30 Mar 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5598 30 Mar 11 nicklas 17   GNU General Public License for more details.
5598 30 Mar 11 nicklas 18
5598 30 Mar 11 nicklas 19   You should have received a copy of the GNU General Public License
5598 30 Mar 11 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5598 30 Mar 11 nicklas 21 */
5598 30 Mar 11 nicklas 22 package net.sf.basedb.util.extensions.manager;
5598 30 Mar 11 nicklas 23
5602 07 Apr 11 nicklas 24 import net.sf.basedb.util.extensions.manager.ExtensionsFile.WriteableExtensionsFile;
5602 07 Apr 11 nicklas 25
5598 30 Mar 11 nicklas 26 /**
5598 30 Mar 11 nicklas 27   Interface that is used to request a callback for each extensions file
5598 30 Mar 11 nicklas 28   managed by an extensions manager. Implementations are more or less free
5598 30 Mar 11 nicklas 29   to do whatever they want with the file. Typically, they will scan the
5598 30 Mar 11 nicklas 30   XML metadata or the contents of a JAR file and do something with it.
5598 30 Mar 11 nicklas 31   <p>
5598 30 Mar 11 nicklas 32   
5598 30 Mar 11 nicklas 33   A processer implementation is used by calling {@link 
5598 30 Mar 11 nicklas 34   ExtensionsManager#processFiles(ExtensionsFileProcessor)}.
5598 30 Mar 11 nicklas 35   <p>
5598 30 Mar 11 nicklas 36   
5598 30 Mar 11 nicklas 37   The manager will first call {@link #begin(ExtensionsManager, int)} and
5823 24 Oct 11 nicklas 38   then {@link #processFile(ExtensionsManager, ExtensionsFile.WriteableExtensionsFile)} for each
5598 30 Mar 11 nicklas 39   file that has been confirmed to contain a valid extension definitions 
5598 30 Mar 11 nicklas 40   file. If all files could be processed without problems the manager
5598 30 Mar 11 nicklas 41   finishes by calling {@link #done(ExtensionsManager)}. If the processor
5598 30 Mar 11 nicklas 42   throws an exception the processing is immediately aborted and 
5598 30 Mar 11 nicklas 43   {@link #done(ExtensionsManager, Throwable)} is called instead.
5598 30 Mar 11 nicklas 44   
5598 30 Mar 11 nicklas 45   @author Nicklas
5598 30 Mar 11 nicklas 46   @since 3.0
5598 30 Mar 11 nicklas 47   @base.modified $Date$
5598 30 Mar 11 nicklas 48 */
5598 30 Mar 11 nicklas 49 public interface ExtensionsFileProcessor
5598 30 Mar 11 nicklas 50 {
5598 30 Mar 11 nicklas 51
5598 30 Mar 11 nicklas 52   /**
5598 30 Mar 11 nicklas 53     Called by the extensions manager before the processing starts.
5598 30 Mar 11 nicklas 54     
5598 30 Mar 11 nicklas 55     @param manager The manager that is executing the action
5598 30 Mar 11 nicklas 56     @param numFiles The number of extension files that is going to be processed this time
5598 30 Mar 11 nicklas 57   */
5598 30 Mar 11 nicklas 58   public void begin(ExtensionsManager manager, int numFiles);
5598 30 Mar 11 nicklas 59   
5598 30 Mar 11 nicklas 60   /**
5598 30 Mar 11 nicklas 61     Called by the extensions manager for each extensions file that it
5598 30 Mar 11 nicklas 62     manages. The order of the files is generally not predicatable and
5598 30 Mar 11 nicklas 63     may change from one invokation to the next.
5598 30 Mar 11 nicklas 64     <p>
5598 30 Mar 11 nicklas 65     
5598 30 Mar 11 nicklas 66     If the processor throws an exception the manager will abort
5598 30 Mar 11 nicklas 67     processing and call {@link #done(ExtensionsManager, Throwable)}.
5602 07 Apr 11 nicklas 68     Error that are related to a specific file should be catched
5602 07 Apr 11 nicklas 69     by the processor and registered by calling .......
5598 30 Mar 11 nicklas 70     <p>
5598 30 Mar 11 nicklas 71     
5598 30 Mar 11 nicklas 72     If all files was processed without exceptions the manager
5598 30 Mar 11 nicklas 73     will call {@link #done(ExtensionsManager)}.
5602 07 Apr 11 nicklas 74
5602 07 Apr 11 nicklas 75     <p>
5602 07 Apr 11 nicklas 76     Note that the file is read-only to begin with. If the processor
5602 07 Apr 11 nicklas 77     wants to call any write-operation the file must be opened by
5602 07 Apr 11 nicklas 78     calling {@link WriteableExtensionsFile#open()}. It is recommended
5602 07 Apr 11 nicklas 79     that the processor calls {@link WriteableExtensionsFile#close()}
5602 07 Apr 11 nicklas 80     once it is done writing.
5598 30 Mar 11 nicklas 81     
5598 30 Mar 11 nicklas 82     @param manager The manager that is executing the action
5598 30 Mar 11 nicklas 83     @param file The file to be processed
5598 30 Mar 11 nicklas 84   */
5602 07 Apr 11 nicklas 85   public void processFile(ExtensionsManager manager, WriteableExtensionsFile file);
5598 30 Mar 11 nicklas 86
5598 30 Mar 11 nicklas 87   /**
5598 30 Mar 11 nicklas 88     Called by the extensions manager after a successful completion of the
5598 30 Mar 11 nicklas 89     processing. 
5598 30 Mar 11 nicklas 90     @param manager The manager that is executing the action
5598 30 Mar 11 nicklas 91   */
5598 30 Mar 11 nicklas 92   public void done(ExtensionsManager manager);
5598 30 Mar 11 nicklas 93   
5598 30 Mar 11 nicklas 94   /**
5598 30 Mar 11 nicklas 95     Called by the extensions manager if an exception was thrown
5598 30 Mar 11 nicklas 96     by the processor. 
5598 30 Mar 11 nicklas 97     @param manager The manager that is executing the action
5598 30 Mar 11 nicklas 98     @param t The exception
5598 30 Mar 11 nicklas 99   */
5598 30 Mar 11 nicklas 100   public void done(ExtensionsManager manager, Throwable t);
5598 30 Mar 11 nicklas 101   
5598 30 Mar 11 nicklas 102 }