src/core/net/sf/basedb/util/gtf/GtfValidationFactory.java

Code
Comments
Other
Rev Date Author Line
5764 27 Sep 11 nicklas 1 /**
5764 27 Sep 11 nicklas 2   $Id$
5764 27 Sep 11 nicklas 3
5764 27 Sep 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5764 27 Sep 11 nicklas 5
5764 27 Sep 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5764 27 Sep 11 nicklas 7   Available at http://base.thep.lu.se/
5764 27 Sep 11 nicklas 8
5764 27 Sep 11 nicklas 9   BASE is free software; you can redistribute it and/or
5764 27 Sep 11 nicklas 10   modify it under the terms of the GNU General Public License
5764 27 Sep 11 nicklas 11   as published by the Free Software Foundation; either version 3
5764 27 Sep 11 nicklas 12   of the License, or (at your option) any later version.
5764 27 Sep 11 nicklas 13
5764 27 Sep 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5764 27 Sep 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5764 27 Sep 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5764 27 Sep 11 nicklas 17   GNU General Public License for more details.
5764 27 Sep 11 nicklas 18
5764 27 Sep 11 nicklas 19   You should have received a copy of the GNU General Public License
5764 27 Sep 11 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5764 27 Sep 11 nicklas 21 */
5764 27 Sep 11 nicklas 22 package net.sf.basedb.util.gtf;
5764 27 Sep 11 nicklas 23
5764 27 Sep 11 nicklas 24 import net.sf.basedb.core.ArrayDesign;
5764 27 Sep 11 nicklas 25 import net.sf.basedb.core.DataFileType;
5764 27 Sep 11 nicklas 26 import net.sf.basedb.core.DbControl;
5764 27 Sep 11 nicklas 27 import net.sf.basedb.core.Platform;
5764 27 Sep 11 nicklas 28 import net.sf.basedb.util.extensions.ActionFactory;
5764 27 Sep 11 nicklas 29 import net.sf.basedb.util.extensions.InvokationContext;
5764 27 Sep 11 nicklas 30
5764 27 Sep 11 nicklas 31 /**
5764 27 Sep 11 nicklas 32   Action factory for creating GTF file validators.
5764 27 Sep 11 nicklas 33   
5764 27 Sep 11 nicklas 34   @author Nicklas
5764 27 Sep 11 nicklas 35   @since 3.0
5764 27 Sep 11 nicklas 36   @base.modified $Date$
5764 27 Sep 11 nicklas 37 */
5764 27 Sep 11 nicklas 38 public class GtfValidationFactory
5764 27 Sep 11 nicklas 39   implements ActionFactory<GtfValidationAction>
5764 27 Sep 11 nicklas 40 {
5764 27 Sep 11 nicklas 41
5764 27 Sep 11 nicklas 42   public GtfValidationFactory()
5764 27 Sep 11 nicklas 43   {}
5764 27 Sep 11 nicklas 44   
5764 27 Sep 11 nicklas 45   /*
5764 27 Sep 11 nicklas 46     From the ActionFactory interface
5764 27 Sep 11 nicklas 47     --------------------------------
5764 27 Sep 11 nicklas 48   */
5764 27 Sep 11 nicklas 49   @Override
5764 27 Sep 11 nicklas 50   public boolean prepareContext(InvokationContext<? super GtfValidationAction> context)
5764 27 Sep 11 nicklas 51   {
5764 27 Sep 11 nicklas 52     Object item = context.getClientContext().getCurrentItem();
5764 27 Sep 11 nicklas 53     boolean isInContext = false;
5764 27 Sep 11 nicklas 54     if (item instanceof ArrayDesign)
5764 27 Sep 11 nicklas 55     {
5764 27 Sep 11 nicklas 56       // Validation context
5764 27 Sep 11 nicklas 57       ArrayDesign design = (ArrayDesign)item;
5764 27 Sep 11 nicklas 58       isInContext = design.isPlatform(Platform.SEQUENCING);
5764 27 Sep 11 nicklas 59     }
5764 27 Sep 11 nicklas 60     else if (item instanceof DataFileType)
5764 27 Sep 11 nicklas 61     {
5764 27 Sep 11 nicklas 62       // Do we support validating the given file type?
5764 27 Sep 11 nicklas 63       DataFileType fileType = (DataFileType)item;
5764 27 Sep 11 nicklas 64       isInContext = DataFileType.REF_SEQ_GTF.equals(fileType.getExternalId());
5764 27 Sep 11 nicklas 65     }
5764 27 Sep 11 nicklas 66     return isInContext;
5764 27 Sep 11 nicklas 67   }
5764 27 Sep 11 nicklas 68
5764 27 Sep 11 nicklas 69
5764 27 Sep 11 nicklas 70   @Override
5764 27 Sep 11 nicklas 71   public GtfValidationAction[] getActions(InvokationContext<? super GtfValidationAction> context)
5764 27 Sep 11 nicklas 72   {
5764 27 Sep 11 nicklas 73     Object item = context.getClientContext().getCurrentItem();
5764 27 Sep 11 nicklas 74     ArrayDesign ownerItem = null;
5764 27 Sep 11 nicklas 75     if (item instanceof ArrayDesign)
5764 27 Sep 11 nicklas 76     {
5764 27 Sep 11 nicklas 77       ownerItem = (ArrayDesign)item;
5764 27 Sep 11 nicklas 78     }
5764 27 Sep 11 nicklas 79     
5764 27 Sep 11 nicklas 80     GtfValidationAction[] actions = null;
5764 27 Sep 11 nicklas 81     if (ownerItem != null)
5764 27 Sep 11 nicklas 82     {
5764 27 Sep 11 nicklas 83       DbControl dc = context.getClientContext().getDbControl();
5764 27 Sep 11 nicklas 84       actions = new GtfValidationAction[] { new GtfValidationAction(dc, ownerItem, Integer.MAX_VALUE) };
5764 27 Sep 11 nicklas 85     }
5764 27 Sep 11 nicklas 86     return actions;
5764 27 Sep 11 nicklas 87   }
5764 27 Sep 11 nicklas 88   // -----------------------------------
5764 27 Sep 11 nicklas 89
5764 27 Sep 11 nicklas 90 }