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:
22: import de.finix.contelligent.CallData;
23: import de.finix.contelligent.Component;
24: import de.finix.contelligent.core.TimeService;
25: import de.finix.contelligent.exception.ComponentPersistenceException;
26: import de.finix.contelligent.logging.LoggingService;
27: import de.finix.contelligent.resource.StringResource;
28:
29: public class ContelligentBooleanContent extends ContelligentContent
30: implements BooleanContent {
31: final static org.apache.log4j.Logger log = LoggingService
32: .getLogger(ContelligentBooleanContent.class);
33:
34: public ContelligentBooleanContent(Component component)
35: throws Exception {
36: super (component);
37: }
38:
39: public Object getContentValue(CallData callData)
40: throws IOException, ComponentPersistenceException {
41: return getBoolean(callData);
42: }
43:
44: public long lastModified(CallData callData) throws IOException {
45: return getStringResource(callData).getLastModified();
46: }
47:
48: public Boolean getBoolean(CallData callData) throws IOException {
49: StringResource resource = getStringResource(callData);
50: if (resource != null) {
51: return Boolean.valueOf(resource.getString());
52: } else {
53: return Boolean.FALSE;
54: }
55: }
56:
57: public boolean getBooleanValue(CallData callData)
58: throws IOException {
59: StringResource resource = getStringResource(callData);
60: if (resource != null) {
61: return Boolean.valueOf(
62: getStringResource(callData).getString())
63: .booleanValue();
64: }
65: log.debug("getBooleanValue(): Resource not set!");
66: return false;
67: }
68:
69: public void setBoolean(Boolean value, CallData callData)
70: throws ComponentPersistenceException {
71: setBooleanValue(value.booleanValue(), callData);
72: }
73:
74: public void setBooleanValue(boolean value, CallData callData)
75: throws ComponentPersistenceException {
76: StringResource resource = new StringResource(String
77: .valueOf(value), TimeService.getInstance()
78: .currentTimeMillis());
79: setResource(resource, callData);
80: }
81:
82: private StringResource getStringResource(CallData callData) {
83: return (StringResource) getResourceMap().get(
84: getResourceIdentifier(callData));
85: }
86: }
|