[seam-commits] Seam SVN: r12873 - in modules/international/trunk: api/src/main/java/org/jboss/seam/international/status/builder and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu May 27 13:54:31 EDT 2010


Author: lincolnthree
Date: 2010-05-27 13:54:30 -0400 (Thu, 27 May 2010)
New Revision: 12873

Added:
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessage.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/BundleTemplateMessageTest.java
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/status/
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/status/TestBundle.properties
Removed:
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/status/builder/
Modified:
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageFactory.java
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/TemplateMessage.java
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/TemplateMessageTest.java
Log:
Repackaged, updated Messages API to be more user-friendly.

Modified: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageFactory.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageFactory.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageFactory.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -26,12 +26,12 @@
 import javax.inject.Inject;
 
 import org.jboss.seam.international.status.builder.BundleKey;
-import org.jboss.seam.international.status.builder.BundleMessage;
+import org.jboss.seam.international.status.builder.BundleTemplateMessage;
 import org.jboss.seam.international.status.builder.TemplateMessage;
 
 /**
  * A utility for building {@link Message} objects via message templates, or
- * message bundles. See {@link TemplateMessage} or {@link BundleMessage}.
+ * message bundles. See {@link TemplateMessage} or {@link BundleTemplateMessage}.
  * 
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
@@ -46,44 +46,44 @@
    /*
     * Bundle Factory Methods
     */
-   public BundleMessage info(final BundleKey message)
+   public BundleTemplateMessage info(final BundleKey message)
    {
-      return new BundleMessage(bundles, Level.INFO).text(message);
+      return new BundleTemplateMessage(bundles, Level.INFO).text(message);
    }
 
-   public BundleMessage info(final BundleKey message, final Object... params)
+   public BundleTemplateMessage info(final BundleKey message, final Object... params)
    {
-      return new BundleMessage(bundles, Level.INFO).text(message).textParams(params);
+      return new BundleTemplateMessage(bundles, Level.INFO).text(message).textParams(params);
    }
 
-   public BundleMessage warn(final BundleKey message)
+   public BundleTemplateMessage warn(final BundleKey message)
    {
-      return new BundleMessage(bundles, Level.WARN).text(message);
+      return new BundleTemplateMessage(bundles, Level.WARN).text(message);
    }
 
-   public BundleMessage warn(final BundleKey message, final Object... params)
+   public BundleTemplateMessage warn(final BundleKey message, final Object... params)
    {
-      return new BundleMessage(bundles, Level.WARN).text(message).textParams(params);
+      return new BundleTemplateMessage(bundles, Level.WARN).text(message).textParams(params);
    }
 
-   public BundleMessage error(final BundleKey message)
+   public BundleTemplateMessage error(final BundleKey message)
    {
-      return new BundleMessage(bundles, Level.ERROR).text(message);
+      return new BundleTemplateMessage(bundles, Level.ERROR).text(message);
    }
 
-   public BundleMessage error(final BundleKey message, final Object... params)
+   public BundleTemplateMessage error(final BundleKey message, final Object... params)
    {
-      return new BundleMessage(bundles, Level.ERROR).text(message).textParams(params);
+      return new BundleTemplateMessage(bundles, Level.ERROR).text(message).textParams(params);
    }
 
-   public BundleMessage fatal(final BundleKey message)
+   public BundleTemplateMessage fatal(final BundleKey message)
    {
-      return new BundleMessage(bundles, Level.FATAL).text(message);
+      return new BundleTemplateMessage(bundles, Level.FATAL).text(message);
    }
 
