Author: arne
Date: Fri Jun 14 23:12:23 2013
New Revision: 1493278
URL: http://svn.apache.org/r1493278
Log:
OWB-846: CDI 1.1 integration: Some more @Specializes checks and throwing of
correct exception
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1493278&r1=1493277&r2=1493278&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Fri Jun 14 23:12:23 2013
@@ -47,6 +47,7 @@ import org.apache.webbeans.exception.Web
import org.apache.webbeans.exception.WebBeansDeploymentException;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.exception.inject.DefinitionException;
+import org.apache.webbeans.exception.inject.DeploymentException;
import
org.apache.webbeans.exception.inject.InconsistentSpecializationException;
import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.portable.AnnotatedElementFactory;
@@ -188,7 +189,7 @@ public class BeansDeployer
deployAdditionalAnnotatedTypes();
//Check Specialization
- checkSpecializations(scanner);
+ processSpecializations(scanner);
//Fire Event
fireAfterBeanDiscoveryEvent();
@@ -719,7 +720,7 @@ public class BeansDeployer
* Checks specialization.
* @param scanner scanner instance
*/
- protected void checkSpecializations(ScannerService scanner)
+ protected void processSpecializations(ScannerService scanner)
{
logger.fine("Checking Specialization constraints has started.");
@@ -746,7 +747,10 @@ public class BeansDeployer
}
if (superClassList.contains(superClass))
{
- throw new
InconsistentSpecializationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0005)
+ superClass.getName());
+ // since CDI 1.1 we have to wrap this in a
DeploymentException
+ InconsistentSpecializationException exception
+ = new
InconsistentSpecializationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0005)
+ superClass.getName());
+ throw new WebBeansDeploymentException(exception);
}
superClassList.add(superClass);
specialClassList.add(specialClass);
@@ -759,7 +763,15 @@ public class BeansDeployer
//configure specialized producer beans.
webBeansContext.getWebBeansUtil().configureProducerMethodSpecializations();
}
- catch(Exception e)
+ catch (DefinitionException e)
+ {
+ throw e;
+ }
+ catch (DeploymentException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
{
throw new WebBeansDeploymentException(e);
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java?rev=1493278&r1=1493277&r2=1493278&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java
Fri Jun 14 23:12:23 2013
@@ -18,15 +18,10 @@
*/
package org.apache.webbeans.exception.inject;
-public class InconsistentSpecializationException extends DeploymentException
+public class InconsistentSpecializationException extends DefinitionException
{
private static final long serialVersionUID = 5398575103682514128L;
- public InconsistentSpecializationException()
- {
- super();
- }
-
public InconsistentSpecializationException(String message)
{
super(message);
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1493278&r1=1493277&r2=1493278&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Fri Jun 14 23:12:23 2013
@@ -75,16 +75,16 @@ import javax.inject.Named;
import org.apache.webbeans.annotation.AnnotationManager;
import org.apache.webbeans.annotation.NewLiteral;
-import org.apache.webbeans.component.BeanAttributesImpl;
-import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.AbstractProducerBean;
+import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.component.BeanManagerBean;
import org.apache.webbeans.component.ConversationBean;
import org.apache.webbeans.component.EnterpriseBeanMarker;
import org.apache.webbeans.component.EventBean;
import org.apache.webbeans.component.ExtensionBean;
import org.apache.webbeans.component.InjectionPointBean;
+import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.InstanceBean;
import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.component.NewBean;
@@ -104,6 +104,7 @@ import org.apache.webbeans.config.WebBea
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansDeploymentException;
import org.apache.webbeans.exception.inject.DefinitionException;
import
org.apache.webbeans.exception.inject.InconsistentSpecializationException;
import org.apache.webbeans.inject.AlternativesManager;
@@ -651,8 +652,7 @@ public final class WebBeansUtil
continue;
}
- if (((AbstractOwbBean<?>)sp).getReturnType().
-
isAssignableFrom(((AbstractOwbBean<?>)specialized).getReturnType()))
+ if (sp.getTypes().size() > specialized.getTypes().size()
&& sp.getTypes().containsAll(specialized.getTypes()))
{
specialized = sp;
}
@@ -681,6 +681,24 @@ public final class WebBeansUtil
if (superBean != null)
{
+ for (Class<?> beanClass: beanClasses)
+ {
+ if (beanClass.equals(specializedClass))
+ {
+ continue;
+ }
+ if (beanClass.getSuperclass().equals(superClass))
+ {
+ InconsistentSpecializationException exception = new
InconsistentSpecializationException(superClass.getName()
+ + " is @Specialized by two classes: " +
beanClass.getName() + " and " + specializedClass.getName());
+ throw new WebBeansDeploymentException(exception);
+ }
+ }
+ if (!specialized.getTypes().containsAll(superBean.getTypes()))
+ {
+ throw new DefinitionException("@Specialized Class : " +
specializedClass.getName()
+ + " must have all bean types of its super class");
+ }
webBeansContext.getBeanManagerImpl().getNotificationManager().disableOverriddenObservers(superClass);
// Recursively configure super class first if super class is
also a special bean.
@@ -713,7 +731,7 @@ public final class WebBeansUtil
//Check types of the beans
if(comp.getClass() != superBean.getClass())
{
- throw new DefinitionException("@Specialized Class : " +
specializedClass.getName()
+ throw new
InconsistentSpecializationException("@Specialized Class : " +
specializedClass.getName()
+ " and its super class may be the same type of
bean,i.e, ManagedBean, SessionBean etc.");
}
@@ -721,7 +739,7 @@ public final class WebBeansUtil
{
if (!superBean.getName().equals(comp.getName()))
{
- throw new DefinitionException("@Specialized Class : "
+ specializedClass.getName()
+ throw new
InconsistentSpecializationException("@Specialized Class : " +
specializedClass.getName()
+ " may not explicitly declare a bean name");
}
@@ -742,7 +760,7 @@ public final class WebBeansUtil
}
else
{
- throw new InconsistentSpecializationException("WebBean
component class : " + specializedClass.getName()
+ throw new DefinitionException("WebBean component class : " +
specializedClass.getName()
+ " is not enabled for specialized by the " +
specializedClass + " class");
}
}