01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.desktop.dp.xml;
06:
07: import org.w3c.dom.Element;
08: import org.w3c.dom.Document;
09:
10: import com.sun.portal.desktop.context.DPContext;
11:
12: import com.sun.portal.desktop.dp.DPBoolean;
13: import com.sun.portal.desktop.dp.DPTypes;
14: import com.sun.portal.desktop.dp.DPRoot;
15:
16: class XMLDPBoolean extends XMLDPAtomic implements DPBoolean, DPTypes,
17: XMLDPTags {
18:
19: XMLDPBoolean(DPContext dpc, DPRoot r, Document d, String name,
20: boolean value) {
21: this (dpc, r, createElement(dpc, d, name, value));
22: }
23:
24: XMLDPBoolean(DPContext dpc, DPRoot r, Document d, boolean value) {
25: this (dpc, r, createElement(dpc, d, null, value));
26: }
27:
28: XMLDPBoolean(DPContext dpc, DPRoot r, Document d, String name,
29: Boolean value) {
30: this (dpc, r, createElement(dpc, d, name, value));
31: }
32:
33: XMLDPBoolean(DPContext dpc, DPRoot r, Document d, Boolean value) {
34: this (dpc, r, createElement(dpc, d, null, value));
35: }
36:
37: XMLDPBoolean(DPContext dpc, DPRoot r, Element e) {
38: super (dpc, r, e);
39: }
40:
41: public Object getValue() {
42: String val = (String) super .getValue();
43: if (toBoolean(val)) {
44: return Boolean.TRUE;
45: } else {
46: return Boolean.FALSE;
47: }
48: }
49:
50: public boolean getBooleanValue() {
51: return toBoolean((String) super .getValue());
52: }
53:
54: public Object setValue(Object val) {
55: Object old = getValue();
56: //
57: // make sure we only set "true" or "false" into a boolean property.
58: //
59: Boolean b = Boolean.valueOf(val.toString());
60: super .setValue(b);
61:
62: return old;
63: }
64:
65: public void setBooleanValue(boolean v) {
66: if (v) {
67: setValue(Boolean.TRUE.toString());
68: } else {
69: setValue(Boolean.FALSE.toString());
70: }
71: }
72:
73: public short getType() {
74: return BOOLEAN_DP;
75: }
76:
77: public String getTag() {
78: return BOOLEAN_TAG;
79: }
80:
81: static Element createElement(DPContext dpc, Document d, String n,
82: Boolean v) {
83: return createElement(dpc, d, BOOLEAN_TAG, n, v.toString());
84: }
85:
86: static Element createElement(DPContext dpc, Document d, String n,
87: boolean v) {
88: return createElement(dpc, d, BOOLEAN_TAG, n, new Boolean(v)
89: .toString());
90: }
91: }
|