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