-   public BundleMessage fatal(final BundleKey message, final Object... params)
+   public BundleTemplateMessage fatal(final BundleKey message, final Object... params)
    {
-      return new BundleMessage(bundles, Level.FATAL).text(message).textParams(params);
+      return new BundleTemplateMessage(bundles, Level.FATAL).text(message).textParams(params);
    }
 
    /*

Modified: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -31,7 +31,7 @@
 import javax.inject.Inject;
 
 import org.jboss.seam.international.status.builder.BundleKey;
-import org.jboss.seam.international.status.builder.BundleMessage;
+import org.jboss.seam.international.status.builder.BundleTemplateMessage;
 import org.jboss.seam.international.status.builder.TemplateMessage;
 
 /**
@@ -47,6 +47,7 @@
    private static final long serialVersionUID = -2908193057765795662L;
 
    private final Set<Message> messages = Collections.synchronizedSet(new HashSet<Message>());
+   private final Set<MessageBuilder> builders = Collections.synchronizedSet(new HashSet<MessageBuilder>());
 
    @Inject
    private MessageFactory factory;
@@ -61,11 +62,24 @@
 
    /**
     * Retrieve all pending {@link Messages} in their final state - as they will
-    * be displayed to the user.
+    * be displayed to the user. Calling this method will call
+    * {@link MessageBuilder#build()} on any queued {@link MessageBuilder}
+    * instances, adding the resulting {@link Message} objects to the message
+    * cache, and clearing the builders from the builder cache.
     */
    public Set<Message> getAll()
    {
       Set<Message> result = new HashSet<Message>();
+
+      synchronized (builders)
+      {
+         for (MessageBuilder builder : builders)
+         {
+            messages.add(builder.build());
+         }
+         builders.clear();
+      }
+
       synchronized (messages)
       {
          result.addAll(messages);
@@ -86,55 +100,66 @@
    }
 
    /**
-    * Add a {@link Message} object, produced by the provided
-    * {@link MessageBuilder}, to the pending message cache.
+    * Add a {@link MessageBuilder} object to the pending builder cache. A
+    * subsequent call to {@link Messages#getAll()} will trigger,
+    * {@link MessageBuilder#build()} to be called called on each builder added
+    * in this way.
     */
    public void add(final MessageBuilder builder)
    {
-      messages.add(builder.build());
+      builders.add(builder);
    }
 
+   /**
+    * Convenience add & pass-through for factory methods.
+    */
+   private <T extends MessageBuilder> T enqueueBuilder(final T builder)
+   {
+      add(builder);
+      return builder;
+   }
+
    /*
     * Bundle Factory Methods
     */
-   public BundleMessage info(final BundleKey message)
+   public BundleTemplateMessage info(final BundleKey message)
    {
-      return factory.info(message);
+      return enqueueBuilder(factory.info(message));
    }
 
-   public BundleMessage info(final BundleKey message, final Object... params)
+   public BundleTemplateMessage info(final BundleKey message, final Object... params)
    {
-      return factory.info(message, params);
+      return enqueueBuilder(factory.info(message, params));
    }
 
-   public BundleMessage warn(final BundleKey message)
+   public BundleTemplateMessage warn(final BundleKey message)
    {
-      return factory.warn(message);
+      return enqueueBuilder(factory.warn(message));
    }
 
-   public BundleMessage warn(final BundleKey message, final Object... params)
+   public BundleTemplateMessage warn(final BundleKey message, final Object... params)
    {
-      return factory.warn(message, params);
+      return enqueueBuilder(factory.warn(message, params));
    }
 
-   public BundleMessage error(final BundleKey message)
+   public BundleTemplateMessage error(final BundleKey message)
    {
-      return factory.error(message);
+      return enqueueBuilder(factory.error(message));
    }
 
-   public BundleMessage error(final BundleKey message, final Object... params)
+   public BundleTemplateMessage error(final BundleKey message, final Object... params)
    {
-      return factory.error(message, params);
+      return enqueueBuilder(factory.error(message, params));
    }
 
-   public BundleMessage fatal(final BundleKey message)
+   public BundleTemplateMessage fatal(final BundleKey message)
    {
-      return factory.fatal(message);
+      return enqueueBuilder(factory.fatal(message));
    }
 
-   public BundleMessage fatal(final BundleKey message, final Object... params)
+   public BundleTemplateMessage fatal(final BundleKey message, final Object... params)
    {
-      return factory.fatal(message, params);
+      return enqueueBuilder(factory.fatal(message, params));
    }
 
    /*
@@ -142,42 +167,42 @@
     */
    public TemplateMessage info(final String message)
    {
-      return factory.info(message);
+      return enqueueBuilder(factory.info(message));
    }
 
    public TemplateMessage info(final String message, final Object... params)
    {
-      return factory.info(message, params);
+      return enqueueBuilder(factory.info(message, params));
    }
 
    public TemplateMessage warn(final String message)
    {
-      return factory.warn(message);
+      return enqueueBuilder(factory.warn(message));
    }
 
    public TemplateMessage warn(final String message, final Object... params)
    {
-      return factory.warn(message, params);
+      return enqueueBuilder(factory.warn(message, params));
    }
 
    public TemplateMessage error(final String message)
    {
-      return factory.error(message);
+      return enqueueBuilder(factory.error(message));
    }
 
    public TemplateMessage error(final String message, final Object... params)
    {
-      return factory.error(message, params);
+      return enqueueBuilder(factory.error(message, params));
    }
 
    public TemplateMessage fatal(final String message)
    {
-      return factory.fatal(message);
+      return enqueueBuilder(factory.fatal(message));
    }
 
    public TemplateMessage fatal(final String message, final Object... params)
    {
-      return factory.fatal(message, params);
+      return enqueueBuilder(factory.fatal(message, params));
    }
 
 }

