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 package org.opends.server.admin.client.ldap;
028
029
030 import java.util.Collection;
031
032 import javax.naming.NamingException;
033 import javax.naming.directory.Attributes;
034 import javax.naming.ldap.LdapName;
035
036
037
038 /**
039 * An LDAP connection adaptor interface which is used to perform LDAP
040 * client operations.
041 * <p>
042 * This interface is provided in order to make it easier to keep track
043 * of which JNDI DirContext methods we require and also to facilitate
044 * implementation of mock JNDI contexts for unit-testing.
045 */
046 public abstract class LDAPConnection {
047
048 /**
049 * Create a new LDAP connection.
050 */
051 protected LDAPConnection() {
052 // No implementation required.
053 }
054
055
056
057 /**
058 * Creates a new entry with the specified set of attributes.
059 *
060 * @param dn
061 * The name of the entry to be created.
062 * @param attributes
063 * The set of attributes.
064 * @throws NamingException
065 * If an error occurred whilst creating the entry.
066 */
067 public abstract void createEntry(LdapName dn, Attributes attributes)
068 throws NamingException;
069
070
071
072 /**
073 * Deletes the named subtree.
074 *
075 * @param dn
076 * The name of the subtree to be deleted.
077 * @throws NamingException
078 * If an error occurred whilst deleting the subtree.
079 */
080 public abstract void deleteSubtree(LdapName dn) throws NamingException;
081
082
083
084 /**
085 * Determines whether or not the named entry exists.
086 *
087 * @param dn
088 * The name of the entry.
089 * @return Returns <code>true</code> if the entry exists.
090 * @throws NamingException
091 * If an error occurred whilst making the determination.
092 */
093 public abstract boolean entryExists(LdapName dn) throws NamingException;
094
095
096
097 /**
098 * Lists the children of the named entry.
099 *
100 * @param dn
101 * The name of the entry to list.
102 * @param filter
103 * An LDAP filter string, or <code>null</code> indicating
104 * the default filter of <code>(objectclass=*)</code>.
105 * @return Returns the names of the children.
106 * @throws NamingException
107 * If an error occurred whilst listing the children.
108 */
109 public abstract Collection<LdapName> listEntries(LdapName dn, String filter)
110 throws NamingException;
111
112
113
114 /**
115 * Modifies the attributes of the named entry.
116 *
117 * @param dn
118 * The name of the entry to be modified.
119 * @param mods
120 * The list of attributes which need replacing.
121 * @throws NamingException
122 * If an error occurred whilst applying the modifications.
123 */
124 public abstract void modifyEntry(LdapName dn, Attributes mods)
125 throws NamingException;
126
127
128
129 /**
130 * Reads the attributes of the named entry.
131 *
132 * @param dn
133 * The name of the entry to be read.
134 * @param attrIds
135 * The list of attributes to be retrievd.
136 * @return Returns the attributes of the requested entry.
137 * @throws NamingException
138 * If an error occurred whilst reading the entry.
139 */
140 public abstract Attributes readEntry(LdapName dn, Collection<String> attrIds)
141 throws NamingException;
142
143
144
145 /**
146 * Closes the LDAP connection.
147 */
148 public abstract void unbind();
149 }