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 2013-2016 ForgeRock AS.
015 */
016package org.forgerock.opendj.config.server.spi;
017
018import java.util.List;
019import java.util.Set;
020
021import org.forgerock.opendj.config.server.ConfigException;
022import org.forgerock.opendj.ldap.DN;
023import org.forgerock.opendj.ldap.Entry;
024
025/** Provides configuration entries and listener registration on the entries. */
026public interface ConfigurationRepository {
027
028    /**
029     * Returns the set of DNs of children of the entry corresponding to the
030     * provided DN. .
031     *
032     * @param dn
033     *            DN of a configuration entry.
034     * @return the set of DN of children of the corresponding entry
035     * @throws ConfigException
036     *             If a problem occurs during retrieval.
037     */
038    Set<DN> getChildren(DN dn) throws ConfigException;
039
040    /**
041     * Returns the configuration entry for the provided DN.
042     *
043     * @param dn
044     *            DN of the configuration entry
045     * @return the config entry
046     * @throws ConfigException
047     *             If a problem occurs while trying to retrieve the requested
048     *             entry.
049     */
050    Entry getEntry(DN dn) throws ConfigException;
051
052    /**
053     * Checks if the provided DN corresponds to a configuration entry.
054     *
055     * @param dn
056     *            DN of the configuration entry
057     * @return {@code true} if and only if there is a configuration entry with
058     *         this DN
059     * @throws ConfigException
060     *             If a problem occurs.
061     */
062    boolean hasEntry(DN dn) throws ConfigException;
063
064    /**
065     * Registers the provided add listener so that it will be notified if any
066     * new entries are added immediately below the entry corresponding to the
067     * provided DN.
068     *
069     * @param dn
070     *            The DN of the configuration entry.
071     * @param listener
072     *            The add listener that should be registered.
073     */
074    void registerAddListener(DN dn, ConfigAddListener listener);
075
076    /**
077     * Registers the provided delete listener so that it will be notified if any
078     * entries are deleted immediately below the entry corresponding to the
079     * provided DN.
080     *
081     * @param dn
082     *            The DN of the configuration entry.
083     * @param listener
084     *            The delete listener that should be registered.
085     */
086    void registerDeleteListener(DN dn, ConfigDeleteListener listener);
087
088    /**
089     * Registers the provided change listener so that it will be notified of any
090     * changes to the entry corrresponding to provided DN. No check will be made
091     * to determine whether the provided listener is already registered.
092     *
093     * @param dn
094     *            The DN of the configuration entry.
095     * @param listener
096     *            The change listener that should be registered.
097     */
098    void registerChangeListener(DN dn, ConfigChangeListener listener);
099
100    /**
101     * Deregisters the provided add listener so that it will no longer be
102     * notified if any new entries are added immediately below the entry
103     * corresponding to the provided DN.
104     *
105     * @param dn
106     *            The DN of the configuration entry.
107     * @param listener
108     *            The add listener that should be deregistered.
109     */
110    void deregisterAddListener(DN dn, ConfigAddListener listener);
111
112    /**
113     * Deregisters the provided delete listener so that it will no longer be
114     * notified if any entries are deleted immediately below the entry
115     * corresponding to the provided DN.
116     *
117     * @param dn
118     *            The DN of the configuration entry.
119     * @param listener
120     *            The delete listener that should be deregistered.
121     */
122    void deregisterDeleteListener(DN dn, ConfigDeleteListener listener);
123
124    /**
125     * Attempts to deregister the provided change listener with the provided DN.
126     *
127     * @param dn
128     *            The DN of the configuration entry.
129     * @param listener
130     *            The change listener to deregister with this DN.
131     * @return <CODE>true</CODE> if the specified listener was deregistered, or
132     *         <CODE>false</CODE> if it was not.
133     */
134    boolean deregisterChangeListener(DN dn, ConfigChangeListener listener);
135
136    /**
137     * Retrieves the add listeners that have been registered with the provided
138     * DN.
139     *
140     * @param dn
141     *            The DN of the configuration entry.
142     * @return The list of add listeners.
143     */
144    List<ConfigAddListener> getAddListeners(DN dn);
145
146    /**
147     * Retrieves the delete listeners that have been registered with the
148     * provided DN.
149     *
150     * @param dn
151     *            The DN of the configuration entry.
152     * @return The list of delete listeners.
153     */
154    List<ConfigDeleteListener> getDeleteListeners(DN dn);
155
156    /**
157     * Retrieves the change listeners that have been registered with the
158     * provided DN.
159     *
160     * @param dn
161     *            The DN of the configuration entry.
162     * @return The list of change listeners.
163     */
164    List<ConfigChangeListener> getChangeListeners(DN dn);
165
166}