1 23 24 29 30 package com.sun.jdo.api.persistence.mapping.ejb; 31 32 import java.util.*; 33 34 42 abstract public class AbstractNameMapper { 43 public static final int USER_DEFINED_KEY_CLASS = 1; 44 public static final int PRIMARY_KEY_FIELD = 2; 45 public static final int UNKNOWN_KEY_CLASS = 3; 46 47 48 public static final String GENERATED_KEY_FIELD_NAME = "generatedPKField"; 50 public static final String GENERATED_VERSION_FIELD_PREFIX = 51 "thisVersionFieldWasGeneratedByTheNameMapper"; protected static final String GENERATED_CMR_FIELD_PREFIX = 53 "thisRelationshipFieldWasGeneratedByTheNameMapper"; 55 abstract protected Map getGeneratedFieldsMap(); 56 57 abstract protected Map getInverseFieldsMap(); 58 59 64 abstract public boolean isEjbName(String name); 65 66 71 abstract public String getAbstractBeanClassForEjbName(String name); 72 73 78 abstract public String getKeyClassForEjbName(String name); 79 80 86 public String getKeyClassForPersistenceKeyClass(String className) { 87 String ejbName = getEjbNameForPersistenceKeyClass(className); 88 89 return ((ejbName != null) ? getKeyClassForEjbName(ejbName) : null); 90 } 91 92 100 public String getEjbNameForPersistenceKeyClass(String className) { 101 if (className.toUpperCase().endsWith("OID")) { return getEjbNameForPersistenceClass( 103 className.substring(0, className.length() - 4)); 104 } 105 106 return null; 107 } 108 109 113 abstract public int getKeyClassTypeForEjbName (String name); 114 115 120 abstract public String getAbstractSchemaForEjbName(String name); 121 122 127 abstract public String getEjbNameForPersistenceClass(String className); 128 129 134 abstract public String getPersistenceClassForEjbName(String name); 135 136 141 abstract public boolean isLocalInterface(String name); 142 143 154 public String getPersistenceClassForLocalInterface(String className, 155 String fieldName, String interfaceName) { 156 if (isLocalInterface(interfaceName)) { 157 String ejbName = getEjbNameForPersistenceClass(className); 158 String ejbField = 159 getEjbFieldForPersistenceField(className, fieldName); 160 161 return getPersistenceClassForEjbName( 162 getEjbNameForLocalInterface(ejbName, ejbField, interfaceName)); 163 } 164 165 return null; 166 } 167 168 176 abstract public String getEjbNameForLocalInterface(String ejbName, 177 String fieldName, String interfaceName); 178 179 184 abstract public String getLocalInterfaceForEjbName(String name); 185 186 191 abstract public boolean isRemoteInterface(String name); 192 193 204 public String getPersistenceClassForRemoteInterface( 205 String className, String fieldName, String interfaceName) { 206 if (isRemoteInterface(interfaceName)) { 207 String ejbName = getEjbNameForPersistenceClass(className); 208 String ejbField = 209 getEjbFieldForPersistenceField(className, fieldName); 210 211 return getPersistenceClassForEjbName( 212 getEjbNameForRemoteInterface(ejbName, ejbField, interfaceName)); 213 } 214 215 return null; 216 } 217 218 226 abstract public String getEjbNameForRemoteInterface(String ejbName, 227 String fieldName, String interfaceName); 228 229 234 abstract public String getRemoteInterfaceForEjbName(String name); 235 236 243 abstract public String getEjbFieldForPersistenceField(String className, 244 String fieldName); 245 246 253 abstract public String getPersistenceFieldForEjbField(String name, 254 String fieldName); 255 256 265 public boolean isGeneratedField(String name, String fieldName) { 266 return isGeneratedEjbRelationship(name, fieldName) || 267 fieldName.equals(GENERATED_KEY_FIELD_NAME) || 268 fieldName.startsWith(GENERATED_VERSION_FIELD_PREFIX); 269 } 270 271 281 public boolean isGeneratedEjbRelationship(String name, String fieldName) { 282 return getGeneratedFieldsMap().keySet().contains( 283 Arrays.asList(new String []{name, fieldName})); 284 } 285 286 290 public List getGeneratedRelationshipsForEjbName(String name) { 291 Map generatedFieldsMap = getGeneratedFieldsMap(); 292 Iterator iterator = generatedFieldsMap.keySet().iterator(); 293 List returnList = new ArrayList(); 294 295 while (iterator.hasNext()) { 296 List nextField = (List)iterator.next(); 297 298 if (nextField.get(0).equals(name)) 299 returnList.add(nextField.get(1)); 300 } 301 302 return returnList; 303 } 304 305 312 public String [] getGeneratedFieldForEjbField(String name, 313 String fieldName) { 314 List field = (List)getInverseFieldsMap().get( 315 Arrays.asList(new String []{name, fieldName})); 316 317 return ((field != null) ? 318 (String [])field.toArray(new String [2]) : null); 319 } 320 321 328 public String [] getEjbFieldForGeneratedField(String name, String fieldName) 329 { 330 List field = (List)getGeneratedFieldsMap().get( 331 Arrays.asList(new String []{name, fieldName})); 332 333 return ((field != null) ? 334 (String [])field.toArray(new String [2]) : null); 335 } 336 } 337 | Popular Tags |