Author: dblevins
Date: Thu Sep  6 18:31:31 2007
New Revision: 573423

URL: http://svn.apache.org/viewvc?rev=573423&view=rev
Log:
Turned exceptions thrown regarding usage of @Remote and @Local into validation 
failures, dramatically improved the information given, and made them i18n 
messages.  These will now be printed in compiler-style errors rather than "hit 
the first invalid thing and immediately fail all deployment" style.

Modified:
    
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
    
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/util/resources/Messages.properties

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=573423&r1=573422&r2=573423&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
 Thu Sep  6 18:31:31 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.config;
 
+import static org.apache.openejb.util.Join.join;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.jee.ActivationConfig;
@@ -64,7 +65,6 @@
 import org.apache.openejb.jee.SessionType;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
-import org.apache.openejb.util.SafeToolkit;
 import org.apache.xbean.finder.ClassFinder;
 
 import javax.annotation.PostConstruct;
@@ -336,6 +336,8 @@
         public EjbModule deploy(EjbModule ejbModule) throws OpenEJBException {
             if (ejbModule.getEjbJar() != null && 
ejbModule.getEjbJar().isMetadataComplete()) return ejbModule;
 
+            ValidationContext validation = ejbModule.getValidation();
+
             ClassLoader classLoader = ejbModule.getClassLoader();
             EnterpriseBean[] enterpriseBeans = 
ejbModule.getEjbJar().getEnterpriseBeans();
             for (EnterpriseBean bean : enterpriseBeans) {
@@ -615,19 +617,19 @@
                         Remote remote = clazz.getAnnotation(Remote.class);
                         if (remote != null) {
                             if (remote.value().length == 0) {
-                                if (interfaces.size() != 1)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Remote with no annotation attributes, the bean must 
implement exactly one business interface, no more and no less.");
-                                if (clazz.getAnnotation(Local.class) != null)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Remote with no annotation attributes you must not 
also annotate it with @Local.");
-                                if 
(interfaces.get(0).getAnnotation(Local.class) != null)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Remote with no annotation attributes, the business 
interface itself must not be annotated as @Local.");
-
-                                validateInterface(interfaces.get(0));          
                                                          
-                                remotes.add(interfaces.get(0));
-                                interfaces.remove(0);
-                            }
-                            for (Class interfce : remote.value()) {
-                                validateInterface(interfce);                   
                 
+                                if (interfaces.size() != 1) {
+                                    validation.fail(ejbName, 
"ann.remote.noAttributes", join(", ", interfaces));
+                                } else if (clazz.getAnnotation(Local.class) != 
null) {
+                                    validation.fail(ejbName, 
"ann.remoteLocal.ambiguous", join(", ", interfaces));
+                                } else if 
(interfaces.get(0).getAnnotation(Local.class) != null) {
+                                    validation.fail(ejbName, 
"ann.remoteLocal.conflict", join(", ", interfaces));
+                                } else {
+                                    validateRemoteInterface(interfaces.get(0), 
validation, ejbName);
+                                    remotes.add(interfaces.get(0));
+                                    interfaces.remove(0);
+                                }
+                            } else for (Class interfce : remote.value()) {
+                                validateRemoteInterface(interfce, validation, 
ejbName);
                                 remotes.add(interfce);
                                 interfaces.remove(interfce);
                             }
@@ -637,19 +639,19 @@
                         Local local = clazz.getAnnotation(Local.class);
                         if (local != null) {
                             if (local.value().length == 0) {
-                                if (interfaces.size() != 1)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Local with no annotation attributes, the bean must 
implement exactly one business interface, no more and no less.");
-                                if (clazz.getAnnotation(Remote.class) != null)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Local with no annotation attributes you must not 
also annotate it with @Remote.");
-                                if 
(interfaces.get(0).getAnnotation(Remote.class) != null)
-                                    throw new IllegalStateException("When 
annotating a bean class as @Local with no annotation attributes, the business 
interface itself must not be annotated as @Remote.");
-
-                                validateInterface(interfaces.get(0));
-                                locals.add(interfaces.get(0));
-                                interfaces.remove(0);
-                            }
-                            for (Class interfce : local.value()) {
-                                validateInterface(interfce);
+                                if (interfaces.size() != 1) {
+                                    validation.fail(ejbName, 
"ann.local.noAttributes", join(", ", interfaces));
+                                } else if (clazz.getAnnotation(Remote.class) 
!= null) {
+                                    validation.fail(ejbName, 
"ann.localRemote.ambiguous", join(", ", interfaces));
+                                } else if 
(interfaces.get(0).getAnnotation(Remote.class) != null) {
+                                    validation.fail(ejbName, 
"ann.localRemote.conflict", join(", ", interfaces));
+                                } else {
+                                    validateLocalInterface(interfaces.get(0), 
validation, ejbName);
+                                    locals.add(interfaces.get(0));
+                                    interfaces.remove(0);
+                                }
+                            } else for (Class interfce : local.value()) {
+                                validateLocalInterface(interfce, validation, 
ejbName);
                                 locals.add(interfce);
                                 interfaces.remove(interfce);
                             }
@@ -677,23 +679,19 @@
 
                         for (Class interfce : copy(interfaces)) {
                             if (interfce.isAnnotationPresent(Remote.class)) {
-                                validateInterface(interfce);
                                 remotes.add(interfce);
                                 interfaces.remove(interfce);
                             } else {
-                                validateInterface(interfce);
                                 locals.add(interfce);
                                 interfaces.remove(interfce);
                             }
                         }
 
                         for (Class interfce : remotes) {
-                            // TODO: This should be turned back into an array
                             sessionBean.addBusinessRemote(interfce.getName());
                         }
 
                         for (Class interfce : locals) {
-                            // TODO: This should be turned back into an array
                             sessionBean.addBusinessLocal(interfce.getName());
                         }
                     }
@@ -1446,13 +1444,25 @@
             }
             return null;
         }
-        
-        private void validateInterface(Class interfce) {
-            if (EJBHome.class.isAssignableFrom(interfce) || 
EJBObject.class.isAssignableFrom(interfce)){
-                throw new 
IllegalStateException(SafeToolkit.messages.format("conf.3901", 
interfce.getName() ));
-            }
-            if (EJBLocalHome.class.isAssignableFrom(interfce) || 
EJBLocalObject.class.isAssignableFrom(interfce)){
-                throw new 
IllegalStateException(SafeToolkit.messages.format("conf.3902", 
interfce.getName() ));
+
+
+        private void validateRemoteInterface(Class interfce, ValidationContext 
validation, String ejbName) {
+            validateInterface(interfce, validation, ejbName, "Remote");
+        }
+
+        private void validateLocalInterface(Class interfce, ValidationContext 
validation, String ejbName) {
+            validateInterface(interfce, validation, ejbName, "Local");
+        }
+
+        private void validateInterface(Class interfce, ValidationContext 
validation, String ejbName, String annotationName) {
+            if (EJBHome.class.isAssignableFrom(interfce)){
+                validation.fail(ejbName, "ann.remoteOrLocal.ejbHome", 
annotationName, interfce.getName());
+            } else if (EJBObject.class.isAssignableFrom(interfce)){
+                validation.fail(ejbName, "ann.remoteOrLocal.ejbObject", 
annotationName, interfce.getName());
+            } else if (EJBLocalHome.class.isAssignableFrom(interfce)) {
+                validation.fail(ejbName, "ann.remoteOrLocal.ejbLocalHome", 
annotationName, interfce.getName());
+            } else if (EJBLocalObject.class.isAssignableFrom(interfce)){
+                validation.fail(ejbName, "ann.remoteOrLocal.ejbLocalObject", 
annotationName, interfce.getName());
             }
         }
     }
@@ -1520,6 +1530,5 @@
             return field.getName();
         }
     }
-
 
 }

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=573423&r1=573422&r2=573423&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
 Thu Sep  6 18:31:31 2007
