FileDocCategorySizeDatePackage
NameMapper.javaAPI DocGlassfish v2 API15448Fri May 04 22:34:48 BST 2007com.sun.jdo.spi.persistence.support.ejb.ejbc

NameMapper

public class NameMapper extends com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper
This is a subclass of {@link com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper} (in the com.sun.jdo.spi.persistence.support.ejb.model.util package) which implements the abstract methods based on an IAS implementation.
author
Rochelle Raccah

Fields Summary
private static String
EJB_NAME
private static String
ABSTRACT_SCHEMA_NAME
private static String
PERSISTENCE_NAME
private static String
LOCAL_NAME
private static String
REMOTE_NAME
private final boolean
_expandPCNames
private Map
_nameTypeToNameMap
public static final String
SIGNATURE
Signature with CVS keyword substitution for identifying the generated code
Constructors Summary
public NameMapper(com.sun.enterprise.deployment.EjbBundleDescriptor bundleDescriptor)
Creates a new instance of NameMapper

param
bundleDescriptor the IASEjbBundleDescriptor which defines the universe of names for this application.

 //NOI18N         
        
	                    	 
	   
	
		this(bundleDescriptor, true);
	
public NameMapper(com.sun.enterprise.deployment.EjbBundleDescriptor bundleDescriptor, boolean expandPersistenceClassNames)
Creates a new instance of NameMapper

param
bundleDescriptor the IASEjbBundleDescriptor which defines the universe of names for this application.
param
expandPersistenceClassNames flag to indicate whether persistence class names should differ from bean names

		super(bundleDescriptor);
		_expandPCNames = expandPersistenceClassNames;
		initMap();
	
Methods Summary
public java.lang.StringgetAbstractBeanClassForEjbName(java.lang.String name)
Gets the name of the abstract bean class which corresponds to the specified ejb name.

param
name the name of the ejb
return
the name of the abstract bean for the specified ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? descriptor.getEjbClassName() : null);
	
public java.lang.StringgetAbstractSchemaForEjbName(java.lang.String name)
Gets the name of the abstract schema which corresponds to the specified ejb.

param
name the name of the ejb
return
the name of the abstract schema for the specified ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? 
			descriptor.getAbstractSchemaName() : null);
	
public java.lang.StringgetConcreteBeanClassForEjbName(java.lang.String name)
Gets the name of the concrete bean class which corresponds to the specified ejb.

param
name the name of the ejb
return
the name of the concrete bean for the specified ejb

		IASEjbCMPEntityDescriptor descriptor = 
			getIASDescriptorForEjbName(name);

		return ((descriptor != null) ? getQualifiedName(
			getAbstractBeanClassForEjbName(name), 
			descriptor.getConcreteImplClassName()) : null);
	
public EjbCMPEntityDescriptorgetDescriptorForEjbName(java.lang.String name)
Gets the EjbCMPEntityDescriptor which represents the ejb with the specified name.

param
name the name of the ejb
return
the EjbCMPEntityDescriptor which represents the ejb.

		Map ejbMap = (Map)getMap().get(EJB_NAME);
		Object descriptor = ejbMap.get(name);

		return (((descriptor != null) && 
			(descriptor instanceof EjbCMPEntityDescriptor)) ? 
			(EjbCMPEntityDescriptor)descriptor : null);
	
public java.lang.StringgetEjbFieldForPersistenceField(java.lang.String className, java.lang.String fieldName)
Gets the name of the field in the ejb which corresponds to the specified persistence-capable class name and field name pair.

param
className the name of the persistence-capable
param
fieldName the name of the field in the persistence-capable
return
the name of the field in the ejb for the specified persistence-capable field

		return fieldName;
	
public java.lang.StringgetEjbNameForAbstractSchema(java.lang.String schemaName)
Gets the name of the ejb which corresponds to the specified abstract schema name.

param
schemaName the name of the abstract schema
return
the name of the ejb for the specified abstract schema

		Map abstractSchemaMap = (Map)getMap().get(ABSTRACT_SCHEMA_NAME);

		return (String)abstractSchemaMap.get(schemaName);
	
