Search in sources :

Example 6 with FieldDescriptor

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

the class PrimaryKeyClassModifier method check.

/**
 * Enterprise Java Bean primary key class modifier test.
 * The class must be defined as public
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
            // field in entity bean class and this test in notApplicable
            try {
                FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
                if (fd != null) {
                    String pkf = fd.getName();
                    if (pkf.length() > 0) {
                        // N/A case
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
                    }
                } else {
                    try {
                        VerifierTestContext context = getVerifierContext();
                        ClassLoader jcl = context.getClassLoader();
                        Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
                        boolean isPublic = false;
                        int modifiers = c.getModifiers();
                        if (Modifier.isPublic(modifiers)) {
                            isPublic = true;
                        }
                        if (isPublic) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares public class modifier.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                        } else if (!isPublic) {
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Ejb primary key class [ {0} ] was found, but was not declared as public.  The primary key class  [ {1} ] must be defined as public.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                        }
                    } catch (ClassNotFoundException e) {
                        Verifier.debug(e);
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                    }
                }
            } catch (NullPointerException e) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
            }
            return result;
        } else {
            // if (BEAN_PERSISTENCE.equals(persistence)
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean, but called with {2}.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Result(com.sun.enterprise.tools.verifier.Result) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 7 with FieldDescriptor

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

the class BeanMethodCalculatorImpl method getPossibleCmpCmrFields.

public Vector getPossibleCmpCmrFields(ClassLoader cl, String className) throws ClassNotFoundException {
    Vector fieldDescriptors = new Vector();
    Class theClass = cl.loadClass(className);
    // Start with all *public* methods
    Method[] methods = theClass.getMethods();
    // on method signature.
    for (int mIndex = 0; mIndex < methods.length; mIndex++) {
        Method next = methods[mIndex];
        String nextName = next.getName();
        int nextModifiers = next.getModifiers();
        if (Modifier.isAbstract(nextModifiers)) {
            if (nextName.startsWith("get") && nextName.length() > 3) {
                String field = nextName.substring(3, 4).toLowerCase(Locale.US) + nextName.substring(4);
                fieldDescriptors.add(new FieldDescriptor(field));
            }
        }
    }
    return fieldDescriptors;
}
Also used : Method(java.lang.reflect.Method) Vector(java.util.Vector) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor)

Example 8 with FieldDescriptor

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

the class EjbEntityNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, EjbEntityDescriptor ejbDesc) {
    Node ejbNode = super.writeDescriptor(parent, nodeName, ejbDesc);
    writeDisplayableComponentInfo(ejbNode, ejbDesc);
    writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
    appendTextChild(ejbNode, EjbTagNames.PERSISTENCE_TYPE, ejbDesc.getPersistenceType());
    appendTextChild(ejbNode, EjbTagNames.PRIMARY_KEY_CLASS, ejbDesc.getPrimaryKeyClassName());
    appendTextChild(ejbNode, EjbTagNames.REENTRANT, ejbDesc.getReentrant());
    // cmp entity beans related tags
    if (ejbDesc instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmpDesc = (EjbCMPEntityDescriptor) ejbDesc;
        if (cmpDesc.getCMPVersion() == EjbCMPEntityDescriptor.CMP_1_1) {
            appendTextChild(ejbNode, EjbTagNames.CMP_VERSION, EjbTagNames.CMP_1_VERSION);
        } else {
            appendTextChild(ejbNode, EjbTagNames.CMP_VERSION, EjbTagNames.CMP_2_VERSION);
        }
        appendTextChild(ejbNode, EjbTagNames.ABSTRACT_SCHEMA_NAME, cmpDesc.getAbstractSchemaName());
        // cmp-field*
        CmpFieldNode cmpNode = new CmpFieldNode();
        for (Iterator fields = cmpDesc.getPersistenceDescriptor().getCMPFields().iterator(); fields.hasNext(); ) {
            FieldDescriptor aField = (FieldDescriptor) fields.next();
            cmpNode.writeDescriptor(ejbNode, EjbTagNames.CMP_FIELD, aField);
        }
        if (cmpDesc.getPrimaryKeyFieldDesc() != null) {
            appendTextChild(ejbNode, EjbTagNames.PRIMARY_KEY_FIELD, cmpDesc.getPrimaryKeyFieldDesc().getName());
        }
    }
    // env-entry*
    writeEnvEntryDescriptors(ejbNode, ejbDesc.getEnvironmentProperties().iterator());
    // ejb-ref * and ejb-local-ref*
    writeEjbReferenceDescriptors(ejbNode, ejbDesc.getEjbReferenceDescriptors().iterator());
    // service-ref*
    writeServiceReferenceDescriptors(ejbNode, ejbDesc.getServiceReferenceDescriptors().iterator());
    // resource-ref*
    writeResourceRefDescriptors(ejbNode, ejbDesc.getResourceReferenceDescriptors().iterator());
    // resource-env-ref*
    writeResourceEnvRefDescriptors(ejbNode, ejbDesc.getResourceEnvReferenceDescriptors().iterator());
    // message-destination-ref*
    writeMessageDestinationRefDescriptors(ejbNode, ejbDesc.getMessageDestinationReferenceDescriptors().iterator());
    // persistence-context-ref*
    writeEntityManagerReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerReferenceDescriptors().iterator());
    // persistence-unit-ref*
    writeEntityManagerFactoryReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
    // post-construct
    writeLifeCycleCallbackDescriptors(ejbNode, TagNames.POST_CONSTRUCT, ejbDesc.getPostConstructDescriptors());
    // pre-destroy
    writeLifeCycleCallbackDescriptors(ejbNode, TagNames.PRE_DESTROY, ejbDesc.getPreDestroyDescriptors());
    // all descriptors (includes DSD, MSD, JMSCFD, JMSDD,AOD, CFD)*
    writeResourceDescriptors(ejbNode, ejbDesc.getAllResourcesDescriptors().iterator());
    // security-role-ref*
    writeRoleReferenceDescriptors(ejbNode, ejbDesc.getRoleReferences().iterator());
    // security-identity
    writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
    // query
    if (ejbDesc instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmpDesc = (EjbCMPEntityDescriptor) ejbDesc;
        Set queriedMethods = cmpDesc.getPersistenceDescriptor().getQueriedMethods();
        if (queriedMethods.size() > 0) {
            QueryNode queryNode = new QueryNode();
            for (Iterator e = queriedMethods.iterator(); e.hasNext(); ) {
                queryNode.writeDescriptor(ejbNode, EjbTagNames.QUERY, cmpDesc.getPersistenceDescriptor().getQueryFor((MethodDescriptor) e.next()));
            }
        }
    }
    return ejbNode;
}
Also used : Set(java.util.Set) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor)

Example 9 with FieldDescriptor

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

the class EjbBundleValidator method accept.

/**
 * visits an ejb descriptor
 * @param ejb descriptor
 */
