001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (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 *     Nuxeo
016 */
017
018package org.nuxeo.ecm.platform.publisher.impl.service;
019
020import org.nuxeo.ecm.core.api.CoreSession;
021import org.nuxeo.ecm.platform.publisher.api.*;
022import org.nuxeo.runtime.api.Framework;
023
024import java.util.List;
025import java.util.Map;
026
027/**
028 * Remotable implementation of the {@link PublicationTree} interface. Because some {@link PublicationTree}
029 * implementation may be bound to local resources (network connexions, local filesystem ...) all {@link PublicationTree}
030 * returned by the service are wrapped into this RemotablePublicationTree.
031 *
032 * @author tiry
033 */
034public class ProxyTree extends AbstractRemotableTree implements PublicationTree {
035
036    private static final long serialVersionUID = 1L;
037
038    protected String name;
039
040    protected String title;
041
042    protected String treeType;
043
044    protected String path;
045
046    protected String iconCollapsed;
047
048    protected String iconExpanded;
049
050    protected ProxyNode rootNode;
051
052    protected String treeTitle;
053
054    protected String getTargetTreeName() {
055        return name;
056    }
057
058    @Override
059    protected List<PublicationNode> switchToClientNodes(List<PublicationNode> nodes) {
060        return nodes;
061    }
062
063    protected RemotePublicationTreeManager getTreeService() {
064        if (treeService == null) {
065            treeService = Framework.getService(RemotePublicationTreeManager.class);
066        }
067        return treeService;
068    }
069
070    public ProxyTree(PublicationTree tree, String sid) {
071        this.sessionId = sid;
072        this.name = tree.getName();
073        this.title = tree.getTitle();
074        this.treeTitle = tree.getTreeTitle();
075        this.treeType = tree.getTreeType();
076        this.path = tree.getPath();
077        this.rootNode = new ProxyNode(tree, sid);
078        this.configName = tree.getConfigName();
079        this.iconCollapsed = tree.getIconCollapsed();
080        this.iconExpanded = tree.getIconExpanded();
081    }
082
083    public String getTitle() {
084        return title;
085    }
086
087    public String getTreeTitle() {
088        return treeTitle;
089    }
090
091    public String getName() {
092        return name;
093    }
094
095    public String getTreeType() {
096        return treeType;
097    }
098
099    public void initTree(String sid, CoreSession coreSession, Map<String, String> parameters,
100            PublishedDocumentFactory factory, String configName) {
101        // NOP
102    }
103
104    public void initTree(String sid, CoreSession coreSession, Map<String, String> parameters,
105            PublishedDocumentFactory factory, String configName, String title) {
106        // NOP
107    }
108
109    public List<PublishedDocument> getChildrenDocuments() {
110        return rootNode.getChildrenDocuments();
111    }
112
113    public String getNodeType() {
114        return rootNode.getNodeType();
115    }
116
117    public String getPath() {
118        return path;
119    }
120
121    public String getTreeConfigName() {
122        return configName;
123    }
124
125    public String getSessionId() {
126        return sessionId;
127    }
128
129    @Override
130    protected String getServerTreeSessionId() {
131        return getSessionId();
132    }
133
134    // make fail tests with surefire !
135    /*
136     * @Override protected void finalize() throws Throwable { try { release(); } finally { super.finalize(); } }
137     */
138
139    public List<PublicationNode> getChildrenNodes() {
140        return rootNode.getChildrenNodes();
141    }
142
143    @Override
144    protected PublicationNode switchToClientNode(PublicationNode node) {
145        // no wrap
146        return node;
147    }
148
149    @Override
150    protected PublicationNode switchToServerNode(PublicationNode node) {
151        return node;
152    }
153
154    public String getType() {
155        return this.getClass().getSimpleName();
156    }
157
158    public String getIconExpanded() {
159        return iconExpanded;
160    }
161
162    public String getIconCollapsed() {
163        return iconCollapsed;
164    }
165
166}