Author: lincolnthree
Date: 2010-06-15 18:31:25 -0400 (Tue, 15 Jun 2010)
New Revision: 13170
Added:
modules/international/trunk/api/build/
modules/international/trunk/api/build/classes/
modules/international/trunk/impl/build/
modules/international/trunk/impl/build/classes/
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessagesImpl.java
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/builder/BundleKey.java
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessageImpl.java
modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java
Log:
Fixed messages API. Impl is now in the IMPL, Messages is converted to an interface
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-06-15
22:30:05 UTC (rev 13169)
+++
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java 2010-06-15
22:31:25 UTC (rev 13170)
@@ -23,12 +23,9 @@
package org.jboss.seam.international.status;
import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
import org.jboss.seam.international.status.builder.BundleKey;
import org.jboss.seam.international.status.builder.BundleTemplateMessage;
@@ -45,23 +42,12 @@
*
*/
@RequestScoped
-public class Messages implements Serializable
+public interface Messages extends Serializable
{
- 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;
-
/**
* Clear all pending messages.
*/
- public void clear()
- {
- messages.clear();
- }
+ public void clear();
/**
* Retrieve all pending {@link Messages} in their final state - as they will
@@ -70,26 +56,8 @@
* 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>();
+ public Set<Message> getAll();
- synchronized (builders)
- {
- for (MessageBuilder builder : builders)
- {
- messages.add(builder.build());
- }
- builders.clear();
- }
-
- synchronized (messages)
- {
- result.addAll(messages);
- }
- return result;
- }
-
/**
* Add a {@link Message} object to the pending message cache. Messages remain
* pending until cleared by and displayed in the View Layer, or until cleared
@@ -97,10 +65,7 @@
* <p>
* <b>Note:</b> Duplicate messages are ignored.
*/
- public void add(final Message message)
- {
- messages.add(message);
- }
+ public void add(final Message message);
/**
* Add a {@link MessageBuilder} object to the pending builder cache. A
@@ -108,170 +73,102 @@
* {@link MessageBuilder#build()} to be called called on each builder added
* in this way.
*/
- public void add(final MessageBuilder builder)
- {
- builders.add(builder);
- }
+ public void add(final MessageBuilder builder);
/**
- * Convenience add & pass-through for factory methods.
- */
- private <T extends MessageBuilder> T enqueueBuilder(final T builder)
- {
- add(builder);
- return builder;
- }
-
- /*
- * Bundle Factory Methods
- */
-
- /**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage info(final BundleKey message)
- {
- return enqueueBuilder(factory.info(message));
- }
+ public BundleTemplateMessage info(final BundleKey message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage info(final BundleKey message, final Object... params)
- {
- return enqueueBuilder(factory.info(message, params));
- }
+ public BundleTemplateMessage info(final BundleKey message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage warn(final BundleKey message)
- {
- return enqueueBuilder(factory.warn(message));
- }
+ public BundleTemplateMessage warn(final BundleKey message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage warn(final BundleKey message, final Object... params)
- {
- return enqueueBuilder(factory.warn(message, params));
- }
+ public BundleTemplateMessage warn(final BundleKey message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage error(final BundleKey message)
- {
- return enqueueBuilder(factory.error(message));
- }
+ public BundleTemplateMessage error(final BundleKey message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage error(final BundleKey message, final Object... params)
- {
- return enqueueBuilder(factory.error(message, params));
- }
+ public BundleTemplateMessage error(final BundleKey message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage fatal(final BundleKey message)
- {
- return enqueueBuilder(factory.fatal(message));
- }
+ public BundleTemplateMessage fatal(final BundleKey message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public BundleTemplateMessage fatal(final BundleKey message, final Object... params)
- {
- return enqueueBuilder(factory.fatal(message, params));
- }
+ public BundleTemplateMessage fatal(final BundleKey message, final Object... params);
- /*
- * Template Factory Methods
- */
-
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage info(final String message)
- {
- return enqueueBuilder(factory.info(message));
- }
+ public TemplateMessage info(final String message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage info(final String message, final Object... params)
- {
- return enqueueBuilder(factory.info(message, params));
- }
+ public TemplateMessage info(final String message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage warn(final String message)
- {
- return enqueueBuilder(factory.warn(message));
- }
+ public TemplateMessage warn(final String message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage warn(final String message, final Object... params)
- {
- return enqueueBuilder(factory.warn(message, params));
- }
+ public TemplateMessage warn(final String message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage error(final String message)
- {
- return enqueueBuilder(factory.error(message));
- }
+ public TemplateMessage error(final String message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage error(final String message, final Object... params)
- {
- return enqueueBuilder(factory.error(message, params));
- }
+ public TemplateMessage error(final String message, final Object... params);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage fatal(final String message)
- {
- return enqueueBuilder(factory.fatal(message));
- }
+ public TemplateMessage fatal(final String message);
/**
* Create a {@link MessageBuilder} with the specified {@link Level}, add it
* to the internal queue, and return it.
*/
- public TemplateMessage fatal(final String message, final Object... params)
- {
- return enqueueBuilder(factory.fatal(message, params));
- }
+ public TemplateMessage fatal(final String message, final Object... params);
}
Modified:
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleKey.java
===================================================================
---
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleKey.java 2010-06-15
22:30:05 UTC (rev 13169)
+++
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleKey.java 2010-06-15
22:31:25 UTC (rev 13170)
@@ -45,6 +45,12 @@
}
@Override
+ public String toString()
+ {
+ return "BundleKey [bundle=" + bundle + ", key=" + key +
"]";
+ }
+
+ @Override
public int hashCode()
{
final int prime = 31;
Copied:
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessagesImpl.java
(from rev 13166,
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java)
===================================================================
---
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessagesImpl.java
(rev 0)
+++
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessagesImpl.java 2010-06-15
22:31:25 UTC (rev 13170)
@@ -0,0 +1,185 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import org.jboss.seam.international.status.builder.BundleKey;
+import org.jboss.seam.international.status.builder.BundleTemplateMessage;
+import org.jboss.seam.international.status.builder.TemplateMessage;
+
+/**
+ * An implementation of the {@link Messages} interface.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com>Lincoln Baxter,
III</a>
+ *
+ */
+@RequestScoped
+public class MessagesImpl implements Messages
+{
+ 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;
+
+ public void clear()
+ {
+ messages.clear();
+ }
+
+ public boolean isEmpty()
+ {
+ return messages.isEmpty() && builders.isEmpty();
+ }
+
+ 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);
+ }
+ return result;
+ }
+
+ public void add(final Message message)
+ {
+ messages.add(message);
+ }
+
+ public void add(final MessageBuilder builder)
+ {
+ builders.add(builder);
+ }
+
+ private <T extends MessageBuilder> T enqueueBuilder(final T builder)
+ {
+ add(builder);
+ return builder;
+ }
+
+ /*
+ * Bundle Factory Methods
+ */
+ public BundleTemplateMessage info(final BundleKey message)
+ {
+ return enqueueBuilder(factory.info(message));
+ }
+
+ public BundleTemplateMessage info(final BundleKey message, final Object... params)
+ {
+ return enqueueBuilder(factory.info(message, params));
+ }
+
+ public BundleTemplateMessage warn(final BundleKey message)
+ {
+ return enqueueBuilder(factory.warn(message));
+ }
+
+ public BundleTemplateMessage warn(final BundleKey message, final Object... params)
+ {
+ return enqueueBuilder(factory.warn(message, params));
+ }
+
+ public BundleTemplateMessage error(final BundleKey message)
+ {
+ return enqueueBuilder(factory.error(message));
+ }
+
+ public BundleTemplateMessage error(final BundleKey message, final Object... params)
+ {
+ return enqueueBuilder(factory.error(message, params));
+ }
+
+ public BundleTemplateMessage fatal(final BundleKey message)
+ {
+ return enqueueBuilder(factory.fatal(message));
+ }
+
+ public BundleTemplateMessage fatal(final BundleKey message, final Object... params)
+ {
+ return enqueueBuilder(factory.fatal(message, params));
+ }
+
+ /*
+ * Template Factory Methods
+ */
+ public TemplateMessage info(final String message)
+ {
+ return enqueueBuilder(factory.info(message));
+ }
+
+ public TemplateMessage info(final String message, final Object... params)
+ {
+ return enqueueBuilder(factory.info(message, params));
+ }
+
+ public TemplateMessage warn(final String message)
+ {
+ return enqueueBuilder(factory.warn(message));
+ }
+
+ public TemplateMessage warn(final String message, final Object... params)
+ {
+ return enqueueBuilder(factory.warn(message, params));
+ }
+
+ public TemplateMessage error(final String message)
+ {
+ return enqueueBuilder(factory.error(message));
+ }
+
+ public TemplateMessage error(final String message, final Object... params)
+ {
+ return enqueueBuilder(factory.error(message, params));
+ }
+
+ public TemplateMessage fatal(final String message)
+ {
+ return enqueueBuilder(factory.fatal(message));
+ }
+
+ public TemplateMessage fatal(final String message, final Object... params)
+ {
+ return enqueueBuilder(factory.fatal(message, params));
+ }
+
+}
Modified:
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessageImpl.java
===================================================================
---
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessageImpl.java 2010-06-15
22:30:05 UTC (rev 13169)
+++
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/builder/BundleTemplateMessageImpl.java 2010-06-15
22:31:25 UTC (rev 13170)
@@ -26,6 +26,7 @@
import org.jboss.seam.international.status.Bundles;
import org.jboss.seam.international.status.Level;
import org.jboss.seam.international.status.Message;
+import org.slf4j.Logger;
/**
*
@@ -43,6 +44,9 @@
@Inject
Bundles bundles;
+ @Inject
+ Logger log;
+
public Message build()
{
String text;
@@ -52,6 +56,7 @@
}
catch (Exception e)
{
+ log.warn("Could not load bundle: " + textKey);
text = textDefault;
}
Modified:
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 2010-06-15
22:30:05 UTC (rev 13169)
+++
modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/status/MessagesTest.java 2010-06-15
22:31:25 UTC (rev 13170)
@@ -31,7 +31,7 @@
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.MessagesImpl;
import org.jboss.seam.international.status.MutableMessage;
import org.jboss.seam.international.status.builder.BundleKey;
import org.jboss.seam.international.status.builder.BundleTemplateMessageImpl;
@@ -56,11 +56,11 @@
@Deployment
public static JavaArchive createTestArchive()
{
- return ShrinkWrap.create("test.jar",
JavaArchive.class).addClasses(Messages.class, MessageFactory.class,
BundleTemplateMessageImpl.class, TemplateMessageImpl.class,
Bundles.class).addManifestResource(new ByteArrayAsset(new byte[0]),
ArchivePaths.create("beans.xml"));
+ return ShrinkWrap.create("test.jar",
JavaArchive.class).addClasses(MessagesImpl.class, MessageFactory.class,
BundleTemplateMessageImpl.class, TemplateMessageImpl.class,
Bundles.class).addManifestResource(new ByteArrayAsset(new byte[0]),
ArchivePaths.create("beans.xml"));
}
@Inject
- Messages messages;
+ MessagesImpl messages;
@Before
public void before()