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.DPException;
13: import com.sun.portal.desktop.dp.DPRoot;
14: import com.sun.portal.desktop.dp.DPInteger;
15:
16: class XMLDPInteger extends XMLDPAtomic implements DPInteger, XMLDPTags {
17:
18: XMLDPInteger(DPContext dpc, DPRoot r, Document d, String name,
19: Integer value) {
20: this (dpc, r, createElement(dpc, d, name, value));
21: }
22:
23: XMLDPInteger(DPContext dpc, DPRoot r, Document d, Integer value) {
24: this (dpc, r, createElement(dpc, d, null, value));
25: }
26:
27: XMLDPInteger(DPContext dpc, DPRoot r, Document d, String name,
28: int value) {
29: this (dpc, r, createElement(dpc, d, name, value));
30: }
31:
32: XMLDPInteger(DPContext dpc, DPRoot r, Document d, int value) {
33: this (dpc, r, createElement(dpc, d, null, value));
34: }
35:
36: XMLDPInteger(DPContext dpc, DPRoot r, Element e) {
37: super (dpc, r, e);
38: }
39:
40: public short getType() {
41: return INTEGER_DP;
42: }
43:
44: public String getTag() {
45: return INTEGER_TAG;
46: }
47:
48: public Object getValue() {
49: //
50: // this ensures that the string value converts to an integer properly
51: //
52: return new Integer((String) super .getValue());
53: }
54:
55: public int getIntValue() {
56: String v = (String) super .getValue();
57: return Integer.parseInt(v);
58: }
59:
60: public Object setValue(Object val) {
61: Object old = getValue();
62: String s = val.toString();
63:
64: //
65: // make sure it's an integer
66: //
67: int i = Integer.parseInt(s);
68:
69: super .setValue(s);
70:
71: return old;
72: }
73:
74: public void setIntValue(int v) {
75: super .setValue(Integer.toString(v));
76: }
77:
78: static Element createElement(DPContext dpc, Document d, String n,
79: Integer v) {
80: return createElement(dpc, d, INTEGER_TAG, n, v.toString());
81: }
82:
83: static Element createElement(DPContext dpc, Document d, String n,
84: int v) {
85: return createElement(dpc, d, INTEGER_TAG, n, Integer
86: .toString(v));
87: }
88: }
|