myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1154790 - in /myfaces/extensions/cdi/trunk: core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ jee-modules/jsf-module/impl/src/main/java...
Date Sun, 07 Aug 2011 23:16:47 GMT
Author: gpetracek
Date: Sun Aug  7 23:16:46 2011
New Revision: 1154790

URL: http://svn.apache.org/viewvc?rev=1154790&view=rev
Log:
EXTCDI-204 and EXTCDI-211 injectable resource-bundle and resource-bundle-key

Added:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/JsfAwareResourceBundleProducer.java
Modified:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/Bundle.java
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ResourceBundleKey.java
    myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ResourceBundleProducer.java

Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/Bundle.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/Bundle.java?rev=1154790&r1=1154789&r2=1154790&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/Bundle.java
(original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/Bundle.java
Sun Aug  7 23:16:46 2011
@@ -18,8 +18,6 @@
  */
 package org.apache.myfaces.extensions.cdi.core.api.resource;
 
-import javax.enterprise.util.Nonbinding;
-import javax.inject.Qualifier;
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -34,17 +32,14 @@ import static java.lang.annotation.Reten
  */
 @Documented
 @Retention(RUNTIME)
-@Target({TYPE, CONSTRUCTOR, METHOD, FIELD})
+@Target({TYPE, CONSTRUCTOR, METHOD, FIELD, PARAMETER})
 
-//cdi annotations
-@Qualifier
 public @interface Bundle
 {
     /**
      * Allows to specify the class which is mapped to the resource-bundle
      * @return class which represents the resource-bundle
      */
-    @Nonbinding
     Class<?> value() default Class.class;
 
     /**
@@ -52,6 +47,5 @@ public @interface Bundle
      * and can't be mapped to the bundle via convention. #name allows to explicitly specify
the name of the bundle.
      * @return the overridden name which should be used to identify the resource-bundle
      */
-    @Nonbinding
     String name() default "";
 }

Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ResourceBundleKey.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ResourceBundleKey.java?rev=1154790&r1=1154789&r2=1154790&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ResourceBundleKey.java
(original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/resource/ResourceBundleKey.java
Sun Aug  7 23:16:46 2011
@@ -21,6 +21,8 @@ package org.apache.myfaces.extensions.cd
 import org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider;
 import org.apache.myfaces.extensions.cdi.core.api.tools.DefaultAnnotation;
 
+import java.lang.annotation.Annotation;
+
 /**
  * Base class which has to be extended if a key should be injected.
  *
@@ -30,6 +32,21 @@ public abstract class ResourceBundleKey 
 {
     private transient ResourceBundle resourceBundle;
 
+    private static Class<? extends Annotation> qualifierClass;
+
+    static
+    {
+        try
+        {
+            qualifierClass = (Class<? extends Annotation>)
+                    Class.forName("org.apache.myfaces.extensions.cdi.jsf.api.Jsf");
+        }
+        catch (Exception e)
+        {
+            qualifierClass = null;
+        }
+    }
+
     /**
      * Returns the value of the resource-bundle represented by this key
      *
@@ -66,8 +83,16 @@ public abstract class ResourceBundleKey 
                         "which is annotated with @" + Bundle.class.getName());
             }
 
-            this.resourceBundle = BeanManagerProvider.getInstance()
-                    .getContextualReference(ResourceBundle.class, DefaultAnnotation.of(Bundle.class));
+            if(qualifierClass != null)
+            {
+                this.resourceBundle = BeanManagerProvider.getInstance()
+                        .getContextualReference(ResourceBundle.class, DefaultAnnotation.of(qualifierClass));
+            }
+            else
+            {
+                this.resourceBundle = BeanManagerProvider.getInstance()
+                        .getContextualReference(ResourceBundle.class);
+            }
             this.resourceBundle.useBundle(bundleClass);
         }
         return resourceBundle;

Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ResourceBundleProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ResourceBundleProducer.java?rev=1154790&r1=1154789&r2=1154790&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ResourceBundleProducer.java
(original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/resource/ResourceBundleProducer.java
Sun Aug  7 23:16:46 2011
@@ -35,11 +35,10 @@ import java.util.Set;
 public class ResourceBundleProducer
 {
     @Produces
-    @Bundle
     @Dependent
     protected ResourceBundle injectableResourceBundle(InjectionPoint injectionPoint)
     {
-        Bundle bundle = getBundleClass(injectionPoint.getQualifiers());
+        Bundle bundle = getBundleClass(injectionPoint.getAnnotated().getAnnotations());
 
         if(bundle != null)
         {

Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/JsfAwareResourceBundleProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/JsfAwareResourceBundleProducer.java?rev=1154790&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/JsfAwareResourceBundleProducer.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/resource/JsfAwareResourceBundleProducer.java
Sun Aug  7 23:16:46 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.myfaces.extensions.cdi.jsf.impl.resource;
+
+import org.apache.myfaces.extensions.cdi.core.api.resource.ResourceBundle;
+import org.apache.myfaces.extensions.cdi.core.impl.resource.ResourceBundleProducer;
+import org.apache.myfaces.extensions.cdi.jsf.api.Jsf;
+import org.apache.myfaces.extensions.cdi.jsf.impl.message.JsfAwareLocaleResolver;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Dependent
+public class JsfAwareResourceBundleProducer extends ResourceBundleProducer
+{
+    @Produces
+    @Jsf
+    @Dependent
+    protected ResourceBundle jsfAwareResourceBundle(InjectionPoint injectionPoint)
+    {
+        ResourceBundle resourceBundle = injectableResourceBundle(injectionPoint);
+        return resourceBundle.useLocale(new JsfAwareLocaleResolver().getLocale());
+    }
+}



Mime
View raw message