1 22 23 package de.laures.cewolf.taglib.util; 24 25 import java.io.IOException ; 26 import java.io.Serializable ; 27 import java.rmi.MarshalledObject ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 35 public abstract class KeyGenerator { 36 37 private static final Log log = LogFactory.getLog(KeyGenerator.class); 38 39 private static class NoKeyException extends RuntimeException { 40 public NoKeyException(String msg){ 41 super(msg); 42 } 43 } 44 45 public static int generateKey(Serializable obj) { 46 if (obj == null) { 47 NoKeyException ex = new NoKeyException("assertion failed: can not generate key for null,"); 48 throw ex; 49 } 50 try { 51 MarshalledObject mo = new MarshalledObject (obj); 52 return mo.hashCode(); 53 } catch (IOException ioex) { 54 log.error("IOException during key generation KeyGenerator.generateKey()", ioex); 55 throw new NoKeyException(obj + " is not serializable."); 56 } 57 } 58 } 59 | Popular Tags |