1 23 24 29 30 package com.sun.jdo.spi.persistence.support.ejb.ejbc; 31 32 import java.util.*; 33 34 import com.sun.enterprise.deployment.*; 35 36 import com.sun.enterprise.deployment.EjbBundleDescriptor; 37 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor; 38 39 import com.sun.jdo.spi.persistence.utility.StringHelper; 40 import com.sun.jdo.spi.persistence.utility.JavaTypeHelper; 41 42 50 public class NameMapper extends 51 com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper 52 { 53 private static String EJB_NAME = "EJB_NAME"; private static String ABSTRACT_SCHEMA_NAME = "ABSTRACT_SCHEMA_NAME"; private static String PERSISTENCE_NAME = "PERSISTENCE_NAME"; private static String LOCAL_NAME = "LOCAL_NAME"; private static String REMOTE_NAME = "REMOTE_NAME"; 59 private final boolean _expandPCNames; 60 private Map _nameTypeToNameMap; 61 62 65 public static final String SIGNATURE = "$RCSfile: NameMapper.java,v $ $Revision: 1.2 $"; 67 71 public NameMapper (EjbBundleDescriptor bundleDescriptor) 72 { 73 this(bundleDescriptor, true); 74 } 75 76 82 public NameMapper (EjbBundleDescriptor bundleDescriptor, 83 boolean expandPersistenceClassNames) 84 { 85 super(bundleDescriptor); 86 _expandPCNames = expandPersistenceClassNames; 87 initMap(); 88 } 89 90 private void initMap () 91 { 92 Iterator iterator = getBundleDescriptor().getEjbs().iterator(); 93 Map ejbMap = new HashMap(); 94 Map persistenceClassMap = new HashMap(); 95 Set localNames = new HashSet(); 96 Set remoteNames = new HashSet(); 97 Map abstractSchemaMap = new HashMap(); 98 99 _nameTypeToNameMap = new HashMap(); 100 101 while (iterator.hasNext()) 102 { 103 Object next = iterator.next(); 104 105 if (next instanceof IASEjbCMPEntityDescriptor) 106 { 107 IASEjbCMPEntityDescriptor descriptor = 108 (IASEjbCMPEntityDescriptor)next; 109 String ejbName = descriptor.getName(); 110 111 ejbMap.put(ejbName, descriptor); 112 safePut(persistenceClassMap, 113 getPersistenceClassForDescriptor(descriptor), ejbName); 114 safeAdd(localNames, descriptor.getLocalClassName()); 115 safeAdd(remoteNames, descriptor.getRemoteClassName()); 116 safePut(abstractSchemaMap, 117 descriptor.getAbstractSchemaName(), ejbName); 118 } 119 } 120 _nameTypeToNameMap.put(EJB_NAME, ejbMap); 121 _nameTypeToNameMap.put(PERSISTENCE_NAME, persistenceClassMap); 122 _nameTypeToNameMap.put(LOCAL_NAME, localNames); 123 _nameTypeToNameMap.put(REMOTE_NAME, remoteNames); 124 _nameTypeToNameMap.put(ABSTRACT_SCHEMA_NAME, abstractSchemaMap); 125 } 126 127 private void safePut (Map map, Object key, Object value) 129 { 130 if ((key != null) && (map != null)) 131 map.put(key, value); 132 } 133 private void safeAdd (Set set, Object value) 135 { 136 if ((value != null) && (set != null)) 137 set.add(value); 138 } 139 140 private Map getMap () { return _nameTypeToNameMap; } 141 142 147 public boolean isEjbName (String name) 148 { 149 return mapContainsKey(EJB_NAME, name); 150 } 151 152 157 public EjbCMPEntityDescriptor getDescriptorForEjbName (String name) 158 { 159 Map ejbMap = (Map)getMap().get(EJB_NAME); 160 Object descriptor = ejbMap.get(name); 161 162 return (((descriptor != null) && 163 (descriptor instanceof EjbCMPEntityDescriptor)) ? 164 (EjbCMPEntityDescriptor)descriptor : null); 165 } 166 167 private IASEjbCMPEntityDescriptor getIASDescriptorForEjbName (String name) 168 { 169 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 170 171 return (((descriptor != null) && 172 (descriptor instanceof IASEjbCMPEntityDescriptor)) ? 173 (IASEjbCMPEntityDescriptor)descriptor : null); 174 } 175 176 181 public String getAbstractBeanClassForEjbName (String name) 182 { 183 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 184 185 return ((descriptor != null) ? descriptor.getEjbClassName() : null); 186 } 187 188 193 public String getKeyClassForEjbName (String name) 194 { 195 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 196 197 return ((descriptor != null) ? 198 descriptor.getPrimaryKeyClassName() : null); 199 } 200 201 206 public String getEjbNameForAbstractSchema (String schemaName) 207 { 208 Map abstractSchemaMap = (Map)getMap().get(ABSTRACT_SCHEMA_NAME); 209 210 return (String )abstractSchemaMap.get(schemaName); 211 } 212 213 218 public String getAbstractSchemaForEjbName (String name) 219 { 220 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 221 222 return ((descriptor != null) ? 223 descriptor.getAbstractSchemaName() : null); 224 } 225 226 231 public String getConcreteBeanClassForEjbName (String name) 232 { 233 IASEjbCMPEntityDescriptor descriptor = 234 getIASDescriptorForEjbName(name); 235 236 return ((descriptor != null) ? getQualifiedName( 237 getAbstractBeanClassForEjbName(name), 238 descriptor.getConcreteImplClassName()) : null); 239 } 240 241 private String getQualifiedName (String classNameWithPackage, 242 String classNameToQualify) 243 { 244 if (!StringHelper.isEmpty(classNameToQualify)) 245 { 246 String packageName = 247 JavaTypeHelper.getPackageName(classNameToQualify); 248 249 if (StringHelper.isEmpty(packageName)) { 251 packageName = 252 JavaTypeHelper.getPackageName(classNameWithPackage); 253 254 if (!StringHelper.isEmpty(packageName)) 255 return packageName + '.' + classNameToQualify; 256 } 257 } 258 259 return classNameToQualify; 260 } 261 262 267 public String getEjbNameForPersistenceClass (String className) 268 { 269 Map pcMap = (Map)getMap().get(PERSISTENCE_NAME); 270 271 return (String )pcMap.get(className); 272 } 273 274 279 public String getPersistenceClassForEjbName (String name) 280 { 281 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 282 283 return ((descriptor != null) ? 284 getPersistenceClassForDescriptor(descriptor) : null); 285 } 286 287 private String getPersistenceClassForDescriptor ( 288 EjbCMPEntityDescriptor descriptor) 289 { 290 String pcName = ((descriptor instanceof IASEjbCMPEntityDescriptor) ? 291 ((IASEjbCMPEntityDescriptor)descriptor).getPcImplClassName() : 292 null); 293 294 if ((pcName != null) && !_expandPCNames) 296 { 297 pcName = JavaTypeHelper.getPackageName(pcName) + 298 '.' + descriptor.getName(); 299 } 300 301 return pcName; 302 } 303 304 private boolean mapContainsKey (String stringIndex, String name) 305 { 306 Object mapObject = getMap().get(stringIndex); 307 Set testSet = ((mapObject instanceof Set) ? (Set)mapObject : 308 ((Map)mapObject).keySet()); 309 310 return ((name != null) ? testSet.contains(name) : false); 311 } 312 313 318 public boolean isLocalInterface (String name) 319 { 320 return mapContainsKey(LOCAL_NAME, name); 321 } 322 323 331 public String getEjbNameForLocalInterface (String ejbName, 332 String fieldName, String interfaceName) 333 { 334 EjbCMPEntityDescriptor descriptor = 335 getRelatedEjbDescriptor(ejbName, fieldName); 336 337 return (((descriptor != null) && !StringHelper.isEmpty(interfaceName) 338 && interfaceName.equals(descriptor.getLocalClassName())) ? 339 descriptor.getName() : null); 340 } 341 342 347 public String getLocalInterfaceForEjbName (String name) 348 { 349 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 350 351 return ((descriptor != null) ? descriptor.getLocalClassName() : null); 352 } 353 354 359 public boolean isRemoteInterface (String name) 360 { 361 return mapContainsKey(REMOTE_NAME, name); 362 } 363 364 372 public String getEjbNameForRemoteInterface (String ejbName, 373 String fieldName, String interfaceName) 374 { 375 EjbCMPEntityDescriptor descriptor = 376 getRelatedEjbDescriptor(ejbName, fieldName); 377 378 return (((descriptor != null) && !StringHelper.isEmpty(interfaceName) 379 && interfaceName.equals(descriptor.getRemoteClassName())) ? 380 descriptor.getName() : null); 381 } 382 383 388 public String getRemoteInterfaceForEjbName (String name) 389 { 390 EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name); 391 392 return ((descriptor != null) ? descriptor.getRemoteClassName() : null); 393 } 394 395 private EjbCMPEntityDescriptor getRelatedEjbDescriptor ( 396 String ejbName, String ejbFieldName) 397 { 398 EjbCMPEntityDescriptor descriptor = ((ejbName != null) ? 399 getDescriptorForEjbName(ejbName) : null); 400 401 if (descriptor != null) 402 { 403 PersistenceDescriptor persistenceDescriptor = 404 descriptor.getPersistenceDescriptor(); 405 CMRFieldInfo cmrf = 406 persistenceDescriptor.getCMRFieldInfoByName(ejbFieldName); 407 408 return cmrf.role.getPartner().getOwner(); 409 } 410 411 return null; 412 } 413 414 421 public String getEjbFieldForPersistenceField (String className, 422 String fieldName) 423 { 424 return fieldName; 425 } 426 427 434 public String getPersistenceFieldForEjbField (String name, String fieldName) 435 { 436 return fieldName; 437 } 438 } 439 | Popular Tags |