| | |
| | | import static com.sun.opends.sdk.messages.Messages.*; |
| | | import static com.sun.opends.sdk.util.StaticUtils.*; |
| | | |
| | | import java.util.Comparator; |
| | | |
| | | import org.opends.sdk.schema.*; |
| | | |
| | | import com.sun.opends.sdk.util.StaticUtils; |
| | |
| | | } |
| | | catch (final UnknownSchemaElementException e) |
| | | { |
| | | final LocalizableMessage message = ERR_RDN_TYPE_NOT_FOUND.get(ava, e |
| | | .getMessageObject()); |
| | | final LocalizableMessage message = ERR_RDN_TYPE_NOT_FOUND.get(ava, |
| | | e.getMessageObject()); |
| | | throw new LocalizedIllegalArgumentException(message); |
| | | } |
| | | } |
| | |
| | | char c; |
| | | if ((c = reader.read()) != '=') |
| | | { |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_DN_NO_EQUAL.get(reader |
| | | .getString(), attribute.getNameOrOID(), c); |
| | | final LocalizableMessage message = ERR_ATTR_SYNTAX_DN_NO_EQUAL.get( |
| | | reader.getString(), attribute.getNameOrOID(), c); |
| | | throw new LocalizedIllegalArgumentException(message); |
| | | } |
| | | |
| | |
| | | |
| | | private final ByteString attributeValue; |
| | | |
| | | // Cached normalized value using equality matching rule. |
| | | private ByteString equalityNormalizedAttributeValue = null; |
| | | |
| | | // Cached normalized value using ordering matching rule. |
| | | private ByteString orderingNormalizedAttributeValue = null; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | * @param attributeValue |
| | | * The attribute value. |
| | | * @throws NullPointerException |
| | | * If {@code attributeType} or {@code attributeValue} was {@code |
| | | * null}. |
| | | * If {@code attributeType} or {@code attributeValue} was |
| | | * {@code null}. |
| | | */ |
| | | public AVA(final AttributeType attributeType, final ByteString attributeValue) |
| | | throws NullPointerException |
| | |
| | | * @throws UnknownSchemaElementException |
| | | * If {@code attributeType} was not found in the default schema. |
| | | * @throws NullPointerException |
| | | * If {@code attributeType} or {@code attributeValue} was {@code |
| | | * null}. |
| | | * If {@code attributeType} or {@code attributeValue} was |
| | | * {@code null}. |
| | | */ |
| | | public AVA(final String attributeType, final Object attributeValue) |
| | | throws UnknownSchemaElementException, NullPointerException |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int compareTo(final AVA ava) |
| | | { |
| | | int result = attributeType.compareTo(ava.attributeType); |
| | | final int result = attributeType.compareTo(ava.attributeType); |
| | | if (result != 0) |
| | | { |
| | | return result > 0 ? 1 : -1; |
| | | } |
| | | final ByteString normalizedValue = getNormalizeValue(); |
| | | |
| | | final ByteString normalizedValue = getOrderingNormalizedValue(); |
| | | final ByteString otherNormalizedValue = ava.getOrderingNormalizedValue(); |
| | | final MatchingRule rule = attributeType.getOrderingMatchingRule(); |
| | | try |
| | | if (rule != null) |
| | | { |
| | | if (rule != null) |
| | | { |
| | | // Check equality assertion first. |
| | | final Assertion lteAssertion = rule |
| | | .getLessOrEqualAssertion(ava.attributeValue); |
| | | final ConditionResult lteResult = lteAssertion.matches(normalizedValue); |
| | | final Assertion gteAssertion = rule |
| | | .getGreaterOrEqualAssertion(ava.attributeValue); |
| | | final ConditionResult gteResult = gteAssertion.matches(normalizedValue); |
| | | |
| | | if (lteResult.equals(gteResult)) |
| | | { |
| | | // it is equal to the assertion value. |
| | | return 0; |
| | | } |
| | | else if (lteResult == ConditionResult.TRUE) |
| | | { |
| | | return -1; |
| | | } |
| | | else |
| | | { |
| | | return 1; |
| | | } |
| | | } |
| | | final Comparator<ByteSequence> comparator = rule.comparator(); |
| | | return comparator.compare(normalizedValue, otherNormalizedValue); |
| | | } |
| | | catch (final DecodeException de) |
| | | else |
| | | { |
| | | // use the bytestring comparison as default. |
| | | return normalizedValue.compareTo(otherNormalizedValue); |
| | | } |
| | | |
| | | if (result == 0) |
| | | { |
| | | final ByteString nv1 = normalizedValue; |
| | | final ByteString nv2 = ava.getNormalizeValue(); |
| | | result = nv1.compareTo(nv2); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | else if (obj instanceof AVA) |
| | | { |
| | | return compareTo((AVA) obj) == 0; |
| | | final AVA ava = (AVA) obj; |
| | | |
| | | if (!attributeType.equals(ava.attributeType)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | final ByteString normalizedValue = getEqualityNormalizedValue(); |
| | | final ByteString otherNormalizedValue = ava.getEqualityNormalizedValue(); |
| | | final MatchingRule rule = attributeType.getEqualityMatchingRule(); |
| | | if (rule != null) |
| | | { |
| | | final Comparator<ByteSequence> comparator = rule.comparator(); |
| | | return comparator.compare(normalizedValue, otherNormalizedValue) != 0 ? false |
| | | : true; |
| | | } |
| | | else |
| | | { |
| | | return normalizedValue.equals(otherNormalizedValue); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | | return attributeType.hashCode() * 31 + getNormalizeValue().hashCode(); |
| | | return attributeType.hashCode() * 31 |
| | | + getEqualityNormalizedValue().hashCode(); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private ByteString getNormalizeValue() |
| | | { |
| | | final MatchingRule matchingRule = attributeType.getEqualityMatchingRule(); |
| | | if (matchingRule != null) |
| | | { |
| | | try |
| | | { |
| | | return matchingRule.normalizeAttributeValue(attributeValue); |
| | | } |
| | | catch (final DecodeException de) |
| | | { |
| | | // Ignore - we'll drop back to the user provided value. |
| | | } |
| | | } |
| | | return attributeValue; |
| | | } |
| | | |
| | | |
| | | |
| | | StringBuilder toString(final StringBuilder builder) |
| | | { |
| | | if (!attributeType.getNames().iterator().hasNext()) |
| | |
| | | } |
| | | return builder; |
| | | } |
| | | |
| | | |
| | | |
| | | private ByteString getEqualityNormalizedValue() |
| | | { |
| | | final ByteString normalizedValue = equalityNormalizedAttributeValue; |
| | | |
| | | if (normalizedValue != null) |
| | | { |
| | | return normalizedValue; |
| | | } |
| | | |
| | | final MatchingRule matchingRule = attributeType.getEqualityMatchingRule(); |
| | | if (matchingRule != null) |
| | | { |
| | | try |
| | | { |
| | | equalityNormalizedAttributeValue = matchingRule |
| | | .normalizeAttributeValue(attributeValue); |
| | | } |
| | | catch (final DecodeException de) |
| | | { |
| | | // Unable to normalize, so default to byte-wise comparison. |
| | | equalityNormalizedAttributeValue = attributeValue; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // No matching rule, so default to byte-wise comparison. |
| | | equalityNormalizedAttributeValue = attributeValue; |
| | | } |
| | | |
| | | return equalityNormalizedAttributeValue; |
| | | } |
| | | |
| | | |
| | | |
| | | private ByteString getOrderingNormalizedValue() |
| | | { |
| | | final ByteString normalizedValue = orderingNormalizedAttributeValue; |
| | | |
| | | if (normalizedValue != null) |
| | | { |
| | | return normalizedValue; |
| | | } |
| | | |
| | | final MatchingRule matchingRule = attributeType.getEqualityMatchingRule(); |
| | | if (matchingRule != null) |
| | | { |
| | | try |
| | | { |
| | | orderingNormalizedAttributeValue = matchingRule |
| | | .normalizeAttributeValue(attributeValue); |
| | | } |
| | | catch (final DecodeException de) |
| | | { |
| | | // Unable to normalize, so default to equality matching. |
| | | orderingNormalizedAttributeValue = getEqualityNormalizedValue(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // No matching rule, so default to equality matching. |
| | | orderingNormalizedAttributeValue = getEqualityNormalizedValue(); |
| | | } |
| | | |
| | | return orderingNormalizedAttributeValue; |
| | | } |
| | | } |