Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 8df9ab1 | 2009-07-24 17:06:37 +0000 | [diff] [blame] | 2 | * Copyright (c) OSGi Alliance (2004, 2008). All Rights Reserved. |
Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 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 info.dmtree; |
| 17 | |
| 18 | /** |
Richard S. Hall | 8df9ab1 | 2009-07-24 17:06:37 +0000 | [diff] [blame] | 19 | * The MetaNode contains meta data as standardized by OMA DM but extends it |
| 20 | * (without breaking the compatibility) to provide for better DMT data quality |
Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 21 | * in an environment where many software components manipulate this data. |
| 22 | * <p> |
| 23 | * The interface has several types of functions to describe the nodes in the |
| 24 | * DMT. Some methods can be used to retrieve standard OMA DM metadata such as |
| 25 | * access type, cardinality, default, etc., others are for data extensions such |
| 26 | * as valid names and values. In some cases the standard behaviour has been |
| 27 | * extended, for example it is possible to provide several valid MIME types, or |
| 28 | * to differentiate between normal and automatic dynamic nodes. |
| 29 | * <p> |
| 30 | * Most methods in this interface receive no input, just return information |
| 31 | * about some aspect of the node. However, there are two methods that behave |
Richard S. Hall | 8df9ab1 | 2009-07-24 17:06:37 +0000 | [diff] [blame] | 32 | * differently, {@link #isValidName} and {@link #isValidValue}. These validation |
| 33 | * methods are given a potential node name or value (respectively), and can |
| 34 | * decide whether it is valid for the given node. Passing the validation methods |
| 35 | * is a necessary condition for a name or value to be used, but it is not |
| 36 | * necessarily sufficient: the plugin may carry out more thorough (more |
Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 37 | * expensive) checks when the node is actually created or set. |
| 38 | * <p> |
Richard S. Hall | 8df9ab1 | 2009-07-24 17:06:37 +0000 | [diff] [blame] | 39 | * If a <code>MetaNode</code> is available for a node, the DmtAdmin must use the |
| 40 | * information provided by it to filter out invalid requests on that node. |
Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 41 | * However, not all methods on this interface are actually used for this |
| 42 | * purpose, as many of them (e.g. {@link #getFormat} or {@link #getValidNames}) |
| 43 | * can be substituted with the validating methods. For example, |
| 44 | * {@link #isValidValue} can be expected to check the format, minimum, maximum, |
| 45 | * etc. of a given value, making it unnecessary for the DmtAdmin to call |
| 46 | * {@link #getFormat()}, {@link #getMin()}, {@link #getMax()} etc. separately. |
| 47 | * It is indicated in the description of each method if the DmtAdmin does not |
| 48 | * enforce the constraints defined by it - such methods are only for external |
| 49 | * use, for example in user interfaces. |
| 50 | * <p> |
Richard S. Hall | 8df9ab1 | 2009-07-24 17:06:37 +0000 | [diff] [blame] | 51 | * Most of the methods of this class return <code>null</code> if a certain piece |
| 52 | * of meta information is not defined for the node or providing this information |
| 53 | * is not supported. Methods of this class do not throw exceptions. |
| 54 | * |
| 55 | * @version $Revision: 5673 $ |
Christian van Spaandonk | 6381441 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 56 | */ |
| 57 | public interface MetaNode { |
| 58 | |
| 59 | /** |
| 60 | * Constant for the ADD access type. If {@link #can(int)} returns |
| 61 | * <code>true</code> for this operation, this node can potentially be |
| 62 | * added to its parent. Nodes with {@link #PERMANENT} or {@link #AUTOMATIC} |
| 63 | * scope typically do not have this access type. |
| 64 | */ |
| 65 | int CMD_ADD = 0; |
| 66 | |
| 67 | /** |
| 68 | * Constant for the DELETE access type. If {@link #can(int)} returns |
| 69 | * <code>true</code> for this operation, the node can potentially be |
| 70 | * deleted. |
| 71 | */ |
| 72 | int CMD_DELETE = 1; |
| 73 | |
| 74 | /** |
| 75 | * Constant for the EXECUTE access type. If {@link #can(int)} returns |
| 76 | * <code>true</code> for this operation, the node can potentially be |
| 77 | * executed. |
| 78 | */ |
| 79 | int CMD_EXECUTE = 2; |
| 80 | |
| 81 | /** |
| 82 | * Constant for the REPLACE access type. If {@link #can(int)} returns |
| 83 | * <code>true</code> for this operation, the value and other properties of |
| 84 | * the node can potentially be modified. |
| 85 | */ |
| 86 | int CMD_REPLACE = 3; |
| 87 | |
| 88 | /** |
| 89 | * Constant for the GET access type. If {@link #can(int)} returns |
| 90 | * <code>true</code> for this operation, the value, the list of child nodes |
| 91 | * (in case of interior nodes) and the properties of the node can |
| 92 | * potentially be retrieved. |
| 93 | */ |
| 94 | int CMD_GET = 4; |
| 95 | |
| 96 | /** |
| 97 | * Constant for representing a permanent node in the tree. This must be |
| 98 | * returned by {@link #getScope} if the node cannot be added, deleted or |
| 99 | * modified in any way through tree operations. Permanent nodes cannot have |
| 100 | * non-permanent nodes as parents. |
| 101 | */ |
| 102 | int PERMANENT = 0; |
| 103 | |
| 104 | /** |
| 105 | * Constant for representing a dynamic node in the tree. This must be |
| 106 | * returned by {@link #getScope} for all nodes that are not permanent and |
| 107 | * are not created automatically by the management object. |
| 108 | */ |
| 109 | int DYNAMIC = 1; |
| 110 | |
| 111 | /** |
| 112 | * Constant for representing an automatic node in the tree. This must be |
| 113 | * returned by {@link #getScope()} for all nodes that are created |
| 114 | * automatically by the management object. Automatic nodes represent a |
| 115 | * special case of dynamic nodes, so this scope should be mapped to |
| 116 | * {@link #DYNAMIC} when used in an OMA DM context. |
| 117 | * <p> |
| 118 | * An automatic node is usually created instantly when its parent is |
| 119 | * created, but it is also valid if it only appears later, triggered by some |
| 120 | * other condition. The exact behaviour must be defined by the Management |
| 121 | * Object. |
| 122 | */ |
| 123 | int AUTOMATIC = 2; |
| 124 | |
| 125 | /** |
| 126 | * Check whether the given operation is valid for this node. If no meta-data |
| 127 | * is provided for a node, all operations are valid. |
| 128 | * |
| 129 | * @param operation One of the <code>MetaNode.CMD_...</code> constants. |
| 130 | * @return <code>false</code> if the operation is not valid for this node |
| 131 | * or the operation code is not one of the allowed constants |
| 132 | */ |
| 133 | boolean can(int operation); |
| 134 | |
| 135 | /** |
| 136 | * Check whether the node is a leaf node or an internal one. |
| 137 | * |
| 138 | * @return <code>true</code> if the node is a leaf node |
| 139 | */ |
| 140 | boolean isLeaf(); |
| 141 | |
| 142 | /** |
| 143 | * Return the scope of the node. Valid values are |
| 144 | * {@link #PERMANENT MetaNode.PERMANENT}, {@link #DYNAMIC MetaNode.DYNAMIC} |
| 145 | * and {@link #AUTOMATIC MetaNode.AUTOMATIC}. Note that a permanent node is |
| 146 | * not the same as a node where the DELETE operation is not allowed. |
| 147 | * Permanent nodes never can be deleted, whereas a non-deletable node can |
| 148 | * disappear in a recursive DELETE operation issued on one of its parents. |
| 149 | * If no meta-data is provided for a node, it can be assumed to be a dynamic |
| 150 | * node. |
| 151 | * |
| 152 | * @return {@link #PERMANENT} for permanent nodes, {@link #AUTOMATIC} for |
| 153 | * nodes that are automatically created, and {@link #DYNAMIC} |
| 154 | * otherwise |
| 155 | */ |
| 156 | int getScope(); |
| 157 | |
| 158 | /** |
| 159 | * Get the explanation string associated with this node. Can be |
| 160 | * <code>null</code> if no description is provided for this node. |
| 161 | * |
| 162 | * @return node description string or <code>null</code> for no description |
| 163 | */ |
| 164 | String getDescription(); |
| 165 | |
| 166 | /** |
| 167 | * Get the number of maximum occurrences of this type of nodes on the same |
| 168 | * level in the DMT. Returns <code>Integer.MAX_VALUE</code> if there is no |
| 169 | * upper limit. Note that if the occurrence is greater than 1 then this node |
| 170 | * can not have siblings with different metadata. In other words, if |
| 171 | * different types of nodes coexist on the same level, their occurrence can |
| 172 | * not be greater than 1. If no meta-data is provided for a node, there is |
| 173 | * no upper limit on the number of occurrences. |
| 174 | * |
| 175 | * @return The maximum allowed occurrence of this node type |
| 176 | */ |
| 177 | int getMaxOccurrence(); |
| 178 | |
| 179 | /** |
| 180 | * Check whether zero occurrence of this node is valid. If no meta-data is |
| 181 | * returned for a node, zero occurrences are allowed. |
| 182 | * |
| 183 | * @return <code>true</code> if zero occurrence of this node is valid |
| 184 | */ |
| 185 | boolean isZeroOccurrenceAllowed(); |
| 186 | |
| 187 | /** |
| 188 | * Get the default value of this node if any. |
| 189 | * |
| 190 | * @return The default value or <code>null</code> if not defined |
| 191 | */ |
| 192 | DmtData getDefault(); |
| 193 | |
| 194 | /** |
| 195 | * Get the list of MIME types this node can hold. The first element of the |
| 196 | * returned list must be the default MIME type. |
| 197 | * <p> |
| 198 | * All MIME types are considered valid if no meta-data is provided for a |
| 199 | * node or if <code>null</code> is returned by this method. In this case |
| 200 | * the default MIME type cannot be retrieved from the meta-data, but the |
| 201 | * node may still have a default. This hidden default (if it exists) can be |
| 202 | * utilized by passing <code>null</code> as the type parameter of |
| 203 | * {@link DmtSession#setNodeType(String, String)} or |
| 204 | * {@link DmtSession#createLeafNode(String, DmtData, String)}. |
| 205 | * |
| 206 | * @return the list of allowed MIME types for this node, starting with the |
| 207 | * default MIME type, or <code>null</code> if all types are |
| 208 | * allowed |
| 209 | */ |
| 210 | String[] getMimeTypes(); |
| 211 | |
| 212 | /** |
| 213 | * Get the maximum allowed value associated with a node of numeric format. |
| 214 | * If no meta-data is provided for a node, there is no upper limit to its |
| 215 | * value. This method is only meaningful if the node has integer or float |
| 216 | * format. The returned limit has <code>double</code> type, as this can be |
| 217 | * used to denote both integer and float limits with full precision. The |
| 218 | * actual maximum should be the largest integer or float number that does |
| 219 | * not exceed the returned value. |
| 220 | * <p> |
| 221 | * The information returned by this method is not checked by DmtAdmin, it |
| 222 | * is only for external use, for example in user interfaces. DmtAdmin only |
| 223 | * calls {@link #isValidValue} for checking the value, its behaviour should |
| 224 | * be consistent with this method. |
| 225 | * |
| 226 | * @return the allowed maximum, or <code>Double.MAX_VALUE</code> if there |
| 227 | * is no upper limit defined or the node's format is not integer or |
| 228 | * float |
| 229 | */ |
| 230 | double getMax(); |
| 231 | |
| 232 | /** |
| 233 | * Get the minimum allowed value associated with a node of numeric format. |
| 234 | * If no meta-data is provided for a node, there is no lower limit to its |
| 235 | * value. This method is only meaningful if the node has integer or float |
| 236 | * format. The returned limit has <code>double</code> type, as this can be |
| 237 | * used to denote both integer and float limits with full precision. The |
| 238 | * actual minimum should be the smallest integer or float number that is |
| 239 | * larger than the returned value. |
| 240 | * <p> |
| 241 | * The information returned by this method is not checked by DmtAdmin, it |
| 242 | * is only for external use, for example in user interfaces. DmtAdmin only |
| 243 | * calls {@link #isValidValue} for checking the value, its behaviour should |
| 244 | * be consistent with this method. |
| 245 | * |
| 246 | * @return the allowed minimum, or <code>Double.MIN_VALUE</code> if there |
| 247 | * is no lower limit defined or the node's format is not integer or |
| 248 | * float |
| 249 | */ |
| 250 | double getMin(); |
| 251 | |
| 252 | /** |
| 253 | * Return an array of DmtData objects if valid values are defined for the |
| 254 | * node, or <code>null</code> otherwise. If no meta-data is provided for a |
| 255 | * node, all values are considered valid. |
| 256 | * <p> |
| 257 | * The information returned by this method is not checked by DmtAdmin, it |
| 258 | * is only for external use, for example in user interfaces. DmtAdmin only |
| 259 | * calls {@link #isValidValue} for checking the value, its behaviour should |
| 260 | * be consistent with this method. |
| 261 | * |
| 262 | * @return the valid values for this node, or <code>null</code> if not |
| 263 | * defined |
| 264 | */ |
| 265 | DmtData[] getValidValues(); |
| 266 | |
| 267 | /** |
| 268 | * Get the node's format, expressed in terms of type constants defined in |
| 269 | * {@link DmtData}. If there are multiple formats allowed for the node then |
| 270 | * the format constants are OR-ed. Interior nodes must have |
| 271 | * {@link DmtData#FORMAT_NODE} format, and this code must not be returned |
| 272 | * for leaf nodes. If no meta-data is provided for a node, all applicable |
| 273 | * formats are considered valid (with the above constraints regarding |
| 274 | * interior and leaf nodes). |
| 275 | * <p> |
| 276 | * Note that the 'format' term is a legacy from OMA DM, it is more customary |
| 277 | * to think of this as 'type'. |
| 278 | * <p> |
| 279 | * The formats returned by this method are not checked by DmtAdmin, they |
| 280 | * are only for external use, for example in user interfaces. DmtAdmin only |
| 281 | * calls {@link #isValidValue} for checking the value, its behaviour should |
| 282 | * be consistent with this method. |
| 283 | * |
| 284 | * @return the allowed format(s) of the node |
| 285 | */ |
| 286 | int getFormat(); |
| 287 | |
| 288 | /** |
| 289 | * Get the format names for any raw formats supported by the node. This |
| 290 | * method is only meaningful if the list of supported formats returned by |
| 291 | * {@link #getFormat()} contains {@link DmtData#FORMAT_RAW_STRING} or |
| 292 | * {@link DmtData#FORMAT_RAW_BINARY}: it specifies precisely which raw |
| 293 | * format(s) are actually supported. If the node cannot contain data in one |
| 294 | * of the raw types, this method must return <code>null</code>. |
| 295 | * <p> |
| 296 | * The format names returned by this method are not checked by DmtAdmin, |
| 297 | * they are only for external use, for example in user interfaces. DmtAdmin |
| 298 | * only calls {@link #isValidValue} for checking the value, its behaviour |
| 299 | * should be consistent with this method. |
| 300 | * |
| 301 | * @return the allowed format name(s) of raw data stored by the node, or |
| 302 | * <code>null</code> if raw formats are not supported |
| 303 | */ |
| 304 | String[] getRawFormatNames(); |
| 305 | |
| 306 | /** |
| 307 | * Checks whether the given value is valid for this node. This method can be |
| 308 | * used to ensure that the value has the correct format and range, that it |
| 309 | * is well formed, etc. This method should be consistent with the |
| 310 | * constraints defined by the {@link #getFormat}, {@link #getValidValues}, |
| 311 | * {@link #getMin} and {@link #getMax} methods (if applicable), as the Dmt |
| 312 | * Admin only calls this method for value validation. |
| 313 | * <p> |
| 314 | * This method may return <code>true</code> even if not all aspects of the |
| 315 | * value have been checked, expensive operations (for example those that |
| 316 | * require external resources) need not be performed here. The actual value |
| 317 | * setting method may still indicate that the value is invalid. |
| 318 | * |
| 319 | * @param value the value to check for validity |
| 320 | * @return <code>false</code> if the specified value is found to be |
| 321 | * invalid for the node described by this meta-node, |
| 322 | * <code>true</code> otherwise |
| 323 | */ |
| 324 | boolean isValidValue(DmtData value); |
| 325 | |
| 326 | /** |
| 327 | * Return an array of Strings if valid names are defined for the node, or |
| 328 | * <code>null</code> if no valid name list is defined or if this piece of |
| 329 | * meta info is not supported. If no meta-data is provided for a node, all |
| 330 | * names are considered valid. |
| 331 | * <p> |
| 332 | * The information returned by this method is not checked by DmtAdmin, it |
| 333 | * is only for external use, for example in user interfaces. DmtAdmin only |
| 334 | * calls {@link #isValidName} for checking the name, its behaviour should be |
| 335 | * consistent with this method. |
| 336 | * |
| 337 | * @return the valid values for this node name, or <code>null</code> if |
| 338 | * not defined |
| 339 | */ |
| 340 | String[] getValidNames(); |
| 341 | |
| 342 | /** |
| 343 | * Checks whether the given name is a valid name for this node. This method |
| 344 | * can be used for example to ensure that the node name is always one of a |
| 345 | * predefined set of valid names, or that it matches a specific pattern. |
| 346 | * This method should be consistent with the values returned by |
| 347 | * {@link #getValidNames} (if any), the DmtAdmin only calls this method for |
| 348 | * name validation. |
| 349 | * <p> |
| 350 | * This method may return <code>true</code> even if not all aspects of the |
| 351 | * name have been checked, expensive operations (for example those that |
| 352 | * require external resources) need not be performed here. The actual node |
| 353 | * creation may still indicate that the node name is invalid. |
| 354 | * |
| 355 | * @param name the node name to check for validity |
| 356 | * @return <code>false</code> if the specified name is found to be invalid |
| 357 | * for the node described by this meta-node, <code>true</code> |
| 358 | * otherwise |
| 359 | */ |
| 360 | boolean isValidName(String name); |
| 361 | |
| 362 | /** |
| 363 | * Returns the list of extension property keys, if the provider of this |
| 364 | * <code>MetaNode</code> provides proprietary extensions to node meta |
| 365 | * data. The method returns <code>null</code> if the node doesn't provide |
| 366 | * such extensions. |
| 367 | * |
| 368 | * @return the array of supported extension property keys |
| 369 | */ |
| 370 | String[] getExtensionPropertyKeys(); |
| 371 | |
| 372 | /** |
| 373 | * Returns the value for the specified extension property key. This method |
| 374 | * only works if the provider of this <code>MetaNode</code> provides |
| 375 | * proprietary extensions to node meta data. |
| 376 | * |
| 377 | * @param key the key for the extension property |
| 378 | * @return the value of the requested property, cannot be <code>null</code> |
| 379 | * @throws IllegalArgumentException if the specified key is not supported by |
| 380 | * this <code>MetaNode</code> |
| 381 | */ |
| 382 | Object getExtensionProperty(String key); |
| 383 | } |