/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt * or http://forgerock.org/license/CDDLv1.0.html. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at legal-notices/CDDLv1_0.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2008-2009 Sun Microsystems, Inc. */ package org.opends.server.admin.client; import java.util.Set; import java.util.SortedSet; import org.forgerock.opendj.admin.client.RootCfgClient; import org.forgerock.opendj.ldap.ErrorResultException; import org.opends.server.admin.AbstractManagedObjectDefinition; import org.opends.server.admin.Configuration; import org.opends.server.admin.ConfigurationClient; import org.opends.server.admin.DefinitionDecodingException; import org.opends.server.admin.InstantiableRelationDefinition; import org.opends.server.admin.ManagedObjectNotFoundException; import org.opends.server.admin.ManagedObjectPath; import org.opends.server.admin.OptionalRelationDefinition; import org.opends.server.admin.PropertyDefinition; import org.opends.server.admin.PropertyException; import org.opends.server.admin.SetRelationDefinition; import org.opends.server.admin.client.spi.Driver; /** * Client management connection context. */ public abstract class ManagementContext { /** * Creates a new management context. */ protected ManagementContext() { // No implementation required. } /** * Deletes the named instantiable child managed object from the named parent * managed object. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The instantiable relation definition. * @param name * The name of the child managed object to be removed. * @return Returns true if the named instantiable child managed * object was found, or false if it was not found. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws OperationRejectedException * If the managed object cannot be removed due to some * client-side or server-side constraint which cannot be * satisfied (for example, if it is referenced by another * managed object). * @throws ErrorResultException * If any other error occurs. */ public final boolean deleteManagedObject( ManagedObjectPath parent, InstantiableRelationDefinition rd, String name) throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { return getDriver().deleteManagedObject(parent, rd, name); } /** * Deletes the optional child managed object from the named parent managed * object. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The optional relation definition. * @return Returns true if the optional child managed object * was found, or false if it was not found. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws OperationRejectedException * If the managed object cannot be removed due to some * client-side or server-side constraint which cannot be * satisfied (for example, if it is referenced by another * managed object). * @throws ErrorResultException * If any other error occurs. */ public final boolean deleteManagedObject( ManagedObjectPath parent, OptionalRelationDefinition rd) throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { return getDriver().deleteManagedObject(parent, rd); } /** * Deletes s set child managed object from the named parent managed object. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The set relation definition. * @param name * The name of the child managed object to be removed. * @return Returns true if the set child managed object was * found, or false if it was not found. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws OperationRejectedException * If the managed object cannot be removed due to some * client-side or server-side constraint which cannot be * satisfied (for example, if it is referenced by another * managed object). * @throws ErrorResultException * If any other error occurs. */ public final boolean deleteManagedObject( ManagedObjectPath parent, SetRelationDefinition rd, String name) throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { return getDriver().deleteManagedObject(parent, rd, name); } /** * Gets the named managed object. * * @param * The type of client managed object configuration that the path * definition refers to. * @param * The type of server managed object configuration that the path * definition refers to. * @param path * The path of the managed object. * @return Returns the named managed object. * @throws DefinitionDecodingException * If the managed object was found but its type could not be * determined. * @throws ManagedObjectDecodingException * If the managed object was found but one or more of its * properties could not be decoded. * @throws ManagedObjectNotFoundException * If the requested managed object could not be found on the * server. * @throws ErrorResultException * If any other error occurs. */ @SuppressWarnings("unchecked") public final ManagedObject getManagedObject( ManagedObjectPath path) throws DefinitionDecodingException, ManagedObjectDecodingException, ManagedObjectNotFoundException, ErrorResultException { // Be careful to handle the root configuration. if (path.isEmpty()) { return (ManagedObject) getRootConfigurationManagedObject(); } return getDriver().getManagedObject(path); } /** * Gets the effective value of a property in the named managed object. * * @param

