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.remoting.client;
021
022import org.nuxeo.ecm.platform.publisher.api.PublicationNode;
023import org.nuxeo.ecm.platform.publisher.api.RemotePublicationTreeManager;
024import org.nuxeo.ecm.platform.publisher.impl.service.AbstractRemotableNode;
025import org.nuxeo.ecm.platform.publisher.impl.service.ProxyNode;
026import org.nuxeo.ecm.platform.publisher.remoting.marshaling.basic.BasicPublicationNode;
027
028/**
029 * {@link PublicationNode} implementation that points to a remote tree on a remote server.
030 *
031 * @author tiry
032 */
033public class ClientRemotePublicationNode extends AbstractRemotableNode {
034
035    private static final long serialVersionUID = 1L;
036
037    protected String targetTreeName;
038
039    protected String name;
040
041    protected String serverSessionId;
042
043    protected String path;
044
045    protected String nodeType;
046
047    protected String nodeTitle;
048
049    protected String treeName;
050
051    public ClientRemotePublicationNode(String treeConfigName, String sid, PublicationNode node, String serverSessionId,
052            RemotePublicationTreeManager service, String targetTreeName) {
053        this.serverSessionId = serverSessionId;
054        this.sessionId = sid;
055        this.service = service;
056        this.path = node.getPath();
057        this.nodeType = node.getNodeType();
058        this.nodeTitle = node.getTitle();
059        this.treeName = treeConfigName;
060        this.targetTreeName = targetTreeName;
061        this.name = node.getName();
062    }
063
064    @Override
065    protected PublicationNode switchToServerNode(PublicationNode node) {
066
067        if (node instanceof ClientRemotePublicationNode) {
068            ClientRemotePublicationNode cNode = (ClientRemotePublicationNode) node;
069            return new BasicPublicationNode(cNode.getNodeType(), cNode.getPath(), cNode.getTitle(),
070                    cNode.getUnwrappedTreeName(), serverSessionId);
071        }
072        if (node instanceof ProxyNode) {
073            ProxyNode rNode = (ProxyNode) node;
074            return new BasicPublicationNode(rNode.getNodeType(), rNode.getPath(), rNode.getTitle(),
075                    getTargetTreeName(), serverSessionId);
076        } else {
077            return node;
078        }
079
080        // return new ClientRemotePublicationNode(treeName, sessionId,node,
081        // serverSessionId,
082        // service, getTargetTreeName());
083    }
084
085    @Override
086    protected PublicationNode switchToClientNode(PublicationNode node) {
087        return new ClientRemotePublicationNode(treeName, sessionId, node, serverSessionId, service, getTargetTreeName());
088    }
089
090    @Override
091    protected String getServerTreeSessionId() {
092        return serverSessionId;
093    }
094
095    @Override
096    protected RemotePublicationTreeManager getPublisher() {
097        return service;
098    }
099
100    public String getNodeType() {
101        return nodeType;
102    }
103
104    public String getType() {
105        return this.getClass().getSimpleName();
106    }
107
108    public String getPath() {
109        return path;
110    }
111
112    public String getTitle() {
113        return nodeTitle;
114    }
115
116    public String getName() {
117        return name;
118    }
119
120    public String getTreeConfigName() {
121        return treeName;
122    }
123
124    @Override
125    protected String getTargetTreeName() {
126        return targetTreeName;
127    }
128
129    public String getUnwrappedTreeName() {
130        return getTargetTreeName();
131    }
132
133    public String getSessionId() {
134        return sessionId;
135    }
136
137    public String getRemoteSessionId() {
138        return serverSessionId;
139    }
140}