src/core/net/sf/basedb/util/overview/loader/AbstractNodeLoader.java

Code
Comments
Other
Rev Date Author Line
4740 05 Feb 09 nicklas 1 /**
4740 05 Feb 09 nicklas 2   $Id$
4740 05 Feb 09 nicklas 3
4740 05 Feb 09 nicklas 4   Copyright (C) 2008 Nicklas Nordborg
4740 05 Feb 09 nicklas 5
4740 05 Feb 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4740 05 Feb 09 nicklas 7   Available at http://base.thep.lu.se/
4740 05 Feb 09 nicklas 8
4740 05 Feb 09 nicklas 9   BASE is free software; you can redistribute it and/or
4740 05 Feb 09 nicklas 10   modify it under the terms of the GNU General Public License
4740 05 Feb 09 nicklas 11   as published by the Free Software Foundation; either version 3
4740 05 Feb 09 nicklas 12   of the License, or (at your option) any later version.
4740 05 Feb 09 nicklas 13
4740 05 Feb 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4740 05 Feb 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4740 05 Feb 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4740 05 Feb 09 nicklas 17   GNU General Public License for more details.
4740 05 Feb 09 nicklas 18
4740 05 Feb 09 nicklas 19   You should have received a copy of the GNU General Public License
4740 05 Feb 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4740 05 Feb 09 nicklas 21 */
4740 05 Feb 09 nicklas 22 package net.sf.basedb.util.overview.loader;
4740 05 Feb 09 nicklas 23
4740 05 Feb 09 nicklas 24 import net.sf.basedb.core.DbControl;
4740 05 Feb 09 nicklas 25 import net.sf.basedb.util.overview.OverviewContext;
4740 05 Feb 09 nicklas 26 import net.sf.basedb.util.overview.node.ChildNodeDirection;
4740 05 Feb 09 nicklas 27 import net.sf.basedb.util.overview.Node;
4740 05 Feb 09 nicklas 28
4740 05 Feb 09 nicklas 29 /**
4740 05 Feb 09 nicklas 30   Abstract node loader implementation that does nothing/throws an
4740 05 Feb 09 nicklas 31   exception. It is recommended that all {@link NodeLoader} implementations 
4740 05 Feb 09 nicklas 32   extend this class (or a subclass) and only override the methods
4740 05 Feb 09 nicklas 33   they need to support. The node loader interface may be extended in the
4740 05 Feb 09 nicklas 34   future with new methods. Default implementations will be added to this class
4740 05 Feb 09 nicklas 35   which ensures that subclass implementation will continue to work.
4740 05 Feb 09 nicklas 36
4740 05 Feb 09 nicklas 37   @author Nicklas
4740 05 Feb 09 nicklas 38   @version 2.10
4740 05 Feb 09 nicklas 39   @base.modified $Date$
4740 05 Feb 09 nicklas 40 */
4740 05 Feb 09 nicklas 41 public abstract class AbstractNodeLoader<I>
4740 05 Feb 09 nicklas 42   implements NodeLoader<I>
4740 05 Feb 09 nicklas 43 {
6444 09 Apr 14 nicklas 44   private static final org.slf4j.Logger log = 
6444 09 Apr 14 nicklas 45     org.slf4j.LoggerFactory.getLogger(AbstractNodeLoader.class);
6444 09 Apr 14 nicklas 46   
4740 05 Feb 09 nicklas 47   private static final boolean debug = log.isDebugEnabled();
4740 05 Feb 09 nicklas 48
4740 05 Feb 09 nicklas 49   protected AbstractNodeLoader()
4740 05 Feb 09 nicklas 50   {}
4740 05 Feb 09 nicklas 51
4740 05 Feb 09 nicklas 52   /*
4740 05 Feb 09 nicklas 53     From the NodeLoader interface
4740 05 Feb 09 nicklas 54     -----------------------------
4740 05 Feb 09 nicklas 55   */
4740 05 Feb 09 nicklas 56   /**
6898 12 May 15 nicklas 57     @throws UnsupportedOperationException Always
4740 05 Feb 09 nicklas 58   */
4740 05 Feb 09 nicklas 59   @Override
4740 05 Feb 09 nicklas 60   public Node createRootNode(DbControl dc, OverviewContext context, I rootItem)
4740 05 Feb 09 nicklas 61   {
4740 05 Feb 09 nicklas 62     throw new UnsupportedOperationException();
4740 05 Feb 09 nicklas 63   }
4740 05 Feb 09 nicklas 64   /**
6898 12 May 15 nicklas 65     @throws UnsupportedOperationException Always
4740 05 Feb 09 nicklas 66   */
4740 05 Feb 09 nicklas 67   @Override
4740 05 Feb 09 nicklas 68   public Node createForwardNode(DbControl dc, OverviewContext context, Node parentNode)
4740 05 Feb 09 nicklas 69   {
4740 05 Feb 09 nicklas 70     throw new UnsupportedOperationException();
4740 05 Feb 09 nicklas 71   }
4740 05 Feb 09 nicklas 72
4740 05 Feb 09 nicklas 73   /**
6898 12 May 15 nicklas 74     @throws UnsupportedOperationException Always
4740 05 Feb 09 nicklas 75   */
4740 05 Feb 09 nicklas 76   @Override
4740 05 Feb 09 nicklas 77   public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
4740 05 Feb 09 nicklas 78   {
4740 05 Feb 09 nicklas 79     throw new UnsupportedOperationException();
4740 05 Feb 09 nicklas 80   }
4740 05 Feb 09 nicklas 81
4740 05 Feb 09 nicklas 82   /**
6898 12 May 15 nicklas 83     @throws UnsupportedOperationException Always
4740 05 Feb 09 nicklas 84   */
4740 05 Feb 09 nicklas 85   @Override
4740 05 Feb 09 nicklas 86   public Node createReverseNode(DbControl dc, OverviewContext context, Node childNode)
4740 05 Feb 09 nicklas 87   {
4740 05 Feb 09 nicklas 88     throw new UnsupportedOperationException();
4740 05 Feb 09 nicklas 89   }
4740 05 Feb 09 nicklas 90   
4740 05 Feb 09 nicklas 91   /**
4740 05 Feb 09 nicklas 92     Load childs nodes. This method simplifies the loading of child nodes.
4740 05 Feb 09 nicklas 93     First, it will check if child nodes has already been loaded. If so it 
4740 05 Feb 09 nicklas 94     simply returns. Then depending on the node's {@link ChildNodeDirection}
4740 05 Feb 09 nicklas 95     it will call {@link #loadForwardChildNodes(DbControl, OverviewContext, Node)},
4740 05 Feb 09 nicklas 96     {@link #loadReverseChildNodes(DbControl, OverviewContext, Node)} and 
4740 05 Feb 09 nicklas 97     {@link #loadPropertyChildNodes(DbControl, OverviewContext, Node)} as needed.
4740 05 Feb 09 nicklas 98     <p>
4740 05 Feb 09 nicklas 99     NOTE! If the given node is a folder-node, this method will iterate
4740 05 Feb 09 nicklas 100     over the children in the folder and do the above for each one of them.
4740 05 Feb 09 nicklas 101   */
6127 14 Sep 12 nicklas 102   @Override
4740 05 Feb 09 nicklas 103   public boolean loadChildNodes(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 104   {
4740 05 Feb 09 nicklas 105     if (debug) log.debug("Loading child nodes: " + node);
4740 05 Feb 09 nicklas 106     if (node.getNodeType() == Node.Type.FOLDER)
4740 05 Feb 09 nicklas 107     {
4740 05 Feb 09 nicklas 108       return loadChildNodesOfFolderNode(dc, context, node);
4740 05 Feb 09 nicklas 109     }
4740 05 Feb 09 nicklas 110     else 
4740 05 Feb 09 nicklas 111     {
4740 05 Feb 09 nicklas 112       return loadChildNodesOfItemNode(dc, context, node);
4740 05 Feb 09 nicklas 113     }
4740 05 Feb 09 nicklas 114   }
4740 05 Feb 09 nicklas 115   // ----------------------------------------------------
4740 05 Feb 09 nicklas 116
4740 05 Feb 09 nicklas 117   /**
4740 05 Feb 09 nicklas 118     Loads child nodes of an item-type node.
4740 05 Feb 09 nicklas 119   */
4740 05 Feb 09 nicklas 120   protected boolean loadChildNodesOfItemNode(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 121   {
4740 05 Feb 09 nicklas 122     if (node.isChildrenLoaded()) return false;
4740 05 Feb 09 nicklas 123     node.setChildrenLoaded();
4740 05 Feb 09 nicklas 124     ChildNodeDirection direction = node.getChildNodeDirection();
6041 02 Apr 12 nicklas 125     if (direction.loadReverse()) loadReverseChildNodes(dc, context, node);
4740 05 Feb 09 nicklas 126     if (direction.loadForward()) loadForwardChildNodes(dc, context, node);
4740 05 Feb 09 nicklas 127     if (direction.loadProperty()) loadPropertyChildNodes(dc, context, node);
4740 05 Feb 09 nicklas 128     return node.numChildren() > 0;
4740 05 Feb 09 nicklas 129   }
4740 05 Feb 09 nicklas 130   
4740 05 Feb 09 nicklas 131   /**
4740 05 Feb 09 nicklas 132     Iterates the children of a folder-type node and loads the children for
4740 05 Feb 09 nicklas 133     each one of them.
4740 05 Feb 09 nicklas 134   */
4740 05 Feb 09 nicklas 135   protected boolean loadChildNodesOfFolderNode(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 136   {
4740 05 Feb 09 nicklas 137     boolean result = false;
4740 05 Feb 09 nicklas 138     if (node.getChildNodeDirection() != ChildNodeDirection.NONE && node.numChildren() > 0)
4740 05 Feb 09 nicklas 139     {
4740 05 Feb 09 nicklas 140       for (Node child : node.getChildren())
4740 05 Feb 09 nicklas 141       {
4740 05 Feb 09 nicklas 142         result |= loadChildNodes(dc, context, child);
4740 05 Feb 09 nicklas 143       }
4740 05 Feb 09 nicklas 144     }
4740 05 Feb 09 nicklas 145     return result;
4740 05 Feb 09 nicklas 146   }
4740 05 Feb 09 nicklas 147   
4740 05 Feb 09 nicklas 148   /**
4740 05 Feb 09 nicklas 149     Load forward-loading child nodes. This method is called from {@link 
4740 05 Feb 09 nicklas 150     #loadChildNodesOfItemNode(DbControl, OverviewContext, Node)}
4740 05 Feb 09 nicklas 151     if the current node has a {@link ChildNodeDirection#loadForward()} that returns true.
4740 05 Feb 09 nicklas 152     The default implementation does nothing. This method is intended to be implemented
4740 05 Feb 09 nicklas 153     by subclasses.
4740 05 Feb 09 nicklas 154   */
4740 05 Feb 09 nicklas 155   protected void loadForwardChildNodes(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 156   {}
4740 05 Feb 09 nicklas 157   
4740 05 Feb 09 nicklas 158   /**
4740 05 Feb 09 nicklas 159     Load reverse-loading child nodes. This method is called from {@link 
4740 05 Feb 09 nicklas 160     #loadChildNodesOfItemNode(DbControl, OverviewContext, Node)}
4740 05 Feb 09 nicklas 161     if the current node has a {@link ChildNodeDirection#loadReverse()} that returns true.
4740 05 Feb 09 nicklas 162     The default implementation does nothing. This method is intended to be implemented
4740 05 Feb 09 nicklas 163     by subclasses.
4740 05 Feb 09 nicklas 164   */
4740 05 Feb 09 nicklas 165   protected void loadReverseChildNodes(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 166   {}
4740 05 Feb 09 nicklas 167   
4740 05 Feb 09 nicklas 168   /**
4740 05 Feb 09 nicklas 169     Load property-type child nodes. This method is called from {@link 
4740 05 Feb 09 nicklas 170     #loadChildNodesOfItemNode(DbControl, OverviewContext, Node)} if the current node
4740 05 Feb 09 nicklas 171     has a {@link ChildNodeDirection#loadProperty()} that returns true.
4740 05 Feb 09 nicklas 172     The default implementation does nothing. This method is intended to be implemented
4740 05 Feb 09 nicklas 173     by subclasses.
4740 05 Feb 09 nicklas 174   */
4740 05 Feb 09 nicklas 175   protected void loadPropertyChildNodes(DbControl dc, OverviewContext context, Node node)
4740 05 Feb 09 nicklas 176   {}
4740 05 Feb 09 nicklas 177
4740 05 Feb 09 nicklas 178 }