Deleted: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -1,134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.international.status.builder;
-
-import org.jboss.seam.international.status.Bundles;
-import org.jboss.seam.international.status.Level;
-import org.jboss.seam.international.status.Message;
-import org.jboss.seam.international.status.MessageBuilder;
-
-/**
- * This {@link MessageBuilder} implementation creates {@link Message} objects by
- * loading resource bundle keys as templates with values supplied as parameters.
- * <p>
- * <b>For example:</b>
- * <p>
- * Given the following {@link Message} m
- * 
- * <pre>
- * Message m = {@link MessageFactory}.info(new {@link BundleKey}(&quot;messageBundle&quot;, &quot;keyName&quot;), 5, &quot;green&quot;)
- * &nbsp;&nbsp;&nbsp;.defaultText("This is default text.").build();
- * </pre>
- * 
- * And the corresponding messageBundle.properties file:<br>
- * 
- * <pre>
- * keyName=There are {0} cars, and they are all {1}.
- * </pre>
- * 
- * A subsequent call to <code>m.getText()</code> will return:<br/>
- * 
- * <pre>
- * &quot;There are 5 cars, and they are all green.&quot;
- * </pre>
- * 
- * <b>Note:</b> If a bundle/key pair cannot be resolved, the default template
- * will be used instead. If there is no default template, a String
- * representation of the {@link BundleKey} will be displayed instead.
- * <p>
- * 
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- * 
- */
-public class BundleMessage implements MessageBuilder
-{
-   private final TemplateMessage template;
-   private String textDefault;
-   private BundleKey textKey;
-
-   private final Bundles bundles;
-
-   public BundleMessage(final Bundles bundles, final Level level)
-   {
-      this.bundles = bundles;
-      this.template = new TemplateMessage(level);
-   }
-
-   /**
-    * Produce a {@link Message} object as represented by the current state of
-    * <code>this</code> builder.
-    */
-   public Message build()
-   {
-      String text;
-      try
-      {
-         text = bundles.get(textKey.getBundle()).getString(textKey.getKey());
-      }
-      catch (Exception e)
-      {
-         text = textDefault;
-      }
-
-      if ((text == null) || "".equals(text))
-      {
-         text = textKey.toString();
-      }
-
-      template.text(text);
-      return template.build();
-   }
-
-   /*
-    * Setters
-    */
-
-   public BundleMessage text(final BundleKey text)
-   {
-      this.textKey = text;
-      return this;
-   }
-
-   public BundleMessage textDefault(final String text)
-   {
-      this.textDefault = text;
-      return this;
-   }
-
-   public BundleMessage textParams(final Object... textParams)
-   {
-      this.template.textParams(textParams);
-      return this;
-   }
-
-   public BundleMessage targets(final String targets)
-   {
-      this.template.targets(targets);
-      return this;
-   }
-
-   public BundleMessage setLevel(final Level level)
-   {
-      this.template.level(level);
-      return this;
-   }
-}

