[seam-commits] Seam SVN: r10559 - modules/trunk/international/src/main/java/org/jboss/seam/international.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 21 21:30:45 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-04-21 21:30:45 -0400 (Tue, 21 Apr 2009)
New Revision: 10559

Added:
   modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java
   modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java
Modified:
   modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java
   modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java
   modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZones.java
Log:
some porting done

Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java	2009-04-22 01:23:11 UTC (rev 10558)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/Messages.java	2009-04-22 01:30:45 UTC (rev 10559)
@@ -1,133 +1,29 @@
 package org.jboss.seam.international;
 
-import static org.jboss.seam.ScopeType.EVENT;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
-import java.util.AbstractMap;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.Set;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
 
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Factory;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.SeamResourceBundle;
+import javax.inject.BindingType;
 
 /**
- * Factory for a Map that contains interpolated messages defined in the
- * Seam ResourceBundle.
- * 
- * @see org.jboss.seam.core.SeamResourceBundle
- * 
- * @author Gavin King
+ * Binding type for messages
+ *  
+ * @author Shane Bryzak
  */
- at Scope(ScopeType.STATELESS)
- at BypassInterceptors
- at Name("org.jboss.seam.international.messagesFactory")
- at Install(precedence=BUILT_IN)
-public class Messages
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+ at Inherited
+public @interface Messages
 {
-   //TODO: now we have ELResolver, it doesn't *have* to be a Map...
-      
-   protected Map createMap() 
-   {  
-	  // AbstractMap uses the implementation of entrySet to perform all its 
-	  // operations - for a resource bundle this is very inefficient for keys
-      return new AbstractMap<String, String>()
-      {
-         private java.util.ResourceBundle bundle = SeamResourceBundle.getBundle();
-         
-         @Override
-         public String get(Object key) 
-         {
-            if (key instanceof String)
-            {
-               String resourceKey = (String) key;
-               String resource=null;
-               if (bundle!=null)
-               {
-                  try
-                  {
-                     resource = bundle.getString(resourceKey);
-                  }
-                  catch (MissingResourceException mre)
-                  {
-                     //Just swallow
-                  }
-               }
-               return resource==null ? resourceKey : resource;
-            }
-            else
-            {
-               return null;
-            }
-         }
-         
-         @Override
-         public Set<Map.Entry<String, String>> entrySet() 
-         {
-        	Enumeration<String> keys = bundle.getKeys();  
-            Map<String, String> map = new HashMap<String, String>();
-            while ( keys.hasMoreElements() )
-            {
-               String key = keys.nextElement();
-               map.put( key, get(key) );
-            }  
-            return Collections.unmodifiableSet(map.entrySet());
-         }
 
-         @Override
-         public boolean containsKey(Object key)
-         {
-            return get(key) != null;
-         }
-
-         @Override
-         public Set<String> keySet()
-         {
-            Enumeration<String> keys = bundle.getKeys();  
-            return new HashSet<String>(Collections.list(keys));
-         }
-
-         @Override
-         public int size()
-         {
-            return keySet().size();
-         }
-         
-      };
-   }
-
-   /**
-    * Create the Map and cache it in the EVENT scope. No need to cache
-    * it in the SESSION scope, since it is inexpensive to create.
-    * 
-    * @return a Map that interpolates messages in the Seam ResourceBundle
-    */
-   @Factory(value="org.jboss.seam.international.messages", autoCreate=true, scope=EVENT)
-   public Map<String, String> getMessages()
-   {
-      return createMap();
-   }
-   
-   /**
-    * @return the message Map instance
-    */
-   public static Map<String, String> instance()
-   {
-      if ( !Contexts.isSessionContextActive() )
-      {
-         throw new IllegalStateException("no event context active");
-      }
-      return (Map<String, String>) Component.getInstance("org.jboss.seam.international.messages", true);
-   }
 }

