001/*
002 *  Copyright 2018 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.runtime.model;
017
018import java.util.Map;
019
020import org.apache.cocoon.ProcessingException;
021import org.xml.sax.ContentHandler;
022import org.xml.sax.SAXException;
023
024import org.ametys.runtime.util.ModifiableLabelable;
025
026/**
027 * Interface for view items
028 */
029public interface ViewItem extends ModifiableLabelable
030{
031    /**
032     * Create an instance of {@link ViewItem}
033     * @return the created instance
034     */
035    public ViewItem createInstance();
036    
037    /**
038     * Retrieves the parent of the view item
039     * @return the parent group
040     */
041    public ViewItemAccessor getParent();
042
043    /**
044     * Sets the parent of the view item
045     * @param parent the parent to set
046     */
047    public void setParent(ViewItemAccessor parent);
048
049    /**
050     * Converts the view item in a JSON map
051     * @param context the context of the definitions referenced in this view item and/or its children
052     * @return The view item as a JSON map
053     * @throws ProcessingException If an error occurs when converting the view item
054     */
055    public Map<String, Object> toJSON(DefinitionContext context) throws ProcessingException;
056    
057    /**
058     * Generates SAX events for the view item
059     * @param contentHandler the {@link ContentHandler} that will receive the SAX events 
060     * @param context the context of the definitions included in the view item
061     * @throws SAXException if an error occurs during the SAX events generation
062     */
063    public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException;
064    
065    /**
066     * Copy the current view item in the given one.
067     * If the view item is an accessor, its view items are copied only if they are not already present in the reference {@link ViewItemAccessor}
068     * @param item the copy
069     * @param referenceViewItemAccessor the reference {@link ViewItemAccessor}
070     * @param itemPath the path of the view item relative to the reference {@link ViewItemAccessor}
071     */
072    public default void copyTo(ViewItem item, ViewItemAccessor referenceViewItemAccessor, String itemPath)
073    {
074        copyTo(item);
075    }
076    
077    /**
078     * Copy the current view item in the given one.
079     * If the view item is an accessor, its view items are not copied
080     * @param item the copy
081     */
082    public void copyTo(ViewItem item);
083    
084    /**
085     * Indicates whether some other object is "equal to" this one.
086     * @param obj the reference object with which to compare.
087     * @param checkDetails <code>true</code> to check the view item's details during comparison (label, description, ...)
088     * @return <code>true</code> if this object is the same as the given obj, <code>false</code> otherwise.
089     */
090    public boolean equals(Object obj, boolean checkDetails);
091}