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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.opends.server.admin.client.ldap; 027 028 029import java.util.Collection; 030 031import javax.naming.NamingException; 032import javax.naming.directory.Attributes; 033import javax.naming.ldap.LdapName; 034 035 036 037/** 038 * An LDAP connection adaptor interface which is used to perform LDAP 039 * client operations. 040 * <p> 041 * This interface is provided in order to make it easier to keep track 042 * of which JNDI DirContext methods we require and also to facilitate 043 * implementation of mock JNDI contexts for unit-testing. 044 */ 045public abstract class LDAPConnection { 046 047 /** 048 * Create a new LDAP connection. 049 */ 050 protected LDAPConnection() { 051 // No implementation required. 052 } 053 054 055 056 /** 057 * Creates a new entry with the specified set of attributes. 058 * 059 * @param dn 060 * The name of the entry to be created. 061 * @param attributes 062 * The set of attributes. 063 * @throws NamingException 064 * If an error occurred whilst creating the entry. 065 */ 066 public abstract void createEntry(LdapName dn, Attributes attributes) 067 throws NamingException; 068 069 070 071 /** 072 * Deletes the named subtree. 073 * 074 * @param dn 075 * The name of the subtree to be deleted. 076 * @throws NamingException 077 * If an error occurred whilst deleting the subtree. 078 */ 079 public abstract void deleteSubtree(LdapName dn) throws NamingException; 080 081 082 083 /** 084 * Determines whether or not the named entry exists. 085 * 086 * @param dn 087 * The name of the entry. 088 * @return Returns <code>true</code> if the entry exists. 089 * @throws NamingException 090 * If an error occurred whilst making the determination. 091 */ 092 public abstract boolean entryExists(LdapName dn) throws NamingException; 093 094 095 096 /** 097 * Lists the children of the named entry. 098 * 099 * @param dn 100 * The name of the entry to list. 101 * @param filter 102 * An LDAP filter string, or <code>null</code> indicating 103 * the default filter of <code>(objectclass=*)</code>. 104 * @return Returns the names of the children. 105 * @throws NamingException 106 * If an error occurred whilst listing the children. 107 */ 108 public abstract Collection<LdapName> listEntries(LdapName dn, String filter) 109 throws NamingException; 110 111 112 113 /** 114 * Modifies the attributes of the named entry. 115 * 116 * @param dn 117 * The name of the entry to be modified. 118 * @param mods 119 * The list of attributes which need replacing. 120 * @throws NamingException 121 * If an error occurred whilst applying the modifications. 122 */ 123 public abstract void modifyEntry(LdapName dn, Attributes mods) 124 throws NamingException; 125 126 127 128 /** 129 * Reads the attributes of the named entry. 130 * 131 * @param dn 132 * The name of the entry to be read. 133 * @param attrIds 134 * The list of attributes to be retrievd. 135 * @return Returns the attributes of the requested entry. 136 * @throws NamingException 137 * If an error occurred whilst reading the entry. 138 */ 139 public abstract Attributes readEntry(LdapName dn, Collection<String> attrIds) 140 throws NamingException; 141 142 143 144 /** 145 * Closes the LDAP connection. 146 */ 147 public abstract void unbind(); 148}