Added: modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java	                        (rev 0)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/MessagesProducer.java	2009-04-22 01:30:45 UTC (rev 10559)
@@ -0,0 +1,123 @@
+package org.jboss.seam.international;
+
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Set;
+
+import javax.context.RequestScoped;
+import javax.inject.Produces;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.SeamResourceBundle;
+
+/**
+ * Factory for a Map that contains interpolated messages defined in the
+ * Seam ResourceBundle.
+ * 
+ * @see org.jboss.seam.core.SeamResourceBundle
+ * 
+ * @author Gavin King
+ */
+public class MessagesProducer
+{
+   //TODO: now we have ELResolver, it doesn't *have* to be a Map...
+      
+   protected Map createMap() 
+   {  
+	  // AbstractMap uses the implementation of entrySet to perform all its 
+	  // operations - for a resource bundle this is very inefficient for keys
+      return new AbstractMap<String, String>()
+      {
+         private java.util.ResourceBundle bundle = SeamResourceBundle.getBundle();
+         
+         @Override
+         public String get(Object key) 
+         {
+            if (key instanceof String)
+            {
+               String resourceKey = (String) key;
+               String resource=null;
+               if (bundle!=null)
+               {
+                  try
+                  {
+                     resource = bundle.getString(resourceKey);
+                  }
+                  catch (MissingResourceException mre)
+                  {
+                     //Just swallow
+                  }
+               }
+               return resource==null ? resourceKey : resource;
+            }
+            else
+            {
+               return null;
+            }
+         }
+         
+         @Override
+         public Set<Map.Entry<String, String>> entrySet() 
+         {
+        	Enumeration<String> keys = bundle.getKeys();  
+            Map<String, String> map = new HashMap<String, String>();
+            while ( keys.hasMoreElements() )
+            {
+               String key = keys.nextElement();
+               map.put( key, get(key) );
+            }  
+            return Collections.unmodifiableSet(map.entrySet());
+         }
+
+         @Override
+         public boolean containsKey(Object key)
+         {
+            return get(key) != null;
+         }
+
+         @Override
+         public Set<String> keySet()
+         {
+            Enumeration<String> keys = bundle.getKeys();  
+            return new HashSet<String>(Collections.list(keys));
+         }
+
+         @Override
+         public int size()
+         {
+            return keySet().size();
+         }
+         
+      };
+   }
+
+   /**
+    * Create the Map and cache it in the EVENT scope. No need to cache
+    * it in the SESSION scope, since it is inexpensive to create.
+    * 
+    * @return a Map that interpolates messages in the Seam ResourceBundle
+    */
+   @Produces @RequestScoped @Messages public Map<String, String> getMessages()
+   {
+      return createMap();
+   }
+   
+   /**
+    * @return the message Map instance
+    */
+   public static Map<String, String> instance()
+   {
+      if ( !Contexts.isSessionContextActive() )
+      {
+         throw new IllegalStateException("no event context active");
+      }
+      return (Map<String, String>) Component.getInstance("org.jboss.seam.international.messages", true);
+   }
+}

Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java	2009-04-22 01:23:11 UTC (rev 10558)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZoneSelector.java	2009-04-22 01:30:45 UTC (rev 10559)
@@ -2,16 +2,10 @@
 
 import static org.jboss.seam.annotations.Install.BUILT_IN;
 
+import javax.context.SessionScoped;
 import javax.faces.event.ValueChangeEvent;
+import javax.inject.Initializer;
 
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.Events;
 import org.jboss.seam.faces.Selector;
 
@@ -21,17 +15,14 @@
  * 
  * @author Gavin King
  */
