PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/deployment/processors/merging/EjbConcurrencyMergingProcessor.java

#
Java | 166 lines | 114 code | 23 blank | 29 comment | 34 complexity | 059ed19dbfbe1eebad3dcb02f85c6841 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2010, Red Hat Inc., and individual contributors as indicated
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ejb3.deployment.processors.merging;
  23. import java.lang.reflect.Method;
  24. import java.util.Collection;
  25. import java.util.List;
  26. import java.util.Map;
  27. import javax.ejb.AccessTimeout;
  28. import javax.ejb.Lock;
  29. import javax.ejb.LockType;
  30. import org.jboss.as.ee.component.EEApplicationClasses;
  31. import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
  32. import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
  33. import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
  34. import org.jboss.as.ejb3.concurrency.AccessTimeoutDetails;
  35. import org.jboss.as.server.deployment.DeploymentUnit;
  36. import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
  37. import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
  38. import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
  39. import org.jboss.invocation.proxy.MethodIdentifier;
  40. import org.jboss.metadata.ejb.spec.ConcurrentMethodMetaData;
  41. import org.jboss.metadata.ejb.spec.ConcurrentMethodsMetaData;
  42. import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
  43. import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
  44. import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
  45. import static org.jboss.as.ejb3.EjbMessages.MESSAGES;
  46. /**
  47. * Class that can merge {@link javax.ejb.Lock} and {@link javax.ejb.AccessTimeout} metadata
  48. *
  49. * @author Stuart Douglas
  50. */
  51. public class EjbConcurrencyMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
  52. public EjbConcurrencyMergingProcessor() {
  53. super(SessionBeanComponentDescription.class);
  54. }
  55. protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) {
  56. //handle lock annotations
  57. final RuntimeAnnotationInformation<LockType> lockData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Lock.class);
  58. for (Map.Entry<String, List<LockType>> entry : lockData.getClassAnnotations().entrySet()) {
  59. if (!entry.getValue().isEmpty()) {
  60. componentConfiguration.setBeanLevelLockType(entry.getKey(), entry.getValue().get(0));
  61. }
  62. }
  63. for (Map.Entry<Method, List<LockType>> entry : lockData.getMethodAnnotations().entrySet()) {
  64. if (!entry.getValue().isEmpty()) {
  65. componentConfiguration.setLockType(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
  66. }
  67. }
  68. final RuntimeAnnotationInformation<AccessTimeoutDetails> accessTimeout = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, AccessTimeout.class);
  69. for (Map.Entry<String, List<AccessTimeoutDetails>> entry : accessTimeout.getClassAnnotations().entrySet()) {
  70. if (!entry.getValue().isEmpty()) {
  71. componentConfiguration.setBeanLevelAccessTimeout(entry.getKey(), entry.getValue().get(0));
  72. }
  73. }
  74. for (Map.Entry<Method, List<AccessTimeoutDetails>> entry : accessTimeout.getMethodAnnotations().entrySet()) {
  75. if (!entry.getValue().isEmpty()) {
  76. componentConfiguration.setAccessTimeout(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
  77. }
  78. }
  79. }
  80. protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
  81. if (componentConfiguration.getDescriptorData() == null) {
  82. return;
  83. }
  84. SessionBeanMetaData sessionBeanMetaData = componentConfiguration.getDescriptorData();
  85. if (sessionBeanMetaData instanceof SessionBean31MetaData) {
  86. SessionBean31MetaData descriptor = (SessionBean31MetaData) sessionBeanMetaData;
  87. //handle lock
  88. if (descriptor.getLockType() != null) {
  89. componentConfiguration.setBeanLevelLockType(componentConfiguration.getEJBClassName(), descriptor.getLockType());
  90. }
  91. //handle access timeout
  92. if (descriptor.getAccessTimeout() != null) {
  93. componentConfiguration.setBeanLevelAccessTimeout(componentConfiguration.getEJBClassName(), new AccessTimeoutDetails(descriptor.getAccessTimeout().getTimeout(), descriptor.getAccessTimeout().getUnit()));
  94. }
  95. final ConcurrentMethodsMetaData methods = descriptor.getConcurrentMethods();
  96. if (methods != null) {
  97. for (final ConcurrentMethodMetaData method : methods) {
  98. final Method realMethod = resolveMethod(deploymentReflectionIndex, componentClass, componentClass, method.getMethod());
  99. final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(realMethod);
  100. if (method.getLockType() != null) {
  101. componentConfiguration.setLockType(method.getLockType(), methodIdentifier);
  102. }
  103. if (method.getAccessTimeout() != null) {
  104. componentConfiguration.setAccessTimeout(new AccessTimeoutDetails(method.getAccessTimeout().getTimeout(), method.getAccessTimeout().getUnit()), methodIdentifier);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. private Method resolveMethod(final DeploymentReflectionIndex index, final Class<?> currentClass, final Class<?> componentClass, final NamedMethodMetaData methodData) throws DeploymentUnitProcessingException {
  111. if (currentClass == null) {
  112. throw MESSAGES.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
  113. }
  114. final ClassReflectionIndex<?> classIndex = index.getClassIndex(currentClass);
  115. if (methodData.getMethodParams() == null) {
  116. final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
  117. if (methods.isEmpty()) {
  118. return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
  119. } else if (methods.size() > 1) {
  120. throw MESSAGES.multipleMethodReferencedInEjbJarXml( methodData.getMethodName(),currentClass.getName());
  121. }
  122. return methods.iterator().next();
  123. } else {
  124. final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
  125. for (final Method method : methods) {
  126. boolean match = true;
  127. for (int i = 0; i < method.getParameterTypes().length; ++i) {
  128. if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
  129. match = false;
  130. break;
  131. }
  132. }
  133. if (match) {
  134. return method;
  135. }
  136. }
  137. }
  138. return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
  139. }
  140. @Override
  141. public void undeploy(final DeploymentUnit context) {
  142. }
  143. }