001/* 002 * (C) Copyright 2007 Nuxeo SAS (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 - initial API and implementation 016 * 017 * $Id: ResourceAdapter.java 22854 2007-07-22 21:10:27Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.relations.api; 021 022import java.io.Serializable; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.CoreSession; 026import org.nuxeo.ecm.core.api.DocumentModel; 027 028/** 029 * Adapter to transform any java {@link Serializable} into a qualified name resource and conversely. 030 * 031 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 032 */ 033public interface ResourceAdapter { 034 035 String CORE_SESSION_CONTEXT_KEY = "CoreSession"; 036 037 String getNamespace(); 038 039 void setNamespace(String namespace); 040 041 /** 042 * Transforms an incoming object into a Resource. 043 * 044 * @since 5.2-M1 045 * @param object the object to transform 046 * @param context a context map 047 * @return the resource 048 */ 049 Resource getResource(Serializable object, Map<String, Object> context); 050 051 /** 052 * Resolves the resource to an applicative representation, for instance a {@link DocumentModel}. 053 * 054 * @param resource 055 * @param context a context map (holding for instance a {@link CoreSession} instance. 056 * @return the representation 057 */ 058 Serializable getResourceRepresentation(Resource resource, Map<String, Object> context); 059 060 /** 061 * @return the class being adapted 062 */ 063 Class<?> getKlass(); 064 065}