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.virtual;
017
018import org.ametys.plugins.repository.AmetysObject;
019import org.ametys.plugins.repository.AmetysObjectFactory;
020import org.ametys.plugins.repository.AmetysObjectIterable;
021import org.ametys.plugins.repository.TraversableAmetysObject;
022import org.ametys.plugins.repository.jcr.JCRAmetysObject;
023
024/**
025 * {@link AmetysObjectFactory} for handling "virtual" objects, in that they did
026 * not rely directly to the JCR storage.<br>
027 * Such factory is bounded to an object through a particular property in the JCR tree.<br>
028 * Virtual {@link AmetysObject} handled by a {@link VirtualAmetysObjectFactory} are considered as children of the {@link JCRAmetysObject} corresponding to the JCR Node holding that property.
029 * @param <A> the actual type of {@link AmetysObject}s
030 */
031public interface VirtualAmetysObjectFactory<A extends AmetysObject> extends AmetysObjectFactory<A>
032{
033    /**
034     * Returns the "root" objects of this virtual factory, hosted in the Ametys
035     * hierarchy under a {@link TraversableAmetysObject}, which is backed by a
036     * concrete JCR Node.
037     * @param parent the {@link JCRAmetysObject} "hosting" this factory.
038     * @return the root objects of this virtual factory.
039     */
040    AmetysObjectIterable<A> getChildren(JCRAmetysObject parent);
041    
042    /**
043     * Returns a named {@link AmetysObject}.
044     * @param parent the {@link JCRAmetysObject} "hosting" this factory.
045     * @param childName the name of the virtual child.
046     * @return the corresponding {@link AmetysObject}.
047     */
048    A getChild(JCRAmetysObject parent, String childName);
049    
050    /**
051     * Returns true if the named {@link AmetysObject} exists.
052     * @param parent the {@link JCRAmetysObject} "hosting" this factory.
053     * @param childName the name of the virtual child.
054     * @return true if the named {@link AmetysObject} exists.
055     */
056    boolean hasChild(JCRAmetysObject parent, String childName);
057}