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.marshaling.basic;
021
022import org.nuxeo.common.utils.Path;
023import org.nuxeo.ecm.core.api.NuxeoException;
024import org.nuxeo.ecm.platform.publisher.api.PublicationNode;
025import org.nuxeo.ecm.platform.publisher.api.PublishedDocument;
026
027import java.util.List;
028
029/**
030 * Java implementation for the marshaled {@link PublicationNode}.
031 *
032 * @author tiry
033 */
034public class BasicPublicationNode implements PublicationNode {
035
036    private static final long serialVersionUID = 1L;
037
038    protected String nodeType;
039
040    protected String nodePath;
041
042    protected String nodeTitle;
043
044    protected String treeName;
045
046    protected String sid;
047
048    public BasicPublicationNode(String nodeType, String nodePath, String nodeTitle, String treeName) {
049        this(nodeType, nodePath, nodeTitle, treeName, null);
050    }
051
052    public BasicPublicationNode(String nodeType, String nodePath, String nodeTitle, String treeName, String sid) {
053        this.nodePath = nodePath;
054        this.nodeType = nodeType;
055        this.nodeTitle = nodeTitle;
056        this.treeName = treeName;
057        this.sid = sid;
058    }
059
060    public List<PublishedDocument> getChildrenDocuments() {
061        throw new NuxeoException("Can not be called on a remote node");
062    }
063
064    public List<PublicationNode> getChildrenNodes() {
065        throw new NuxeoException("Can not be called on a remote node");
066    }
067
068    public String getNodeType() {
069        return nodeType;
070    }
071
072    public PublicationNode getParent() {
073        return null;
074    }
075
076    public String getPath() {
077        return nodePath;
078    }
079
080    public String getTitle() {
081        return nodeTitle;
082    }
083
084    public String getName() {
085        if (nodePath == null) {
086            return null;
087        }
088        return new Path(nodePath).lastSegment();
089    }
090
091    public String getTreeConfigName() {
092        return treeName;
093    }
094
095    public String getSessionId() {
096        return sid;
097    }
098
099    public String getType() {
100        return this.getClass().getSimpleName();
101    }
102
103}