- at Scope(ScopeType.SESSION)
- at Name("org.jboss.seam.international.timeZoneSelector")
- at BypassInterceptors
- at Install(precedence=BUILT_IN, classDependencies="javax.faces.context.FacesContext")
+ at SessionScoped
 public class TimeZoneSelector extends Selector
 {
    private static final long serialVersionUID = -5013819375360015369L;
    
    private String id;
    
-   @Create
+   @Initializer
    public void initTimeZone()
    {
       String timeZoneId = getCookieValueIfEnabled();

Modified: modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZones.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZones.java	2009-04-22 01:23:11 UTC (rev 10558)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZones.java	2009-04-22 01:30:45 UTC (rev 10559)
@@ -1,71 +1,29 @@
-package org.jboss.seam.international;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.TimeZone;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.Create;
-
-/**
- * <p>Seam component that provides a list of time zones, limited to time zones
- * with IDs in the form Continent/Place, excluding deprecated three-letter time
- * zone IDs. The time zones returned have a fixed offset from UTC, which takes
- * daylight savings time into account. For example, Europe/Amsterdam is UTC+1;
- * in winter this is GMT+1 and in summer GMT+2.</p>
- *
- * <p>The time zone objects returned are wrapped in an implementation of
- * TimeZone that provides a more friendly interface for accessing the time zone
- * information. In particular, this type provides a more bean-friend property
- * for the time zone id (id than ID) and provides a convenience property named
- * label that formats the time zone for display in the UI. This wrapper can be
- * disabled by setting the component property wrap to false.</p>
- *
- * @author Peter Hilton, Lunatech Research
- * @author Dan Allen
- */
- at Scope(ScopeType.APPLICATION)
- at Name("org.jboss.seam.international.timeZones")
-public class TimeZones
-{
-   private static final String TIMEZONE_ID_PREFIXES =
-      "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";
-
-   private boolean wrap = true;
-
-   private List<TimeZone> timeZones = null;
-   
-   @Create
-   public void init() {
-      timeZones = new ArrayList<TimeZone>();
-      final String[] timeZoneIds = TimeZone.getAvailableIDs();
-      for (final String id : timeZoneIds) {
-         if (id.matches(TIMEZONE_ID_PREFIXES)) {
-            timeZones.add(wrap ? new TimeZoneWrapper(TimeZone.getTimeZone(id)) : TimeZone.getTimeZone(id));
-         }
-      }
-      Collections.sort(timeZones, new Comparator<TimeZone>() {
-         public int compare(final TimeZone a, final TimeZone b) {
-            return a.getID().compareTo(b.getID());
-         }
-      });
-   }
-
-   @Unwrap
-   public List<TimeZone> getTimeZones() {
-      return timeZones;
-   }
-
-   public boolean isWrap() {
-      return wrap;
-   }
-
-   public void setWrap(boolean wrap) {
-      this.wrap = wrap;
-   }
-}
+package org.jboss.seam.international;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+/**
+ * Binding type for timezones
+ * 
+ * @author Shane Bryzak
+ */
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+ at Inherited
+public @interface Timezones
+{
+
+}

Added: modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java
===================================================================
--- modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java	                        (rev 0)
+++ modules/trunk/international/src/main/java/org/jboss/seam/international/TimeZonesProducer.java	2009-04-22 01:30:45 UTC (rev 10559)
@@ -0,0 +1,66 @@
+package org.jboss.seam.international;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.context.ApplicationScoped;
+import javax.inject.Initializer;
+import javax.inject.Produces;
+
+/**
+ * <p>Seam component that provides a list of time zones, limited to time zones
+ * with IDs in the form Continent/Place, excluding deprecated three-letter time
+ * zone IDs. The time zones returned have a fixed offset from UTC, which takes
+ * daylight savings time into account. For example, Europe/Amsterdam is UTC+1;
+ * in winter this is GMT+1 and in summer GMT+2.</p>
+ *
+ * <p>The time zone objects returned are wrapped in an implementation of
+ * TimeZone that provides a more friendly interface for accessing the time zone
+ * information. In particular, this type provides a more bean-friend property
+ * for the time zone id (id than ID) and provides a convenience property named
+ * label that formats the time zone for display in the UI. This wrapper can be
+ * disabled by setting the component property wrap to false.</p>
+ *
+ * @author Peter Hilton, Lunatech Research
+ * @author Dan Allen
+ */
+public class TimeZonesProducer
+{
+   private static final String TIMEZONE_ID_PREFIXES =
+      "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";
+
+   private boolean wrap = true;
+
+   private List<TimeZone> timeZones = null;
+   
+   @Initializer
+   public void init() {
+      timeZones = new ArrayList<TimeZone>();
+      final String[] timeZoneIds = TimeZone.getAvailableIDs();
+      for (final String id : timeZoneIds) {
+         if (id.matches(TIMEZONE_ID_PREFIXES)) {
+            timeZones.add(wrap ? new TimeZoneWrapper(TimeZone.getTimeZone(id)) : TimeZone.getTimeZone(id));
+         }
+      }
+      Collections.sort(timeZones, new Comparator<TimeZone>() {
+         public int compare(final TimeZone a, final TimeZone b) {
+            return a.getID().compareTo(b.getID());
+         }
+      });
+   }
+
+   @Produces @ApplicationScoped @Timezones public List<TimeZone> getTimeZones() {
+      return timeZones;
+   }
+
+   public boolean isWrap() {
+      return wrap;
+   }
+
+   public void setWrap(boolean wrap) {
+      this.wrap = wrap;
+   }
+}




More information about the seam-commits mailing list