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