* The type of the property to be retrieved. * @param path * The path of the managed object containing the property. * @param pd * The property to be retrieved. * @return Returns the property's effective value, or null if * there are no values defined. * @throws IllegalArgumentException * If the property definition is not associated with the * referenced managed object's definition. * @throws DefinitionDecodingException * If the managed object was found but its type could not be * determined. * @throws PropertyException * If the managed object was found but the requested property * could not be decoded. * @throws ManagedObjectNotFoundException * If the requested managed object could not be found on the * server. * @throws ErrorResultException * If any other error occurs. */ public final

P getPropertyValue(ManagedObjectPath path, PropertyDefinition

pd) throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { Set

values = getPropertyValues(path, pd); if (values.isEmpty()) { return null; } else { return values.iterator().next(); } } /** * Gets the effective values of a property in the named managed object. * * @param

* The type of the property to be retrieved. * @param path * The path of the managed object containing the property. * @param pd * The property to be retrieved. * @return Returns the property's effective values, or an empty set if there * are no values defined. * @throws IllegalArgumentException * If the property definition is not associated with the * referenced managed object's definition. * @throws DefinitionDecodingException * If the managed object was found but its type could not be * determined. * @throws PropertyException * If the managed object was found but the requested property * could not be decoded. * @throws ManagedObjectNotFoundException * If the requested managed object could not be found on the * server. * @throws ErrorResultException * If any other error occurs. */ public final

SortedSet

getPropertyValues(ManagedObjectPath path, PropertyDefinition

pd) throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { return getDriver().getPropertyValues(path, pd); } /** * Gets the root configuration client associated with this management * context. * * @return Returns the root configuration client associated with this * management context. */ public final RootCfgClient getRootConfiguration() { return getRootConfigurationManagedObject().getConfiguration(); } /** * Gets the root configuration managed object associated with this * management context. * * @return Returns the root configuration managed object associated with * this management context. */ public final ManagedObject getRootConfigurationManagedObject() { return getDriver().getRootConfigurationManagedObject(); } /** * Lists the child managed objects of the named parent managed object. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The instantiable relation definition. * @return Returns the names of the child managed objects. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws ErrorResultException * If any other error occurs. */ public final String[] listManagedObjects( ManagedObjectPath parent, InstantiableRelationDefinition rd) throws ManagedObjectNotFoundException, ErrorResultException { return listManagedObjects(parent, rd, rd.getChildDefinition()); } /** * Lists the child managed objects of the named parent managed object which * are a sub-type of the specified managed object definition. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The instantiable relation definition. * @param d * The managed object definition. * @return Returns the names of the child managed objects which are a * sub-type of the specified managed object definition. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws ErrorResultException * If any other error occurs. */ public final String[] listManagedObjects( ManagedObjectPath parent, InstantiableRelationDefinition rd, AbstractManagedObjectDefinition d) throws ManagedObjectNotFoundException, ErrorResultException { return getDriver().listManagedObjects(parent, rd, d); } /** * Lists the child managed objects of the named parent managed object. * * @param * The type of client managed object configuration that the * relation definition refers to. * @param * The type of server managed object configuration that the * relation definition refers to. * @param parent * The path of the parent managed object. * @param rd * The set relation definition. * @return Returns the names of the child managed objects. * @throws IllegalArgumentException * If the relation definition is not associated with the parent * managed object's definition. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws ErrorResultException * If any other error occurs. */ public final String[] listManagedObjects( ManagedObjectPath parent, SetRelationDefinition rd) throws ManagedObjectNotFoundException, ErrorResultException { return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition()); } /** * Determines whether or not the named managed object exists. * * @param path * The path of the named managed object. * @return Returns true if the named managed object exists, * false otherwise. * @throws ManagedObjectNotFoundException * If the parent managed object could not be found. * @throws ErrorResultException * If any other error occurs. */ public final boolean managedObjectExists(ManagedObjectPath path) throws ManagedObjectNotFoundException, ErrorResultException { return getDriver().managedObjectExists(path); } /** * Gets the driver associated with this management context. * * @return Returns the driver associated with this management context. */ protected abstract Driver getDriver(); /** * Closes this management context. */ public final void close() { this.getDriver().close(); } }