You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by jo...@apache.org on 2013/03/08 13:52:43 UTC

git commit: DELTASPIKE-295 Made JsfMessageProducer parameter aware.

Updated Branches:
  refs/heads/master e97ee9233 -> d97fc6805


DELTASPIKE-295 Made JsfMessageProducer parameter aware.


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/d97fc680
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/d97fc680
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/d97fc680

Branch: refs/heads/master
Commit: d97fc6805fc3209653e9818e8f148603026aed6f
Parents: e97ee92
Author: John D. Ament <jo...@gmail.com>
Authored: Fri Mar 8 07:22:51 2013 -0500
Committer: John D. Ament <jo...@gmail.com>
Committed: Fri Mar 8 07:36:45 2013 -0500

----------------------------------------------------------------------
 .../jsf/impl/message/JsfMessageProducer.java       |   23 +++++++++-----
 .../test/jsf/impl/message/JsfMessageTest.java      |    2 +-
 2 files changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/d97fc680/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfMessageProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfMessageProducer.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfMessageProducer.java
index 8fbcc77..c035b23 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfMessageProducer.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfMessageProducer.java
@@ -36,9 +36,9 @@ public class JsfMessageProducer
 {
     @Produces
     @Dependent
-    public JsfMessage createJsfMessage(InjectionPoint injectionPoint)
+    public <M> JsfMessage<M> createJsfMessage(InjectionPoint injectionPoint)
     {
-        if (! (injectionPoint.getType() instanceof ParameterizedType))
+        if (!(injectionPoint.getType() instanceof ParameterizedType))
         {
             throw new IllegalArgumentException("JsfMessage must be used as generic type");
         }
@@ -48,14 +48,21 @@ public class JsfMessageProducer
         {
             throw new IllegalArgumentException("JsfMessage must have the MessageBundle as generic type parameter");
         }
-
-        return createJsfMessageFor(injectionPoint, actualTypes[0]);
+        try
+        {
+            @SuppressWarnings("unchecked")
+            Class<M> type = (Class<M>) actualTypes[0];
+            return createJsfMessageFor(injectionPoint, type);
+        }
+        catch (ClassCastException e)
+        {
+            throw new IllegalArgumentException("Incorrect class found when trying to convert to parameterized type",e);
+        }
     }
 
-    private JsfMessage createJsfMessageFor(InjectionPoint injectionPoint, Type rawType)
+    private <M> JsfMessage<M> createJsfMessageFor(InjectionPoint injectionPoint, Class<M> rawType)
     {
-        //X TODO check if the JsfMessage should get injected into a UIComponent and use #getClientId()
-
-        return new DefaultJsfMessage((Class) rawType, null);
+        // X TODO check if the JsfMessage should get injected into a UIComponent and use #getClientId()
+        return new DefaultJsfMessage<M>(rawType, null);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/d97fc680/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
index 2a2e25b..e1579cb 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
@@ -43,7 +43,7 @@ import org.openqa.selenium.support.ui.ExpectedConditions;
 
 
 /**
- * Test for the DeltaSpike ViewScoped context
+ * Test for the DeltaSpike JsfMessage Producer
  */
 @WarpTest
 @RunWith(Arquillian.class)