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