public java.lang.StringgetEjbNameForLocalInterface(java.lang.String ejbName, java.lang.String fieldName, java.lang.String interfaceName)
Gets the name of the ejb which corresponds to the specified local interface name.

param
ejbName the name of the ejb which contains fieldName from which to find relationship and therefore the local interface
param
fieldName the name of the field in the ejb
param
interfaceName the name of the local interface
return
the name of the ejb for the specified local interface

		EjbCMPEntityDescriptor descriptor = 
			getRelatedEjbDescriptor(ejbName, fieldName);

		return (((descriptor != null) && !StringHelper.isEmpty(interfaceName)
			&& interfaceName.equals(descriptor.getLocalClassName())) ? 
			descriptor.getName() : null);
	
public java.lang.StringgetEjbNameForPersistenceClass(java.lang.String className)
Gets the name of the ejb name which corresponds to the specified persistence-capable class name.

param
className the name of the persistence-capable
return
the name of the ejb for the specified persistence-capable

		Map pcMap = (Map)getMap().get(PERSISTENCE_NAME);

		return (String)pcMap.get(className);
	
public java.lang.StringgetEjbNameForRemoteInterface(java.lang.String ejbName, java.lang.String fieldName, java.lang.String interfaceName)
Gets the name of the ejb which corresponds to the specified remote interface name.

param
ejbName the name of the ejb which contains fieldName from which to find relationship and therefore the remote interface
param
fieldName the name of the field in the ejb
param
interfaceName the name of the remote interface
return
the name of the ejb for the specified remote interface

		EjbCMPEntityDescriptor descriptor = 
			getRelatedEjbDescriptor(ejbName, fieldName);

		return (((descriptor != null) && !StringHelper.isEmpty(interfaceName)
			&& interfaceName.equals(descriptor.getRemoteClassName())) ? 
			descriptor.getName() : null);
	
private com.sun.enterprise.deployment.IASEjbCMPEntityDescriptorgetIASDescriptorForEjbName(java.lang.String name)

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return (((descriptor != null) && 
			(descriptor instanceof IASEjbCMPEntityDescriptor)) ? 
			(IASEjbCMPEntityDescriptor)descriptor : null);
	
public java.lang.StringgetKeyClassForEjbName(java.lang.String name)
Gets the name of the key class which corresponds to the specified ejb name.

param
name the name of the ejb
return
the name of the key class for the ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? 
			descriptor.getPrimaryKeyClassName() : null);
	
public java.lang.StringgetLocalInterfaceForEjbName(java.lang.String name)
Gets the name of the local interface which corresponds to the specified ejb name.

param
name the name of the ejb
return
the name of the local interface for the specified ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? descriptor.getLocalClassName() : null);
	
private java.util.MapgetMap()

 return _nameTypeToNameMap; 
private java.lang.StringgetPersistenceClassForDescriptor(EjbCMPEntityDescriptor descriptor)

		String pcName = ((descriptor instanceof IASEjbCMPEntityDescriptor) ? 
			((IASEjbCMPEntityDescriptor)descriptor).getPcImplClassName() : 
			null);

		// use the package name, keep the ejb name
		if ((pcName != null) && !_expandPCNames)
		{
			pcName = JavaTypeHelper.getPackageName(pcName) + 
				'." + descriptor.getName();
		}

		return pcName;
	
public java.lang.StringgetPersistenceClassForEjbName(java.lang.String name)
Gets the name of the persistence-capable class which corresponds to the specified ejb name.

param
name the name of the ejb
return
the name of the persistence-capable for the specified ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? 
			getPersistenceClassForDescriptor(descriptor) : null);
	
public java.lang.StringgetPersistenceFieldForEjbField(java.lang.String name, java.lang.String fieldName)
Gets the name of the field in the persistence-capable class which corresponds to the specified ejb name and field name pair.

param
name the name of the ejb
param
fieldName the name of the field in the ejb
return
the name of the field in the persistence-capable for the specified ejb field

		return fieldName;
	
