1 /* 2 * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.properties.api.core.domain; 17 18 import java.io.Serializable; 19 import java.util.List; 20 import java.util.Locale; 21 22 import de.smartics.properties.api.core.annotations.AccessType; 23 import de.smartics.properties.api.core.annotations.PropertyDefinitionTime; 24 import de.smartics.properties.api.core.annotations.PropertyUse.UseType; 25 26 /** 27 * Defines property meta data. This information excludes the actual property 28 * value. It provides information such as name, type, default values and 29 * constraints on the property value. 30 */ 31 public interface PropertyDescriptor extends Serializable 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 // ****************************** Initializer ******************************* 38 39 // ****************************** Inner Classes ***************************** 40 41 // ********************************* Methods ******************************** 42 43 // --- get&set -------------------------------------------------------------- 44 45 /** 46 * Returns the context of the property descriptor. 47 * 48 * @return the context of the property descriptor. 49 */ 50 PropertyContext getContext(); 51 52 /** 53 * Returns the type that declares the property that is described by this 54 * instance. 55 * 56 * @return the declaring type of the property this instance is the descriptor 57 * for. 58 */ 59 Class<?> getDeclaringType(); 60 61 /** 62 * Returns the key of the property. 63 * <p> 64 * This value must not be <code>null</code>. 65 * </p> 66 * 67 * @return the name of the component the property belongs to. 68 */ 69 PropertyKey getKey(); 70 71 /** 72 * Returns the type of the property value. 73 * <p> 74 * This value must not be <code>null</code>. 75 * </p> 76 * <p> 77 * If there is no value range specified for the property type, the type is 78 * either required to specify a static fromString method or is a standard or 79 * registered type whose conversion rules are well known. 80 * </p> 81 * 82 * <pre> 83 * public static T fromString(String value); 84 * </pre> 85 * 86 * @return the type of the property value. 87 */ 88 PropertyType getType(); 89 90 /** 91 * Checks if the property is mandatory to be not <code>null</code>. If the 92 * property is not mandatory, it is optional. 93 * 94 * @return <code>true</code> if the property is mandatory to be not 95 * <code>null</code>, <code>false</code> otherwise. 96 */ 97 boolean isMandatory(); 98 99 /** 100 * Checks if the property is secured. 101 * 102 * @return <code>true</code> if the property is secured, <code>false</code> if 103 * is readable by anyone. 104 */ 105 boolean isSecured(); 106 107 /** 108 * Returns the flag to define the access type. 109 * 110 * @return the flag to define the access type. 111 */ 112 AccessType getAccessType(); 113 114 /** 115 * Checks whether or not the property is mutable at runtime. 116 * 117 * @return <code>true</code> if the property may be changed after startup, 118 * <code>false</code> if the property value is immutable (that is: 119 * stays the same) after startup. 120 * @see #getUpdateIntervalInMs() 121 */ 122 boolean isRuntimeMutable(); 123 124 /** 125 * Returns the update interval in milliseconds (ms). 126 * <p> 127 * An application may cache the value of the property for the given period of 128 * time. 129 * </p> 130 * 131 * <pre> 132 * {@table [nofill] 133 * || value | description || 134 * || < 0 | Property is not mutable. || 135 * || 0 | Property is read on each access. || 136 * || > 0 | Property is required to be read new after the given number 137 * of ms elapsed. In the meantime a previously read cached value 138 * is returned.|| 139 * } 140 * </pre> 141 * <p> 142 * The constants defined in 143 * {@link de.smartics.properties.api.core.annotations.PropertyLifecycle.UpdateInterval} 144 * provide constants to define intervals. 145 * </p> 146 * 147 * @return the update interval in milliseconds (ms). 148 */ 149 long getUpdateIntervalInMs(); 150 151 // TODO: Discussion: Maybe we should allow an expression here that would 152 // a) make the time more readable (e.g. "5min") 153 // b) allow to reference other properties (e.g. "${my.defaultTime}") 154 // The problem is that 155 // a) The syntax may be more confusing (e.g. "5 minutes" will not be parsed) 156 // and could be made more clear by Java constants. 157 // b) the name of the referenced property is given as a 158 // String. Refactoring the name property of the property in the interface will 159 // not affect the property name here. 160 161 /** 162 * The designed time the property is defined. 163 * <p> 164 * This value must not be <code>null</code>. 165 * </p> 166 * 167 * @return the designed time the property is defined. 168 */ 169 PropertyDefinitionTime getConfigurationTime(); 170 171 /** 172 * Returns the expression to use to construct the value of the property. An 173 * expression may reference another property or may serve as a template 174 * containing any number of property references. 175 * <p> 176 * Resolving fails if at least one property reference cannot be resolved. 177 * </p> 178 * {@example $ server}/path/${command}} 179 * 180 * @return the value of the expression. May be <code>null</code>. 181 */ 182 PropertyExpression getDefaultExpression(); 183 184 /** 185 * Returns the range of values allowed for this property. 186 * <p> 187 * The returned value may be <code>null</code> if there is no specific range 188 * of values the value of the property has to be part of. For instance a 189 * property may have no value range or only value ranges that are not 190 * enumerable. The latter may only be modeled by a property constraint. 191 * </p> 192 * 193 * @return the range for values allowed for this property. May be 194 * <code>null</code>. 195 */ 196 PropertyValueRange<?> getValueRange(); 197 198 /** 199 * Returns a list of constraints a value for the property has to meet. 200 * 201 * @return a list of constraints a value for the property has to meet. The 202 * list may be empty, but is never <code>null</code>. 203 */ 204 List<? extends PropertyConstraint<?>> getConstraints(); 205 206 /** 207 * Returns the name of the document that identifies the document uniquely 208 * within the context of the project. It is used to select the projectdoc 209 * document in the <code>META-INF</code> folder. 210 * 211 * @return the name of the document that identifies the document uniquely 212 * within the context of the project. 213 */ 214 DocumentName getDocumentName(); 215 216 /** 217 * Returns the meta data information for the property. 218 * <p> 219 * This value must not be <code>null</code>. 220 * </p> 221 * 222 * @return the meta data information for the property. 223 */ 224 PropertyProjectdoc getDocumentMetaData(); 225 226 /** 227 * Returns the meta data information for the property. 228 * <p> 229 * This value must not be <code>null</code>. 230 * </p> 231 * 232 * @param locale the locale to determine which bundle to use. 233 * @return the meta data information for the property. 234 */ 235 PropertyProjectdoc getDocumentMetaData(Locale locale); 236 237 /** 238 * Returns the meta data information for the property set. 239 * <p> 240 * This value must not be <code>null</code>. 241 * </p> 242 * 243 * @return the meta data information for the property set. 244 */ 245 PropertySetProjectdoc getDocumentMetaDataProjectSet(); 246 247 /** 248 * Returns the meta data information for the property set. 249 * <p> 250 * This value must not be <code>null</code>. 251 * </p> 252 * 253 * @param locale the locale to determine which bundle to use. 254 * @return the meta data information for the property set. 255 */ 256 PropertySetProjectdoc getDocumentMetaDataProjectSet(Locale locale); 257 258 /** 259 * Returns the comment to the property and its values. 260 * <p> 261 * This value must not be <code>null</code>. 262 * </p> 263 * 264 * @return the comment to the property and its values. 265 */ 266 PropertyComment getComment(); 267 268 /** 269 * Returns the comment to the property and its values. 270 * <p> 271 * This value must not be <code>null</code>. 272 * </p> 273 * 274 * @param locale the locale to determine which bundle to use. 275 * @return the comment to the property and its values. 276 */ 277 PropertyComment getComment(Locale locale); 278 279 /** 280 * Returns the categories this property is associated with. 281 * 282 * @return the categories this property is associated with. 283 */ 284 PropertyCategories getCategories(); 285 286 /** 287 * Returns the use type of the property. 288 * 289 * @return the use type of the property. 290 */ 291 UseType getUseType(); 292 293 // --- business ------------------------------------------------------------- 294 295 // --- object basics -------------------------------------------------------- 296 297 }