Copied: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessage.java (from rev 12817, modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java)
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessage.java	                        (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessage.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.status.builder;
+
+import org.jboss.seam.international.status.Bundles;
+import org.jboss.seam.international.status.Level;
+import org.jboss.seam.international.status.Message;
+import org.jboss.seam.international.status.MessageBuilder;
+
+/**
+ * This {@link MessageBuilder} implementation creates {@link Message} objects by
+ * loading resource bundle keys as templates with values supplied as parameters.
+ * <p>
+ * <b>For example:</b>
+ * <p>
+ * Given the following {@link Message} m
+ * 
+ * <pre>
+ * Message m = {@link MessageFactory}.info(new {@link BundleKey}(&quot;messageBundle&quot;, &quot;keyName&quot;), 5, &quot;green&quot;)
+ * &nbsp;&nbsp;&nbsp;.defaultText("This is default text.").build();
+ * </pre>
+ * 
+ * And the corresponding messageBundle.properties file:<br>
+ * 
+ * <pre>
+ * keyName=There are {0} cars, and they are all {1}.
+ * </pre>
+ * 
+ * A subsequent call to <code>m.getText()</code> will return:<br/>
+ * 
+ * <pre>
+ * &quot;There are 5 cars, and they are all green.&quot;
+ * </pre>
+ * 
+ * <b>Note:</b> If a bundle/key pair cannot be resolved, the default template
+ * will be used instead. If there is no default template, a String
+ * representation of the {@link BundleKey} will be displayed instead.
+ * <p>
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class BundleTemplateMessage implements MessageBuilder
+{
+   private final TemplateMessage template;
+   private String textDefault;
+   private BundleKey textKey;
+
+   private final Bundles bundles;
+
+   public BundleTemplateMessage(final Bundles bundles, final Level level)
+   {
+      this.bundles = bundles;
+      this.template = new TemplateMessage(level);
+   }
+
+   /**
+    * Produce a {@link Message} object as represented by the current state of
+    * <code>this</code> builder.
+    */
+   public Message build()
+   {
+      String text;
+      try
+      {
+         text = bundles.get(textKey.getBundle()).getString(textKey.getKey());
+      }
+      catch (Exception e)
+      {
+         text = textDefault;
+      }
+
+      if ((text == null) || "".equals(text))
+      {
+         text = textKey.toString();
+      }
+
+      template.text(text);
+      return template.build();
+   }
+
+   /*
+    * Setters
+    */
+
+   public BundleTemplateMessage text(final BundleKey text)
+   {
+      this.textKey = text;
+      return this;
+   }
+
+   public BundleTemplateMessage textDefault(final String text)
+   {
+      this.textDefault = text;
+      return this;
+   }
+
+   public BundleTemplateMessage textParams(final Object... textParams)
+   {
+      this.template.textParams(textParams);
+      return this;
+   }
+
+   public BundleTemplateMessage targets(final String targets)
+   {
+      this.template.targets(targets);
+      return this;
+   }
+
+   public BundleTemplateMessage setLevel(final Level level)
+   {
+      this.template.level(level);
+      return this;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((template == null) ? 0 : template.hashCode());
+      result = prime * result + ((textDefault == null) ? 0 : textDefault.hashCode());
+      result = prime * result + ((textKey == null) ? 0 : textKey.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      BundleTemplateMessage other = (BundleTemplateMessage) obj;
+      if (template == null)
+      {
+         if (other.template != null)
+            return false;
+      }
+      else if (!template.equals(other.template))
+         return false;
+      if (textDefault == null)
+      {
+         if (other.textDefault != null)
+            return false;
+      }
+      else if (!textDefault.equals(other.textDefault))
+         return false;
+      if (textKey == null)
+      {
+         if (other.textKey != null)
+            return false;
+      }
+      else if (!textKey.equals(other.textKey))
+         return false;
+      return true;
+   }
+}

Modified: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -48,7 +48,7 @@
    public String populate(final String template, final Object... params)
    {
       StringBuffer result = new StringBuffer();
-      if (template != null)
+      if ((template != null) && (params != null))
       {
          Matcher matcher = templatePattern.matcher(template);
          while (matcher.find())
@@ -67,6 +67,10 @@
          }
          matcher.appendTail(result);
       }
+      else if (template != null)
+      {
+         result = new StringBuffer(template);
+      }
       return result.toString();
    }
 }

Modified: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/TemplateMessage.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/TemplateMessage.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/TemplateMessage.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -21,6 +21,8 @@
  */
 package org.jboss.seam.international.status.builder;
 
+import java.util.Arrays;
+
 import org.jboss.seam.international.status.Level;
 import org.jboss.seam.international.status.Message;
 import org.jboss.seam.international.status.MessageBuilder;
