deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject git commit: DELTASPIKE-356 fix @Dependent handling for MessageContext
Date Wed, 08 May 2013 14:48:23 GMT
Updated Branches:
  refs/heads/master 2b0f0fa30 -> cb8c0861e


DELTASPIKE-356 fix @Dependent handling for MessageContext


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

Branch: refs/heads/master
Commit: cb8c0861e16bbab6ad11d1dc2b1820d054aa2fba
Parents: 2b0f0fa
Author: Mark Struberg <struberg@apache.org>
Authored: Wed May 8 16:46:25 2013 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Wed May 8 16:46:25 2013 +0200

----------------------------------------------------------------------
 .../core/api/message/MessageContext.java           |    1 -
 .../core/impl/message/DefaultMessageContext.java   |   12 +++-
 .../message/MessageBundleInvocationHandler.java    |   12 ++-
 .../core/impl/message/MessageContextProducer.java  |   58 ---------------
 .../impl/message/TypedMessageBundleProducer.java   |   10 ++-
 deltaspike/examples/jsf-examples/pom.xml           |   12 +++-
 6 files changed, 35 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/message/MessageContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/message/MessageContext.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/message/MessageContext.java
index 1faa087..e765b10 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/message/MessageContext.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/message/MessageContext.java
@@ -31,7 +31,6 @@ public interface MessageContext extends LocaleResolver, Serializable, Cloneable
     /**
      * Clones the current MessageContext
      */
-    @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
     MessageContext clone();
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageContext.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageContext.java
index 5f8a926..b776471 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageContext.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/DefaultMessageContext.java
@@ -24,20 +24,30 @@ import org.apache.deltaspike.core.api.message.MessageContext;
 import org.apache.deltaspike.core.api.message.MessageInterpolator;
 import org.apache.deltaspike.core.api.message.MessageResolver;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Typed;
+import javax.inject.Inject;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
-@Typed()
+@Dependent
+@Typed(MessageContext.class)
 class DefaultMessageContext implements MessageContext
 {
     private static final long serialVersionUID = -110779217295211303L;
 
+
+    @Inject
     private MessageInterpolator messageInterpolator = null;
+
+    @Inject
     private MessageResolver messageResolver = null;
+
+    @Inject
     private LocaleResolver localeResolver = null;
+
     private List<String> messageSources = new ArrayList<String>();
 
     public DefaultMessageContext()

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
index fc8ff2e..3bb99f7 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
@@ -18,6 +18,8 @@
  */
 package org.apache.deltaspike.core.impl.message;
 
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
 import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -36,8 +38,12 @@ import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.util.ClassUtils;
 
 
+@Dependent
 public class MessageBundleInvocationHandler implements InvocationHandler, Serializable
 {
+    @Inject
+    private MessageContext baseMessageContext = null;
+
     /**
      * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
      *      java.lang.reflect.Method, java.lang.Object[])
@@ -63,7 +69,7 @@ public class MessageBundleInvocationHandler implements InvocationHandler,
Serial
 
         if (messageContext == null)
         {
-            messageContext = getDefaultMessageContext().clone();
+            messageContext = baseMessageContext.clone();
 
             MessageContextConfig messageContextConfig =
                 method.getDeclaringClass().getAnnotation(MessageContextConfig.class);
@@ -163,8 +169,4 @@ public class MessageBundleInvocationHandler implements InvocationHandler,
Serial
         return null;
     }
 
-    private MessageContext getDefaultMessageContext()
-    {
-        return BeanProvider.getContextualReference(MessageContext.class);
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageContextProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageContextProducer.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageContextProducer.java
deleted file mode 100644
index e45d40f..0000000
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageContextProducer.java
+++ /dev/null
@@ -1,58 +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.core.impl.message;
-
-import org.apache.deltaspike.core.api.message.LocaleResolver;
-import org.apache.deltaspike.core.api.message.MessageContext;
-import org.apache.deltaspike.core.api.message.MessageInterpolator;
-import org.apache.deltaspike.core.api.message.MessageResolver;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Typed;
-import javax.inject.Inject;
-
-@ApplicationScoped
-@SuppressWarnings("UnusedDeclaration")
-public class MessageContextProducer
-{
-    @Inject
-    private LocaleResolver localeResolver;
-
-    @Inject
-    private MessageInterpolator messageInterpolator;
-
-    @Inject
-    private MessageResolver messageResolver;
-
-    @Produces
-    @Typed(MessageContext.class) // needed for _not_ serving as LocaleResolver!
-    @Dependent
-    protected MessageContext createDefaultMessageContext()
-    {
-        MessageContext messageContext = new DefaultMessageContext();
-
-        messageContext.messageInterpolator(messageInterpolator);
-        messageContext.localeResolver(localeResolver);
-        messageContext.messageResolver(messageResolver);
-
-        return messageContext;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
index f13ccb1..fa8bc8a 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/TypedMessageBundleProducer.java
@@ -22,6 +22,7 @@ package org.apache.deltaspike.core.impl.message;
 import java.io.Serializable;
 import java.lang.reflect.Proxy;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.InjectionPoint;
 
@@ -37,16 +38,17 @@ public class TypedMessageBundleProducer implements Serializable
     private static final long serialVersionUID = -5077306523543940760L;
 
     @Produces
+    @Dependent
     @TypedMessageBundle
     @SuppressWarnings("UnusedDeclaration")
-    Object produceTypedMessageBundle(InjectionPoint injectionPoint)
+    Object produceTypedMessageBundle(InjectionPoint injectionPoint, MessageBundleInvocationHandler
handler)
     {
-        return createMessageBundleProxy(ReflectionUtils.getRawType(injectionPoint.getType()));
+        return createMessageBundleProxy(ReflectionUtils.getRawType(injectionPoint.getType()),
handler);
     }
 
-    private <T> T createMessageBundleProxy(Class<T> type)
+    private <T> T createMessageBundleProxy(Class<T> type, MessageBundleInvocationHandler
handler)
     {
         return type.cast(Proxy.newProxyInstance(ClassUtils.getClassLoader(null),
-                new Class<?>[]{type}, new MessageBundleInvocationHandler()));
+                new Class<?>[]{type}, handler));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/cb8c0861/deltaspike/examples/jsf-examples/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/examples/jsf-examples/pom.xml b/deltaspike/examples/jsf-examples/pom.xml
index 0a709df..131db20 100644
--- a/deltaspike/examples/jsf-examples/pom.xml
+++ b/deltaspike/examples/jsf-examples/pom.xml
@@ -38,7 +38,13 @@
 
     <profiles>
         <profile>
-            <!-- run it with: mvn clean package tomee:run -PtomeeConfig-->
+            <!--
+             * Run it with: mvn clean package tomee:run -PtomeeConfig
+             *
+             * For debugging add: -Dopenejb.server.debug=true
+             *
+             * The application can be browsed under http://localhost:8080/ds
+             -->
             <id>tomeeConfig</id>
             <build>
                 <defaultGoal>install</defaultGoal>
@@ -104,5 +110,9 @@
         </dependency>
 
     </dependencies>
+
+    <build>
+        <finalName>ds</finalName>
+    </build>
 </project>
 


Mime
View raw message