private java.lang.StringgetQualifiedName(java.lang.String classNameWithPackage, java.lang.String classNameToQualify)

		if (!StringHelper.isEmpty(classNameToQualify))
		{
			String packageName = 
				JavaTypeHelper.getPackageName(classNameToQualify);
			
			if (StringHelper.isEmpty(packageName))	// not already qualified
			{
				packageName = 
					JavaTypeHelper.getPackageName(classNameWithPackage);

				if (!StringHelper.isEmpty(packageName))
					return packageName + '." + classNameToQualify;
			}
		}

		return classNameToQualify;
	
private EjbCMPEntityDescriptorgetRelatedEjbDescriptor(java.lang.String ejbName, java.lang.String ejbFieldName)

		EjbCMPEntityDescriptor descriptor = ((ejbName != null) ? 
			getDescriptorForEjbName(ejbName) : null);

		if (descriptor != null)
		{
			PersistenceDescriptor persistenceDescriptor =
				descriptor.getPersistenceDescriptor();
			CMRFieldInfo cmrf = 
				persistenceDescriptor.getCMRFieldInfoByName(ejbFieldName);
			
			return cmrf.role.getPartner().getOwner();
		}

		return null;
	
public java.lang.StringgetRemoteInterfaceForEjbName(java.lang.String name)
Gets the name of the remote interface which corresponds to the specified ejb name.

param
name the name of the ejb
return
the name of the remote interface for the specified ejb

		EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

		return ((descriptor != null) ? descriptor.getRemoteClassName() : null);
	
private voidinitMap()

		Iterator iterator = getBundleDescriptor().getEjbs().iterator();
		Map ejbMap = new HashMap();
		Map persistenceClassMap = new HashMap();
		Set localNames = new HashSet();
		Set remoteNames = new HashSet();
		Map abstractSchemaMap = new HashMap();

		_nameTypeToNameMap = new HashMap();

		while (iterator.hasNext())
		{
			Object next = iterator.next();

			if (next instanceof IASEjbCMPEntityDescriptor)
			{
				IASEjbCMPEntityDescriptor descriptor = 
					(IASEjbCMPEntityDescriptor)next;
				String ejbName = descriptor.getName();

				ejbMap.put(ejbName, descriptor);
				safePut(persistenceClassMap, 
					getPersistenceClassForDescriptor(descriptor), ejbName);
				safeAdd(localNames, descriptor.getLocalClassName());
				safeAdd(remoteNames, descriptor.getRemoteClassName());
				safePut(abstractSchemaMap, 
					descriptor.getAbstractSchemaName(), ejbName);
			}
		}
		_nameTypeToNameMap.put(EJB_NAME, ejbMap);
		_nameTypeToNameMap.put(PERSISTENCE_NAME, persistenceClassMap);
		_nameTypeToNameMap.put(LOCAL_NAME, localNames);
		_nameTypeToNameMap.put(REMOTE_NAME, remoteNames);
		_nameTypeToNameMap.put(ABSTRACT_SCHEMA_NAME, abstractSchemaMap);
	
public booleanisEjbName(java.lang.String name)
Determines if the specified name represents an ejb.

param
name the fully qualified name to be checked
return
true if this name represents an ejb; false otherwise.

		return mapContainsKey(EJB_NAME, name);
	
public booleanisLocalInterface(java.lang.String name)
Determines if the specified name represents a local interface.

param
name the fully qualified name to be checked
return
true if this name represents a local interface; false otherwise.

		return mapContainsKey(LOCAL_NAME, name);
	
public booleanisRemoteInterface(java.lang.String name)
Determines if the specified name represents a remote interface.

param
name the fully qualified name to be checked
return
true if this name represents a remote interface; false otherwise.

		return mapContainsKey(REMOTE_NAME, name);
	
private booleanmapContainsKey(java.lang.String stringIndex, java.lang.String name)

		Object mapObject = getMap().get(stringIndex);
		Set testSet = ((mapObject instanceof Set) ? (Set)mapObject : 
			((Map)mapObject).keySet());

		return ((name != null) ? testSet.contains(name) : false);
	
private voidsafeAdd(java.util.Set set, java.lang.Object value)

		if ((value != null) && (set != null))
			set.add(value);
	
private voidsafePut(java.util.Map map, java.lang.Object key, java.lang.Object value)

		if ((key != null) && (map != null))
			map.put(key, value);