@@ -47,7 +49,7 @@
 {
    private static final String MESSAGE_IMPL_CLASS = "org.jboss.seam.international.status.MessageImpl";
 
-   private final Interpolator templater = new Interpolator();
+   private final Interpolator interpolator = new Interpolator();
 
    private String summary;
    private Object[] summaryParams;
@@ -73,7 +75,7 @@
          MutableMessage message = (MutableMessage) type.newInstance();
 
          message.setLevel(level);
-         message.setText(templater.populate(summary, summaryParams));
+         message.setText(interpolator.populate(summary, summaryParams));
          message.setTargets(targets);
 
          return message;
@@ -110,4 +112,72 @@
       this.level = level;
       return this;
    }
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((level == null) ? 0 : level.hashCode());
+      result = prime * result + ((summary == null) ? 0 : summary.hashCode());
+      result = prime * result + Arrays.hashCode(summaryParams);
+      result = prime * result + ((targets == null) ? 0 : targets.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(final Object obj)
+   {
+      if (this == obj)
+      {
+         return true;
+      }
+      if (obj == null)
+      {
+         return false;
+      }
+      if (getClass() != obj.getClass())
+      {
+         return false;
+      }
+      TemplateMessage other = (TemplateMessage) obj;
+      if (level == null)
+      {
+         if (other.level != null)
+         {
+            return false;
+         }
+      }
+      else if (!level.equals(other.level))
+      {
+         return false;
+      }
+      if (summary == null)
+      {
+         if (other.summary != null)
+         {
+            return false;
+         }
+      }
+      else if (!summary.equals(other.summary))
+      {
+         return false;
+      }
+      if (!Arrays.equals(summaryParams, other.summaryParams))
+      {
+         return false;
+      }
+      if (targets == null)
+      {
+         if (other.targets != null)
+         {
+            return false;
+         }
+      }
+      else if (!targets.equals(other.targets))
+      {
+         return false;
+      }
+      return true;
+   }
 }

Modified: modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java
===================================================================
--- modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java	2010-05-27 15:56:14 UTC (rev 12872)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -32,7 +32,6 @@
    private static final long serialVersionUID = -1812292372048679525L;
 
    private String summary;
-   private String details;
    private String targets;
    private Level level;
 
@@ -41,10 +40,9 @@
    {
       final int prime = 31;
       int result = 1;
-      result = prime * result + ((details == null) ? 0 : details.hashCode());
-      result = prime * result + ((targets == null) ? 0 : targets.hashCode());
       result = prime * result + ((level == null) ? 0 : level.hashCode());
       result = prime * result + ((summary == null) ? 0 : summary.hashCode());
+      result = prime * result + ((targets == null) ? 0 : targets.hashCode());
       return result;
    }
 
@@ -64,50 +62,39 @@
          return false;
       }
       MessageImpl other = (MessageImpl) obj;
-      if (details == null)
+      if (level == null)
       {
-         if (other.details != null)
+         if (other.level != null)
          {
             return false;
          }
       }
-      else if (!details.equals(other.details))
+      else if (!level.equals(other.level))
       {
          return false;
       }
-      if (targets == null)
+      if (summary == null)
       {
-         if (other.targets != null)
+         if (other.summary != null)
          {
             return false;
          }
       }
-      else if (!targets.equals(other.targets))
+      else if (!summary.equals(other.summary))
       {
          return false;
       }
-      if (level == null)
+      if (targets == null)
       {
-         if (other.level != null)
+         if (other.targets != null)
          {
             return false;
          }
       }
-      else if (!level.equals(other.level))
+      else if (!targets.equals(other.targets))
       {
          return false;
       }
-      if (summary == null)
-      {
-         if (other.summary != null)
-         {
-            return false;
-         }
-      }
-      else if (!summary.equals(other.summary))
-      {
-         return false;
-      }
       return true;
    }
 
@@ -119,11 +106,6 @@
       return summary;
    }
 
-   public String getDetails()
-   {
-      return details;
-   }
-
    public String getTargets()
    {
       return targets;
@@ -139,11 +121,6 @@
       this.summary = summary;
    }
 
