/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2006-2007 Sun Microsystems, Inc. */ package org.opends.server.core; import org.opends.messages.Message; import static org.opends.messages.SchemaMessages.*; import java.util.HashSet; import java.util.InputMismatchException; import java.util.NoSuchElementException; import org.opends.server.types.DirectoryException; import org.opends.server.types.DN; import org.opends.server.types.Entry; import org.opends.server.types.ResultCode; import org.opends.server.types.SearchFilter; import org.opends.server.util.StaticUtils; /** * An absolute subtree specification. *
* Absolute subtree specifications are based on RFC 3672 subtree * specifications but have the following differences: *
* The string representation of an absolute subtree specification is * defined by the following grammar: * *
* SubtreeSpecification = "{" sp ss-absolute-base
* [ sep sp ss-specificExclusions ]
* [ sep sp ss-minimum ]
* [ sep sp ss-maximum ]
* [ sep sp ss-specificationFilter ]
* sp "}"
*
* ss-absolute-base = "absoluteBase" msp DistinguishedName
*
* ss-specificExclusions = "specificExclusions"
* msp SpecificExclusions
*
* ss-minimum = "minimum" msp BaseDistance
*
* ss-maximum = "maximum" msp BaseDistance
*
* ss-specificationFilter = "specificationFilter" msp Filter
*
* SpecificExclusions = "{"
* [ sp SpecificExclusion
* ( "," sp SpecificExclusion ) ]
* sp "}"
*
* SpecificExclusion = chopBefore / chopAfter
*
* chopBefore = "chopBefore" ":" LocalName
*
* chopAfter = "chopAfter" ":" LocalName
*
* Filter = dquote *SafeUTF8Character dquote
*
*/
public final class AbsoluteSubtreeSpecification extends
SimpleSubtreeSpecification {
// The optional search filter.
private SearchFilter filter;
/**
* Parses the string argument as an absolute subtree specification.
*
* The parser is very lenient regarding the ordering of the various
* subtree specification fields. However, it will not except multiple
* occurrances of a particular field.
*
* @param s
* The string to be parsed.
* @return The absolute subtree specification represented by the
* string argument.
* @throws DirectoryException
* If the string does not contain a parsable absolute
* subtree specification.
*/
public static AbsoluteSubtreeSpecification valueOf(String s)
throws DirectoryException {
// Default values.
DN absoluteBaseDN = null;
int minimum = -1;
int maximum = -1;
HashSetnull if there are none.
* @param chopAfter
* The set of chop after local names (relative to the base
* DN), or null if there are none.
* @param filter
* The optional search filter (null if there
* is no filter).
*/
public AbsoluteSubtreeSpecification(DN absoluteBaseDN, int minimumDepth,
int maximumDepth, Iterablenull if there
* is no filter.
*/
public SearchFilter getFilter() {
return filter;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isWithinScope(Entry entry) {
if (isDNWithinScope(entry.getDN())) {
try {
return filter.matchesEntry(entry);
} catch (DirectoryException e) {
// TODO: need to decide what to do with the exception here. It's
// probably safe to ignore, but we could log it perhaps.
return false;
}
} else {
return false;
}
}
/**
* {@inheritDoc}
*/
@Override
public StringBuilder toString(StringBuilder builder) {
builder.append("{ absoluteBase ");
StaticUtils.toRFC3641StringValue(builder, getBaseDN().toString());
Iterable