1 56 package org.objectstyle.cayenne.client; 57 58 import java.io.Serializable ; 59 import java.util.Map ; 60 61 67 public class ClientEntityResolver implements Serializable { 68 69 protected Map entityNameByClientClass; 70 71 public ClientEntityResolver(Map entityNameByClientClass) { 72 this.entityNameByClientClass = entityNameByClientClass; 73 } 74 75 81 public String lookupEntity(Class objectClass) { 82 if (objectClass == null) { 83 throw new CayenneClientException("Null object class."); 84 } 85 86 String entity = doLookupEntity(objectClass); 87 88 if (entity == null) { 89 throw new CayenneClientException("Unmapped class hierarchy: " + objectClass); 90 } 91 return entity; 92 } 93 94 protected String doLookupEntity(Class objectClass) { 95 if (objectClass == null) { 96 return null; 97 } 98 99 String entity = (String ) entityNameByClientClass.get(objectClass.getName()); 100 return (entity != null) ? entity : doLookupEntity(objectClass.getSuperclass()); 101 } 102 } 103 | Popular Tags |