001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 028 package org.opends.server.admin.client; 029 030 031 032 import java.util.SortedSet; 033 034 import org.opends.server.admin.AbstractManagedObjectDefinition; 035 import org.opends.server.admin.Configuration; 036 import org.opends.server.admin.ConfigurationClient; 037 import org.opends.server.admin.DefinitionDecodingException; 038 import org.opends.server.admin.InstantiableRelationDefinition; 039 import org.opends.server.admin.ManagedObjectNotFoundException; 040 import org.opends.server.admin.ManagedObjectPath; 041 import org.opends.server.admin.OptionalRelationDefinition; 042 import org.opends.server.admin.PropertyDefinition; 043 import org.opends.server.admin.PropertyException; 044 import org.opends.server.admin.client.spi.Driver; 045 import org.opends.server.admin.std.client.RootCfgClient; 046 047 048 049 /** 050 * Client management connection context. 051 */ 052 public abstract class ManagementContext { 053 054 /** 055 * Creates a new management context. 056 */ 057 protected ManagementContext() { 058 // No implementation required. 059 } 060 061 062 063 /** 064 * Deletes the named instantiable child managed object from the 065 * named parent managed object. 066 * 067 * @param <C> 068 * The type of client managed object configuration that the 069 * relation definition refers to. 070 * @param <S> 071 * The type of server managed object configuration that the 072 * relation definition refers to. 073 * @param parent 074 * The path of the parent managed object. 075 * @param rd 076 * The instantiable relation definition. 077 * @param name 078 * The name of the child managed object to be removed. 079 * @return Returns <code>true</code> if the named instantiable 080 * child managed object was found, or <code>false</code> 081 * if it was not found. 082 * @throws IllegalArgumentException 083 * If the relation definition is not associated with the 084 * parent managed object's definition. 085 * @throws ManagedObjectNotFoundException 086 * If the parent managed object could not be found. 087 * @throws OperationRejectedException 088 * If the managed object cannot be removed due to some 089 * client-side or server-side constraint which cannot be 090 * satisfied (for example, if it is referenced by another 091 * managed object). 092 * @throws AuthorizationException 093 * If the server refuses to remove the managed objects 094 * because the client does not have the correct 095 * privileges. 096 * @throws CommunicationException 097 * If the client cannot contact the server due to an 098 * underlying communication problem. 099 */ 100 public final <C extends ConfigurationClient, S extends Configuration> 101 boolean deleteManagedObject( 102 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, 103 String name) throws IllegalArgumentException, 104 ManagedObjectNotFoundException, OperationRejectedException, 105 AuthorizationException, CommunicationException { 106 return getDriver().deleteManagedObject(parent, rd, name); 107 } 108 109 110 111 /** 112 * Deletes the optional child managed object from the named parent 113 * managed object. 114 * 115 * @param <C> 116 * The type of client managed object configuration that the 117 * relation definition refers to. 118 * @param <S> 119 * The type of server managed object configuration that the 120 * relation definition refers to. 121 * @param parent 122 * The path of the parent managed object. 123 * @param rd 124 * The optional relation definition. 125 * @return Returns <code>true</code> if the optional child managed 126 * object was found, or <code>false</code> if it was not 127 * found. 128 * @throws IllegalArgumentException 129 * If the relation definition is not associated with the 130 * parent managed object's definition. 131 * @throws ManagedObjectNotFoundException 132 * If the parent managed object could not be found. 133 * @throws OperationRejectedException 134 * If the managed object cannot be removed due to some 135 * client-side or server-side constraint which cannot be 136 * satisfied (for example, if it is referenced by another 137 * managed object). 138 * @throws AuthorizationException 139 * If the server refuses to remove the managed objects 140 * because the client does not have the correct 141 * privileges. 142 * @throws CommunicationException 143 * If the client cannot contact the server due to an 144 * underlying communication problem. 145 */ 146 public final <C extends ConfigurationClient, S extends Configuration> 147 boolean deleteManagedObject( 148 ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) 149 throws IllegalArgumentException, ManagedObjectNotFoundException, 150 OperationRejectedException, AuthorizationException, 151 CommunicationException { 152 return getDriver().deleteManagedObject(parent, rd); 153 } 154 155 156 157 /** 158 * Gets the named managed object. 159 * 160 * @param <C> 161 * The type of client managed object configuration that the 162 * path definition refers to. 163 * @param <S> 164 * The type of server managed object configuration that the 165 * path definition refers to. 166 * @param path 167 * The path of the managed object. 168 * @return Returns the named managed object. 169 * @throws DefinitionDecodingException 170 * If the managed object was found but its type could not 171 * be determined. 172 * @throws ManagedObjectDecodingException 173 * If the managed object was found but one or more of its 174 * properties could not be decoded. 175 * @throws ManagedObjectNotFoundException 176 * If the requested managed object could not be found on 177 * the server. 178 * @throws AuthorizationException 179 * If the server refuses to retrieve the managed object 180 * because the client does not have the correct 181 * privileges. 182 * @throws CommunicationException 183 * If the client cannot contact the server due to an 184 * underlying communication problem. 185 */ 186 @SuppressWarnings("unchecked") 187 public final <C extends ConfigurationClient, S extends Configuration> 188 ManagedObject<? extends C> getManagedObject( 189 ManagedObjectPath<C, S> path) throws DefinitionDecodingException, 190 ManagedObjectDecodingException, ManagedObjectNotFoundException, 191 AuthorizationException, CommunicationException { 192 // Be careful to handle the root configuration. 193 if (path.isEmpty()) { 194 return (ManagedObject<C>) getRootConfigurationManagedObject(); 195 } 196 197 return getDriver().getManagedObject(path); 198 } 199 200 201 202 /** 203 * Gets the effective value of a property in the named managed 204 * object. 205 * 206 * @param <PD> 207 * The type of the property to be retrieved. 208 * @param path 209 * The path of the managed object containing the property. 210 * @param pd 211 * The property to be retrieved. 212 * @return Returns the property's effective value, or 213 * <code>null</code> if there are no values defined. 214 * @throws IllegalArgumentException 215 * If the property definition is not associated with the 216 * referenced managed object's definition. 217 * @throws DefinitionDecodingException 218 * If the managed object was found but its type could not 219 * be determined. 220 * @throws PropertyException 221 * If the managed object was found but the requested 222 * property could not be decoded. 223 * @throws ManagedObjectNotFoundException 224 * If the requested managed object could not be found on 225 * the server. 226 * @throws AuthorizationException 227 * If the server refuses to retrieve the managed object 228 * because the client does not have the correct 229 * privileges. 230 * @throws CommunicationException 231 * If the client cannot contact the server due to an 232 * underlying communication problem. 233 */ 234 public final <PD> PD getPropertyValue(ManagedObjectPath<?, ?> path, 235 PropertyDefinition<PD> pd) throws IllegalArgumentException, 236 DefinitionDecodingException, AuthorizationException, 237 ManagedObjectNotFoundException, CommunicationException, 238 PropertyException { 239 return getDriver().getPropertyValue(path, pd); 240 } 241 242 243 244 /** 245 * Gets the effective values of a property in the named managed 246 * object. 247 * 248 * @param <PD> 249 * The type of the property to be retrieved. 250 * @param path 251 * The path of the managed object containing the property. 252 * @param pd 253 * The property to be retrieved. 254 * @return Returns the property's effective values, or an empty set 255 * if there are no values defined. 256 * @throws IllegalArgumentException 257 * If the property definition is not associated with the 258 * referenced managed object's definition. 259 * @throws DefinitionDecodingException 260 * If the managed object was found but its type could not 261 * be determined. 262 * @throws PropertyException 263 * If the managed object was found but the requested 264 * property could not be decoded. 265 * @throws ManagedObjectNotFoundException 266 * If the requested managed object could not be found on 267 * the server. 268 * @throws AuthorizationException 269 * If the server refuses to retrieve the managed object 270 * because the client does not have the correct 271 * privileges. 272 * @throws CommunicationException 273 * If the client cannot contact the server due to an 274 * underlying communication problem. 275 */ 276 public final <PD> SortedSet<PD> getPropertyValues( 277 ManagedObjectPath<?, ?> path, PropertyDefinition<PD> pd) 278 throws IllegalArgumentException, DefinitionDecodingException, 279 AuthorizationException, ManagedObjectNotFoundException, 280 CommunicationException, PropertyException { 281 return getDriver().getPropertyValues(path, pd); 282 } 283 284 285 286 /** 287 * Gets the root configuration client associated with this 288 * management context. 289 * 290 * @return Returns the root configuration client associated with 291 * this management context. 292 */ 293 public final RootCfgClient getRootConfiguration() { 294 return getRootConfigurationManagedObject().getConfiguration(); 295 } 296 297 298 299 /** 300 * Gets the root configuration managed object associated with this 301 * management context. 302 * 303 * @return Returns the root configuration managed object associated 304 * with this management context. 305 */ 306 public final 307 ManagedObject<RootCfgClient> getRootConfigurationManagedObject() { 308 return getDriver().getRootConfigurationManagedObject(); 309 } 310 311 312 313 /** 314 * Lists the child managed objects of the named parent managed 315 * object. 316 * 317 * @param <C> 318 * The type of client managed object configuration that the 319 * relation definition refers to. 320 * @param <S> 321 * The type of server managed object configuration that the 322 * relation definition refers to. 323 * @param parent 324 * The path of the parent managed object. 325 * @param rd 326 * The instantiable relation definition. 327 * @return Returns the names of the child managed objects. 328 * @throws IllegalArgumentException 329 * If the relation definition is not associated with the 330 * parent managed object's definition. 331 * @throws ManagedObjectNotFoundException 332 * If the parent managed object could not be found. 333 * @throws AuthorizationException 334 * If the server refuses to list the managed objects 335 * because the client does not have the correct 336 * privileges. 337 * @throws CommunicationException 338 * If the client cannot contact the server due to an 339 * underlying communication problem. 340 */ 341 public final <C extends ConfigurationClient, S extends Configuration> 342 String[] listManagedObjects( 343 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) 344 throws IllegalArgumentException, ManagedObjectNotFoundException, 345 AuthorizationException, CommunicationException { 346 return getDriver().listManagedObjects(parent, rd); 347 } 348 349 350 351 /** 352 * Lists the child managed objects of the named parent managed 353 * object which are a sub-type of the specified managed object 354 * definition. 355 * 356 * @param <C> 357 * The type of client managed object configuration that the 358 * relation definition refers to. 359 * @param <S> 360 * The type of server managed object configuration that the 361 * relation definition refers to. 362 * @param parent 363 * The path of the parent managed object. 364 * @param rd 365 * The instantiable relation definition. 366 * @param d 367 * The managed object definition. 368 * @return Returns the names of the child managed objects which are 369 * a sub-type of the specified managed object definition. 370 * @throws IllegalArgumentException 371 * If the relation definition is not associated with the 372 * parent managed object's definition. 373 * @throws ManagedObjectNotFoundException 374 * If the parent managed object could not be found. 375 * @throws AuthorizationException 376 * If the server refuses to list the managed objects 377 * because the client does not have the correct 378 * privileges. 379 * @throws CommunicationException 380 * If the client cannot contact the server due to an 381 * underlying communication problem. 382 */ 383 public final <C extends ConfigurationClient, S extends Configuration> 384 String[] listManagedObjects( 385 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, 386 AbstractManagedObjectDefinition<? extends C, ? extends S> d) 387 throws IllegalArgumentException, ManagedObjectNotFoundException, 388 AuthorizationException, CommunicationException { 389 return getDriver().listManagedObjects(parent, rd, d); 390 } 391 392 393 394 /** 395 * Determines whether or not the named managed object exists. 396 * 397 * @param path 398 * The path of the named managed object. 399 * @return Returns <code>true</code> if the named managed object 400 * exists, <code>false</code> otherwise. 401 * @throws ManagedObjectNotFoundException 402 * If the parent managed object could not be found. 403 * @throws AuthorizationException 404 * If the server refuses to make the determination because 405 * the client does not have the correct privileges. 406 * @throws CommunicationException 407 * If the client cannot contact the server due to an 408 * underlying communication problem. 409 */ 410 public final boolean managedObjectExists(ManagedObjectPath<?, ?> path) 411 throws ManagedObjectNotFoundException, AuthorizationException, 412 CommunicationException { 413 return getDriver().managedObjectExists(path); 414 } 415 416 417 418 /** 419 * Gets the driver associated with this management context. 420 * 421 * @return Returns the driver associated with this management 422 * context. 423 */ 424 protected abstract Driver getDriver(); 425 426 427 428 /** 429 * Closes this management context. 430 */ 431 public final void close() { 432 this.getDriver().close(); 433 } 434 435 }