1 /* 2 * Copyright 2009 :torweg free software group 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 package org.torweg.pulse.component.statistics.view; 19 20 import java.io.Serializable; 21 22 import javax.xml.bind.annotation.XmlAccessOrder; 23 import javax.xml.bind.annotation.XmlAccessType; 24 import javax.xml.bind.annotation.XmlAccessorOrder; 25 import javax.xml.bind.annotation.XmlAccessorType; 26 import javax.xml.bind.annotation.XmlAttribute; 27 import javax.xml.bind.annotation.XmlElement; 28 import javax.xml.bind.annotation.XmlRootElement; 29 30 import org.torweg.pulse.result.StringMapResult; 31 32 /** 33 * A basic JAXB-enabled class representing a basic result as being generated by 34 * an {@code AbstractStatisticsViewController}, which is to be used for 35 * extending. 36 * 37 * @param <T> 38 * the type of {@code AbstractStatisticsViewControllerResultData} of 39 * the {@code AbstractStatisticsViewControllerResult} 40 * 41 * @author Daniel Dietz 42 * @version $Revision: 2013 $ 43 */ 44 @XmlRootElement(name = "abstract-statistics-view-result") 45 @XmlAccessorOrder(XmlAccessOrder.UNDEFINED) 46 @XmlAccessorType(XmlAccessType.FIELD) 47 public abstract class AbstractStatisticsViewControllerResult<T extends AbstractStatisticsViewControllerResultData> 48 extends StringMapResult implements Serializable { 49 50 /** 51 * The serialVersionUID. 52 */ 53 private static final long serialVersionUID = -4283300379830505240L; 54 55 /** 56 * The {@code AbstractStatisticsViewControllerConfiguration} of the 57 * {@code AbstractStatisticsViewController} the produced the result. 58 */ 59 @XmlElement(name = "configuration") 60 private AbstractStatisticsViewControllerConfiguration configuration; 61 62 /** 63 * The {@code AbstractStatisticsViewControllerResultData} of the 64 * {@code AbstractStatisticsViewControllerResult}. 65 */ 66 @XmlElement(name = "data") 67 private T data; 68 69 /** 70 * The f.q. class name for identifying the result during XSL processing. 71 */ 72 @SuppressWarnings("unused") 73 @XmlAttribute(name = "class") 74 private final String className = getClass().getCanonicalName(); 75 76 /** 77 * If set, holds the {@code ResultError} for the 78 * {@code GroupAnalysisViewControllerResult}. 79 */ 80 @XmlElement(name = "error") 81 private ResultError error; 82 83 /** 84 * Sets the {@code AbstractStatisticsViewControllerConfiguration} for the 85 * {@code AbstractStatisticsViewControllerResult}. 86 * 87 * @param conf 88 * the {@code AbstractStatisticsViewControllerConfiguration} 89 */ 90 protected final void setConfiguration( 91 final AbstractStatisticsViewControllerConfiguration conf) { 92 this.configuration = conf; 93 } 94 95 /** 96 * Returns the {@code AbstractStatisticsViewControllerConfiguration} of the 97 * {@code AbstractStatisticsViewControllerResult}. 98 * 99 * @return the {@code AbstractStatisticsViewControllerConfiguration} 100 */ 101 public final AbstractStatisticsViewControllerConfiguration getConfiguration() { 102 return this.configuration; 103 } 104 105 /** 106 * Sets the {@code AbstractStatisticsViewControllerResultData} for the 107 * {@code AbstractStatisticsViewControllerResult}. 108 * 109 * @param resultData 110 * the {@code AbstractStatisticsViewControllerResultData} 111 */ 112 protected final void setResultData(final T resultData) { 113 this.data = resultData; 114 } 115 116 /** 117 * Returns the {@code AbstractStatisticsViewControllerResultData} of the 118 * {@code AbstractStatisticsViewControllerResult}. 119 * 120 * @return the {@code AbstractStatisticsViewControllerResultData} 121 */ 122 public final T getResultData() { 123 return this.data; 124 } 125 126 /** 127 * Returns the {@code ResultError}. 128 * 129 * @return the error 130 */ 131 public final ResultError getError() { 132 return this.error; 133 } 134 135 /** 136 * Sets the given {@code ResultError}. 137 * 138 * @param resultError 139 * the error to set 140 */ 141 protected final void setError(final ResultError resultError) { 142 this.error = resultError; 143 } 144 145 /** 146 * Maps an error type string to an error message string. 147 * 148 * @author Daniel Dietz 149 * @version $Revision: 2013 $ 150 */ 151 @XmlRootElement(name = "error") 152 @XmlAccessorOrder(XmlAccessOrder.UNDEFINED) 153 @XmlAccessorType(XmlAccessType.FIELD) 154 protected static final class ResultError implements Serializable { 155 156 /** 157 * The serialVersionUID. 158 */ 159 private static final long serialVersionUID = -9142197306123143973L; 160 161 /** 162 * The type of the {@code ResultError}. 163 */ 164 @XmlAttribute(name = "type") 165 private String type; 166 167 /** 168 * The message of the {@code ResultError}. 169 */ 170 @XmlElement(name = "message") 171 private String message; 172 173 /** 174 * Default constructor. 175 */ 176 @Deprecated 177 protected ResultError() { 178 super(); 179 } 180 181 /** 182 * Creates a new {@code ResultError} with the given type and the given 183 * message. 184 * 185 * @param errorType 186 * the type of the error 187 * @param errorMessage 188 * the message 189 */ 190 protected ResultError(final String errorType, final String errorMessage) { 191 super(); 192 setType(errorType); 193 setMessage(errorMessage); 194 } 195 196 /** 197 * Returns the type of the {@code ResultError}. 198 * 199 * @return the type 200 */ 201 public String getType() { 202 return this.type; 203 } 204 205 /** 206 * Sets the type for the {@code ResultError}. 207 * 208 * @param errorType 209 * the type to set 210 */ 211 private void setType(final String errorType) { 212 this.type = errorType; 213 } 214 215 /** 216 * Returns the message of the {@code ResultError}. 217 * 218 * @return the message 219 */ 220 public String getMessage() { 221 return this.message; 222 } 223 224 /** 225 * Sets the message for the {@code ResultError}. 226 * 227 * @param errorMessage 228 * the message to set 229 */ 230 private void setMessage(final String errorMessage) { 231 this.message = errorMessage; 232 } 233 234 } 235 236 } 237