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