001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.value;
034:
035: import com.flexive.shared.exceptions.FxInvalidStateException;
036:
037: import java.io.Serializable;
038: import java.util.Date;
039: import java.util.Map;
040:
041: /**
042: * A multilingual DateTime range, internally represented as java.util.Date; EMPTY is a Date range with a timestamp of <code>0</code> (usually 01/01/1970)
043: *
044: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
045: */
046: public class FxDateTimeRange extends
047: FxValue<DateRange, FxDateTimeRange> implements Serializable {
048: private static final long serialVersionUID = -6939627748513819758L;
049:
050: public final static DateRange EMPTY = new DateRange(new Date(0),
051: new Date(0));
052:
053: /**
054: * Constructor
055: *
056: * @param multiLanguage multilanguage value?
057: * @param defaultLanguage the default language
058: * @param translations HashMap containing language->translation mapping
059: */
060: public FxDateTimeRange(boolean multiLanguage, long defaultLanguage,
061: Map<Long, DateRange> translations) {
062: super (multiLanguage, defaultLanguage, translations);
063: }
064:
065: /**
066: * Constructor
067: *
068: * @param defaultLanguage the default language
069: * @param translations HashMap containing language->translation mapping
070: */
071: public FxDateTimeRange(long defaultLanguage,
072: Map<Long, DateRange> translations) {
073: super (defaultLanguage, translations);
074: }
075:
076: /**
077: * Constructor
078: *
079: * @param multiLanguage multilanguage value?
080: * @param translations HashMap containing language->translation mapping
081: */
082: public FxDateTimeRange(boolean multiLanguage,
083: Map<Long, DateRange> translations) {
084: super (multiLanguage, translations);
085: }
086:
087: /**
088: * Constructor
089: *
090: * @param translations HashMap containing language->translation mapping
091: */
092: public FxDateTimeRange(Map<Long, DateRange> translations) {
093: super (translations);
094: }
095:
096: /**
097: * Constructor - create value from an array of translations
098: *
099: * @param translations HashMap containing language->translation mapping
100: * @param pos position (index) in the array to use
101: */
102: public FxDateTimeRange(Map<Long, DateRange[]> translations, int pos) {
103: super (translations, pos);
104: }
105:
106: /**
107: * Constructor
108: *
109: * @param multiLanguage multilanguage value?
110: * @param defaultLanguage the default language
111: * @param value single initializing value
112: */
113: public FxDateTimeRange(boolean multiLanguage, long defaultLanguage,
114: DateRange value) {
115: super (multiLanguage, defaultLanguage, value);
116: }
117:
118: /**
119: * Constructor
120: *
121: * @param defaultLanguage the default language
122: * @param value single initializing value
123: */
124: public FxDateTimeRange(long defaultLanguage, DateRange value) {
125: super (defaultLanguage, value);
126: }
127:
128: /**
129: * Constructor
130: *
131: * @param multiLanguage multilanguage value?
132: * @param value single initializing value
133: */
134: public FxDateTimeRange(boolean multiLanguage, DateRange value) {
135: super (multiLanguage, value);
136: }
137:
138: /**
139: * Constructor
140: *
141: * @param value single initializing value
142: */
143: public FxDateTimeRange(DateRange value) {
144: super (value);
145: }
146:
147: /**
148: * Constructor
149: *
150: * @param clone original FxValue to be cloned
151: */
152: public FxDateTimeRange(FxValue<DateRange, FxDateTimeRange> clone) {
153: super (clone);
154: }
155:
156: /**
157: * Return true if T is immutable (e.g. java.lang.String). This prevents cloning
158: * of the translations in copy constructors.
159: *
160: * @return true if T is immutable (e.g. java.lang.String)
161: */
162: @Override
163: public boolean isImmutableValueType() {
164: return true;
165: }
166:
167: /**
168: * Evaluates the given string value to an object of type T.
169: *
170: * @param value string value to be evaluated
171: * @return the value interpreted as T
172: */
173: @Override
174: public DateRange fromString(String value) {
175: return null; //TODO!!!
176: }
177:
178: /**
179: * Creates a copy of the given object (useful if the actual type is unknown).
180: *
181: * @return a copy of the given object (useful if the actual type is unknown).
182: */
183: @Override
184: public FxDateTimeRange copy() {
185: return new FxDateTimeRange(this );
186: }
187:
188: /**
189: * {@inheritDoc}
190: */
191: @Override
192: public Class<DateRange> getValueClass() {
193: return DateRange.class;
194: }
195:
196: /**
197: * {@inheritDoc}
198: */
199: @Override
200: public String getSqlValue() {
201: throw new FxInvalidStateException(
202: "ex.content.value.sql.notSupported", getClass()
203: .getSimpleName()).asRuntimeException();
204: }
205:
206: @Override
207: public int compareTo(FxValue o) {
208: if (o instanceof FxDateRange && !isEmpty() && !o.isEmpty()) {
209: return getBestTranslation().getLower().compareTo(
210: ((FxDateRange) o).getBestTranslation().getLower());
211: } else if (o instanceof FxDateTimeRange && !isEmpty()
212: && !o.isEmpty()) {
213: return getBestTranslation().getLower().compareTo(
214: ((FxDateTimeRange) o).getBestTranslation()
215: .getLower());
216: } else if (o instanceof FxDate && !isEmpty() && !o.isEmpty()) {
217: return getBestTranslation().getLower().compareTo(
218: ((FxDate) o).getBestTranslation());
219: } else if (o instanceof FxDateTime && !isEmpty()
220: && !o.isEmpty()) {
221: return getBestTranslation().getLower().compareTo(
222: ((FxDateTime) o).getBestTranslation());
223: }
224: return super.compareTo(o);
225: }
226: }
|