PageRenderTime 44ms CodeModel.GetById 26ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 1ms

/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 */
 22package org.jboss.as.ejb3.deployment.processors.merging;
 23
 24import java.lang.reflect.Method;
 25import java.util.Collection;
 26import java.util.List;
 27import java.util.Map;
 28
 29import javax.ejb.AccessTimeout;
 30import javax.ejb.Lock;
 31import javax.ejb.LockType;
 32
 33import org.jboss.as.ee.component.EEApplicationClasses;
 34import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
 35import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
 36import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
 37import org.jboss.as.ejb3.concurrency.AccessTimeoutDetails;
 38import org.jboss.as.server.deployment.DeploymentUnit;
 39import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
 40import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
 41import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
 42import org.jboss.invocation.proxy.MethodIdentifier;
 43import org.jboss.metadata.ejb.spec.ConcurrentMethodMetaData;
 44import org.jboss.metadata.ejb.spec.ConcurrentMethodsMetaData;
 45import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
 46import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
 47import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
 48
 49import static org.jboss.as.ejb3.EjbMessages.MESSAGES;
 50/**
 51 * Class that can merge {@link javax.ejb.Lock} and {@link javax.ejb.AccessTimeout} metadata
 52 *
 53 * @author Stuart Douglas
 54 */
 55public class EjbConcurrencyMergingProcessor extends AbstractMergingProcessor<SessionBeanComponentDescription> {
 56
 57    public EjbConcurrencyMergingProcessor() {
 58        super(SessionBeanComponentDescription.class);
 59    }
 60
 61    protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) {
 62
 63        //handle lock annotations
 64
 65        final RuntimeAnnotationInformation<LockType> lockData = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Lock.class);
 66        for (Map.Entry<String, List<LockType>> entry : lockData.getClassAnnotations().entrySet()) {
 67            if (!entry.getValue().isEmpty()) {
 68                componentConfiguration.setBeanLevelLockType(entry.getKey(), entry.getValue().get(0));
 69            }
 70        }
 71        for (Map.Entry<Method, List<LockType>> entry : lockData.getMethodAnnotations().entrySet()) {
 72            if (!entry.getValue().isEmpty()) {
 73                componentConfiguration.setLockType(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
 74            }
 75        }
 76
 77        final RuntimeAnnotationInformation<AccessTimeoutDetails> accessTimeout = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, AccessTimeout.class);
 78        for (Map.Entry<String, List<AccessTimeoutDetails>> entry : accessTimeout.getClassAnnotations().entrySet()) {
 79            if (!entry.getValue().isEmpty()) {
 80                componentConfiguration.setBeanLevelAccessTimeout(entry.getKey(), entry.getValue().get(0));
 81            }
 82        }
 83        for (Map.Entry<Method, List<AccessTimeoutDetails>> entry : accessTimeout.getMethodAnnotations().entrySet()) {
 84            if (!entry.getValue().isEmpty()) {
 85                componentConfiguration.setAccessTimeout(entry.getValue().get(0), MethodIdentifier.getIdentifierForMethod(entry.getKey()));
 86            }
 87        }
 88
 89    }
 90
 91    protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
 92
 93        if (componentConfiguration.getDescriptorData() == null) {
 94            return;
 95        }
 96        SessionBeanMetaData sessionBeanMetaData = componentConfiguration.getDescriptorData();
 97        if (sessionBeanMetaData instanceof SessionBean31MetaData) {
 98            SessionBean31MetaData descriptor = (SessionBean31MetaData) sessionBeanMetaData;
 99
100            //handle lock
101            if (descriptor.getLockType() != null) {
102                componentConfiguration.setBeanLevelLockType(componentConfiguration.getEJBClassName(), descriptor.getLockType());
103            }
104
105            //handle access timeout
106            if (descriptor.getAccessTimeout() != null) {
107                componentConfiguration.setBeanLevelAccessTimeout(componentConfiguration.getEJBClassName(), new AccessTimeoutDetails(descriptor.getAccessTimeout().getTimeout(), descriptor.getAccessTimeout().getUnit()));
108            }
109
110            final ConcurrentMethodsMetaData methods = descriptor.getConcurrentMethods();
111            if (methods != null) {
112                for (final ConcurrentMethodMetaData method : methods) {
113                    final Method realMethod = resolveMethod(deploymentReflectionIndex, componentClass, componentClass, method.getMethod());
114                    final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(realMethod);
115                    if (method.getLockType() != null) {
116                        componentConfiguration.setLockType(method.getLockType(), methodIdentifier);
117                    }
118                    if (method.getAccessTimeout() != null) {
119                        componentConfiguration.setAccessTimeout(new AccessTimeoutDetails(method.getAccessTimeout().getTimeout(), method.getAccessTimeout().getUnit()), methodIdentifier);
120                    }
121
122                }
123            }
124
125
126        }
127    }
128
129
130    private Method resolveMethod(final DeploymentReflectionIndex index, final Class<?> currentClass, final Class<?> componentClass, final NamedMethodMetaData methodData) throws DeploymentUnitProcessingException {
131        if (currentClass == null) {
132            throw MESSAGES.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
133        }
134        final ClassReflectionIndex<?> classIndex = index.getClassIndex(currentClass);
135
136        if (methodData.getMethodParams() == null) {
137            final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
138            if (methods.isEmpty()) {
139                return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
140            } else if (methods.size() > 1) {
141                throw MESSAGES.multipleMethodReferencedInEjbJarXml( methodData.getMethodName(),currentClass.getName());
142            }
143            return methods.iterator().next();
144        } else {
145            final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
146            for (final Method method : methods) {
147                boolean match = true;
148                for (int i = 0; i < method.getParameterTypes().length; ++i) {
149                    if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
150                        match = false;
151                        break;
152                    }
153                }
154                if (match) {
155                    return method;
156                }
157            }
158        }
159        return resolveMethod(index, currentClass.getSuperclass(), componentClass, methodData);
160    }
161
162    @Override
163    public void undeploy(final DeploymentUnit context) {
164
165    }
166}