001/*
002 * (C) Copyright 2010-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *    mcedica
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.routing.api;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import org.nuxeo.ecm.core.api.DocumentModel;
028
029/**
030 * Wraps a documentElement adding informations about the level where the document is inside the container documentRoute
031 *
032 * @author <a href="mailto:mcedica@nuxeo.com">Mariana Cedica</a>
033 * @deprecated since 5.9.2 - Use only routes of type 'graph'
034 */
035@Deprecated
036public class DocumentRouteTableElement {
037
038    protected final DocumentRouteElement element;
039
040    protected final RouteTable table;
041
042    protected final int depth;
043
044    protected RouteFolderElement parent;
045
046    protected boolean isFirstChild;
047
048    protected List<RouteFolderElement> firstChildList = new ArrayList<>();
049
050    public DocumentRouteTableElement(DocumentRouteElement element, RouteTable table, int depth,
051            RouteFolderElement parent, boolean isFirstChild) {
052        this.table = table;
053        this.depth = depth;
054        this.element = element;
055        this.parent = parent;
056        this.isFirstChild = isFirstChild;
057    }
058
059    public RouteFolderElement getParent() {
060        return parent;
061    }
062
063    public DocumentRouteElement getElement() {
064        return element;
065    }
066
067    public int getDepth() {
068        return depth;
069    }
070
071    public RouteTable getRouteTable() {
072        return table;
073    }
074
075    public List<RouteFolderElement> getFirstChildFolders() {
076        return firstChildList;
077    }
078
079    public int getRouteMaxDepth() {
080        return table.getMaxDepth();
081    }
082
083    public DocumentModel getDocument() {
084        return element.getDocument();
085    }
086
087    public void computeFirstChildList() {
088        RouteFolderElement currentParent = parent;
089        boolean currentIsFirst = isFirstChild;
090        while (currentIsFirst && currentParent != null) {
091            currentIsFirst = currentParent.isFirstChild;
092            firstChildList.add(0, currentParent);
093            currentParent = currentParent.parent;
094        }
095    }
096}