001/*
002 * (C) Copyright 2010-2011 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *    mcedica
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.routing.api;
021
022import java.util.ArrayList;
023import java.util.List;
024
025import org.nuxeo.ecm.core.api.DocumentModel;
026
027/**
028 * Wraps a documentElement adding informations about the level where the document is inside the container documentRoute
029 *
030 * @author <a href="mailto:mcedica@nuxeo.com">Mariana Cedica</a>
031 * @deprecated since 5.9.2 - Use only routes of type 'graph'
032 */
033public class DocumentRouteTableElement {
034
035    protected final DocumentRouteElement element;
036
037    protected final RouteTable table;
038
039    protected final int depth;
040
041    protected RouteFolderElement parent;
042
043    protected boolean isFirstChild;
044
045    protected List<RouteFolderElement> firstChildList = new ArrayList<RouteFolderElement>();
046
047    public DocumentRouteTableElement(DocumentRouteElement element, RouteTable table, int depth,
048            RouteFolderElement parent, boolean isFirstChild) {
049        this.table = table;
050        this.depth = depth;
051        this.element = element;
052        this.parent = parent;
053        this.isFirstChild = isFirstChild;
054    }
055
056    public RouteFolderElement getParent() {
057        return parent;
058    }
059
060    public DocumentRouteElement getElement() {
061        return element;
062    }
063
064    public int getDepth() {
065        return depth;
066    }
067
068    public RouteTable getRouteTable() {
069        return table;
070    }
071
072    public List<RouteFolderElement> getFirstChildFolders() {
073        return firstChildList;
074    }
075
076    public int getRouteMaxDepth() {
077        return table.getMaxDepth();
078    }
079
080    public DocumentModel getDocument() {
081        return element.getDocument();
082    }
083
084    public void computeFirstChildList() {
085        RouteFolderElement currentParent = parent;
086        boolean currentIsFirst = isFirstChild;
087        while (currentIsFirst && currentParent != null) {
088            currentIsFirst = currentParent.isFirstChild;
089            firstChildList.add(0, currentParent);
090            currentParent = currentParent.parent;
091        }
092    }
093}