001/* 002 * (C) Copyright 2006-2011 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 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.opencmis.impl.client; 020 021import java.util.List; 022 023import org.apache.chemistry.opencmis.client.api.CmisObject; 024import org.apache.chemistry.opencmis.client.api.ObjectId; 025import org.apache.chemistry.opencmis.client.api.ObjectType; 026import org.apache.chemistry.opencmis.client.api.OperationContext; 027import org.apache.chemistry.opencmis.client.api.Relationship; 028import org.apache.chemistry.opencmis.client.api.RelationshipType; 029import org.apache.chemistry.opencmis.client.api.SecondaryType; 030import org.apache.chemistry.opencmis.commons.PropertyIds; 031import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoObjectData; 032 033/** 034 * Live local CMIS Relationship, which is backed by a Nuxeo document. 035 */ 036public class NuxeoRelationship extends NuxeoObject implements Relationship { 037 038 public NuxeoRelationship(NuxeoSession session, NuxeoObjectData data, ObjectType type, 039 List<SecondaryType> secondaryTypes) { 040 super(session, data, type, secondaryTypes); 041 } 042 043 @Override 044 public RelationshipType getRelationshipType() { 045 ObjectType objectType = getType(); 046 if (objectType instanceof RelationshipType) { 047 return (RelationshipType) objectType; 048 } else { 049 throw new ClassCastException("Object type is not a relationship type."); 050 } 051 } 052 053 @Override 054 public ObjectId getSourceId() { 055 String id = getPropertyValue(PropertyIds.SOURCE_ID); 056 return id == null ? null : session.createObjectId(id); 057 } 058 059 @Override 060 public CmisObject getSource() { 061 String id = getPropertyValue(PropertyIds.SOURCE_ID); 062 return id == null ? null : session.getObject(session.createObjectId(id)); 063 } 064 065 @Override 066 public CmisObject getSource(OperationContext context) { 067 String id = getPropertyValue(PropertyIds.SOURCE_ID); 068 return id == null ? null : session.getObject(session.createObjectId(id), context); 069 } 070 071 @Override 072 public ObjectId getTargetId() { 073 String id = getPropertyValue(PropertyIds.TARGET_ID); 074 return id == null ? null : session.createObjectId(id); 075 } 076 077 @Override 078 public CmisObject getTarget() { 079 String id = getPropertyValue(PropertyIds.TARGET_ID); 080 return id == null ? null : session.getObject(session.createObjectId(id)); 081 } 082 083 @Override 084 public CmisObject getTarget(OperationContext context) { 085 String id = getPropertyValue(PropertyIds.TARGET_ID); 086 return id == null ? null : session.getObject(session.createObjectId(id), context); 087 } 088 089}