Christian van Spaandonk | 569a4c5 | 2008-08-02 09:56:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * $Header: /cvshome/build/info.dmtree/src/info/dmtree/DmtAdmin.java,v 1.9 2006/07/11 16:59:41 tszeredi Exp $ |
| 3 | * |
| 4 | * Copyright (c) OSGi Alliance (2004, 2006). All Rights Reserved. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | package info.dmtree; |
| 19 | |
| 20 | /** |
| 21 | * An interface providing methods to open sessions and register listeners. The |
| 22 | * implementation of <code>DmtAdmin</code> should register itself in the OSGi |
| 23 | * service registry as a service. <code>DmtAdmin</code> is the entry point for |
| 24 | * applications to use the DMT API. |
| 25 | * <p> |
| 26 | * The <code>getSession</code> methods are used to open a session on a |
| 27 | * specified subtree of the DMT. A typical way of usage: |
| 28 | * <pre> |
| 29 | * serviceRef = context.getServiceReference(DmtAdmin.class.getName()); |
| 30 | * DmtAdmin admin = (DmtAdmin) context.getService(serviceRef); |
| 31 | * DmtSession session = admin.getSession("./OSGi/Configuration"); |
| 32 | * session.createInteriorNode("./OSGi/Configuration/my.table"); |
| 33 | * </pre> |
| 34 | * <p> |
| 35 | * The methods for opening a session take a node URI (the session root) as a |
| 36 | * parameter. All segments of the given URI must be within the segment length |
| 37 | * limit of the implementation, and the special characters '/' and '\' must be |
| 38 | * escaped (preceded by a '\'). Any string can be converted to a valid URI |
| 39 | * segment using the {@link Uri#mangle(String)} method. |
| 40 | * <p> |
| 41 | * It is possible to specify a lock mode when opening the session (see lock type |
| 42 | * constants in {@link DmtSession}). This determines whether the session can |
| 43 | * run in parallel with other sessions, and the kinds of operations that can be |
| 44 | * performed in the session. All Management Objects constituting the device |
| 45 | * management tree must support read operations on their nodes, while support |
| 46 | * for write operations depends on the Management Object. Management Objects |
| 47 | * supporting write access may support transactional write, non-transactional |
| 48 | * write or both. Users of <code>DmtAdmin</code> should consult the Management |
| 49 | * Object specification and implementation for the supported update modes. If |
| 50 | * Management Object definition permits, implementations are encouraged to |
| 51 | * support both update modes. |
| 52 | * <p> |
| 53 | * This interface also contains methods for manipulating the set of |
| 54 | * <code>DmtEventListener</code> objects that are called when the structure or |
| 55 | * content of the tree is changed. These methods are not needed in an OSGi |
| 56 | * environment, clients should register listeners through the Event Admin |
| 57 | * service. |
| 58 | */ |
| 59 | public interface DmtAdmin { |
| 60 | /** |
| 61 | * Opens a <code>DmtSession</code> for local usage on a given subtree of |
| 62 | * the DMT with non transactional write lock. This call is equivalent to the |
| 63 | * following: |
| 64 | * <code>getSession(null, subtreeUri, DmtSession.LOCK_TYPE_EXCLUSIVE)</code> |
| 65 | * <p> |
| 66 | * The <code>subtreeUri</code> parameter must contain an absolute URI. It |
| 67 | * can also be <code>null</code>, in this case the session is opened with |
| 68 | * the default session root, ".", that gives access to the whole |
| 69 | * tree. |
| 70 | * <p> |
| 71 | * To perform this operation the caller must have <code>DmtPermission</code> |
| 72 | * for the <code>subtreeUri</code> node with the Get action present. |
| 73 | * |
| 74 | * @param subtreeUri the subtree on which DMT manipulations can be performed |
| 75 | * within the returned session |
| 76 | * @return a <code>DmtSession</code> object for the requested subtree |
| 77 | * @throws DmtException with the following possible error codes: |
| 78 | * <ul> |
| 79 | * <li><code>URI_TOO_LONG</code> if <code>subtreeUri</code> or |
| 80 | * a segment of it is too long, or if it has too many segments |
| 81 | * <li><code>INVALID_URI</code> if <code>subtreeUri</code> is |
| 82 | * syntactically invalid |
| 83 | * <li><code>NODE_NOT_FOUND</code> if <code>subtreeUri</code> |
| 84 | * specifies a non-existing node |
| 85 | * <li><code>SESSION_CREATION_TIMEOUT</code> if the operation |
| 86 | * timed out because of another ongoing session |
| 87 | * <li><code>COMMAND_FAILED</code> if <code>subtreeUri</code> |
| 88 | * specifies a relative URI, or some unspecified error is |
| 89 | * encountered while attempting to complete the command |
| 90 | * </ul> |
| 91 | * @throws SecurityException if the caller does not have |
| 92 | * <code>DmtPermission</code> for the given root node with the Get |
| 93 | * action present |
| 94 | */ |
| 95 | DmtSession getSession(String subtreeUri) throws DmtException; |
| 96 | |
| 97 | /** |
| 98 | * Opens a <code>DmtSession</code> for local usage on a specific DMT |
| 99 | * subtree with a given lock mode. This call is equivalent to the |
| 100 | * following: <code>getSession(null, subtreeUri, lockMode)</code> |
| 101 | * <p> |
| 102 | * The <code>subtreeUri</code> parameter must contain an absolute URI. It |
| 103 | * can also be <code>null</code>, in this case the session is opened with |
| 104 | * the default session root, ".", that gives access to the whole |
| 105 | * tree. |
| 106 | * <p> |
| 107 | * To perform this operation the caller must have <code>DmtPermission</code> |
| 108 | * for the <code>subtreeUri</code> node with the Get action present. |
| 109 | * |
| 110 | * @param subtreeUri the subtree on which DMT manipulations can be performed |
| 111 | * within the returned session |
| 112 | * @param lockMode one of the lock modes specified in |
| 113 | * <code>DmtSession</code> |
| 114 | * @return a <code>DmtSession</code> object for the requested subtree |
| 115 | * @throws DmtException with the following possible error codes: |
| 116 | * <ul> |
| 117 | * <li><code>URI_TOO_LONG</code> if <code>subtreeUri</code> or |
| 118 | * a segment of it is too long, or if it has too many segments |
| 119 | * <li><code>INVALID_URI</code> if <code>subtreeUri</code> is |
| 120 | * syntactically invalid |
| 121 | * <li><code>NODE_NOT_FOUND</code> if <code>subtreeUri</code> |
| 122 | * specifies a non-existing node |
| 123 | * <li><code>FEATURE_NOT_SUPPORTED</code> if atomic sessions are |
| 124 | * not supported by the implementation and <code>lockMode</code> |
| 125 | * requests an atomic session |
| 126 | * <li><code>SESSION_CREATION_TIMEOUT</code> if the operation |
| 127 | * timed out because of another ongoing session |
| 128 | * <li><code>COMMAND_FAILED</code> if <code>subtreeUri</code> |
| 129 | * specifies a relative URI, if <code>lockMode</code> is unknown, |
| 130 | * or some unspecified error is encountered while attempting to |
| 131 | * complete the command |
| 132 | * </ul> |
| 133 | * @throws SecurityException if the caller does not have |
| 134 | * <code>DmtPermission</code> for the given root node with the Get |
| 135 | * action present |
| 136 | */ |
| 137 | DmtSession getSession(String subtreeUri, int lockMode) throws DmtException; |
| 138 | |
| 139 | /** |
| 140 | * Opens a <code>DmtSession</code> on a specific DMT subtree using a |
| 141 | * specific lock mode on behalf of a remote principal. If local management |
| 142 | * applications are using this method then they should provide |
| 143 | * <code>null</code> as the first parameter. Alternatively they can use |
| 144 | * other forms of this method without providing a principal string. |
| 145 | * <p> |
| 146 | * The <code>subtreeUri</code> parameter must contain an absolute URI. It |
| 147 | * can also be <code>null</code>, in this case the session is opened with |
| 148 | * the default session root, ".", that gives access to the whole |
| 149 | * tree. |
| 150 | * <p> |
| 151 | * This method is guarded by <code>DmtPrincipalPermission</code> in case of |
| 152 | * remote sessions. In addition, the caller must have Get access rights |
| 153 | * (ACL in case of remote sessions, <code>DmtPermission</code> in case of |
| 154 | * local sessions) on the <code>subtreeUri</code> node to perform this |
| 155 | * operation. |
| 156 | * |
| 157 | * @param principal the identifier of the remote server on whose behalf the |
| 158 | * data manipulation is performed, or <code>null</code> for local |
| 159 | * sessions |
| 160 | * @param subtreeUri the subtree on which DMT manipulations can be performed |
| 161 | * within the returned session |
| 162 | * @param lockMode one of the lock modes specified in |
| 163 | * <code>DmtSession</code> |
| 164 | * @return a <code>DmtSession</code> object for the requested subtree |
| 165 | * @throws DmtException with the following possible error codes: |
| 166 | * <ul> |
| 167 | * <li><code>URI_TOO_LONG</code> if <code>subtreeUri</code> or |
| 168 | * a segment of it is too long, or if it has too many segments |
| 169 | * <li><code>INVALID_URI</code> if <code>subtreeUri</code> is |
| 170 | * syntactically invalid |
| 171 | * <li><code>NODE_NOT_FOUND</code> if <code>subtreeUri</code> |
| 172 | * specifies a non-existing node |
| 173 | * <li><code>PERMISSION_DENIED</code> if <code>principal</code> is |
| 174 | * not <code>null</code> and the ACL of the node does not allow the |
| 175 | * <code>Get</code> operation for the principal on the given root |
| 176 | * node |
| 177 | * <li><code>FEATURE_NOT_SUPPORTED</code> if atomic sessions are |
| 178 | * not supported by the implementation and <code>lockMode</code> |
| 179 | * requests an atomic session |
| 180 | * <li><code>SESSION_CREATION_TIMEOUT</code> if the operation |
| 181 | * timed out because of another ongoing session |
| 182 | * <li><code>COMMAND_FAILED</code> if <code>subtreeUri</code> |
| 183 | * specifies a relative URI, if <code>lockMode</code> is unknown, |
| 184 | * or some unspecified error is encountered while attempting to |
| 185 | * complete the command |
| 186 | * </ul> |
| 187 | * @throws SecurityException in case of remote sessions, if the caller does |
| 188 | * not have the required <code>DmtPrincipalPermission</code> with a |
| 189 | * target matching the <code>principal</code> parameter, or in case |
| 190 | * of local sessions, if the caller does not have |
| 191 | * <code>DmtPermission</code> for the given root node with the Get |
| 192 | * action present |
| 193 | */ |
| 194 | DmtSession getSession(String principal, String subtreeUri, int lockMode) |
| 195 | throws DmtException; |
| 196 | |
| 197 | /** |
| 198 | * Registers an event listener on behalf of a local application. The given |
| 199 | * listener will receive notification on all changes affecting the specified |
| 200 | * subtree. The subtree is specified by its root node URI. An event is |
| 201 | * delivered to the registered listener if at least one affected node is |
| 202 | * within this subtree. The events can also be filtered by specifying a |
| 203 | * bitmask of relevant event types (e.g. |
| 204 | * <code>DmtEvent.ADDED | DmtEvent.REPLACED | DmtEvent.SESSION_CLOSED</code>). |
| 205 | * Only event types included in the bitmask will be delivered to the |
| 206 | * listener. |
| 207 | * <p> |
| 208 | * The listener will only receive the change notifications of nodes for |
| 209 | * which the registering application has the appropriate GET |
| 210 | * {@link info.dmtree.security.DmtPermission}. |
| 211 | * <p> |
| 212 | * If the specified <code>listener</code> was already registered, calling |
| 213 | * this method will update the registration. |
| 214 | * |
| 215 | * @param type a bitmask of event types the caller is interested in |
| 216 | * @param uri the URI of the root node of a subtree, must not be |
| 217 | * <code>null</code> |
| 218 | * @param listener the listener to be registered, must not be |
| 219 | * <code>null</code> |
| 220 | * @throws SecurityException if the caller doesn't have the necessary GET |
| 221 | * <code>DmtPermission</code> for the given URI |
| 222 | * @throws NullPointerException if the <code>uri</code> or |
| 223 | * <code>listener</code> parameter is <code>null</code> |
| 224 | * @throws IllegalArgumentException if the <code>type</code> parameter |
| 225 | * contains invalid bits (not corresponding to any event type |
| 226 | * defined in <code>DmtEvent</code>), or if the <code>uri</code> |
| 227 | * parameter is invalid (is not an absolute URI or is syntactically |
| 228 | * incorrect) |
| 229 | */ |
| 230 | void addEventListener(int type, String uri, DmtEventListener listener); |
| 231 | |
| 232 | /** |
| 233 | * Registers an event listener on behalf of a remote principal. The given |
| 234 | * listener will receive notification on all changes affecting the specified |
| 235 | * subtree. The subtree is specified by its root node URI. An event is |
| 236 | * delivered to the registered listener if at least one affected node is |
| 237 | * within this subtree. The events can also be filtered by specifying a |
| 238 | * bitmask of relevant event types (e.g. |
| 239 | * <code>DmtEvent.ADDED | DmtEvent.REPLACED | DmtEvent.SESSION_CLOSED</code>). |
| 240 | * Only event types included in the bitmask will be delivered to the |
| 241 | * listener. |
| 242 | * <p> |
| 243 | * The listener will only receive the change notifications of nodes for |
| 244 | * which the node ACL grants GET access to the specified principal. |
| 245 | * <p> |
| 246 | * If the specified <code>listener</code> was already registered, calling |
| 247 | * this method will update the registration. |
| 248 | * |
| 249 | * @param principal the management server identity the caller is acting on |
| 250 | * behalf of, must not be <code>null</code> |
| 251 | * @param type a bitmask of event types the caller is interested in |
| 252 | * @param uri the URI of the root node of a subtree, must not be |
| 253 | * <code>null</code> |
| 254 | * @param listener the listener to be registered, must not be |
| 255 | * <code>null</code> |
| 256 | * @throws SecurityException if the caller doesn't have the necessary |
| 257 | * <code>DmtPrincipalPermission</code> to use the specified |
| 258 | * principal |
| 259 | * @throws NullPointerException if the <code>principal</code>, |
| 260 | * <code>uri</code> or <code>listener</code> parameter is |
| 261 | * <code>null</code> |
| 262 | * @throws IllegalArgumentException if the <code>type</code> parameter |
| 263 | * contains invalid bits (not corresponding to any event type |
| 264 | * defined in <code>DmtEvent</code>), or if the <code>uri</code> |
| 265 | * parameter is invalid (is not an absolute URI or is syntactically |
| 266 | * incorrect) |
| 267 | */ |
| 268 | void addEventListener(String principal, int type, String uri, |
| 269 | DmtEventListener listener); |
| 270 | |
| 271 | /** |
| 272 | * Remove a previously registered listener. After this call, the listener |
| 273 | * will not receive change notifications. |
| 274 | * |
| 275 | * @param listener the listener to be unregistered, must not be |
| 276 | * <code>null</code> |
| 277 | * @throws NullPointerException if the <code>listener</code> parameter is |
| 278 | * <code>null</code> |
| 279 | */ |
| 280 | void removeEventListener(DmtEventListener listener); |
| 281 | } |