@@ -227,3 +227,45 @@
 3.serviceRef.unsupported = The web service ref '{0}' will be ignored as this 
feature is not yet implemented.  The entry 'java:comp/env/{0}' will not be 
available in JNDI and any associated injects will not be performed.
 
 
+1.ann.remote.noAttributes = Ambiguous @Remote() usage on bean class
+2.ann.remote.noAttributes = Ambiguous @Remote() usage on bean class.  Must 
list interfaces explicitly in annotation.
+3.ann.remote.noAttributes = When annotating a bean class as @Remote with no 
annotation attributes, the bean must implement exactly one business interface, 
no more and no less.  List the remote interfaces explicitly in the annotation, 
such as @Remote(\{{0}\}).  Alternatively, apply the @Remote annotation to the 
individual interfaces and remove it from the bean class.
+
+1.ann.remoteLocal.ambiguous = Ambiguous @Remote and @Local usage on bean class.
+2.ann.remoteLocal.ambiguous = Ambiguous @Remote and @Local usage on bean 
class.  Must list interfaces explicitly in @Remote annotation.
+3.ann.remoteLocal.ambiguous = When annotating a bean class as @Remote with no 
annotation attributes you must not also annotate it with @Local.  List the 
remote interfaces explicitly in the annotation, such as @Remote(\{{0}\}).  
Alternatively, apply the @Remote annotation to the individual interfaces and 
remove it from the bean class.
+
+1.ann.remoteLocal.conflict = @Remote annotation in bean class conflicts with 
@Local in interface.
+2.ann.remoteLocal.conflict = @Remote annotation in bean class conflicts with 
@Local in interface '{0}'.
+3.ann.remoteLocal.conflict = When annotating a bean class as @Remote, the 
corresponding business interfaces cannot be annotated with @Local.  Revise the 
business interface '{0}'.
+
+
+1.ann.local.noAttributes = Ambiguous @Local() usage on bean class
+2.ann.local.noAttributes = Ambiguous @Local() usage on bean class.  Must list 
interfaces explicitly in annotation.
+3.ann.local.noAttributes = When annotating a bean class as @Local with no 
annotation attributes, the bean must implement exactly one business interface, 
no more and no less.  List the local interfaces explicitly in the annotation, 
such as @Local(\{{0}\}).  Alternatively, apply the @Local annotation to the 
individual interfaces and remove it from the bean class.
+
+1.ann.localRemote.ambiguous = Ambiguous @Local and @Remote usage on bean class.
+2.ann.localRemote.ambiguous = Ambiguous @Local and @Remote usage on bean 
class.  Must list interfaces explicitly in @Local annotation.
+3.ann.localRemote.ambiguous = When annotating a bean class as @Local with no 
annotation attributes you must not also annotate it with @Remote.  List the 
local interfaces explicitly in the annotation, such as @Local(\{{0}\}).  
Alternatively, apply the @Local annotation to the individual interfaces and 
remove it from the bean class.
+
+1.ann.localRemote.conflict = @Local annotation in bean class conflicts with 
@Remote in interface.
+2.ann.localRemote.conflict = @Local annotation in bean class conflicts with 
@Remote in interface '{0}'.
+3.ann.localRemote.conflict = When annotating a bean class as @Local, the 
corresponding business interfaces cannot be annotated with @Remote.  Revise the 
business interface '{0}'.
+
+
+1.ann.remoteOrLocal.ejbHome = @{0} used in bean class lists a 
javax.ejb.EJBHome interface.
+2.ann.remoteOrLocal.ejbHome = @{0} used in bean class lists a 
javax.ejb.EJBHome interface. Use @RemoteHome({1})
+3.ann.remoteOrLocal.ejbHome = When applied to a bean class, the @{0} 
annotation must only list business interfaces and cannot list legacy EJBHome 
interfaces.  EJBHome interfaces can be annotated on the bean class with 
@RemoteHome({1})
+
+1.ann.remoteOrLocal.ejbLocalHome = @{0} used in bean class lists a 
javax.ejb.EJBLocalHome interface.
+2.ann.remoteOrLocal.ejbLocalHome = @{0} used in bean class lists a 
javax.ejb.EJBLocalHome interface. Use @LocalHome({1})
+3.ann.remoteOrLocal.ejbLocalHome = When applied to a bean class, the @{0} 
annotation must only list business interfaces and cannot list legacy 
EJBLocalHome interfaces.  EJBLocalHome interfaces can be annotated on the bean 
class with @LocalHome({1})
+
+1.ann.remoteOrLocal.ejbObject = @{0} used in bean class lists a 
javax.ejb.EJBObject interface.
+2.ann.remoteOrLocal.ejbObject = @{0} used in bean class lists a 
javax.ejb.EJBObject interface. Use @RemoteHome with home interface of '{1}'.
+3.ann.remoteOrLocal.ejbObject = When applied to a bean class, the @{0} 
annotation must only list business interfaces and cannot list legacy EJBObject 
interfaces.  The EJBHome of interface for '{1}' can be annotated on the bean 
class with @RemoteHome
+
+1.ann.remoteOrLocal.ejbLocalObject = @{0} used in bean class lists a 
javax.ejb.EJBLocalObject interface.
+2.ann.remoteOrLocal.ejbLocalObject = @{0} used in bean class lists a 
javax.ejb.EJBLocalObject interface. Use @LocalHome with home interface of '{1}'.
+3.ann.remoteOrLocal.ejbLocalObject = When applied to a bean class, the @{0} 
annotation must only list business interfaces and cannot list legacy 
EJBLocalObject interfaces.  The EJBLocalHome of interface for '{1}' can be 
annotated on the bean class with @LocalHome
+

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/util/resources/Messages.properties
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/util/resources/Messages.properties?rev=573423&r1=573422&r2=573423&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/util/resources/Messages.properties
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/util/resources/Messages.properties
 Thu Sep  6 18:31:31 2007
@@ -200,8 +200,6 @@
 conf.3130=Cannot validate ejb-jar.xml file. Received message: {1}
 conf.3140=Cannot parse the XML of the ejb-jar.xml file. Received message: {1}
 conf.3900=Cannot find the ejb-jar.xml.
-conf.3901="The remote business interface {0} must not extend either the 
javax.ejb.EJBHome or javax.ejb.EJBObject interface."
-conf.3902="The local business interface {0} must not extend either the 
javax.ejb.EJBLocalHome or javax.ejb.EJBLocalObject interface."
 
 #xml.cannotValidate  = Cannot validate the {0} data. Received message: {2}
 xml.cannotMarshal   = Cannot marshal the {0} data to file {1}. Received 
message: {2}


Reply via email to