summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/CompositeErrorMessage.java
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2012-03-14 12:32:21 +0200
committerArtur Signell <artur@vaadin.com>2012-03-21 17:42:34 +0200
commite905f033ff2b2aa094b51eae72fef63e68bd1800 (patch)
tree4d81f4d1e1bd5a7c0b1a356905f328ec5059c5c2 /src/com/vaadin/terminal/CompositeErrorMessage.java
parentead998ecf701bb270ac810ab76af48484d9b1296 (diff)
downloadvaadin-framework-e905f033ff2b2aa094b51eae72fef63e68bd1800.tar.gz
vaadin-framework-e905f033ff2b2aa094b51eae72fef63e68bd1800.zip
Refactor error messages on server side (#8437).
This is an intermediate step towards moving error messages from UIDL to shared state.
Diffstat (limited to 'src/com/vaadin/terminal/CompositeErrorMessage.java')
-rw-r--r--src/com/vaadin/terminal/CompositeErrorMessage.java108
1 files changed, 14 insertions, 94 deletions
diff --git a/src/com/vaadin/terminal/CompositeErrorMessage.java b/src/com/vaadin/terminal/CompositeErrorMessage.java
index efe29196d8..b82b622f54 100644
--- a/src/com/vaadin/terminal/CompositeErrorMessage.java
+++ b/src/com/vaadin/terminal/CompositeErrorMessage.java
@@ -4,15 +4,8 @@
package com.vaadin.terminal;
-import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
-
-import com.vaadin.terminal.gwt.client.communication.SharedState;
-import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
/**
* Class for combining multiple error messages together.
@@ -23,17 +16,7 @@ import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
* @since 3.0
*/
@SuppressWarnings("serial")
-public class CompositeErrorMessage implements ErrorMessage, Serializable {
-
- /**
- * Array of all the errors.
- */
- private final List<ErrorMessage> errors;
-
- /**
- * Level of the error.
- */
- private ErrorLevel level;
+public class CompositeErrorMessage extends AbstractErrorMessage {
/**
* Constructor for CompositeErrorMessage.
@@ -43,14 +26,14 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
* ignored, but at least one message is required.
*/
public CompositeErrorMessage(ErrorMessage[] errorMessages) {
- errors = new ArrayList<ErrorMessage>(errorMessages.length);
- level = ErrorLevel.INFORMATION;
+ super(null);
+ setErrorLevel(ErrorLevel.INFORMATION);
for (int i = 0; i < errorMessages.length; i++) {
addErrorMessage(errorMessages[i]);
}
- if (errors.size() == 0) {
+ if (getCauses().size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
@@ -66,30 +49,21 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
*/
public CompositeErrorMessage(
Collection<? extends ErrorMessage> errorMessages) {
- errors = new ArrayList<ErrorMessage>(errorMessages.size());
- level = ErrorLevel.INFORMATION;
+ super(null);
+ setErrorLevel(ErrorLevel.INFORMATION);
for (final Iterator<? extends ErrorMessage> i = errorMessages
.iterator(); i.hasNext();) {
addErrorMessage(i.next());
}
- if (errors.size() == 0) {
+ if (getCauses().size() == 0) {
throw new IllegalArgumentException(
"Composite error message must have at least one error");
}
}
/**
- * The error level is the largest error level in
- *
- * @see com.vaadin.terminal.ErrorMessage#getErrorLevel()
- */
- public final ErrorLevel getErrorLevel() {
- return level;
- }
-
- /**
* Adds a error message into this composite message. Updates the level
* field.
*
@@ -97,10 +71,10 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
* the error message to be added. Duplicate errors are ignored.
*/
private void addErrorMessage(ErrorMessage error) {
- if (error != null && !errors.contains(error)) {
- errors.add(error);
- if (error.getErrorLevel().intValue() > level.intValue()) {
- level = error.getErrorLevel();
+ if (error != null && !getCauses().contains(error)) {
+ addCause(error);
+ if (error.getErrorLevel().intValue() > getErrorLevel().intValue()) {
+ setErrorLevel(error.getErrorLevel());
}
}
}
@@ -111,53 +85,7 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
* @return the error iterator.
*/
public Iterator<ErrorMessage> iterator() {
- return errors.iterator();
- }
-
- /**
- * @see com.vaadin.terminal.Paintable#paint(com.vaadin.terminal.PaintTarget)
- */
- public void paint(PaintTarget target) throws PaintException {
-
- if (errors.size() == 1) {
- (errors.iterator().next()).paint(target);
- } else {
- target.startTag("error");
- target.addAttribute("level", level.getText());
-
- // Paint all the exceptions
- for (final Iterator<ErrorMessage> i = errors.iterator(); i
- .hasNext();) {
- i.next().paint(target);
- }
-
- target.endTag("error");
- }
- }
-
- public SharedState getState() {
- // TODO implement: move relevant parts from paint() to getState()
- return null;
- }
-
- public List<ClientMethodInvocation> retrievePendingRpcCalls() {
- return Collections.emptyList();
- }
-
- /* Documented in super interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void requestRepaint() {
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
+ return getCauses().iterator();
}
/**
@@ -169,7 +97,8 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
public String toString() {
String retval = "[";
int pos = 0;
- for (final Iterator<ErrorMessage> i = errors.iterator(); i.hasNext();) {
+ for (final Iterator<ErrorMessage> i = getCauses().iterator(); i
+ .hasNext();) {
if (pos > 0) {
retval += ",";
}
@@ -180,13 +109,4 @@ public class CompositeErrorMessage implements ErrorMessage, Serializable {
return retval;
}
-
- public String getDebugId() {
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
- }
}