You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/10/10 00:45:41 UTC
[2/2] git commit: DELTASPIKE-277 fix JsfMessageProducer type detection
DELTASPIKE-277 fix JsfMessageProducer type detection
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/497c7441
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/497c7441
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/497c7441
Branch: refs/heads/master
Commit: 497c7441ad1370b383d3c00c614d32dec4ef1952
Parents: bfbc502
Author: Mark Struberg <st...@apache.org>
Authored: Wed Oct 10 00:10:11 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Oct 10 00:10:11 2012 +0200
----------------------------------------------------------------------
.../jsf/impl/message/JsfMessageProducer.java | 20 +++++-
.../jsf/impl/scope/view/beans/BackingBean.java | 49 ---------------
.../scope/view/beans/ViewScopedBackingBean.java | 49 +++++++++++++++
3 files changed, 66 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/497c7441/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 6dc58b8..2a26c82 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
@@ -23,6 +23,9 @@ import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
import org.apache.deltaspike.core.util.ReflectionUtils;
import org.apache.deltaspike.jsf.message.JsfMessage;
@@ -36,13 +39,24 @@ public class JsfMessageProducer
@Dependent
public JsfMessage createJsfMessage(InjectionPoint injectionPoint)
{
- return createJsfMessageFor(injectionPoint, ReflectionUtils.getRawType(injectionPoint.getType()));
+ if (! (injectionPoint.getType() instanceof ParameterizedType))
+ {
+ throw new IllegalArgumentException("JsfMessage must be used as generic type");
+ }
+ ParameterizedType paramType = (ParameterizedType) injectionPoint.getType();
+ Type[] actualTypes = paramType.getActualTypeArguments();
+ if (actualTypes.length != 1)
+ {
+ throw new IllegalArgumentException("JsfMessage must have the MessageBundle as generic type parameter");
+ }
+
+ return createJsfMessageFor(injectionPoint, actualTypes[0]);
}
- private JsfMessage createJsfMessageFor(InjectionPoint injectionPoint, Class<Object> rawType)
+ private JsfMessage createJsfMessageFor(InjectionPoint injectionPoint, Type rawType)
{
//X TODO check if the JsfMessage should get injected into a UIComponent and use #getClientId()
- return new DefaultJsfMessage(rawType, null);
+ return new DefaultJsfMessage((Class) rawType, null);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/497c7441/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/BackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/BackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/BackingBean.java
deleted file mode 100644
index cf6eb6c..0000000
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/BackingBean.java
+++ /dev/null
@@ -1,49 +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.deltaspike.test.jsf.impl.scope.view.beans;
-
-import javax.faces.bean.ViewScoped;
-import javax.inject.Named;
-import java.io.Serializable;
-
-/**
- * ViewScoped sample backing bean.
- */
-@ViewScoped
-@Named("viewScopedBean")
-public class BackingBean implements Serializable
-{
- private int i = 0;
-
- public int getI()
- {
- return i;
- }
-
- public void setI(int i)
- {
- this.i = i;
- }
-
- public String someAction()
- {
- // stay on the page.
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/497c7441/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/ViewScopedBackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/ViewScopedBackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/ViewScopedBackingBean.java
new file mode 100644
index 0000000..cb59e88
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/view/beans/ViewScopedBackingBean.java
@@ -0,0 +1,49 @@
+/*
+* 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.deltaspike.test.jsf.impl.scope.view.beans;
+
+import javax.faces.bean.ViewScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ * ViewScoped sample backing bean.
+ */
+@ViewScoped
+@Named("viewScopedBean")
+public class ViewScopedBackingBean implements Serializable
+{
+ private int i = 0;
+
+ public int getI()
+ {
+ return i;
+ }
+
+ public void setI(int i)
+ {
+ this.i = i;
+ }
+
+ public String someAction()
+ {
+ // stay on the page.
+ return null;
+ }
+}