Hi

I synchronized the validation for invalid ConcurrencyManagement annotation 
which I wrote weeks ago with the latest 
trunk. I hope this is the way of submitting patches. If not, let me know.  
I had problems to execute a full build. 
Within eclipse the validation test for this check passes.

The JIRA task is: OPENEJB-453 Validation for EJB 3.0 beans / 
OPENEJB-849

Let me know if there are issues or things I have to improve.

Thanks
Ralf

diff -ru -N tomee/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java tomee-new/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
--- tomee/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java	2013-05-24 19:57:48.854941735 +0200
+++ tomee-new/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java	2013-05-24 19:51:30.117958621 +0200
@@ -31,7 +31,6 @@
 import org.apache.openejb.config.rules.CheckCallbacks;
 import org.apache.openejb.config.rules.CheckCdiEnabled;
 import org.apache.openejb.config.rules.CheckClasses;
-import org.apache.openejb.config.rules.CheckConcurrencyManagement;
 import org.apache.openejb.config.rules.CheckDependsOn;
 import org.apache.openejb.config.rules.CheckDescriptorLocation;
 import org.apache.openejb.config.rules.CheckInjectionPointUsage;
@@ -131,8 +130,7 @@
                 new CheckAnnotations(),
                 new CheckIncorrectPropertyNames(),
                 new CheckRestMethodArePublic(),
-                new CheckCdiEnabled(),
-                new CheckConcurrencyManagement(),
+                new CheckCdiEnabled()
         };
         if (additionalValidators == null || additionalValidators.length == 0) {
             return defaultRules;
diff -ru -N tomee/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java tomee-new/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java
--- tomee/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java	2013-03-28 19:58:35.000000000 +0100
+++ tomee-new/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java	1970-01-01 01:00:00.000000000 +0100
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.openejb.config.rules;
-
-import java.lang.annotation.Annotation;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.ejb.ConcurrencyManagementType;
-
-import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.config.WebModule;
-import org.apache.openejb.jee.EnterpriseBean;
-import org.apache.openejb.jee.SessionBean;
-import org.apache.openejb.jee.SessionType;
-import org.apache.openejb.util.LogCategory;
-import org.apache.openejb.util.Logger;
-import org.apache.xbean.finder.IAnnotationFinder;
-
-public class CheckConcurrencyManagement extends ValidationBase {
-
-	private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_VALIDATION, CheckAnnotations.class);
-	private static final String VALIDATION_KEY = "concurrencyManagement.invalidSessionBeanType";
-	
-	public void validate(final AppModule appModule) {
-        try {
-            for (final EjbModule ejbModule : appModule.getEjbModules()) {
-                module = ejbModule;
-                findInvalidAnnotatedClasses(ejbModule);
-                findInvalidConfiguredClasses(ejbModule);
-            }
-
-            for (final WebModule webModule : appModule.getWebModules()) {
-                module = webModule;
-                findInvalidAnnotatedClasses(webModule);
-            }            
-        } catch (Exception e) {
-            logger.error("Error while validating @ConcurrencyManagement, @Lock annotations", e);
-        }
-	}
-	
-	//------------------------------------------------------------------------------||
-	//-- Privates Methods ----------------------------------------------------------||
-	//------------------------------------------------------------------------------||	
-
-    private void findInvalidAnnotatedClasses(final EjbModule ejbModule) {                                                            
-    	final IAnnotationFinder finder = ejbModule.getFinder();
-        if (finder != null) {
-        	findIncorrectAnnotations(finder, ejbModule.toString());
-        }
-    }
-
-    private void findInvalidAnnotatedClasses(final WebModule webModule) { 
-    	final IAnnotationFinder finder = webModule.getFinder();
-        if (finder != null) {
-        	findIncorrectAnnotations(finder, webModule.toString());
-        }
-    }
-    
-    private void findInvalidConfiguredClasses(final EjbModule ejbModule) {                                                            
-    	for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
-    		if (enterpriseBean instanceof SessionBean) {
-    			final SessionBean sessionBean = (SessionBean)enterpriseBean;    					
-    			if (sessionBean.getSessionType() == SessionType.STATEFUL) {
-    			    if (sessionBean.getConcurrencyManagementType() != null 
-    			     && sessionBean.getConcurrencyManagementType().name().equals(ConcurrencyManagementType.BEAN.name())) {
-    			    	module.getValidation().warn(ejbModule.toString(), VALIDATION_KEY, enterpriseBean.getMappedName());
-    			    }
-    			} else if (sessionBean.getSessionType() == SessionType.MANAGED || sessionBean.getSessionType() == SessionType.STATELESS) {
-    				if (sessionBean.getConcurrencyManagementType() != null) {
-    			    	module.getValidation().warn(ejbModule.toString(), VALIDATION_KEY, enterpriseBean.getMappedName());
-    			    }
-    			}
-    		} 
-        }
-    }
-    
-    private void findIncorrectAnnotations(final IAnnotationFinder finder, final String component) {
-        final List<Class<?>> classes = finder.findAnnotatedClasses(javax.ejb.ConcurrencyManagement.class); 
-        
-        for (final Class<?> clazz : classes) {        	
-        	final javax.ejb.ConcurrencyManagement concManag = clazz.getAnnotation(javax.ejb.ConcurrencyManagement.class);
-        	final ConcurrencyManagementType type = concManag.value();        	
-        	final Annotation[] annotations = clazz.getDeclaredAnnotations();
-        	final List<Annotation> declaredAnnotations = Arrays.asList(annotations);
-        	
-            for (final Annotation declaredAnn : declaredAnnotations) {
-            	
-                if (declaredAnn.annotationType().getName().equals("javax.ejb.Stateful")) {
-                	if (ConcurrencyManagementType.BEAN.equals(type)) {
-                  	    module.getValidation().warn(component, VALIDATION_KEY, clazz.getName());
-                	}
-                }
-                
-                if (declaredAnn.annotationType().getName().equals("javax.ejb.Stateless")) {
-                	module.getValidation().warn(component, VALIDATION_KEY, clazz.getName());
-                }
-                
-                if (declaredAnn.annotationType().getName().equals("javax.annotation.ManagedBean")) {
-                	module.getValidation().warn(component, VALIDATION_KEY, clazz.getName());
-                }
-                
-                if (declaredAnn.annotationType().getName().equals("javax.ejb.MessageDriven")) {
-                	module.getValidation().warn(component, VALIDATION_KEY, clazz.getName());
-                }
-            }
-        }
-    }
-}
diff -ru -N tomee/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties tomee-new/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
--- tomee/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties	2013-05-24 20:01:22.068932229 +0200
+++ tomee-new/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties	2013-05-24 19:51:30.171958618 +0200
@@ -918,10 +918,4 @@
 
 1.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled.
 2.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled. Maybe you'd need to add a beans.xml file.
