| | |
| | | |
| | | |
| | | |
| | | import static com.sun.opends.sdk.util.StaticUtils.*; |
| | | import static com.sun.opends.sdk.util.StaticUtils.DEBUG_LOG; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | */ |
| | | public final class Matcher |
| | | { |
| | | private static class AndMatcherImpl extends MatcherImpl |
| | | private static final class AndMatcherImpl extends MatcherImpl |
| | | { |
| | | private final List<MatcherImpl> subMatchers; |
| | | |
| | | |
| | | |
| | | private AndMatcherImpl(List<MatcherImpl> subMatchers) |
| | | private AndMatcherImpl(final List<MatcherImpl> subMatchers) |
| | | { |
| | | this.subMatchers = subMatchers; |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | ConditionResult r = ConditionResult.TRUE; |
| | | for (final MatcherImpl m : subMatchers) |
| | |
| | | |
| | | |
| | | |
| | | private static class AssertionMatcherImpl extends MatcherImpl |
| | | private static final class AssertionMatcherImpl extends MatcherImpl |
| | | { |
| | | private final Assertion assertion; |
| | | |
| | |
| | | |
| | | |
| | | private AssertionMatcherImpl( |
| | | AttributeDescription attributeDescription, MatchingRule rule, |
| | | MatchingRuleUse ruleUse, Assertion assertion, |
| | | boolean dnAttributes) |
| | | final AttributeDescription attributeDescription, |
| | | final MatchingRule rule, final MatchingRuleUse ruleUse, |
| | | final Assertion assertion, final boolean dnAttributes) |
| | | { |
| | | this.attributeDescription = attributeDescription; |
| | | this.rule = rule; |
| | |
| | | |
| | | |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | ConditionResult r = ConditionResult.FALSE; |
| | | if (attributeDescription != null) |
| | |
| | | // If the type field is absent and the matchingRule is present, |
| | | // the matchValue is compared against all attributes in an entry |
| | | // that support that matchingRule. |
| | | for (final Attribute a : entry.getAttributes()) |
| | | for (final Attribute a : entry.getAllAttributes()) |
| | | { |
| | | if (ruleUse.hasAttribute(a.getAttributeDescription() |
| | | .getAttributeType())) |
| | | { |
| | | final ConditionResult p = Matcher.matches(a, rule, |
| | | assertion); |
| | | final ConditionResult p = Matcher.matches(a, rule, assertion); |
| | | if (p == ConditionResult.TRUE) |
| | | { |
| | | return p; |
| | |
| | | final DN dn = entry.getName(); |
| | | for (final RDN rdn : dn) |
| | | { |
| | | for (final RDN.AVA ava : rdn) |
| | | for (final AVA ava : rdn) |
| | | { |
| | | if (ruleUse.hasAttribute(ava.getAttributeType())) |
| | | { |
| | | final ConditionResult p = Matcher.matches(ava |
| | | .getAttributeValue(), rule, assertion); |
| | | final ConditionResult p = Matcher.matches( |
| | | ava.getAttributeValue(), rule, assertion); |
| | | if (p == ConditionResult.TRUE) |
| | | { |
| | | return p; |
| | |
| | | private static class FalseMatcherImpl extends MatcherImpl |
| | | { |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return ConditionResult.FALSE; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | private static class NotMatcherImpl extends MatcherImpl |
| | | private static final class NotMatcherImpl extends MatcherImpl |
| | | { |
| | | private final MatcherImpl subFilter; |
| | | |
| | | |
| | | |
| | | private NotMatcherImpl(MatcherImpl subFilter) |
| | | private NotMatcherImpl(final MatcherImpl subFilter) |
| | | { |
| | | this.subFilter = subFilter; |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return ConditionResult.not(subFilter.matches(entry)); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | private static class OrMatcherImpl extends MatcherImpl |
| | | private static final class OrMatcherImpl extends MatcherImpl |
| | | { |
| | | private final List<MatcherImpl> subMatchers; |
| | | |
| | | |
| | | |
| | | private OrMatcherImpl(List<MatcherImpl> subMatchers) |
| | | private OrMatcherImpl(final List<MatcherImpl> subMatchers) |
| | | { |
| | | this.subMatchers = subMatchers; |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | ConditionResult r = ConditionResult.FALSE; |
| | | for (final MatcherImpl m : subMatchers) |
| | |
| | | |
| | | |
| | | |
| | | private static class PresentMatcherImpl extends MatcherImpl |
| | | private static final class PresentMatcherImpl extends MatcherImpl |
| | | { |
| | | private final AttributeDescription attribute; |
| | | |
| | | |
| | | |
| | | private PresentMatcherImpl(AttributeDescription attribute) |
| | | private PresentMatcherImpl(final AttributeDescription attribute) |
| | | { |
| | | this.attribute = attribute; |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return entry.getAttribute(attribute) == null ? ConditionResult.FALSE |
| | | : ConditionResult.TRUE; |
| | |
| | | private static class TrueMatcherImpl extends MatcherImpl |
| | | { |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return ConditionResult.TRUE; |
| | | } |
| | |
| | | private static class UndefinedMatcherImpl extends MatcherImpl |
| | | { |
| | | @Override |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | |
| | | private static final class Visitor implements |
| | | FilterVisitor<MatcherImpl, Schema> |
| | | { |
| | | public MatcherImpl visitAndFilter(Schema schema, |
| | | List<Filter> subFilters) |
| | | public MatcherImpl visitAndFilter(final Schema schema, |
| | | final List<Filter> subFilters) |
| | | { |
| | | if (subFilters.isEmpty()) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitApproxMatchFilter(Schema schema, |
| | | String attributeDescription, ByteString assertionValue) |
| | | public MatcherImpl visitApproxMatchFilter(final Schema schema, |
| | | final String attributeDescription, final ByteString assertionValue) |
| | | { |
| | | AttributeDescription ad; |
| | | MatchingRule rule; |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an approximate matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitEqualityMatchFilter(Schema schema, |
| | | String attributeDescription, ByteString assertionValue) |
| | | public MatcherImpl visitEqualityMatchFilter(final Schema schema, |
| | | final String attributeDescription, final ByteString assertionValue) |
| | | { |
| | | AttributeDescription ad; |
| | | MatchingRule rule; |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an equality matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitExtensibleMatchFilter(Schema schema, |
| | | String matchingRule, String attributeDescription, |
| | | ByteString assertionValue, boolean dnAttributes) |
| | | public MatcherImpl visitExtensibleMatchFilter(final Schema schema, |
| | | final String matchingRule, final String attributeDescription, |
| | | final ByteString assertionValue, final boolean dnAttributes) |
| | | { |
| | | AttributeDescription ad = null; |
| | | MatchingRule rule = null; |
| | |
| | | { |
| | | try |
| | | { |
| | | ad = AttributeDescription.valueOf(attributeDescription, |
| | | schema); |
| | | ad = AttributeDescription.valueOf(attributeDescription, schema); |
| | | } |
| | | catch (final LocalizedIllegalArgumentException e) |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an equality matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The matching rule " + matchingRule |
| | | + " is not valid for attribute type " |
| | | + attributeDescription); |
| | | + " is not valid for attribute type " + attributeDescription); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitGreaterOrEqualFilter(Schema schema, |
| | | String attributeDescription, ByteString assertionValue) |
| | | public MatcherImpl visitGreaterOrEqualFilter(final Schema schema, |
| | | final String attributeDescription, final ByteString assertionValue) |
| | | { |
| | | AttributeDescription ad; |
| | | MatchingRule rule; |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an ordering matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitLessOrEqualFilter(Schema schema, |
| | | String attributeDescription, ByteString assertionValue) |
| | | public MatcherImpl visitLessOrEqualFilter(final Schema schema, |
| | | final String attributeDescription, final ByteString assertionValue) |
| | | { |
| | | AttributeDescription ad; |
| | | MatchingRule rule; |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an ordering matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitNotFilter(Schema schema, Filter subFilter) |
| | | public MatcherImpl visitNotFilter(final Schema schema, |
| | | final Filter subFilter) |
| | | { |
| | | final MatcherImpl subMatcher = subFilter.accept(this, schema); |
| | | return new NotMatcherImpl(subMatcher); |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitOrFilter(Schema schema, |
| | | List<Filter> subFilters) |
| | | public MatcherImpl visitOrFilter(final Schema schema, |
| | | final List<Filter> subFilters) |
| | | { |
| | | if (subFilters.isEmpty()) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitPresentFilter(Schema schema, |
| | | String attributeDescription) |
| | | public MatcherImpl visitPresentFilter(final Schema schema, |
| | | final String attributeDescription) |
| | | { |
| | | AttributeDescription ad; |
| | | try |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitSubstringsFilter(Schema schema, |
| | | String attributeDescription, ByteString initialSubstring, |
| | | List<ByteString> anySubstrings, ByteString finalSubstring) |
| | | public MatcherImpl visitSubstringsFilter(final Schema schema, |
| | | final String attributeDescription, final ByteString initialSubstring, |
| | | final List<ByteString> anySubstrings, final ByteString finalSubstring) |
| | | { |
| | | AttributeDescription ad; |
| | | MatchingRule rule; |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("Attribute description " |
| | | + attributeDescription + " is not recognized: " |
| | | + e.toString()); |
| | | DEBUG_LOG.warning("Attribute description " + attributeDescription |
| | | + " is not recognized: " + e.toString()); |
| | | } |
| | | return UNDEFINED; |
| | | } |
| | |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute type " |
| | | + attributeDescription |
| | | DEBUG_LOG.warning("The attribute type " + attributeDescription |
| | | + " does not define an substring matching rule"); |
| | | } |
| | | return UNDEFINED; |
| | |
| | | |
| | | |
| | | |
| | | public MatcherImpl visitUnrecognizedFilter(Schema schema, |
| | | byte filterTag, ByteString filterBytes) |
| | | public MatcherImpl visitUnrecognizedFilter(final Schema schema, |
| | | final byte filterTag, final ByteString filterBytes) |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | private static ConditionResult matches(Attribute a, |
| | | MatchingRule rule, Assertion assertion) |
| | | private static ConditionResult matches(final Attribute a, |
| | | final MatchingRule rule, final Assertion assertion) |
| | | { |
| | | |
| | | ConditionResult r = ConditionResult.FALSE; |
| | |
| | | |
| | | |
| | | |
| | | private static ConditionResult matches(ByteString v, |
| | | MatchingRule rule, Assertion assertion) |
| | | private static ConditionResult matches(final ByteString v, |
| | | final MatchingRule rule, final Assertion assertion) |
| | | { |
| | | try |
| | | { |
| | | final ByteString normalizedValue = rule |
| | | .normalizeAttributeValue(v); |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(v); |
| | | return assertion.matches(normalizedValue); |
| | | } |
| | | catch (final DecodeException de) |
| | | { |
| | | if (DEBUG_LOG.isLoggable(Level.WARNING)) |
| | | { |
| | | DEBUG_LOG.warning("The attribute value " + v.toString() |
| | | + " is " + "invalid for matching rule " |
| | | + rule.getNameOrOID() + ". Possible schema error? : " |
| | | + de.toString()); |
| | | DEBUG_LOG.warning("The attribute value " + v.toString() + " is " |
| | | + "invalid for matching rule " + rule.getNameOrOID() |
| | | + ". Possible schema error? : " + de.toString()); |
| | | } |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | Matcher(Filter filter, Schema schema) |
| | | Matcher(final Filter filter, final Schema schema) |
| | | { |
| | | this.impl = filter.accept(VISITOR, schema); |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether this filter {@code Matcher} matches the provided |
| | | * {@code Entry}. |
| | | * Indicates whether this filter {@code Matcher} matches the provided {@code |
| | | * Entry}. |
| | | * |
| | | * @param entry |
| | | * The entry to be matched. |
| | | * @return {@code true} if this filter {@code Matcher} matches the |
| | | * provided {@code Entry}. |
| | | * @return {@code true} if this filter {@code Matcher} matches the provided |
| | | * {@code Entry}. |
| | | */ |
| | | public ConditionResult matches(Entry entry) |
| | | public ConditionResult matches(final Entry entry) |
| | | { |
| | | return impl.matches(entry); |
| | | } |