01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.content;
19:
20: import java.io.IOException;
21: import java.util.Date;
22:
23: import de.finix.contelligent.CallData;
24: import de.finix.contelligent.Component;
25: import de.finix.contelligent.core.TimeService;
26: import de.finix.contelligent.exception.ComponentPersistenceException;
27: import de.finix.contelligent.logging.LoggingService;
28: import de.finix.contelligent.resource.NumberResource;
29:
30: public class ContelligentDateContent extends ContelligentContent
31: implements DateContent {
32: final static org.apache.log4j.Logger log = LoggingService
33: .getLogger(ContelligentDateContent.class);
34:
35: public ContelligentDateContent(Component component)
36: throws Exception {
37: super (component);
38: }
39:
40: public Object getContentValue(CallData callData)
41: throws IOException, ComponentPersistenceException {
42: return getDate(callData);
43: }
44:
45: public long lastModified(CallData callData) throws IOException {
46: return getNumberResource(callData).getLastModified();
47: }
48:
49: public Date getDate(CallData callData) throws IOException {
50: return new Date(getNumberResource(callData).getNumber()
51: .longValue());
52: }
53:
54: public void setDate(Date date, CallData callData)
55: throws ComponentPersistenceException {
56: if (date != null) {
57: setTime(date.getTime(), callData);
58: }
59: }
60:
61: public void setTime(long time, CallData callData)
62: throws ComponentPersistenceException {
63: NumberResource resource = new NumberResource(new Long(time),
64: TimeService.getInstance().currentTimeMillis());
65: setResource(resource, callData);
66: }
67:
68: public long getTime(CallData callData) throws IOException {
69: return getNumberResource(callData).getNumber().longValue();
70: }
71:
72: private NumberResource getNumberResource(CallData callData)
73: throws IOException {
74: NumberResource resource = (NumberResource) getResourceMap()
75: .get(getResourceIdentifier(callData));
76: if (resource == null) {
77: throw new IOException("Number resource not set!");
78: }
79: return resource;
80: }
81: }
|