001/*
002 *  Copyright 2022 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.List;
019
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.commons.lang3.tuple.Pair;
022
023import org.ametys.runtime.model.type.ElementType;
024import org.ametys.runtime.parameter.Validator;
025
026/**
027 * Interface of the definition of a single model item (parameter, attribute)
028 * @param <T> Type of the element value
029 */
030public interface ElementDefinition<T> extends ModelItem
031{
032    /** config type for default values */
033    public static final String CONFIG_DEFAULT_VALUE_TYPE = "config";
034    
035    @Override
036    public ElementType<T> getType();
037    
038    /**
039     * Retrieves the enumerator.
040     * @return the enumerator or <code>null</code> if none is defined.
041     */
042    public Enumerator<T> getEnumerator();
043    
044    /**
045     * Set the enumerator.
046     * @param enumerator the enumerator.
047     */
048    public void setEnumerator(Enumerator<T> enumerator);
049    
050    /**
051     * Retrieves the custom enumerator's class name
052     * @return the custom enumerator's class name
053     */
054    public String getCustomEnumerator();
055    
056    /**
057     * Set the custom enumerator's class name
058     * @param customEnumerator the custom enumerator's class name
059     */
060    public void setCustomEnumerator(String customEnumerator);
061    
062    /**
063     * Retrieves the custom enumerator's configuration
064     * @return the custom enumerator's configuration
065     */
066    public Configuration getEnumeratorConfiguration();
067    
068    /**
069     * Set the custom enumerator's configuration
070     * @param enumeratorConfiguration the custom enumerator's configuration
071     */
072    public void setEnumeratorConfiguration(Configuration enumeratorConfiguration);
073    
074    /**
075     * Retrieves the validator.
076     * @return the validator or <code>null</code> if none is defined.
077     */
078    public Validator getValidator();
079    
080    /**
081     * Set the validator.
082     * @param validator the validator.
083     */
084    public void setValidator(Validator validator);
085    
086    /**
087     * Retrieves the custom validator's class name
088     * @return the custom validator's class name
089     */
090    public String getCustomValidator();
091    
092    /**
093     * Set the custom validator's class name
094     * @param customValidator the custom validator's class name
095     */
096    public void setCustomValidator(String customValidator);
097    
098    /**
099     * Retrieves the custom validator's configuraiton
100     * @return the custom validator's configuration
101     */
102    public Configuration getValidatorConfiguration();
103    
104    /**
105     * Set the custom validator's configuration
106     * @param validatorConfiguration the custom validator's configuration
107     */
108    public void setValidatorConfiguration(Configuration validatorConfiguration);
109    
110    /**
111     * Retrieves the default value, as an object corresponding to the definition's type and cardinality
112     * Retrieves <code>null</code> if no default value is defined for this definition
113     * @param <X> The type of the default value
114     * @return the default value.
115     */
116    public <X> X getDefaultValue();
117    
118    /**
119     * Set the parsed default values.
120     * If the definition is not multiple, the list should contain only one element
121     * A parsed default value is described by its type and an object depending on the type 
122     * @param parsedDefaultValues the parsed default values.
123     */
124    public void setParsedDefaultValues(List<Pair<String, Object>> parsedDefaultValues);
125    
126    /**
127     * Set a default value to the definition
128     * The default value is single, classic default value
129     * @param defaultValue the default value to set
130     */
131    public void setDefaultValue(T defaultValue);
132    
133    /**
134     * Retrieves the parsed default values
135     * @return the parsed default values
136     */
137    public List<Pair<String, Object>> getParsedDefaultValues();
138    
139    /**
140     * Test if the element is multiple.
141     * @return <code>true</code> if the metadata is multiple.
142     */
143    public boolean isMultiple();
144    
145    /**
146     * Set the element multiple status.
147     * @param isMultiple the element multiple status.
148     */
149    public void setMultiple(boolean isMultiple);
150    
151    /**
152     * Determines if the definition is editable, i.e. if it can be part of a view used for edition
153     * @return <code>true</code> if the definition is editable, <code>false</code> otherwise
154     */
155    public default boolean isEditable()
156    {
157        // A definition is modifable by default
158        return true;
159    }
160}