private void processSessionBeanMetaData( final DeploymentUnit deploymentUnit, final SessionBeanMetaData sessionBean) throws DeploymentUnitProcessingException { final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final CompositeIndex compositeIndex = deploymentUnit.getAttachment( org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX); final String beanName = sessionBean.getName(); SessionType sessionType = sessionBean.getSessionType(); if (sessionType == null && sessionBean instanceof GenericBeanMetaData) { final GenericBeanMetaData bean = (GenericBeanMetaData) sessionBean; if (bean.getEjbType() == EjbType.SESSION) { sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex); if (sessionType == null) { throw EjbMessages.MESSAGES.sessionTypeNotSpecified(beanName); } } else { // it is not a session bean, so we ignore it return; } } else if (sessionType == null) { sessionType = determineSessionType(sessionBean.getEjbClass(), compositeIndex); if (sessionType == null) { throw EjbMessages.MESSAGES.sessionTypeNotSpecified(beanName); } } final String beanClassName = sessionBean.getEjbClass(); final SessionBeanComponentDescription sessionBeanDescription; switch (sessionType) { case Stateless: sessionBeanDescription = new StatelessComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean); break; case Stateful: sessionBeanDescription = new StatefulComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean); // TODO: Handle passivation capable for stateful beans in EJB3.2 break; case Singleton: sessionBeanDescription = new SingletonComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName(), sessionBean); break; default: throw EjbMessages.MESSAGES.unknownSessionBeanType(sessionType.name()); } addComponent(deploymentUnit, sessionBeanDescription); }
private void processSessionBeans( final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) { final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName(); // process these session bean annotations and create component descriptions out of it for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) { final AnnotationTarget target = sessionBeanAnnotation.target(); if (!(target instanceof ClassInfo)) { // Let's just WARN and move on. No need to throw an error EjbMessages.MESSAGES.annotationOnlyAllowedOnClass( sessionBeanAnnotation.name().toString(), target); continue; } final ClassInfo sessionBeanClassInfo = (ClassInfo) target; // skip if it's not a valid class for session bean if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) { continue; } final String ejbName = sessionBeanClassInfo.name().local(); final AnnotationValue nameValue = sessionBeanAnnotation.value("name"); final String beanName = nameValue == null || nameValue.asString().isEmpty() ? ejbName : nameValue.asString(); final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class); final SessionBeanComponentDescription.SessionBeanType sessionBeanType; final String beanClassName; if (beanMetaData != null) { beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass()); sessionBeanType = override( annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType())); } else { beanClassName = sessionBeanClassInfo.name().toString(); sessionBeanType = annotatedSessionBeanType; } final SessionBeanComponentDescription sessionBeanDescription; switch (sessionBeanType) { case STATELESS: sessionBeanDescription = new StatelessComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); break; case STATEFUL: sessionBeanDescription = new StatefulComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); // If passivation is disabled for the SFSB, either via annotation or via DD, then setup // the component // description appropriately final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean(); // TODO: Pass the DD value as first param for override final boolean passivationApplicable = override(null, passivationCapableAnnotationValue); ((StatefulComponentDescription) sessionBeanDescription) .setPassivationApplicable(passivationApplicable); break; case SINGLETON: sessionBeanDescription = new SingletonComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnitServiceName, beanMetaData); break; default: throw EjbMessages.MESSAGES.unknownSessionBeanType(sessionBeanType.name()); } addComponent(deploymentUnit, sessionBeanDescription); } EjbDeploymentMarker.mark(deploymentUnit); }
public void assertFullSessionBean(String ejbName, SessionBeanMetaData session, Mode mode) { assertId(ejbName, session); // TODO: enrich the jboss xml if (mode == Mode.SPEC) { assertMappedName(ejbName, session.getMappedName()); assertClass(ejbName, "Home", session.getHome()); assertClass(ejbName, "Remote", session.getRemote()); assertClass(ejbName, "LocalHome", session.getLocalHome()); assertClass(ejbName, "Local", session.getLocal()); assertClasses(ejbName, "BusinessLocal", 2, session.getBusinessLocals()); assertClasses(ejbName, "BusinessRemote", 2, session.getBusinessRemotes()); assertClass(ejbName, "ServiceEndpoint", session.getServiceEndpoint()); assertClass(ejbName, "EjbClass", session.getEjbClass()); assertEquals(SessionType.Stateless, session.getSessionType()); assertNamedMethod(ejbName + "TimeoutMethod", 2, session.getTimeoutMethod()); assertInitMethods(ejbName, 2, session.getInitMethods()); assertRemoveMethods(ejbName, 3, session.getRemoveMethods()); assertEquals(TransactionManagementType.CONTAINER, session.getTransactionType()); assertAroundInvokes(ejbName, 2, session.getAroundInvokes()); assertLifecycleCallbacks(ejbName, "PostActivate", 2, session.getPostActivates()); assertLifecycleCallbacks(ejbName, "PrePassivate", 2, session.getPrePassivates()); assertEnvironment(ejbName, session.getJndiEnvironmentRefsGroup(), true, mode); assertContainerTransactions(ejbName, 6, 6, session.getContainerTransactions()); assertMethodPermissions( ejbName, ejbName + "MethodPermission", 3, 3, session.getMethodPermissions()); assertExcludeList(ejbName, 5, 5, session.getExcludeList()); assertSecurityRoleRefs(ejbName, 2, session.getSecurityRoleRefs()); assertSecurityIdentity( ejbName, "SecurityIdentity", session.getSecurityIdentity(), true, mode); } else { assertNull(session.getMappedName()); assertNull(session.getHome()); assertNull(session.getRemote()); assertNull(session.getLocalHome()); assertNull(session.getLocal()); assertNull(session.getBusinessLocals()); assertNull(session.getBusinessRemotes()); assertNull(session.getServiceEndpoint()); assertNull(session.getEjbClass()); assertNull(session.getSessionType()); assertNull(session.getTimeoutMethod()); assertNull(session.getInitMethods()); assertNull(session.getRemoveMethods()); assertNull(session.getTransactionType()); assertNull(session.getAroundInvokes()); assertNull(session.getPostActivates()); assertNull(session.getPrePassivates()); assertEnvironment(ejbName, session.getJndiEnvironmentRefsGroup(), false, mode); assertNull(session.getContainerTransactions()); assertNull(session.getMethodPermissions()); assertNull(session.getExcludeList()); assertNull(session.getSecurityRoleRefs()); assertSecurityIdentity( ejbName, "SecurityIdentity", session.getSecurityIdentity(), false, mode); } }
private void processComponentConfig( final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException, ClassNotFoundException { String home = null; String localHome = null; // first check for annotations if (!MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) { final EEModuleClassDescription clazz = applicationClasses.getClassByName(description.getComponentClassName()); // we only care about annotations on the bean class itself if (clazz != null) { final ClassAnnotationInformation<LocalHome, String> localAnnotations = clazz.getAnnotationInformation(LocalHome.class); if (localAnnotations != null) { if (!localAnnotations.getClassLevelAnnotations().isEmpty()) { localHome = localAnnotations.getClassLevelAnnotations().get(0); if (description.getEjbLocalView() == null) { // If the local home is specified via annotation then the corresponding business // interface is implied // by the signature of the create method // See EJB 3.1 21.4.5 final String localClassName = this.inferLocalInterfaceFromLocalHome( localHome, module, deploymentReflectionIndex, description); description.addEjbLocalObjectView(localClassName); } } } final ClassAnnotationInformation<RemoteHome, String> remoteAnnotations = clazz.getAnnotationInformation(RemoteHome.class); if (remoteAnnotations != null) { if (!remoteAnnotations.getClassLevelAnnotations().isEmpty()) { home = remoteAnnotations.getClassLevelAnnotations().get(0); if (description.getEjbRemoteView() == null) { // If the remote home is specified via annotation then the corresponding business // interface is implied // by the signature of the create method // See EJB 3.1 21.4.5 final String remoteClassName = this.inferRemoteInterfaceFromHome( home, module, deploymentReflectionIndex, description); description.addEjbObjectView(remoteClassName); } } } } } // now allow the annotations to be overridden by the DD final SessionBeanMetaData descriptorData = description.getDescriptorData(); if (descriptorData != null) { if (descriptorData.getHome() != null) { home = descriptorData.getHome(); } if (descriptorData.getLocalHome() != null) { localHome = descriptorData.getLocalHome(); } } if (localHome != null) { description.addLocalHome(localHome); } if (home != null) { description.addRemoteHome(home); } // finally see if we have to infer the remote or local interface from the home/local home views, // respectively if (description.getEjbHomeView() != null && description.getEjbRemoteView() == null) { final String remoteClassName = this.inferRemoteInterfaceFromHome( description.getEjbHomeView().getViewClassName(), module, deploymentReflectionIndex, description); description.addEjbObjectView(remoteClassName); } if (description.getEjbLocalHomeView() != null && description.getEjbLocalView() == null) { final String localClassName = this.inferLocalInterfaceFromLocalHome( description.getEjbLocalHomeView().getViewClassName(), module, deploymentReflectionIndex, description); description.addEjbLocalObjectView(localClassName); } }
private void processSessionBeanMetaData( final DeploymentUnit deploymentUnit, final SessionBeanMetaData sessionBean) throws DeploymentUnitProcessingException { final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final List<ComponentDescription> additionalComponents = deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS); final String beanName = sessionBean.getName(); // the important bit is to skip already processed EJBs via annotations if (ejbJarDescription.hasComponent(beanName)) { final ComponentDescription description = eeModuleDescription.getComponentByName(beanName); if (description instanceof SessionBeanComponentDescription) { ((SessionBeanComponentDescription) description).setDescriptorData(sessionBean); } else { throw new DeploymentUnitProcessingException( "Session bean with name " + beanName + " referenced in ejb-jar.xml could not be created, as existing non session bean component with same name already exists: " + description); } return; } if (appclient) { for (final ComponentDescription component : additionalComponents) { if (component.getComponentName().equals(beanName)) { if (component instanceof SessionBeanComponentDescription) { ((SessionBeanComponentDescription) component).setDescriptorData(sessionBean); } else { throw new DeploymentUnitProcessingException( "Session bean with name " + beanName + " referenced in ejb-jar.xml could not be created, as existing non session bean component with same name already exists: " + component); } return; } } } final SessionType sessionType = sessionBean.getSessionType(); if (sessionType == null) {} if (sessionType == null && sessionBean instanceof GenericBeanMetaData) { // TODO: this is a hack return; } final String beanClassName = sessionBean.getEjbClass(); final SessionBeanComponentDescription sessionBeanDescription; switch (sessionType) { case Stateless: sessionBeanDescription = new StatelessComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName()); break; case Stateful: sessionBeanDescription = new StatefulComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName()); break; case Singleton: sessionBeanDescription = new SingletonComponentDescription( beanName, beanClassName, ejbJarDescription, deploymentUnit.getServiceName()); break; default: throw new IllegalArgumentException("Unknown session bean type: " + sessionType); } if (appclient) { deploymentUnit.addToAttachmentList( Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS, sessionBeanDescription); } else { // Add this component description to module description ejbJarDescription.getEEModuleDescription().addComponent(sessionBeanDescription); } sessionBeanDescription.setDescriptorData(sessionBean); }