@Override
public void accept(EjbDescriptor ejb) {
    // application
    if (ejb instanceof DummyEjbDescriptor) {
        throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.exceptionbeanbundle", "Referencing error: this bundle has no bean of name: {0}", new Object[] { ejb.getName() }));
    }
    this.ejb = ejb;
    setDOLDefault(ejb);
    computeRuntimeDefault(ejb);
    checkDependsOn(ejb);
    validateConcurrencyMetadata(ejb);
    validateStatefulTimeout(ejb);
    validatePassivationConfiguration(ejb);
    try {
        ClassLoader cl = ejb.getEjbBundleDescriptor().getClassLoader();
        Class ejbClass = cl.loadClass(ejb.getEjbClassName());
        if (Globals.getDefaultHabitat() == null) {
            return;
        }
        if (ejb instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor desc = (EjbSessionDescriptor) ejb;
            if (desc.isClustered()) {
                if (!desc.isSingleton()) {
                    throw new IllegalArgumentException("Only Sinlgeton beans can be Clustered: " + desc.getName());
                }
                if (!Serializable.class.isAssignableFrom(ejbClass)) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s must be Serializable", desc.getName()));
                }
                if (desc.getClusteredLockType() == DistributedLockType.LOCK) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s - incompatible lock type LOCK", desc.getName()));
                }
            }
        }
        // Perform 2.x style TimedObject processing if the class
        // hasn't already been identified as a timed object.
        AnnotationTypesProvider provider = Globals.getDefaultHabitat().getService(AnnotationTypesProvider.class, "EJB");
        if (provider == null) {
            throw new RuntimeException("Cannot find AnnotationTypesProvider named 'EJB'");
        }
        if (ejb.getEjbTimeoutMethod() == null && provider.getType("javax.ejb.TimedObject").isAssignableFrom(ejbClass)) {
            MethodDescriptor timedObjectMethod = new MethodDescriptor("ejbTimeout", "TimedObject timeout method", new String[] { "javax.ejb.Timer" }, MethodDescriptor.TIMER_METHOD);
            ejb.setEjbTimeoutMethod(timedObjectMethod);
        } else if (ejb.getEjbTimeoutMethod() != null) {
            // If timeout-method was only processed from the descriptor,
            // we need to create a MethodDescriptor using the actual
            // Method object corresponding to the timeout method.  The
            // timeout method can have any access type and be anywhere
            // in the bean class hierarchy.
            MethodDescriptor timeoutMethodDescOrig = ejb.getEjbTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            ejb.setEjbTimeoutMethod(timeoutMethodDesc);
        }
        for (ScheduledTimerDescriptor sd : ejb.getScheduledTimerDescriptors()) {
            try {
                // This method creates new schedule and attempts to calculate next timeout.
                // The second part ensures that all values that are not verified up-front
                // are also validated.
                // It does not check that such timeout date is a valid date.
                EJBTimerSchedule.isValid(sd);
            } catch (Exception e) {
                throw new RuntimeException(ejb.getName() + ": Invalid schedule " + "defined on method " + sd.getTimeoutMethod().getFormattedString() + ": " + e.getMessage());
            }
            MethodDescriptor timeoutMethodDescOrig = sd.getTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            sd.setTimeoutMethod(timeoutMethodDesc);
        }
    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Error processing EjbDescriptor");
        re.initCause(e);
        throw re;
    }
    // has to be derived from target inject method or inject field.
    for (InjectionCapable injectable : ejb.getEjbBundleDescriptor().getInjectableResources(ejb)) {
        accept(injectable);
    }
    for (Iterator itr = ejb.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
        EjbReference aRef = (EjbReference) itr.next();
        accept(aRef);
    }
    for (Iterator it = ejb.getResourceReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getResourceEnvReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceEnvReferenceDescriptor next = (ResourceEnvReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getMessageDestinationReferenceDescriptors().iterator(); it.hasNext(); ) {
        MessageDestinationReferencer next = (MessageDestinationReferencer) it.next();
        accept(next);
    }
    // referencer as well.
    if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
        if (ejb instanceof MessageDestinationReferencer) {
            MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
            if (msgDestReferencer.getMessageDestinationLinkName() != null) {
                accept(msgDestReferencer);
            }
        }
    }
    Set serviceRefs = ejb.getServiceReferenceDescriptors();
    for (Iterator itr = serviceRefs.iterator(); itr.hasNext(); ) {
        accept((ServiceReferenceDescriptor) itr.next());
    }
    if (ejb instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
        PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
        for (Iterator e = persistenceDesc.getCMPFields().iterator(); e.hasNext(); ) {
            FieldDescriptor fd = (FieldDescriptor) e.next();
            accept(fd);
        }
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbReference(com.sun.enterprise.deployment.types.EjbReference) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) MessageDestinationReferencer(com.sun.enterprise.deployment.types.MessageDestinationReferencer) InjectionCapable(com.sun.enterprise.deployment.InjectionCapable) Iterator(java.util.Iterator) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) AnnotationTypesProvider(org.glassfish.internal.deployment.AnnotationTypesProvider)

Example 10 with FieldDescriptor

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

FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)13 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)12 Result (com.sun.enterprise.tools.verifier.Result)9 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)9 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)9 Field (java.lang.reflect.Field)7 Iterator (java.util.Iterator)7 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)6 Set (java.util.Set)4 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 Vector (java.util.Vector)2 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)2 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 EjbReference (com.sun.enterprise.deployment.types.EjbReference)1 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)1 PersistenceFieldElement (com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement)1 NameMapper (com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper)1 Serializable (java.io.Serializable)1