Search in sources :

Example 6 with NameMapper

use of com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper in project Payara by payara.

the class DeploymentDescriptorModel method getFields.

/**
 * Returns a list of names of all the declared field elements in the
 * class with the specified name.  If the specified className represents
 * a persistence-capable class, the list of field names from the
 * corresponding ejb is returned (even if there is a Class object
 * available for the persistence-capable).
 * @param className the fully qualified name of the class to be checked
 * @return the names of the field elements for the specified class
 */
public List getFields(final String className) {
    final EjbCMPEntityDescriptor descriptor = getCMPDescriptor(className);
    String testClass = className;
    if (// need to get names of ejb fields
    descriptor != null) {
        Iterator iterator = descriptor.getFieldDescriptors().iterator();
        List returnList = new ArrayList();
        while (iterator.hasNext()) returnList.add(((FieldDescriptor) iterator.next()).getName());
        return returnList;
    } else {
        NameMapper nameMapper = getNameMapper();
        String ejbName = nameMapper.getEjbNameForPersistenceKeyClass(className);
        switch(getPersistenceKeyClassType(className)) {
            // ejb key class
            case NameMapper.USER_DEFINED_KEY_CLASS:
                testClass = nameMapper.getKeyClassForEjbName(ejbName);
                break;
            // find the field name we need in the abstract bean
            case NameMapper.PRIMARY_KEY_FIELD:
                return Arrays.asList(new String[] { getCMPDescriptor(ejbName).getPrimaryKeyFieldDesc().getName() });
            // find the field name we need in the persistence capable
            case NameMapper.UNKNOWN_KEY_CLASS:
                String pcClassName = nameMapper.getPersistenceClassForEjbName(ejbName);
                PersistenceFieldElement[] fields = getPersistenceClass(pcClassName).getFields();
                int i, count = ((fields != null) ? fields.length : 0);
                for (i = 0; i < count; i++) {
                    PersistenceFieldElement pfe = fields[i];
                    if (pfe.isKey())
                        return Arrays.asList(new String[] { pfe.getName() });
                }
                break;
        }
    }
    return super.getFields(testClass);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NameMapper(com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper) ArrayList(java.util.ArrayList) List(java.util.List) PersistenceFieldElement(com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor)

Aggregations

NameMapper (com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)6 PersistenceFieldElement (com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement)2 RelationshipElement (com.sun.jdo.api.persistence.model.jdo.RelationshipElement)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)1 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)1