Search in sources :

Example 1 with EjbInitInfo

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

the class InitMethodReturnType method check.

public Result check(EjbSessionDescriptor descriptor) {
    Set<EjbInitInfo> initMethods = descriptor.getInitMethods();
    for (EjbInitInfo initInfo : initMethods) {
        Method method = initInfo.getBeanMethod().getMethod(descriptor);
        if (!method.getReturnType().getName().equals("void")) {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Wrong init method [ {0} ].", new Object[] { method }));
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid init method(s)."));
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo)

Example 2 with EjbInitInfo

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

the class EjbSessionNode method writeDescriptor.

@Override
public Node writeDescriptor(Node parent, String nodeName, EjbSessionDescriptor ejbDesc) {
    Node ejbNode = super.writeDescriptor(parent, nodeName, ejbDesc);
    writeDisplayableComponentInfo(ejbNode, ejbDesc);
    writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
    appendTextChild(ejbNode, EjbTagNames.SESSION_TYPE, ejbDesc.getSessionType());
    if (ejbDesc.hasStatefulTimeout()) {
        TimeoutValueNode timeoutValueNode = new TimeoutValueNode();
        TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
        timeoutDesc.setValue(ejbDesc.getStatefulTimeoutValue());
        timeoutDesc.setUnit(ejbDesc.getStatefulTimeoutUnit());
        timeoutValueNode.writeDescriptor(ejbNode, EjbTagNames.STATEFUL_TIMEOUT, timeoutDesc);
    }
    MethodNode methodNode = new MethodNode();
    if (ejbDesc.isTimedObject()) {
        if (ejbDesc.getEjbTimeoutMethod() != null) {
            methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.TIMEOUT_METHOD, ejbDesc.getEjbTimeoutMethod());
        }
        for (ScheduledTimerDescriptor timerDesc : ejbDesc.getScheduledTimerDescriptors()) {
            ScheduledTimerNode timerNode = new ScheduledTimerNode();
            timerNode.writeDescriptor(ejbNode, EjbTagNames.TIMER, timerDesc);
        }
    }
    if (ejbDesc.isSingleton()) {
        appendTextChild(ejbNode, EjbTagNames.INIT_ON_STARTUP, Boolean.toString(ejbDesc.getInitOnStartup()));
    }
    if (!ejbDesc.isStateless()) {
        appendTextChild(ejbNode, EjbTagNames.CONCURRENCY_MANAGEMENT_TYPE, ejbDesc.getConcurrencyManagementType().toString());
    }
    for (EjbSessionDescriptor.AccessTimeoutHolder next : ejbDesc.getAccessTimeoutInfo()) {
        ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
        cDesc.setConcurrentMethod(next.method);
        TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
        timeoutDesc.setValue(next.value);
        timeoutDesc.setUnit(next.unit);
        cDesc.setAccessTimeout(timeoutDesc);
        ConcurrentMethodNode cNode = new ConcurrentMethodNode();
        cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
    }
    for (MethodDescriptor nextReadLock : ejbDesc.getReadLockMethods()) {
        ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
        cDesc.setConcurrentMethod(nextReadLock);
        cDesc.setWriteLock(false);
        ConcurrentMethodNode cNode = new ConcurrentMethodNode();
        cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
    }
    if (ejbDesc.hasDependsOn()) {
        Node dependsOnNode = appendChild(ejbNode, EjbTagNames.DEPENDS_ON);
        for (String depend : ejbDesc.getDependsOn()) {
            appendTextChild(dependsOnNode, EjbTagNames.EJB_NAME, depend);
        }
    }
    if (ejbDesc.hasInitMethods()) {
        EjbInitNode initNode = new EjbInitNode();
        for (EjbInitInfo next : ejbDesc.getInitMethods()) {
            initNode.writeDescriptor(ejbNode, EjbTagNames.INIT_METHOD, next);
        }
    }
    if (ejbDesc.hasRemoveMethods()) {
        EjbRemoveNode removeNode = new EjbRemoveNode();
        for (EjbRemovalInfo next : ejbDesc.getAllRemovalInfo()) {
            removeNode.writeDescriptor(ejbNode, EjbTagNames.REMOVE_METHOD, next);
        }
    }
    for (MethodDescriptor nextDesc : ejbDesc.getAsynchronousMethods()) {
        methodNode.writeDescriptor(ejbNode, EjbTagNames.ASYNC_METHOD, nextDesc, ejbDesc.getName());
    }
    appendTextChild(ejbNode, EjbTagNames.TRANSACTION_TYPE, ejbDesc.getTransactionType());
    MethodDescriptor afterBeginMethod = ejbDesc.getAfterBeginMethod();
    if (afterBeginMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_BEGIN_METHOD, afterBeginMethod);
    }
    MethodDescriptor beforeCompletionMethod = ejbDesc.getBeforeCompletionMethod();
    if (beforeCompletionMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.BEFORE_COMPLETION_METHOD, beforeCompletionMethod);
    }
    MethodDescriptor afterCompletionMethod = ejbDesc.getAfterCompletionMethod();
    if (afterCompletionMethod != null) {
        methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_COMPLETION_METHOD, afterCompletionMethod);
    }
    // around-invoke-method
    writeAroundInvokeDescriptors(ejbNode, ejbDesc.getAroundInvokeDescriptors().iterator());
    // around-timeout-method
    writeAroundTimeoutDescriptors(ejbNode, ejbDesc.getAroundTimeoutDescriptors().iterator());
    // 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());
    // post-activate-method
    writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.POST_ACTIVATE_METHOD, ejbDesc.getPostActivateDescriptors());
    // pre-passivate-method
    writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.PRE_PASSIVATE_METHOD, ejbDesc.getPrePassivateDescriptors());
    // security-role-ref*
    writeRoleReferenceDescriptors(ejbNode, ejbDesc.getRoleReferences().iterator());
    // security-identity
    writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
    // passivation-capable
    if (ejbDesc.isStateful()) {
        appendTextChild(ejbNode, EjbTagNames.PASSIVATION_CAPABLE, Boolean.toString(ejbDesc.isPassivationCapable()));
    }
    return ejbNode;
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) MethodNode(com.sun.enterprise.deployment.node.MethodNode) MailSessionNode(com.sun.enterprise.deployment.node.MailSessionNode) Node(org.w3c.dom.Node) LifecycleCallbackNode(com.sun.enterprise.deployment.node.LifecycleCallbackNode) DataSourceDefinitionNode(com.sun.enterprise.deployment.node.DataSourceDefinitionNode) ConcurrentMethodDescriptor(org.glassfish.ejb.deployment.descriptor.ConcurrentMethodDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo) ConcurrentMethodDescriptor(org.glassfish.ejb.deployment.descriptor.ConcurrentMethodDescriptor) MethodNode(com.sun.enterprise.deployment.node.MethodNode) EjbRemovalInfo(org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo) TimeoutValueDescriptor(org.glassfish.ejb.deployment.descriptor.TimeoutValueDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 3 with EjbInitInfo

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

the class InitHandler method addInitMethod.

private void addInitMethod(EjbSessionDescriptor descriptor, Method beanMethod, String adaptedCreateMethodName, boolean local) throws Exception {
    String homeIntfName = local ? descriptor.getLocalHomeClassName() : descriptor.getHomeClassName();
    ClassLoader cl = descriptor.getEjbBundleDescriptor().getClassLoader();
    Class homeIntf = cl.loadClass(homeIntfName);
    Method createMethod = null;
    if ((adaptedCreateMethodName == null) || (adaptedCreateMethodName.equals(""))) {
        // signature.
        for (Method next : homeIntf.getMethods()) {
            if (next.getName().startsWith("create") && TypeUtil.sameParamTypes(next, beanMethod)) {
                createMethod = next;
                break;
            }
        }
        if (createMethod == null) {
            throw new NoSuchMethodException("No matching adapted home " + "method found for @Init " + " method " + beanMethod);
        }
    } else {
        createMethod = homeIntf.getMethod(adaptedCreateMethodName, beanMethod.getParameterTypes());
    }
    MethodDescriptor beanMethodDescriptor = new MethodDescriptor(beanMethod, MethodDescriptor.EJB_BEAN);
    MethodDescriptor createMethodDescriptor = new MethodDescriptor(createMethod, (local ? MethodDescriptor.EJB_HOME : MethodDescriptor.EJB_LOCALHOME));
    EjbInitInfo initInfo = new EjbInitInfo();
    initInfo.setBeanMethod(beanMethodDescriptor);
    initInfo.setCreateMethod(createMethodDescriptor);
    descriptor.addInitMethod(initInfo);
}
Also used : Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo)

