Search in sources :

Example 26 with EjbCMPEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.

the class EJBBundleInfoHelper method getEjbNames.

/**
 * @see EJBInfoHelper#getEjbNames
 */
public Collection getEjbNames() {
    Iterator iterator = getBundleDescriptor().getEjbs().iterator();
    ArrayList returnList = new ArrayList();
    while (iterator.hasNext()) {
        EjbDescriptor ejb = (EjbDescriptor) iterator.next();
        if (ejb instanceof EjbCMPEntityDescriptor)
            returnList.add(ejb.getName());
    }
    return returnList;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 27 with EjbCMPEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.

the class NameMapper method getDescriptorForEjbName.

/**
 * 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.
 */
public EjbCMPEntityDescriptor getDescriptorForEjbName(String name) {
    Map ejbMap = (Map) getMap().get(EJB_NAME);
    Object descriptor = ejbMap.get(name);
    return (((descriptor != null) && (descriptor instanceof EjbCMPEntityDescriptor)) ? (EjbCMPEntityDescriptor) descriptor : null);
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Example 28 with EjbCMPEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor 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)

Example 29 with EjbCMPEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.

the class DeploymentDescriptorModel method getFieldWrapper.

private MemberWrapper getFieldWrapper(String className, String fieldName) {
    EjbCMPEntityDescriptor descriptor = getCMPDescriptor(className);
    MemberWrapper returnObject = null;
    if (descriptor != null) {
        PersistenceDescriptor persistenceDescriptor = descriptor.getPersistenceDescriptor();
        if (persistenceDescriptor != null) {
            Class fieldType = null;
            try {
                fieldType = persistenceDescriptor.getTypeFor(fieldName);
            } catch (RuntimeException e) {
            // fieldType will be null - there is no such field
            }
            returnObject = ((fieldType == null) ? null : new MemberWrapper(fieldName, fieldType, Modifier.PRIVATE, (Class) getClass(className)));
        }
    }
    return returnObject;
}
Also used : PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Example 30 with EjbCMPEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor in project Payara by payara.

the class NameMapper method initGeneratedRelationshipMaps.

private void initGeneratedRelationshipMaps() {
    EjbBundleDescriptorImpl bundleDescriptor = getBundleDescriptor();
    Set relationships = bundleDescriptor.getRelationships();
    _generatedRelToInverseRelMap = new HashMap();
    _relToInverseGeneratedRelMap = new HashMap();
    // 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 = (RelationshipDescriptor) iterator.next();
            if (relationship.getSource().getCMRField() == null)
                generatedRels.add(relationship);
            if (relationship.getSink().getCMRField() == null)
                generatedRels.add(relationship);
        }
        // now update the maps to contain this info
        iterator = generatedRels.iterator();
        while (iterator.hasNext()) {
            RelationshipDescriptor relationship = (RelationshipDescriptor) iterator.next();
            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) bundleDescriptor.getEjbByName(ejbName)).getPersistenceDescriptor();
            List generatedField = null;
            String uniqueName = null;
            // with this name
            do {
                counter++;
                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);
        }
    }
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipDescriptor(org.glassfish.ejb.deployment.descriptor.RelationshipDescriptor) RelationRoleDescriptor(org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Aggregations

EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)30 Result (com.sun.enterprise.tools.verifier.Result)17 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)15 Iterator (java.util.Iterator)15 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)15 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)12 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)12 Field (java.lang.reflect.Field)10 Set (java.util.Set)9 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)8 Method (java.lang.reflect.Method)7 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)6 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)5 Descriptor (org.glassfish.deployment.common.Descriptor)4 ArrayList (java.util.ArrayList)3 IASEjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor)3 QueryDescriptor (org.glassfish.ejb.deployment.descriptor.QueryDescriptor)3 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)2 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)2 EjbReference (com.sun.enterprise.deployment.types.EjbReference)2