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.platform.publisher.api.PublicationNode; 021import org.nuxeo.ecm.platform.publisher.api.PublishedDocument; 022import org.nuxeo.ecm.platform.publisher.api.RemotePublicationTreeManager; 023 024import java.util.ArrayList; 025import java.util.List; 026 027/** 028 * Abstract class for {@link PublicationNode} that delegate method calls to a remote service. 029 * 030 * @author tiry 031 */ 032public abstract class AbstractRemotableNode implements PublicationNode { 033 034 protected abstract RemotePublicationTreeManager getPublisher(); 035 036 protected abstract String getServerTreeSessionId(); 037 038 protected String treeName; 039 040 protected String sessionId; 041 042 protected RemotePublicationTreeManager service; 043 044 protected abstract String getTargetTreeName(); 045 046 /** 047 * switch node definition from client to server (for remote publishing) 048 */ 049 protected abstract PublicationNode switchToServerNode(PublicationNode node); 050 051 /** 052 * switch node definition from server to client (for remote publishing) 053 */ 054 protected abstract PublicationNode switchToClientNode(PublicationNode node); 055 056 protected List<PublicationNode> switchToServerNodes(List<PublicationNode> nodes) { 057 List<PublicationNode> wrappedNodes = new ArrayList<PublicationNode>(); 058 059 for (PublicationNode node : nodes) { 060 wrappedNodes.add(switchToServerNode(node)); 061 } 062 return wrappedNodes; 063 } 064 065 protected List<PublicationNode> switchToClientNodes(List<PublicationNode> nodes) { 066 List<PublicationNode> wrappedNodes = new ArrayList<PublicationNode>(); 067 068 for (PublicationNode node : nodes) { 069 wrappedNodes.add(switchToClientNode(node)); 070 } 071 return wrappedNodes; 072 } 073 074 public List<PublishedDocument> getChildrenDocuments() { 075 // return getService().getChildrenDocuments(getServerTreeSessionId(), 076 // this); 077 return getPublisher().getChildrenDocuments(switchToServerNode(this)); 078 } 079 080 public List<PublicationNode> getChildrenNodes() { 081 return switchToClientNodes((getPublisher().getChildrenNodes(switchToServerNode(this)))); 082 } 083 084 public PublicationNode getParent() { 085 return switchToClientNode(getPublisher().getParent(switchToServerNode(this))); 086 } 087 088}