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