*/
public void setOid( String oid ) throws DecoderException
{
if ( ( oid == null ) || ( oid.length() == 0 ) )
{
throw new DecoderException( I18n.err( I18n.ERR_00032_NULL_OID ) );
}
int nbValues = 1;
char[] chars = oid.toCharArray();
boolean dotSeen = false;
// Count the number of int to allocate.
for ( char c : chars )
{
if ( c == '.' )
{
if ( dotSeen )
{
// Two dots, that's an error !
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
nbValues++;
dotSeen = true;
}
else
{
dotSeen = false;
}
}
// We must have at least 2 ints
if ( nbValues < 2 )
{
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
oidValues = new long[nbValues];
int pos = 0;
int intPos = 0;
// This flag is used to forbid a second value above 39 if the
// first value is 0 or 1 (itu_t or iso arcs)
boolean ituOrIso = false;
// The first value
switch ( chars[pos] )
{
case '0': // itu-t
case '1': // iso
case '2': // joint-iso-itu-t
ituOrIso = true;
oidValues[intPos++] = chars[pos++] - '0';
break;
default: // error, this value is not allowed
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
// We must have a dot
if ( chars[pos++] != '.' )
{
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
dotSeen = true;
int value = 0;
for ( int i = pos; i < chars.length; i++ )
{
if ( chars[i] == '.' )
{
if ( dotSeen )
{
// Two dots, that's an error !
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
if ( ituOrIso && ( value > 39 ) )
{
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
else
{
ituOrIso = false;
}
nbValues++;
dotSeen = true;
oidValues[intPos++] = value;
value = 0;
}
else if ( ( chars[i] >= 0x30 ) && ( chars[i] <= 0x39 ) )
{
dotSeen = false;
value = ( ( value * 10 ) + chars[i] ) - '0';
}
else
{
// We don't have a number, this is an error
throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, oid ) );
}
}
oidValues[intPos] = value;
hash = computeHashCode();