type = reader.peekType();
}
catch(Exception e)
{
// TODO: Need a better message.
Message message =
ERR_MVFILTER_INVALID_ELEMENT_TYPE.get(e.toString());
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message);
}
switch (type)
{
case EQUALITY_MATCH_TYPE:
case GREATER_OR_EQUAL_TYPE:
case LESS_OR_EQUAL_TYPE:
case APPROXIMATE_MATCH_TYPE:
// These will all be decoded in the same manner. The element must be a
// sequence consisting of the attribute type and assertion value.
try
{
reader.readStartSequence();
String rawAttributeType = reader.readOctetStringAsString();
ByteString rawAssertionValue = reader.readOctetString();
reader.readEndSequence();
return new MatchedValuesFilter(type, rawAttributeType,
rawAssertionValue, null, null, null, null);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message =
ERR_MVFILTER_CANNOT_DECODE_AVA.get(getExceptionMessage(e));
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message,
e);
}
case SUBSTRINGS_TYPE:
// This must be a sequence of two elements, where the second is a
// sequence of substring types.
try
{
reader.readStartSequence();
String rawAttributeType = reader.readOctetStringAsString();
reader.readStartSequence();
if(!reader.hasNextElement())
{
Message message = ERR_MVFILTER_NO_SUBSTRING_ELEMENTS.get();
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message);
}
ByteString subInitial = null;
ArrayList<ByteString> subAny = null;
ByteString subFinal = null;
if(reader.hasNextElement() &&
reader.peekType() == TYPE_SUBINITIAL)
{
subInitial = reader.readOctetString();
}
while(reader.hasNextElement() &&
reader.peekType() == TYPE_SUBANY)
{
if(subAny == null)
{
subAny = new ArrayList<ByteString>();
}
subAny.add(reader.readOctetString());
}
if(reader.hasNextElement() &&
reader.peekType() == TYPE_SUBFINAL)
{
subFinal = reader.readOctetString();
}
reader.readEndSequence();
reader.readEndSequence();
return new MatchedValuesFilter(type, rawAttributeType,
null, subInitial, subAny, subFinal,
null);
}
catch (LDAPException le)
{
throw le;
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message =
ERR_MVFILTER_CANNOT_DECODE_SUBSTRINGS.get(getExceptionMessage(e));
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message,
e);
}
case PRESENT_TYPE:
// The element must be an ASN.1 octet string holding the attribute type.
try
{
String rawAttributeType = reader.readOctetStringAsString();
return new MatchedValuesFilter(type, rawAttributeType,
null, null, null, null, null);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_MVFILTER_CANNOT_DECODE_PRESENT_TYPE.get(
getExceptionMessage(e));
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message,
e);
}
case EXTENSIBLE_MATCH_TYPE:
// This must be a two or three element sequence with an assertion value
// as the last element and an attribute type and/or matching rule ID as
// the first element(s).
try
{
reader.readStartSequence();
String rawAttributeType = null;
String matchingRuleID = null;
ByteString rawAssertionValue;
if(reader.peekType() == TYPE_MATCHING_RULE_ID)
{
matchingRuleID = reader.readOctetStringAsString();
}
if(matchingRuleID == null ||
reader.peekType() == TYPE_MATCHING_RULE_TYPE)
{
rawAttributeType = reader.readOctetStringAsString();
}
rawAssertionValue = reader.readOctetString();
reader.readEndSequence();
return new MatchedValuesFilter(type, rawAttributeType,
rawAssertionValue, null, null, null,
matchingRuleID);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_MVFILTER_CANNOT_DECODE_EXTENSIBLE_MATCH.get(
getExceptionMessage(e));
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message,
e);
}
default:
Message message =
ERR_MVFILTER_INVALID_ELEMENT_TYPE.get(byteToHex(type));
throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message);
}
}