-3.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled. Maybe you'd need to add a beans.xml file. It should be in WEB-INF for a webapp or in META-INF for a jar.
-
-# warn(module, "concurrencyManagement.invalidSessionBeanType", ejbName);
-1.concurrencyManagement.invalidSessionBeanType = Invalid use of @ConcurrencyManagement or @Lock in non-singleton bean: class {0}
-2.concurrencyManagement.invalidSessionBeanType = Invalid use of @ConcurrencyManagement or @Lock in non-singleton bean: class {0}
-3.concurrencyManagement.invalidSessionBeanType = Invalid use of @ConcurrencyManagement or @Lock in non-singleton bean: class {0}
-
+3.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled. Maybe you'd need to add a beans.xml file. It should be in WEB-INF for a webapp or in META-INF for a jar.
\ No newline at end of file
diff -ru -N tomee/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java tomee-new/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java
--- tomee/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java	2013-03-28 20:02:14.000000000 +0100
+++ tomee-new/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java	1970-01-01 01:00:00.000000000 +0100
@@ -1,146 +0,0 @@
-package org.apache.openejb.config.rules;
-
-import javax.ejb.ConcurrencyManagement;
-import javax.ejb.ConcurrencyManagementType;
-import javax.ejb.Singleton;
-import javax.ejb.Stateful;
-import javax.ejb.Stateless;
-
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.ManagedBean;
-import org.apache.openejb.jee.SingletonBean;
-import org.apache.openejb.jee.StatefulBean;
-import org.apache.openejb.jee.StatelessBean;
-import org.apache.xbean.finder.AnnotationFinder;
-import org.apache.xbean.finder.archive.ClassesArchive;
-import org.junit.runner.RunWith;
-
-@RunWith(ValidationRunner.class)
-public class CheckConcurrencyManagementTest {
-
-	@Keys( { @Key(value = "concurrencyManagement.invalidSessionBeanType", count = 3, type = KeyType.WARNING )})
-    public EjbModule testInvalidAnnotations() throws OpenEJBException {
-        
-        final SingletonBean validSingletonBean1 = new SingletonBean(SingletonBeanConcurrencyTypeBean.class);
-        final SingletonBean validSingletonBean2 = new SingletonBean(SingletonBeanConcurrencyTypeContainer.class);
-        final StatefulBean validStatefulBean1 = new StatefulBean(StatefulBeanConcurrencyTypeContainer.class);
-        
-        final StatelessBean invalidStlsBean1 = new StatelessBean(StatelessBeanConcurrencyTypeBean.class);
-        final StatelessBean invalidStlsBean2 = new StatelessBean(StatelessBeanConcurrencyTypeContainer.class);
-        final StatefulBean invalidStfBean1 = new StatefulBean(StatefulBeanConcurrencyTypeBean.class);
-        final StatefulBean invalidStfBean2 = new StatefulBean(StatefulBeanConcurrencyTypeContainer.class);
-        
-        final EjbJar ejbJar = new EjbJar();
-        ejbJar.addEnterpriseBean(validSingletonBean1);
-        ejbJar.addEnterpriseBean(validSingletonBean2);
-        ejbJar.addEnterpriseBean(validStatefulBean1);
-        ejbJar.addEnterpriseBean(invalidStlsBean1);
-        ejbJar.addEnterpriseBean(invalidStlsBean2);
-        ejbJar.addEnterpriseBean(invalidStfBean1);
-        ejbJar.addEnterpriseBean(invalidStfBean2);   
-        
-        final EjbModule ejbModule = new EjbModule(ejbJar);
-        ejbModule.setFinder(
-    		new AnnotationFinder(new ClassesArchive(
-    				SingletonBeanConcurrencyTypeBean.class,
-    				SingletonBeanConcurrencyTypeContainer.class,
-    				StatefulBeanConcurrencyTypeContainer.class,
-	        		StatelessBeanConcurrencyTypeBean.class,
-	        		StatelessBeanConcurrencyTypeContainer.class,
-	        		StatefulBeanConcurrencyTypeBean.class,
-	        		StatefulBeanConcurrencyTypeContainer.class)).link());
-    
-        return ejbModule;
-    }
-	
-	@Keys( { @Key(value = "concurrencyManagement.invalidSessionBeanType", count = 1, type = KeyType.WARNING )})
-	public EjbModule testInvalidStatefulConfiguration() throws OpenEJBException {
-		 final EjbJar ejbJar = new EjbJar();
-		 final EjbModule ejbModule = new EjbModule(ejbJar);		 
-		 final StatefulBean statefulBean = new StatefulBean(Pojo.class);
-		 
-		 statefulBean.setConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType.BEAN);
-		 ejbJar.addEnterpriseBean(statefulBean);
-		 ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Pojo.class)).link());
-		 
-		 return ejbModule;
-	}
-	
-	@Keys( { @Key(value = "concurrencyManagement.invalidSessionBeanType", count = 1, type = KeyType.WARNING )})
-	public EjbModule testInvalidStatelessConfiguration() throws OpenEJBException {
-		 final EjbJar ejbJar = new EjbJar();
-		 final EjbModule ejbModule = new EjbModule(ejbJar);		 
-		 final StatelessBean statelessBean = new StatelessBean(Pojo.class);
-		 
-		 statelessBean.setConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType.BEAN);
-		 ejbJar.addEnterpriseBean(statelessBean);
-		 ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Pojo.class)).link());
-		 
-		 return ejbModule;
-	}
-	  
-	@Keys( { @Key(value = "concurrencyManagement.invalidSessionBeanType", count = 1, type = KeyType.WARNING )})
-	public EjbModule testInvalidManagedConfiguration() throws OpenEJBException {
-		 final EjbJar ejbJar = new EjbJar();
-		 final EjbModule ejbModule = new EjbModule(ejbJar);		 
-		 final ManagedBean managedBean = new ManagedBean(Pojo.class);
-		 
-		 managedBean.setConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType.BEAN);
-		 ejbJar.addEnterpriseBean(managedBean);
-		 ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Pojo.class)).link());
-		 
-		 return ejbModule;
-	}
-	
-	//---------------------------------------------------------||
-	//-- Valid Singleton Beans --------------------------------||
-	//---------------------------------------------------------||
-	
-	@Singleton
-	@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
-    private static class SingletonBeanConcurrencyTypeBean {
-	}
-	
-	@Singleton
-	@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
-    private static class SingletonBeanConcurrencyTypeContainer {
-	}
-	
-	//---------------------------------------------------------||
-	//-- Valid Stateful Beans ---------------------------------||
-	//---------------------------------------------------------||
-	
-	@Stateful
-	@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
-    private static class StatefulBeanConcurrencyTypeContainer {
-	}
-	
-	//---------------------------------------------------------||
-	//-- Invalid Stateless Beans-------------------------------||
-	//---------------------------------------------------------||
-	
-	@Stateless
-	@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
-    private static class StatelessBeanConcurrencyTypeBean {
-	}
-	
-	@Stateless
-	@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
-    private static class StatelessBeanConcurrencyTypeContainer {
-	}
-	
-	//---------------------------------------------------------||
-	//-- Invalid Stateful Beans--------------------------------||
-	//---------------------------------------------------------||
-	
-	@Stateful
-	@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
-    private static class StatefulBeanConcurrencyTypeBean {
-	}	
-	
-	
-	private static class Pojo {
-	}
-}

Reply via email to