NameMapper.javaAPI DocGlassfish v2 API7981Fri May 04 22:34:54 BST


public abstract class NameMapper extends com.sun.jdo.api.persistence.mapping.ejb.AbstractNameMapper
This is a class which helps translate between the various names of the CMP (ejb name, abstract schema, abstract bean, concrete bean, local interface, remote interface) and the persistence-capable class name. It also has methods for translation of field names. The basic entry point is ejb name or persistence-capable class name. This is a subclass of the AbstractNameMapper and implements the methods based on DOL. It also adds methods which are used during deployment time but not needed during development time and therefore, not in the abstract superclass.
Rochelle Raccah

Fields Summary
private EjbBundleDescriptor
private Map
private Map
Constructors Summary
protected NameMapper(EjbBundleDescriptor bundleDescriptor)
Creates a new instance of NameMapper

bundleDescriptor the EjbBundleDescriptor which defines the universe of names for this application.

		_bundleDescriptor = bundleDescriptor;
Methods Summary
public EjbBundleDescriptorgetBundleDescriptor()
Gets the EjbBundleDescriptor which defines the universe of names for this application.

the EjbBundleDescriptor which defines the universe of names for this application.

		return _bundleDescriptor;
public abstract java.lang.StringgetConcreteBeanClassForEjbName(java.lang.String name)
Gets the name of the concrete bean class which corresponds to the specified ejb.

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

public abstract EjbCMPEntityDescriptorgetDescriptorForEjbName(java.lang.String name)
Gets the EjbCMPEntityDescriptor which represents the ejb with the specified name.

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

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

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

protected java.util.MapgetGeneratedFieldsMap()

		return _generatedRelToInverseRelMap;
protected java.util.MapgetInverseFieldsMap()

 return _relToInverseGeneratedRelMap; 
public intgetKeyClassTypeForEjbName(java.lang.String name)
Get the type of key class of this ejb.

the key class type, one of {@link #USER_DEFINED_KEY_CLASS}, {@link #PRIMARY_KEY_FIELD}, or {@link #UNKNOWN_KEY_CLASS}

		String keyClass = getKeyClassForEjbName(name);

		if (!"java.lang.Object".equals(keyClass))		// NOI18N
			EjbCMPEntityDescriptor descriptor = getDescriptorForEjbName(name);

			return ((descriptor.getPrimaryKeyFieldDesc() != null) ?

private booleanhasField(PersistenceDescriptor persistenceDescriptor, java.lang.String fieldName)

		Class fieldType = null;

			fieldType = persistenceDescriptor.getTypeFor(fieldName);
		catch (RuntimeException e)
			// fieldType will be null - there is no such field

		return (fieldType != null);
private voidinitGeneratedRelationshipMaps()

		EjbBundleDescriptor bundleDescriptor = getBundleDescriptor();
		Set relationships = bundleDescriptor.getRelationships();

		_generatedRelToInverseRelMap = new HashMap();
		_relToInverseGeneratedRelMap = new HashMap();

		// during development time this code may attempt to get the 
		// iterator even with no relationships, so protect it by a 
		// null check
		if (relationships != null)
			Iterator iterator = relationships.iterator();
			List generatedRels = new ArrayList();
			int counter = 0;

			// gather list of generated cmr fields by examining source and sink
			while (iterator.hasNext())
				RelationshipDescriptor relationship = 

				if (relationship.getSource().getCMRField() == null)

				if (relationship.getSink().getCMRField() == null)

			// now update the maps to contain this info
			iterator = generatedRels.iterator();
			while (iterator.hasNext())
				RelationshipDescriptor relationship = 
				RelationRoleDescriptor source = relationship.getSource();
				String sourceEjbName = source.getOwner().getName();
				String sourceCMRField = source.getCMRField();
				boolean sourceIsNull = (sourceCMRField == null);
				RelationRoleDescriptor sink = relationship.getSink();
				String sinkEjbName = sink.getOwner().getName();
				String ejbName = (sourceIsNull ? sourceEjbName : sinkEjbName);
				String otherEjbName = 
					(sourceIsNull ? sinkEjbName : sourceEjbName);
				List ejbField = Arrays.asList(new String[]{otherEjbName, 
					(sourceIsNull ? sink.getCMRField() : sourceCMRField)});
				PersistenceDescriptor pDescriptor = ((EjbCMPEntityDescriptor)
				List generatedField = null;
				String uniqueName = null;

				// make sure the user doesn't already have a field
				// with this name
					uniqueName = GENERATED_CMR_FIELD_PREFIX + counter;
				} while (hasField(pDescriptor, uniqueName));

				generatedField = 
					Arrays.asList(new String[]{ejbName, uniqueName});
				_generatedRelToInverseRelMap.put(generatedField, ejbField);
				_relToInverseGeneratedRelMap.put(ejbField, generatedField);