[seam-commits] Seam SVN: r12781 - in modules: faces/trunk/api/src/main/java/org/jboss/seam/faces and 15 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 24 11:43:42 EDT 2010
Author: lincolnthree
Date: 2010-05-24 11:43:41 -0400 (Mon, 24 May 2010)
New Revision: 12781
Added:
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Bundles.java
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Level.java
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Message.java
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageBuilder.java
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/MutableMessage.java
modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/
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/BundleMessage.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/api/src/test/java/org/
modules/international/trunk/api/src/test/java/org/jboss/
modules/international/trunk/api/src/test/java/org/jboss/seam/
modules/international/trunk/api/src/test/java/org/jboss/seam/international/
modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/
modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/builder/
modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/builder/TemplateMessageTest.java
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/
modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java
Removed:
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/display/
modules/faces/trunk/api/src/test/java/org/jboss/seam/faces/display/
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessage.java
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessages.java
modules/faces/trunk/pom.xml
modules/international/trunk/pom.xml
Log:
Moved SeamMessages to the International Module, with new API.
@Inject Messages messages;
..
messages.add(messages.info("new message using factory & builder pattern!"));
Deleted: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessage.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessage.java 2010-05-24 09:25:47 UTC (rev 12780)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessage.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -1,165 +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.faces.display;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
- *
- */
-public class SeamMessage implements Message
-{
- private static final long serialVersionUID = 6650116552438358826L;
-
- private String message;
- private String details;
- private String clientId;
- private final Level level;
-
- public SeamMessage(final Level level)
- {
- this.level = level;
- }
-
- @Override
- public String toString()
- {
- return "SeamMessage [clientId=" + clientId + ", details=" + details + ", level=" + level + ", message=" + message + "]";
- }
-
- public Message component(final String clientId)
- {
- this.clientId = clientId;
- return this;
- }
-
- public Message details(final String details)
- {
- this.details = details;
- return this;
- }
-
- public Message summary(final String message)
- {
- this.message = message;
- return this;
- }
-
- /*
- * Getters & Setters
- */
- public Level getLevel()
- {
- return level;
- }
-
- public String getMessage()
- {
- return message;
- }
-
- public String getDetails()
- {
- return details;
- }
-
- public String getClientId()
- {
- return clientId;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((clientId == null) ? 0 : clientId.hashCode());
- result = prime * result + ((details == null) ? 0 : details.hashCode());
- result = prime * result + ((level == null) ? 0 : level.hashCode());
- result = prime * result + ((message == null) ? 0 : message.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;
- }
- SeamMessage other = (SeamMessage) obj;
- if (clientId == null)
- {
- if (other.clientId != null)
- {
- return false;
- }
- }
- else if (!clientId.equals(other.clientId))
- {
- return false;
- }
- if (details == null)
- {
- if (other.details != null)
- {
- return false;
- }
- }
- else if (!details.equals(other.details))
- {
- return false;
- }
- if (level == null)
- {
- if (other.level != null)
- {
- return false;
- }
- }
- else if (!level.equals(other.level))
- {
- return false;
- }
- if (message == null)
- {
- if (other.message != null)
- {
- return false;
- }
- }
- else if (!message.equals(other.message))
- {
- return false;
- }
- return true;
- }
-
-}
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessages.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessages.java 2010-05-24 09:25:47 UTC (rev 12780)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/display/SeamMessages.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -23,56 +23,63 @@
package org.jboss.seam.faces.display;
import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Observes;
import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
import javax.faces.event.PhaseEvent;
+import javax.inject.Inject;
import org.jboss.seam.faces.event.qualifier.Before;
import org.jboss.seam.faces.event.qualifier.RenderResponse;
+import org.jboss.seam.international.status.Level;
+import org.jboss.seam.international.status.Message;
+import org.jboss.seam.international.status.Messages;
/**
+ * Convert Seam Messages into FacesMessages <br>
+ * TODO perform EL evaluation.
+ *
* @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
*
*/
@SessionScoped
-public class SeamMessages implements Messages, Serializable
+public class SeamMessages implements Serializable
{
private static final long serialVersionUID = -2908193057765795662L;
- private final Set<Message> messages = Collections.synchronizedSet(new HashSet<Message>());
+ @Inject
+ Messages sm;
+
@SuppressWarnings("unused")
private void convert(@Observes @Before @RenderResponse final PhaseEvent event)
{
- for (Message m : messages)
+ for (Message m : sm.getAll())
{
- event.getFacesContext().addMessage(m.getClientId(), new FacesMessage(m.getLevel().getSeverity(), m.getMessage(), m.getDetails()));
+ event.getFacesContext().addMessage(m.getTargets(), new FacesMessage(getSeverity(m.getLevel()), m.getText(), null));
}
- clear();
+ sm.clear();
}
- public void clear()
+ private Severity getSeverity(final Level level)
{
- messages.clear();
- }
-
- public Message add(final Level level)
- {
- Message result = new SeamMessage(level);
- messages.add(result);
- return result;
- }
-
- public Set<Message> getAll()
- {
- Set<Message> result;
- synchronized (messages)
+ Severity result = FacesMessage.SEVERITY_INFO;
+ switch (level)
{
- result = Collections.unmodifiableSet(messages);
+ case INFO:
+ break;
+ case WARN:
+ result = FacesMessage.SEVERITY_WARN;
+ break;
+ case ERROR:
+ result = FacesMessage.SEVERITY_ERROR;
+ break;
+ case FATAL:
+ result = FacesMessage.SEVERITY_FATAL;
+ break;
+ default:
+ break;
}
return result;
}
Modified: modules/faces/trunk/pom.xml
===================================================================
--- modules/faces/trunk/pom.xml 2010-05-24 09:25:47 UTC (rev 12780)
+++ modules/faces/trunk/pom.xml 2010-05-24 15:43:41 UTC (rev 12781)
@@ -30,6 +30,7 @@
</modules>
<properties>
+ <seam.i18n.version>3.0.0-SNAPSHOT</seam.i18n.version>
<arquillian.version>1.0.0.Alpha1</arquillian.version>
<jsfmock.version>1.0.0</jsfmock.version>
<jsfunit.version>1.2.0.Final</jsfunit.version>
@@ -54,6 +55,11 @@
</dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.jboss.seam.international</groupId>
+ <artifactId>seam-international</artifactId>
+ <version>${seam.i18n.version}</version>
+ </dependency>
<!-- Environment Dependencies -->
<dependency>
Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Bundles.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Bundles.java (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Bundles.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,104 @@
+/*
+ * 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.Collection;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+
+/**
+ * Maintains a global map of {@link ResourceBundle} objects.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+ at Named
+ at ApplicationScoped
+public class Bundles implements Map<String, ResourceBundle>
+{
+ private final Map<String, ResourceBundle> bundles = new ConcurrentHashMap<String, ResourceBundle>();
+
+ public void clear()
+ {
+ bundles.clear();
+ }
+
+ public boolean containsKey(final Object key)
+ {
+ return bundles.containsKey(key);
+ }
+
+ public boolean containsValue(final Object value)
+ {
+ return bundles.containsValue(value);
+ }
+
+ public Set<java.util.Map.Entry<String, ResourceBundle>> entrySet()
+ {
+ return bundles.entrySet();
+ }
+
+ public ResourceBundle get(final Object key)
+ {
+ return bundles.get(key);
+ }
+
+ public boolean isEmpty()
+ {
+ return bundles.isEmpty();
+ }
+
+ public Set<String> keySet()
+ {
+ return keySet();
+ }
+
+ public ResourceBundle put(final String key, final ResourceBundle value)
+ {
+ return put(key, value);
+ }
+
+ public void putAll(final Map<? extends String, ? extends ResourceBundle> m)
+ {
+ bundles.putAll(m);
+ }
+
+ public ResourceBundle remove(final Object key)
+ {
+ return bundles.remove(key);
+ }
+
+ public int size()
+ {
+ return bundles.size();
+ }
+
+ public Collection<ResourceBundle> values()
+ {
+ return bundles.values();
+ }
+}
\ No newline at end of file
Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Level.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Level.java (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Level.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.jboss.seam.international.status;
+
+/**
+ * Severity of a given {@link Message}, used to represent varying levels of
+ * importance to the end user.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public enum Level
+{
+ INFO, WARN, ERROR, FATAL;
+}
\ No newline at end of file
Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Message.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Message.java (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Message.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,48 @@
+/*
+ * 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.io.Serializable;
+
+/**
+ * An object representing a message that needs to be displayed to the User.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ */
+public interface Message extends Serializable
+{
+ /**
+ * Get the {@link Level} representing the severity of this message.
+ */
+ Level getLevel();
+
+ /**
+ * Get the message text.
+ */
+ String getText();
+
+ /**
+ * Get the targets for which a given view-layer or consumer should display
+ * this message, or to which this message should be attached.
+ */
+ String getTargets();
+}
Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageBuilder.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageBuilder.java (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageBuilder.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * A {@link MessageBuilder} is used to generate populated {@link Message}
+ * objects. These messages may then be added to the outgoing message cache via
+ * {@link Messages}
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface MessageBuilder
+{
+ /**
+ * Generate a {@link Message} that represents the internal state of this
+ * builder.
+ */
+ Message build();
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MessageFactory.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,125 @@
+/*
+ * 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 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.TemplateMessage;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class MessageFactory
+{
+ @Inject
+ Bundles bundles;
+
+ /*
+ * Bundle Factory Methods
+ */
+ public BundleMessage info(final BundleKey message)
+ {
+ return new BundleMessage(bundles, Level.INFO).text(message);
+ }
+
+ public BundleMessage info(final BundleKey message, final Object... params)
+ {
+ return new BundleMessage(bundles, Level.INFO).text(message).textParams(params);
+ }
+
+ public BundleMessage warn(final BundleKey message)
+ {
+ return new BundleMessage(bundles, Level.WARN).text(message);
+ }
+
+ public BundleMessage warn(final BundleKey message, final Object... params)
+ {
+ return new BundleMessage(bundles, Level.WARN).text(message).textParams(params);
+ }
+
+ public BundleMessage error(final BundleKey message)
+ {
+ return new BundleMessage(bundles, Level.ERROR).text(message);
+ }
+
+ public BundleMessage error(final BundleKey message, final Object... params)
+ {
+ return new BundleMessage(bundles, Level.ERROR).text(message).textParams(params);
+ }
+
+ public BundleMessage fatal(final BundleKey message)
+ {
+ return new BundleMessage(bundles, Level.FATAL).text(message);
+ }
+
+ public BundleMessage fatal(final BundleKey message, final Object... params)
+ {
+ return new BundleMessage(bundles, Level.FATAL).text(message).textParams(params);
+ }
+
+ /*
+ * Template Factory Methods
+ */
+ public TemplateMessage info(final String message)
+ {
+ return new TemplateMessage(Level.INFO).text(message);
+ }
+
+ public TemplateMessage info(final String message, final Object... params)
+ {
+ return new TemplateMessage(Level.INFO).text(message).textParams(params);
+ }
+
+ public TemplateMessage warn(final String message)
+ {
+ return new TemplateMessage(Level.WARN).text(message);
+ }
+
+ public TemplateMessage warn(final String message, final Object... params)
+ {
+ return new TemplateMessage(Level.WARN).text(message).textParams(params);
+ }
+
+ public TemplateMessage error(final String message)
+ {
+ return new TemplateMessage(Level.ERROR).text(message);
+ }
+
+ public TemplateMessage error(final String message, final Object... params)
+ {
+ return new TemplateMessage(Level.ERROR).text(message).textParams(params);
+ }
+
+ public TemplateMessage fatal(final String message)
+ {
+ return new TemplateMessage(Level.FATAL).text(message);
+ }
+
+ public TemplateMessage fatal(final String message, final Object... params)
+ {
+ return new TemplateMessage(Level.FATAL).text(message).textParams(params);
+ }
+
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/Messages.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,182 @@
+/*
+ * 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.io.Serializable;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.SessionScoped;
+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.TemplateMessage;
+
+/**
+ * A convenient way to add messages to be displayed to the user as Feedback,
+ * Toast, Alerts, etc...
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com>Lincoln Baxter, III</a>
+ *
+ */
+ at SessionScoped
+public class Messages implements Serializable
+{
+ private static final long serialVersionUID = -2908193057765795662L;
+ private final Set<Message> messages = Collections.synchronizedSet(new HashSet<Message>());
+
+ @Inject
+ MessageFactory factory;
+
+ /**
+ * Clear all pending messages.
+ */
+ public void clear()
+ {
+ messages.clear();
+ }
+
+ /**
+ * Retrieve all pending {@link Messages} in their final state - as they will
+ * be displayed to the user.
+ */
+ public Set<Message> getAll()
+ {
+ Set<Message> result = new HashSet<Message>();
+ 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
+ * manually by calling {@link #clear()}, or until the user's Session expires.
+ * <p>
+ * <b>Note:</b> Duplicate messages are ignored.
+ */
+ public void add(final Message message)
+ {
+ messages.add(message);
+ }
+
+ /**
+ * Add a {@link Message} object, produced by the provided
+ * {@link MessageBuilder}, to the pending message cache.
+ */
+ public void add(final MessageBuilder builder)
+ {
+ messages.add(builder.build());
+ }
+
+ /*
+ * Bundle Factory Methods
+ */
+ public BundleMessage info(final BundleKey message)
+ {
+ return factory.info(message);
+ }
+
+ public BundleMessage info(final BundleKey message, final Object... params)
+ {
+ return factory.info(message, params);
+ }
+
+ public BundleMessage warn(final BundleKey message)
+ {
+ return factory.warn(message);
+ }
+
+ public BundleMessage warn(final BundleKey message, final Object... params)
+ {
+ return factory.warn(message, params);
+ }
+
+ public BundleMessage error(final BundleKey message)
+ {
+ return factory.error(message);
+ }
+
+ public BundleMessage error(final BundleKey message, final Object... params)
+ {
+ return factory.error(message, params);
+ }
+
+ public BundleMessage fatal(final BundleKey message)
+ {
+ return factory.fatal(message);
+ }
+
+ public BundleMessage fatal(final BundleKey message, final Object... params)
+ {
+ return factory.fatal(message, params);
+ }
+
+ /*
+ * Template Factory Methods
+ */
+ public TemplateMessage info(final String message)
+ {
+ return factory.info(message);
+ }
+
+ public TemplateMessage info(final String message, final Object... params)
+ {
+ return factory.info(message, params);
+ }
+
+ public TemplateMessage warn(final String message)
+ {
+ return factory.warn(message);
+ }
+
+ public TemplateMessage warn(final String message, final Object... params)
+ {
+ return factory.warn(message, params);
+ }
+
+ public TemplateMessage error(final String message)
+ {
+ return factory.error(message);
+ }
+
+ public TemplateMessage error(final String message, final Object... params)
+ {
+ return factory.error(message, params);
+ }
+
+ public TemplateMessage fatal(final String message)
+ {
+ return factory.fatal(message);
+ }
+
+ public TemplateMessage fatal(final String message, final Object... params)
+ {
+ return factory.fatal(message, params);
+ }
+
+}
Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MutableMessage.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MutableMessage.java (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/MutableMessage.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+/**
+ * A stateful {@link Message} object.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface MutableMessage extends Message
+{
+ /**
+ * Set the {@link Level} representing the severity of this message.
+ */
+ void setLevel(Level level);
+
+ /**
+ * Set the message text.
+ */
+ void setText(String summary);
+
+ /**
+ * Set the targets for which a given view-layer or consumer should display
+ * this message, or to which this message should be attached.
+ */
+ void setTargets(String targets);
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleKey.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -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.status.builder;
+
+import java.io.Serializable;
+import java.util.ResourceBundle;
+
+/**
+ * Represents the name/key pair for a {@link ResourceBundle} lookup.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class BundleKey implements Serializable
+{
+ private static final long serialVersionUID = -4817189437146173796L;
+
+ private String bundle;
+ private String key;
+
+ public BundleKey(final String bundle, final String key)
+ {
+ super();
+ this.bundle = bundle;
+ this.key = key;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((bundle == null) ? 0 : bundle.hashCode());
+ result = prime * result + ((key == null) ? 0 : key.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;
+ }
+ BundleKey other = (BundleKey) obj;
+ if (bundle == null)
+ {
+ if (other.bundle != null)
+ {
+ return false;
+ }
+ }
+ else if (!bundle.equals(other.bundle))
+ {
+ return false;
+ }
+ if (key == null)
+ {
+ if (other.key != null)
+ {
+ return false;
+ }
+ }
+ else if (!key.equals(other.key))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * Getters & Setters
+ */
+ public String getBundle()
+ {
+ return bundle;
+ }
+
+ public void setBundle(final String bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public void setKey(final String key)
+ {
+ this.key = key;
+ }
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/BundleMessage.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,134 @@
+/*
+ * 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}("messageBundle", "keyName"), 5, "green")
+ * .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>
+ * "There are 5 cars, and they are all green."
+ * </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 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.level(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;
+ }
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,72 @@
+/*
+ * 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 java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Populates an interpolated string using the given template and parameters:
+ * <p>
+ * <b>For example:</b><br>
+ * Template:
+ * <code>"This is a {0} template with {1} parameters. Just {1}."</code><br>
+ * Parameters: <code>"simple", 2</code><br>
+ * Result: <code>"This is a simple template with 2 parameters. Just 2"</code>
+ *
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+class Interpolator
+{
+ private static final String templateRegex = "\\{(\\d+)\\}";
+ private static final Pattern templatePattern = Pattern.compile(templateRegex);
+
+ /**
+ * Populate a template with the corresponding parameters.
+ */
+ public String populate(final String template, final Object... params)
+ {
+ StringBuffer result = new StringBuffer();
+ if (template != null)
+ {
+ Matcher matcher = templatePattern.matcher(template);
+ while (matcher.find())
+ {
+ int index = Integer.valueOf(matcher.group(1));
+ Object value = matcher.group();
+
+ if (params.length > index)
+ {
+ if (params[index] != null)
+ {
+ value = params[index];
+ }
+ }
+ matcher.appendReplacement(result, value.toString());
+ }
+ matcher.appendTail(result);
+ }
+ return result.toString();
+ }
+}
Added: 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 (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/status/builder/TemplateMessage.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,113 @@
+/*
+ * 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.Level;
+import org.jboss.seam.international.status.Message;
+import org.jboss.seam.international.status.MessageBuilder;
+import org.jboss.seam.international.status.MutableMessage;
+
+/**
+ * This {@link MessageBuilder} implementation creates {@link Message} objects by
+ * interpolating templates with values supplied as parameters.
+ * <p>
+ * <b>For example:</b> Given the following {@link Message} m
+ *
+ * <pre>
+ * Message m = {@link MessageFactory}.info("There are {0} cars, and they are all {1}.", 5, "green").build();
+ * </pre>
+ *
+ * A subsequent call to <code>m.getSummary()</code> will return:<br/>
+ * <code>"There are 5 cars, and they are all green."</code>;
+ * <p>
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class TemplateMessage implements MessageBuilder
+{
+ private static final String MESSAGE_IMPL_CLASS = "org.jboss.seam.international.status.MessageImpl";
+
+ private final Interpolator templater = new Interpolator();
+
+ private String summary;
+ private Object[] summaryParams;
+
+ private String targets;
+ private Level level;
+
+ public TemplateMessage(final Level level)
+ {
+ this.level = level;
+ }
+
+ /**
+ * Produce a {@link Message} object as represented by the current state of
+ * <code>this</code> builder.
+ */
+ public Message build()
+ {
+ Class<?> type;
+ try
+ {
+ type = Class.forName(MESSAGE_IMPL_CLASS);
+ MutableMessage message = (MutableMessage) type.newInstance();
+
+ message.setLevel(level);
+ message.setText(templater.populate(summary, summaryParams));
+ message.setTargets(targets);
+
+ return message;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create message: " + MESSAGE_IMPL_CLASS, e);
+ }
+ }
+
+ /*
+ * Setters
+ */
+ public TemplateMessage text(final String summary)
+ {
+ this.summary = summary;
+ return this;
+ }
+
+ public TemplateMessage textParams(final Object... summaryParams)
+ {
+ this.summaryParams = summaryParams;
+ return this;
+ }
+
+ public TemplateMessage targets(final String targets)
+ {
+ this.targets = targets;
+ return this;
+ }
+
+ public TemplateMessage level(final Level level)
+ {
+ this.level = level;
+ return this;
+ }
+}
Added: modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/builder/TemplateMessageTest.java
===================================================================
--- modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/builder/TemplateMessageTest.java (rev 0)
+++ modules/international/trunk/api/src/test/java/org/jboss/seam/international/status/builder/TemplateMessageTest.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,87 @@
+/*
+ * 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 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.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 TemplateMessageTest
+{
+ @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());
+ }
+}
Added: 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 (rev 0)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/status/MessageImpl.java 2010-05-24 15:43:41 UTC (rev 12781)
@@ -0,0 +1,157 @@
+/*
+ * 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;
+
+/**
+ * A basic implementation of {@link MutableMessage}.
+ *
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class MessageImpl implements Message, MutableMessage
+{
+ private static final long serialVersionUID = -1812292372048679525L;
+
+ private String summary;
+ private String details;
+ private String targets;
+ private Level level;
+
+ @Override
+ public int hashCode()
+ {
+ 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());
+ 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;
+ }
+ MessageImpl other = (MessageImpl) obj;
+ if (details == null)
+ {
+ if (other.details != null)
+ {
+ return false;
+ }
+ }
+ else if (!details.equals(other.details))
+ {
+ return false;
+ }
+ if (targets == null)
+ {
+ if (other.targets != null)
+ {
+ return false;
+ }
+ }
+ else if (!targets.equals(other.targets))
+ {
+ return false;
+ }
+ 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;
+ }
+ return true;
+ }
+
+ /*
+ * Getters & Setters
+ */
+ public String getText()
+ {
+ return summary;
+ }
+
+ public String getDetails()
+ {
+ return details;
+ }
+
+ public String getTargets()
+ {
+ return targets;
+ }
+
+ public Level getLevel()
+ {
+ return level;
+ }
+
+ public void setText(final String summary)
+ {
+ this.summary = summary;
+ }
+
+ public void setDetails(final String details)
+ {
+ this.details = details;
+ }
+
+ public void setTargets(final String targets)
+ {
+ this.targets = targets;
+ }
+
+ public void setLevel(final Level level)
+ {
+ this.level = level;
+ }
+
+}
Modified: modules/international/trunk/pom.xml
===================================================================
--- modules/international/trunk/pom.xml 2010-05-24 09:25:47 UTC (rev 12780)
+++ modules/international/trunk/pom.xml 2010-05-24 15:43:41 UTC (rev 12781)
@@ -28,7 +28,7 @@
<properties>
<arquillian.version>1.0.0-SNAPSHOT</arquillian.version>
<seam.xml.version>3.0.0-SNAPSHOT</seam.xml.version>
- <weld.extensions.version>1.0.0.Alpha1</weld.extensions.version>
+ <weld.extensions.version>1.0.0.Alpha2</weld.extensions.version>
<weld.api.version>1.0-SP1</weld.api.version>
<junit.version>4.8.1</junit.version>
<slf4j.version>1.5.10</slf4j.version>
More information about the seam-commits
mailing list