001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008-2009 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017package org.forgerock.opendj.config.client; 018 019import java.util.Set; 020import java.util.SortedSet; 021 022import org.forgerock.opendj.config.AbstractManagedObjectDefinition; 023import org.forgerock.opendj.config.Configuration; 024import org.forgerock.opendj.config.ConfigurationClient; 025import org.forgerock.opendj.config.DefinitionDecodingException; 026import org.forgerock.opendj.config.InstantiableRelationDefinition; 027import org.forgerock.opendj.config.ManagedObjectNotFoundException; 028import org.forgerock.opendj.config.ManagedObjectPath; 029import org.forgerock.opendj.config.OptionalRelationDefinition; 030import org.forgerock.opendj.config.PropertyDefinition; 031import org.forgerock.opendj.config.SetRelationDefinition; 032import org.forgerock.opendj.config.client.spi.Driver; 033import org.forgerock.opendj.ldap.LdapException; 034import org.forgerock.opendj.server.config.client.RootCfgClient; 035 036/** 037 * Driver based client management connection context. 038 */ 039public abstract class DriverBasedManagementContext implements ManagementContext { 040 041 /** 042 * Creates a new management context. 043 */ 044 protected DriverBasedManagementContext() { 045 // No implementation required. 046 } 047 048 @Override 049 public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( 050 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) 051 throws ManagedObjectNotFoundException, OperationRejectedException, 052 LdapException { 053 return getDriver().deleteManagedObject(parent, rd, name); 054 } 055 056 @Override 057 public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( 058 ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws 059 ManagedObjectNotFoundException, OperationRejectedException, LdapException { 060 return getDriver().deleteManagedObject(parent, rd); 061 } 062 063 @Override 064 public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( 065 ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) 066 throws ManagedObjectNotFoundException, OperationRejectedException, LdapException { 067 return getDriver().deleteManagedObject(parent, rd, name); 068 } 069 070 @Override 071 @SuppressWarnings("unchecked") 072 public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( 073 ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, 074 ManagedObjectNotFoundException, LdapException { 075 // Be careful to handle the root configuration. 076 if (path.isEmpty()) { 077 return (ManagedObject<C>) getRootConfigurationManagedObject(); 078 } 079 080 return getDriver().getManagedObject(path); 081 } 082 083 @Override 084 public final <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) 085 throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException { 086 Set<P> values = getPropertyValues(path, pd); 087 if (values.isEmpty()) { 088 return null; 089 } else { 090 return values.iterator().next(); 091 } 092 } 093 094 @Override 095 public final <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) 096 throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException { 097 return getDriver().getPropertyValues(path, pd); 098 } 099 100 @Override 101 public final RootCfgClient getRootConfiguration() { 102 return getRootConfigurationManagedObject().getConfiguration(); 103 } 104 105 @Override 106 public final ManagedObject<RootCfgClient> getRootConfigurationManagedObject() { 107 return getDriver().getRootConfigurationManagedObject(); 108 } 109 110 @Override 111 public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( 112 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws 113 ManagedObjectNotFoundException, LdapException { 114 return listManagedObjects(parent, rd, rd.getChildDefinition()); 115 } 116 117 @Override 118 public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( 119 ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, 120 AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws 121 ManagedObjectNotFoundException, LdapException { 122 return getDriver().listManagedObjects(parent, rd, d); 123 } 124 125 @Override 126 public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( 127 ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws 128 ManagedObjectNotFoundException, LdapException { 129 return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition()); 130 } 131 132 @Override 133 public final boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, 134 LdapException { 135 return getDriver().managedObjectExists(path); 136 } 137 138 /** 139 * Gets the driver associated with this management context. 140 * 141 * @return Returns the driver associated with this management context. 142 */ 143 protected abstract Driver getDriver(); 144 145 @Override 146 public final void close() { 147 getDriver().close(); 148 } 149 150}