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