001/*
002 *  Copyright 2010 Anyware Services
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 */
016package org.ametys.plugins.repository.jcr;
017
018import java.util.Collection;
019
020import javax.jcr.Node;
021import javax.jcr.RepositoryException;
022import javax.jcr.Session;
023
024import org.ametys.plugins.repository.AmetysObject;
025import org.ametys.plugins.repository.AmetysObjectFactory;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027
028/**
029 * {@link AmetysObjectFactory} manipulating objects backed by concrete JCR nodes.
030 * @param <A> the actual type of {@link AmetysObject}s
031 */
032public interface JCRAmetysObjectFactory<A extends AmetysObject> extends AmetysObjectFactory<A>
033{
034    /**
035     * Retrieves an {@link AmetysObject} with the provided JCR Session, given its id.<br>
036     * Id are like <code>&lt;protocol&gt;://&lt;protocol-specific-part&gt;</code>.
037     * @param id the identifier.
038     * @param session the JCR Session to use to retrieve the {@link AmetysObject}.
039     * @return the corresponding {@link AmetysObject}.
040     * @throws AmetysRepositoryException if an error occurs.
041     * @throws RepositoryException if a JCR error occurs.
042     */
043    A getAmetysObjectById(String id, Session session) throws AmetysRepositoryException, RepositoryException;
044
045    /**
046     * Creates a {@link AmetysObject} from a persistent JCR node.
047     * @param node the JCR node to use.
048     * @param parentPath the parent Path in the Ametys hierarchy,
049     *        may be <code>null</code> if not known yet.
050     * @return the object.
051     * @throws AmetysRepositoryException if an error occurs.
052     * @throws RepositoryException if a JCR error occurs.
053     */
054    A getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException, RepositoryException;
055
056    /**
057     * Returns the nodetypes of the {@link Node} associated with this factory.
058     * @return the nodetypes of the {@link Node}.
059     */
060    Collection<String> getNodetypes();
061}