Hi

Thanks a lot for your patience. I switched to svn in order to have better 
support and control.

I attached the diff 
produced by svn. I realized that there are two existing lines tracked as 
changed but have the same content. I think 
this could be related to Eclipse.
Let me know if I should correct these lines.

Regards,
Ralf

----Ursprüngliche 
Nachricht----
Von: [email protected]
Datum: 26.05.2013 21:27
An: <[email protected]>
Betreff: Re: Patch for: 
Validation: @ConcurrencyManagement mistakenly used on non-Singleton

Simply reverse the order you provide the 
tomee/tomee-new directories. That
should fix the issue. In the end you should have plus instead of minus
symbols for 
your newly added code in the patch output file.

Cheers
Daniel


On Sun, May 26, 2013 at 9:21 PM, <ralf.
[email protected]> wrote:

> Hi Romain, I will double check when I am back. Your comment lets my think
> that I 
made mistake with the diff command. It should add the validator and
> not remove.
>
> Thanks for informing me.
> Ralf
>

>
> On 26.05.13 20:38 Romain Manni-Bucau wrote:
>
> hi
>
>
> is the patch correct? it removes what you want to add no?

>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
>
>
> 2013/5/26 [email protected] <[email protected]>

>
> 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
>

>
>
>
>
>


Index: container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
===================================================================
--- container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java	(revision 1486670)
+++ container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java	(working copy)
@@ -31,6 +31,7 @@
 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;
@@ -130,7 +131,8 @@
                 new CheckAnnotations(),
                 new CheckIncorrectPropertyNames(),
                 new CheckRestMethodArePublic(),
-                new CheckCdiEnabled()
+                new CheckCdiEnabled(),
+                new CheckConcurrencyManagement(),
         };
         if (additionalValidators == null || additionalValidators.length == 0) {
             return defaultRules;
Index: container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java
===================================================================
--- container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java	(revision 0)
+++ container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckConcurrencyManagement.java	(working copy)
@@ -0,0 +1,124 @@
+/*
+ * 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());
+                }
+            }
+        }
+    }
+}
Index: container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
===================================================================
--- container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties	(revision 1486670)
+++ container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties	(working copy)
@@ -918,4 +918,10 @@
 
 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.
\ No newline at end of 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}
+
Index: container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java
===================================================================
--- container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java	(revision 0)
+++ container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckConcurrencyManagementTest.java	(working copy)
@@ -0,0 +1,146 @@
+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