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;
019import java.util.Set;
020
021import org.apache.avalon.framework.configuration.Configuration;
022import org.apache.cocoon.ProcessingException;
023import org.xml.sax.ContentHandler;
024import org.xml.sax.SAXException;
025
026import org.ametys.runtime.config.DisableConditions;
027import org.ametys.runtime.i18n.I18nizableText;
028import org.ametys.runtime.model.checker.ItemCheckerDescriptor;
029import org.ametys.runtime.model.type.ModelItemType;
030import org.ametys.runtime.util.ModifiableLabelable;
031
032/**
033 * Interface for model items
034 */
035public interface ModelItem extends ModifiableLabelable, Comparable<ModelItem>
036{
037    /** Separator used for item paths in definitions */
038    public static final String ITEM_PATH_SEPARATOR = "/";
039    
040    /**
041     * Returns the {@link ItemCheckerDescriptor}s associated with this group.
042     * @return the {@link ItemCheckerDescriptor}s associated with this group.
043     */
044    public Set<ItemCheckerDescriptor> getItemCheckers();
045    
046    /**
047     * Add an item checker to the group
048     * @param itemChecker the item checker to add
049     */
050    public void addItemChecker(ItemCheckerDescriptor itemChecker);
051
052    /**
053     * Retrieves the path of the model item
054     * @return the item path
055     */
056    public String getPath();
057
058    /**
059     * Retrieves the model of the item
060     * @return the model
061     */
062    public Model getModel();
063    
064    /**
065     * Sets the model of the element
066     * @param model the model to set
067     */
068    public void setModel(Model model);
069    
070    /**
071     * Retrieves the parent of the item
072     * @return the parent group
073     */
074    public ModelItemGroup getParent();
075
076    /**
077     * Sets the parent of the item
078     * @param parent the parent to set
079     */
080    public void setParent(ModelItemGroup parent);
081    
082    /**
083     * Converts the model item in a JSON map
084     * @param context the context of the definition
085     * @return The model item as a JSON map, or an empty map
086     * @throws ProcessingException If an error occurs when converting the model item
087     */
088    public Map<String, Object> toJSON(DefinitionContext context) throws ProcessingException;
089    
090    /**
091     * Generates SAX events for the model item
092     * @param contentHandler the {@link ContentHandler} that will receive the SAX events 
093     * @param context the context of the definition
094     * @throws SAXException if an error occurs during the SAX events generation
095     */
096    public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException;
097    
098    /**
099     * Retrieves the type.
100     * @return the type.
101     */
102    public ModelItemType getType();
103    
104    /**
105     * Set the type.
106     * @param type the type.
107     */
108    public void setType(ModelItemType type);
109    
110    /**
111     * Retrieves the name of the plugin declaring this element.
112     * @return the plugin name.
113     */
114    public String getPluginName();
115
116    /**
117     * Set the name of the plugin declaring this element.
118     * @param pluginName the plugin name.
119     */
120    public void setPluginName(String pluginName);
121    
122
123    /**
124     * Retrieves the widget to use for rendering.
125     * @return the widget or <code>null</code> if none is defined.
126     */
127    public String getWidget();
128
129    /**
130     * Set the widget.
131     * @param widget the widget.
132     */
133    public void setWidget(String widget);
134    
135    /**
136     * Get the default widget to use when rendering this item as a criterion.
137     * @return The default widget to use, or <code>null</code> if no specific widget is necessary.
138     */
139    public default String getCriterionWidget()
140    {
141        return getWidget();
142    }
143    
144    /**
145     * Get the widget's parameters
146     * @return the widget's parameters
147     */
148    public Map<String, I18nizableText> getWidgetParameters();
149    
150    /**
151     * Set the widget's parameters
152     * @param params the parameters to set
153     */
154    public void setWidgetParameters (Map<String, I18nizableText> params);
155    
156    /**
157     * Get the widget parameters to use when rendering this item as a criterion.
158     * @param configuration The widget parameters configuration
159     * @return The default widget parameters to use, or an empty Map if no specific widget parameters are necessary.
160     */
161    public default Map<String, I18nizableText> getCriterionWidgetParameters(Configuration configuration)
162    {
163        return getWidgetParameters();
164    }
165    
166    /**
167     * Retrieves the disable condition.
168     * @return the disable condition or <code>null</code> if none is defined.
169     */
170    public DisableConditions getDisableConditions();
171
172    /**
173     * Sets the disable condition.
174     * @param disableConditions the disable condition.
175     */
176    public void setDisableConditions(DisableConditions disableConditions);    
177}