Example 4 with EjbInitInfo

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

the class SafeProperties method setHomeTargetMethodInfo.

private void setHomeTargetMethodInfo(InvocationInfo invInfo, boolean isLocal) throws EJBException {
    Class homeIntfClazz = isLocal ? javax.ejb.EJBLocalHome.class : javax.ejb.EJBHome.class;
    Class methodClass = invInfo.method.getDeclaringClass();
    Class[] paramTypes = invInfo.method.getParameterTypes();
    String methodName = invInfo.method.getName();
    try {
        Method m = homeIntfClazz.getMethod(methodName, paramTypes);
        // Attempt to override Home/LocalHome method.  Print warning
        // but don't treat it as a fatal error. At runtime,
        // the EJBHome/EJBLocalHome method will be called.
        String[] params = { m.toString(), invInfo.method.toString() };
        _logger.log(Level.WARNING, ILLEGAL_EJB_INTERFACE_OVERRIDE, params);
        invInfo.ejbIntfOverride = true;
        return;
    } catch (NoSuchMethodException nsme) {
    }
    try {
        if (invInfo.startsWithCreate) {
            String extraCreateChars = methodName.substring("create".length());
            invInfo.targetMethod1 = ejbClass.getMethod("ejbCreate" + extraCreateChars, paramTypes);
            adjustHomeTargetMethodInfo(invInfo, methodName, paramTypes);
        } else if (invInfo.startsWithFind) {
            String extraFinderChars = methodName.substring("find".length());
            invInfo.targetMethod1 = ejbClass.getMethod("ejbFind" + extraFinderChars, paramTypes);
        } else {
            // HOME method
            String upperCasedName = methodName.substring(0, 1).toUpperCase(Locale.US) + methodName.substring(1);
            invInfo.targetMethod1 = ejbClass.getMethod("ejbHome" + upperCasedName, paramTypes);
        }
    } catch (NoSuchMethodException nsme) {
        if (methodClass == localBusinessHomeIntf || methodClass == remoteBusinessHomeIntf || methodClass == ejbOptionalLocalBusinessHomeIntf || methodClass == GenericEJBHome.class) {
        // Not an error.  This is the case where the EJB 3.0
        // client view is being used and there is no corresponding
        // create/init method.
        } else if (isStatelessSession || isSingleton) {
        // Ignore.  Not an error.
        // EJB 3.0 Stateless session ejbCreate/PostConstruct
        // is decoupled from RemoteHome/LocalHome create().
        } else {
            Method initMethod = null;
            if (isSession) {
                EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDescriptor;
                for (EjbInitInfo next : sessionDesc.getInitMethods()) {
                    MethodDescriptor beanMethod = next.getBeanMethod();
                    Method m = beanMethod.getMethod(sessionDesc);
                    if (next.getCreateMethod().getName().equals(methodName) && TypeUtil.sameParamTypes(m, invInfo.method)) {
                        initMethod = m;
                        break;
                    }
                }
            }
            if (initMethod != null) {
                invInfo.targetMethod1 = initMethod;
            } else {
                Object[] params = { logParams[0], (isLocal ? "LocalHome" : "Home"), invInfo.method.toString() };
                _logger.log(Level.WARNING, BEAN_CLASS_METHOD_NOT_FOUND, params);
                // Treat this as a warning instead of a fatal error.
                // That matches the behavior of the generated code.
                // Mark the target methods as null.  If this method is
                // invoked at runtime it will be result in an exception
                // from the invocation handlers.
                invInfo.targetMethod1 = null;
                invInfo.targetMethod2 = null;
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) javax.ejb(javax.ejb) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbInitInfo(org.glassfish.ejb.deployment.descriptor.EjbInitInfo)

Aggregations

EjbInitInfo (org.glassfish.ejb.deployment.descriptor.EjbInitInfo)4 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 Method (java.lang.reflect.Method)3 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)2 DataSourceDefinitionNode (com.sun.enterprise.deployment.node.DataSourceDefinitionNode)1 LifecycleCallbackNode (com.sun.enterprise.deployment.node.LifecycleCallbackNode)1 MailSessionNode (com.sun.enterprise.deployment.node.MailSessionNode)1 MethodNode (com.sun.enterprise.deployment.node.MethodNode)1 javax.ejb (javax.ejb)1 ConcurrentMethodDescriptor (org.glassfish.ejb.deployment.descriptor.ConcurrentMethodDescriptor)1 EjbRemovalInfo (org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo)1 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)1 TimeoutValueDescriptor (org.glassfish.ejb.deployment.descriptor.TimeoutValueDescriptor)1 Node (org.w3c.dom.Node)1