| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.opends.server.api; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.opends.server.core.*; |
| | | import org.opends.server.monitors.BackendMonitor; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.BackupConfig; |
| | | import org.opends.server.types.BackupDirectory; |
| | | import org.opends.server.types.CanceledOperationException; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.IndexType; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LDIFExportConfig; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.LDIFImportResult; |
| | | import org.opends.server.types.RestoreConfig; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.WritabilityMode; |
| | | import org.opends.server.types.ConditionResult; |
| | | import org.opends.server.types.*; |
| | | |
| | | import static org.opends.messages.BackendMessages.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines the set of methods and structures that must be |
| | | * implemented for a Directory Server backend. |
| | | * |
| | | * @param <C> |
| | | * the type of the BackendCfg for the current backend |
| | | */ |
| | | @org.opends.server.types.PublicAPI( |
| | | stability=org.opends.server.types.StabilityLevel.VOLATILE, |
| | | mayInstantiate=false, |
| | | mayExtend=true, |
| | | mayInvoke=false) |
| | | public abstract class Backend |
| | | public abstract class Backend<C extends Configuration> |
| | | // should have been BackendCfg instead of Configuration |
| | | { |
| | | // The backend that holds a portion of the DIT that is |
| | | // hierarchically above the information in this backend. |
| | | private Backend parentBackend; |
| | | /** |
| | | * The backend that holds a portion of the DIT that is hierarchically above |
| | | * the information in this backend. |
| | | */ |
| | | private Backend<?> parentBackend; |
| | | |
| | | // The set of backends that hold portions of the DIT that are |
| | | // hierarchically below the information in this backend. |
| | | private Backend[] subordinateBackends; |
| | | /** |
| | | * The set of backends that hold portions of the DIT that are hierarchically |
| | | * below the information in this backend. |
| | | */ |
| | | private Backend<?>[] subordinateBackends; |
| | | |
| | | // The backend monitor associated with this backend. |
| | | /** The backend monitor associated with this backend. */ |
| | | private BackendMonitor backendMonitor; |
| | | |
| | | // Indicates whether this is a private backend or one that holds |
| | | // user data. |
| | | /** |
| | | * Indicates whether this is a private backend or one that holds user data. |
| | | */ |
| | | private boolean isPrivateBackend; |
| | | |
| | | // The unique identifier for this backend. |
| | | /** The unique identifier for this backend. */ |
| | | private String backendID; |
| | | |
| | | // The writability mode for this backend. |
| | | /** The writability mode for this backend. */ |
| | | private WritabilityMode writabilityMode; |
| | | |
| | | |
| | |
| | | * @throws ConfigException |
| | | * If there is an error in the configuration. |
| | | */ |
| | | public abstract void configureBackend(Configuration cfg) |
| | | throws ConfigException; |
| | | public abstract void configureBackend(C cfg) throws ConfigException; |
| | | |
| | | |
| | | |
| | |
| | | * for this backend, or {@code false} if not. |
| | | */ |
| | | public boolean isConfigurationAcceptable( |
| | | Configuration configuration, |
| | | C configuration, |
| | | List<Message> unacceptableReasons) |
| | | { |
| | | // This default implementation does not perform any special |
| | |
| | | return false; |
| | | } |
| | | } |
| | | return (! filter.getFilterComponents().isEmpty()); |
| | | return !filter.getFilterComponents().isEmpty(); |
| | | |
| | | |
| | | case NOT: |
| | |
| | | { |
| | | matchingRule = attrType.getEqualityMatchingRule(); |
| | | } |
| | | |
| | | if (matchingRule == null) |
| | | { |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | return isIndexed(attrType, matchingRule); |
| | | } |
| | | return matchingRule != null && isIndexed(attrType, matchingRule); |
| | | |
| | | |
| | | default: |
| | |
| | | public boolean entryExists(DN entryDN) |
| | | throws DirectoryException |
| | | { |
| | | return (getEntry(entryDN) != null); |
| | | return getEntry(entryDN) != null; |
| | | } |
| | | |
| | | |
| | |
| | | public final boolean supportsControl(String controlOID) |
| | | { |
| | | Set<String> supportedControls = getSupportedControls(); |
| | | return ((supportedControls != null) && |
| | | supportedControls.contains(controlOID)); |
| | | return supportedControls != null && supportedControls.contains(controlOID); |
| | | } |
| | | |
| | | |
| | |
| | | public final boolean supportsFeature(String featureOID) |
| | | { |
| | | Set<String> supportedFeatures = getSupportedFeatures(); |
| | | return ((supportedFeatures != null) && |
| | | supportedFeatures.contains(featureOID)); |
| | | return supportedFeatures != null && supportedFeatures.contains(featureOID); |
| | | } |
| | | |
| | | |
| | |
| | | * @return The parent backend for this backend, or {@code null} if |
| | | * there is none. |
| | | */ |
| | | public final Backend getParentBackend() |
| | | public final Backend<?> getParentBackend() |
| | | { |
| | | return parentBackend; |
| | | } |
| | |
| | | * |
| | | * @param parentBackend The parent backend for this backend. |
| | | */ |
| | | public final void setParentBackend(Backend parentBackend) |
| | | public final void setParentBackend(Backend<?> parentBackend) |
| | | { |
| | | synchronized (this) |
| | | { |
| | |
| | | * @return The set of subordinate backends for this backend, or an |
| | | * empty array if none exist. |
| | | */ |
| | | public final Backend[] getSubordinateBackends() |
| | | public final Backend<?>[] getSubordinateBackends() |
| | | { |
| | | return subordinateBackends; |
| | | } |
| | |
| | | * this backend. |
| | | */ |
| | | public final void setSubordinateBackends( |
| | | Backend[] subordinateBackends) |
| | | Backend<?>[] subordinateBackends) |
| | | { |
| | | synchronized (this) |
| | | { |
| | |
| | | */ |
| | | public final boolean hasSubSuffix(DN subSuffixDN) |
| | | { |
| | | Backend[] subBackends = subordinateBackends; |
| | | for (Backend b : subBackends) |
| | | for (Backend<?> b : subordinateBackends) |
| | | { |
| | | for (DN baseDN : b.getBaseDNs()) |
| | | { |
| | |
| | | synchronized (this) |
| | | { |
| | | boolean matchFound = false; |
| | | ArrayList<Backend> subBackendList = |
| | | new ArrayList<Backend>(subordinateBackends.length); |
| | | for (Backend b : subordinateBackends) |
| | | ArrayList<Backend<?>> subBackendList = |
| | | new ArrayList<Backend<?>>(subordinateBackends.length); |
| | | for (Backend<?> b : subordinateBackends) |
| | | { |
| | | boolean thisMatches = false; |
| | | DN[] subBaseDNs = b.getBaseDNs(); |
| | |
| | | |
| | | if (matchFound) |
| | | { |
| | | Backend[] newSubordinateBackends = |
| | | Backend<?>[] newSubordinateBackends = |
| | | new Backend[subBackendList.size()]; |
| | | subBackendList.toArray(newSubordinateBackends); |
| | | subordinateBackends = newSubordinateBackends; |
| | |
| | | * subordinate backends for this |
| | | * backend. |
| | | */ |
| | | public final void addSubordinateBackend(Backend subordinateBackend) |
| | | public final void addSubordinateBackend(Backend<?> subordinateBackend) |
| | | { |
| | | synchronized (this) |
| | | { |
| | | LinkedHashSet<Backend> backendSet = |
| | | new LinkedHashSet<Backend>(); |
| | | LinkedHashSet<Backend<?>> backendSet = new LinkedHashSet<Backend<?>>(); |
| | | |
| | | for (Backend b : subordinateBackends) |
| | | for (Backend<?> b : subordinateBackends) |
| | | { |
| | | backendSet.add(b); |
| | | } |
| | | |
| | | if (backendSet.add(subordinateBackend)) |
| | | { |
| | | Backend[] newSubordinateBackends = |
| | | Backend<?>[] newSubordinateBackends = |
| | | new Backend[backendSet.size()]; |
| | | backendSet.toArray(newSubordinateBackends); |
| | | subordinateBackends = newSubordinateBackends; |
| | |
| | | * backend. |
| | | */ |
| | | public final void removeSubordinateBackend( |
| | | Backend subordinateBackend) |
| | | Backend<?> subordinateBackend) |
| | | { |
| | | synchronized (this) |
| | | { |
| | | ArrayList<Backend> backendList = |
| | | new ArrayList<Backend>(subordinateBackends.length); |
| | | ArrayList<Backend<?>> backendList = |
| | | new ArrayList<Backend<?>>(subordinateBackends.length); |
| | | |
| | | boolean found = false; |
| | | for (Backend b : subordinateBackends) |
| | | for (Backend<?> b : subordinateBackends) |
| | | { |
| | | if (b.equals(subordinateBackend)) |
| | | { |
| | |
| | | |
| | | if (found) |
| | | { |
| | | Backend[] newSubordinateBackends = |
| | | Backend<?>[] newSubordinateBackends = |
| | | new Backend[backendList.size()]; |
| | | backendList.toArray(newSubordinateBackends); |
| | | subordinateBackends = newSubordinateBackends; |
| | |
| | | */ |
| | | public final boolean handlesEntry(DN entryDN) |
| | | { |
| | | DN[] baseDNs = getBaseDNs(); |
| | | for (DN dn : baseDNs) |
| | | for (DN dn : getBaseDNs()) |
| | | { |
| | | if (entryDN.isDescendantOf(dn)) |
| | | { |
| | | Backend[] subBackends = subordinateBackends; |
| | | for (Backend b : subBackends) |
| | | for (Backend<?> b : subordinateBackends) |
| | | { |
| | | if (b.handlesEntry(entryDN)) |
| | | { |
| | |
| | | { |
| | | if (entryDN.isDescendantOf(baseDN)) |
| | | { |
| | | if ((excludeDNs == null) || excludeDNs.isEmpty()) |
| | | if (excludeDNs == null || excludeDNs.isEmpty()) |
| | | { |
| | | return true; |
| | | } |