directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@gmail.com>
Subject Re: [DAS] Generating OIDs
Date Fri, 13 Apr 2007 22:37:44 GMT
Ole Ersoy a écrit :

> Hey Guys,
>
> I've been experimenting with Alex's (Checksum) and Emmanuel's (Hashcode)
> OID generation suggestions.
> <snip>
> Then there's Emmanuel's way which works like this:
>
> String[] test = "org.apache.tuscany.das.ldap.DASConfig".split( "[.]" );
> String final  = "";
> for (int i=0;i<test.length;i++)
> {
>    String hash = StringUtils.replace(test[i], "-", "1");
>    //We replace "-" with "1".
>    final = final + hash;
> }
>
> This will give the id:
>
> 1103081141151710619648937659922233166471638106712
>
> I'd probably go with this one since it's simpler to just replace
> a "-" than letters...
>
> Thoughts?

This is not what I suggested. Did you read my mails carefully ?

I said that you should :
- have unique OIDs
- use the String structure to generate the oid
- and to avoid insanely long oids, use a hascode of each part of the 
string to generate an oid

Something like :
    private static String getOid( String prefix, String param )
    {
        StringTokenizer tokens = new StringTokenizer( param, "." );
        StringBuilder oid  = new StringBuilder( prefix );
       
        while ( tokens.hasMoreElements() )
        {
            oid.append( '.' ).append( Math.abs( 
tokens.nextElement().hashCode() ) );
        }
       
        return oid.toString();
    }

When you call it with :
getOid( "1.3.6.1.4.1.18060.0.4.100.2", 
"org.apache.tuscany.das.ldap.DASConfig" )

you get this OID :
1.3.6.1.4.1.18060.0.4.100.2.110308.1411517106.964893765.99222.3316647.1638106712

where
org -> 110308
apache -> 1411517106
tuscany -> 964893765
das -> 99222
ldap -> 3316647
DASConfig -> 1638106712

Alex suggestion was more straight forward : simply compute a checksum 
from the whome string, but keeping the result into an int ( values 
longer than an int won't be accepted by the server). In fact, more or 
les a hashcode of the string (absolute value of the hashcode to avoid 
negative number).

Keep it simple, buddy !

Emmanuel


Mime
View raw message