001/* ***** BEGIN LICENSE BLOCK *****
002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003 *
004 * The contents of this file are subject to the Mozilla Public License Version
005 * 1.1 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 * http://www.mozilla.org/MPL/
008 *
009 * Software distributed under the License is distributed on an "AS IS" basis,
010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011 * for the specific language governing rights and limitations under the
012 * License.
013 *
014 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in
015 * Java(TM), hosted at https://github.com/gunterze/dcm4che.
016 *
017 * The Initial Developer of the Original Code is
018 * Agfa Healthcare.
019 * Portions created by the Initial Developer are Copyright (C) 2014
020 * the Initial Developer. All Rights Reserved.
021 *
022 * Contributor(s):
023 * See @authors listed below
024 *
025 * Alternatively, the contents of this file may be used under the terms of
026 * either the GNU General Public License Version 2 or later (the "GPL"), or
027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
028 * in which case the provisions of the GPL or the LGPL are applicable instead
029 * of those above. If you wish to allow use of your version of this file only
030 * under the terms of either the GPL or the LGPL, and not to allow others to
031 * use your version of this file under the terms of the MPL, indicate your
032 * decision by deleting the provisions above and replace them with the notice
033 * and other provisions required by the GPL or the LGPL. If you do not delete
034 * the provisions above, a recipient may use your version of this file under
035 * the terms of any one of the MPL, the GPL or the LGPL.
036 *
037 * ***** END LICENSE BLOCK ***** */
038package org.dcm4che3.conf.core.api;
039
040import java.lang.annotation.ElementType;
041import java.lang.annotation.Retention;
042import java.lang.annotation.RetentionPolicy;
043import java.lang.annotation.Target;
044
045/**
046 * Marks a field of a configuration class to be a persistable configuration property of the bean
047 *
048 * @author Roman K
049 */
050@Retention(RetentionPolicy.RUNTIME)
051@Target(ElementType.FIELD)
052public @interface ConfigurableProperty {
053
054    enum EnumRepresentation {
055        ORDINAL,
056        STRING
057    }
058
059    /**
060     * Name of the node. If not specified, the field/parameter name is used.
061     *
062     * @return
063     */
064    String name() default "";
065
066
067
068    /**
069     * Just a random string very unlikely to be equal to any user-specified default string (java does not allow to use null...)
070     */
071    String NO_DEFAULT_VALUE = " $#!@@#$@!#$%  Default-value-does-not-exist-for-this-property  $#!@@#$@!#$%";
072
073
074    /**
075     * Default for primitives (int, string, boolean, enum). If default is not specified, the property is considered required.
076     *
077     * @return
078     */
079    String defaultValue() default NO_DEFAULT_VALUE;
080
081    /**
082     * Is the property required to be set, i.e. must be non-null for objects, non-empty for Strings
083     *
084     * @return
085     */
086    boolean required() default false;
087
088    EnumRepresentation enumRepresentation() default EnumRepresentation.STRING;
089
090    enum ConfigurablePropertyType {
091        /**
092         * Basic property - default.
093         */
094        Basic,
095
096        /**
097         * Referenceable UUID
098         */
099        UUID,
100
101        /**
102         * Specifies that the annotated field/property is not stored as a child node, but
103         * as a reference to another node instead.
104         *
105         * <p>
106         *   <b>WARNING:</b>
107         *   Introducing references may lead to having circular reference chains.
108         *   This is allowed and properly handled by the framework.
109         *   However, one has to keep in mind, that due to the fact that circular references are allowed,
110         *   you might receive not fully initialized objects as arguments in setters for properties that are references.
111         *   Such objects will be populated later, but might have some (maybe all) fields uninitialized at the time the setter is called.
112         * </p>
113         */
114        Reference,
115
116        /**
117         * Same as {@link org.dcm4che3.conf.core.api.ConfigurableProperty.ConfigurablePropertyType#Reference}
118         * but applicable for Collections and Map values
119         */
120        CollectionOfReferences,
121
122        /**
123         * Enables the extension-by-composition mechanism of the framework for containing class and marks the property as an extension map.
124         * Only may be applied on fields with type Map&lt;Class<? extends T>, T&gt;.
125         * T will be treated as base extension class
126         *
127         */
128        ExtensionsProperty,
129
130
131        /**
132         * Marks the class as a root for the hash-based optimistic locking mechanism.
133         * This field will be auto-calculated on loading,
134         * and will be used to compare against the current state in the backend on persist to prevent conflicting changes.
135         * <p/>
136         * <p>There must be only single property of this type for a configurable class.</p>
137         */
138        OptimisticLockingHash
139
140    }
141
142    /**
143     * Defines special behavior for the property
144     */
145    ConfigurablePropertyType type() default ConfigurablePropertyType.Basic;
146
147    /**
148     * Only affects behavior for references.
149     * Indicates that the frameworks should not prevent removal of the target of this reference from the configuration.
150     * For a reference for which it was detected that the target does not exist anymore, the value gets automatically removed on occasion, i.e. will be set to 'null'
151     * @return
152     */
153    boolean weakReference() default false;
154
155    ///////////////////////////////////////////////////////////////////////////////////////////////
156    /// GUI ///////////////////////////////////////////////////////////////////////////////////////
157    ///////////////////////////////////////////////////////////////////////////////////////////////
158
159    /**
160     * Label to show in configuration UIs. If empty empty string (default), the name will be used.
161     *
162     * @return
163     */
164    String label() default "";
165
166    /**
167     * Description to show in configuration UIs.
168     *
169     * @return
170     */
171    String description() default "";
172
173    enum Tag {
174        /**
175         * Non-required properties could be put into a "advanced..." tab to simplify the view.
176         * This tag indicates that the property should never be hidden from the user with such technique.
177         */
178        PRIMARY;
179
180    }
181
182    /**
183     * Ordering of properties for GUI. The larger the number, the lower in the list the property will be displayed.
184     *
185     * @return
186     */
187    int order() default 0;
188
189    /**
190     * Name of the group in the GUI this property belongs to
191     */
192    String group() default "Other";
193
194    /**
195     * Additional info for the GUI
196     *
197     * @return
198     */
199    Tag[] tags() default {};
200
201    ///////////////////////////////////////////////////////////////////////////////////////////////
202    /// DEPRECATED ////////////////////////////////////////////////////////////////////////////////
203    ///////////////////////////////////////////////////////////////////////////////////////////////
204
205    @Deprecated
206    /**
207     * Use {@link ConfigurableProperty#type()} instead
208     */
209    boolean isReference() default false;
210
211    @Deprecated
212    /**
213     * Use {@link ConfigurableProperty#type()} instead
214     */
215    boolean collectionOfReferences() default false;
216
217
218    @Deprecated
219    /**
220     * Use {@link ConfigurableProperty#type()} instead
221     */
222    boolean isExtensionsProperty() default false;
223
224
225}