-   public void setDetails(final String details)
-   {
-      this.details = details;
-   }
-
    public void setTargets(final String targets)
    {
       this.targets = targets;

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.status;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.status.Bundles;
+import org.jboss.seam.international.status.Level;
+import org.jboss.seam.international.status.MessageFactory;
+import org.jboss.seam.international.status.MessageImpl;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.MutableMessage;
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at RunWith(Arquillian.class)
+public class MessagesTest
+{
+   private static final String BUNDLE_PATH = "org.jboss.seam.international.test.status.TestBundle";
+
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(Messages.class, MessageFactory.class, Bundles.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+   }
+
+   @Inject
+   Messages messages;
+
+   @Before
+   public void before()
+   {
+      messages.clear();
+   }
+
+   @Test
+   public void testMessageBuildersAreAddedWhenUsingFactoryMethods()
+   {
+      messages.info("This is a message");
+      assertEquals(1, messages.getAll().size());
+      assertEquals(Level.INFO, messages.getAll().iterator().next().getLevel());
+   }
+
+   @Test
+   public void testMessageBuildersAreAddedWhenUsingFactoryMethodsBundle()
+   {
+      messages.error(new BundleKey(BUNDLE_PATH, "key1"));
+      assertEquals(1, messages.getAll().size());
+      assertEquals(Level.ERROR, messages.getAll().iterator().next().getLevel());
+   }
+
+   @Test
+   public void testDuplicateMessageBuildersAreIgnored()
+   {
+      messages.warn("This is a message");
+      messages.warn("This is a message");
+      messages.warn("This is a message");
+      assertEquals(1, messages.getAll().size());
+
+      assertEquals(Level.WARN, messages.getAll().iterator().next().getLevel());
+   }
+
+   @Test
+   public void testDuplicateMessageBuildersResultMessagesAreIgnored()
+   {
+      messages.fatal("This is a message");
+      messages.fatal(new BundleKey(BUNDLE_PATH, "key2"));
+      assertEquals(1, messages.getAll().size());
+
+      assertEquals(Level.FATAL, messages.getAll().iterator().next().getLevel());
+   }
+
+   @Test
+   public void testDuplicateMessagesAreIgnored() throws Exception
+   {
+      MutableMessage message = new MessageImpl();
+      String text = "This is a message!";
+      message.setText(text);
+      messages.add(message);
+
+      message = new MessageImpl();
+      message.setText(text);
+      messages.add(message);
+
+      assertEquals(1, messages.getAll().size());
+   }
+}

Copied: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder (from rev 12817, modules/international/trunk/impl/src/test/java/org/jboss/seam/international/status/builder)

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/BundleTemplateMessageTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/BundleTemplateMessageTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/BundleTemplateMessageTest.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.status.builder;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.status.Bundles;
+import org.jboss.seam.international.status.MessageFactory;
+import org.jboss.seam.international.status.builder.TemplateMessage;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at RunWith(Arquillian.class)
+public class BundleTemplateMessageTest
+{
+   @Deployment
+   public static Archive<?> createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MessageFactory.class, Bundles.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+   }
+
+   @Inject
+   MessageFactory factory;
+
+   @Test
+   public void testParameterizedTemplate() throws Exception
+   {
+      String expected = "There are 5 cars, and they are all green; green is the best color.";
+      TemplateMessage builder = factory.info("There are {0} cars, and they are all {1}; {1} is the best color.", 5, "green");
+      assertEquals(expected, builder.build().getText());
+   }
+
+   @Test
+   public void testParameterizedTemplateInsertsParamNumbersIfNotEnoughParamValues() throws Exception
+   {
+      String expected = "There are 5 cars, and they are all {1}; {1} is the best color.";
+      TemplateMessage builder = factory.warn("There are {0} cars, and they are all {1}; {1} is the best color.", 5);
+      assertEquals(expected, builder.build().getText());
+   }
+
+   @Test
+   public void testPlainTextTemplate() throws Exception
+   {
+      String expected = "There are 5 cars, and they are all green; green is the best color.";
+      TemplateMessage builder = factory.error("There are 5 cars, and they are all green; green is the best color.");
+      assertEquals(expected, builder.build().getText());
+   }
+
+   @Test
+   public void testPlainTextTemplateWithParamsIsUnmodified() throws Exception
+   {
+      String expected = "There are 5 cars, and they are all green; green is the best color.";
+      TemplateMessage builder = factory.fatal("There are 5 cars, and they are all green; green is the best color.", "blue", "red", 6);
+      assertEquals(expected, builder.build().getText());
+   }
+}

Modified: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/TemplateMessageTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/status/builder/TemplateMessageTest.java	2010-05-26 18:44:38 UTC (rev 12817)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/builder/TemplateMessageTest.java	2010-05-27 17:54:30 UTC (rev 12873)
@@ -19,7 +19,7 @@
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
-package org.jboss.seam.international.status.builder;
+package org.jboss.seam.international.test.status.builder;
 
 import static org.junit.Assert.assertEquals;
 
@@ -29,6 +29,7 @@
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.seam.international.status.Bundles;
 import org.jboss.seam.international.status.MessageFactory;
+import org.jboss.seam.international.status.builder.TemplateMessage;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/status/TestBundle.properties
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/status/TestBundle.properties	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/status/TestBundle.properties	2010-05-27 17:54:30 UTC (rev 12873)
@@ -0,0 +1,2 @@
+key1=This is a {0} message.
+key2=This is a message
\ No newline at end of file



More information about the seam-commits mailing list