package org.commcare.util.externalizable;

import org.javarosa.core.util.externalizable.Hasher;
import org.javarosa.core.util.externalizable.PrototypeFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author ctsims
 */
public class AndroidClassHasher extends Hasher {

    private static final int CLASS_HASH_SIZE = 4;

    MessageDigest mMessageDigester;
    
    public AndroidClassHasher() {
        try {
            mMessageDigester = java.security.MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    public static void registerAndroidClassHashStrategy() {
        PrototypeFactory.setStaticHasher(new AndroidClassHasher());
    }

    public byte[] getHash(Class c){
        byte[] ret;
        synchronized(mMessageDigester) {
            ret = mMessageDigester.digest(c.getName().getBytes());
        }
        return ret;
    }


    @Override
    public int getHashSize(){
        return CLASS_HASH_SIZE;
    }


}

@@ -368,16 +368,30 @@
 4;%0A%0A    
+private final 
 MessageD
@@ -414,16 +414,16 @@
 gester;%0A
-
     %0A   
@@ -609,73 +609,36 @@
     
-// TODO Auto-generated catch block%0A            e.printStackTrace(
+throw new RuntimeException(e
 );%0A 
@@ -993,17 +993,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove
@@ -1073,14 +1073,12 @@
 ZE;%0A
+
     %7D%0A
-%0A%0A
 %7D%0A

Raise runtime exception on unfound hasher method