1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans.
5 *
6 * CosyBeans is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.displayers;
21
22 import java.io.Serializable;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25
26
27 /**
28 * <code>DataState</code> describes quality of dinamic value.
29 *
30 * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
31 * @version $Id: DataState.java,v 1.8 2008-04-22 12:31:02 jbobnar Exp $
32 *
33 * @since Nov 24, 2003.
34 */
35 public class DataState implements Serializable
36 {
37 private static final long serialVersionUID = -7654199155702253489L;
38
39 private static SimpleDateFormat dateTimeFormatter = new SimpleDateFormat(
40 "yyyy-MM-dd HH:mm:ss.SSS");
41
42 /**
43 * Type identifying this data quality state. This DataState objec defines
44 * several usefull states, but there is not limitation to define new
45 * identifiers in contract data source and consumer implementation.
46 */
47 public String type = UNDEFINED;
48
49 /** Timestamp of data quality */
50 public long timestamp = System.currentTimeMillis();
51
52 /** Detailed description of this data quality representativ. */
53 public String description = null;
54
55 /** State when dynamic value source receives data with timelag. */
56 public static final String TIMELAG = "Timelag";
57
58 /** State when dynamic value data is in timeout. */
59 public static final String TIMEOUT = "Timeout";
60
61 /** State when warning condition was rased for the dynamic value. */
62 public static final String WARNING = "Warning";
63
64 /** State when alarm condition was rased for the dynamic value. */
65 public static final String ALARM = "Alarm";
66
67 /** State when error condition was rased for the dynamic value. */
68 public static final String ERROR = "Error";
69
70 /** State for normal conditions. */
71 public static final String NORMAL = "Normal";
72
73 /** State for not initialized source of dynamic data. */
74 public static final String NOT_INITIALIZED = "Not Initialized";
75
76 /** State for connected source of dynamic data. */
77 public static final String CONNECTED = "Connected";
78
79 /** State for disconnected source of dynamic data. */
80 public static final String DISCONNECTED = "Disconnected";
81
82 /** State when data quality can not be determined. */
83 public static final String UNDEFINED = "Undefined";
84
85 /** State when dynamic data source ahs been suspended. */
86 public static final String SUSPENDED = "Suspended";
87
88 /**
89 * Creates a new DataState object.
90 *
91 * @param type the string identifier for type.
92 * @param timestamp the time of data qyality change
93 * @param description detailed description of this data quality state
94 */
95 public DataState(String type, long timestamp, String description)
96 {
97 this.type = type;
98 this.timestamp = timestamp;
99 this.description = description;
100 }
101
102 /**
103 * Creates a new DataState object. The timestamp is set to time of object
104 * creation.
105 *
106 * @param type the string identifier for type.
107 * @param description detailed description of this data quality state
108 */
109 public DataState(String type, String description)
110 {
111 this(type, System.currentTimeMillis(), description);
112 }
113
114 /**
115 * Creates a new DateState object. The timestamp is set to time of object
116 * creation.
117 *
118 * @param type the string identifier for type.
119 */
120 public DataState(String type)
121 {
122 this(type, System.currentTimeMillis(), null);
123 }
124
125 /**
126 * Returns the type identifyer of this data quality state.
127 *
128 * @return the type identifyer of this data quality state
129 */
130 public String toString()
131 {
132 StringBuffer sb = new StringBuffer();
133 sb.append(type);
134 sb.append(" = { ");
135 sb.append(dateTimeFormatter.format(new Date(timestamp)));
136
137 if (description != null) {
138 sb.append(" \"");
139 sb.append(description);
140 sb.append("\"");
141 }
142
143 sb.append(" }");
144
145 return sb.toString();
146 }
147
148 /**
149 * Returns the type of this DataState.
150 *
151 * @return
152 */
153 public String getType() {
154 return type;
155 }
156 }
157
158 /* __oOo__ */