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 java.util.List;
11:
12: import com.sun.portal.desktop.context.DPContext;
13:
14: import com.sun.portal.desktop.dp.DPAvailable;
15: import com.sun.portal.desktop.dp.DPProperty;
16: import com.sun.portal.desktop.dp.DPTypes;
17: import com.sun.portal.desktop.dp.DPRoot;
18: import com.sun.portal.desktop.dp.DPError;
19:
20: class XMLDPAvailable extends XMLDPReferenceList implements DPAvailable,
21: DPTypes, XMLDPTags {
22:
23: XMLDPAvailable(DPContext dpc, DPRoot r, Element e) {
24: super (dpc, r, e);
25: }
26:
27: XMLDPAvailable(DPContext dpc, DPRoot r, Document d) {
28: this (dpc, r, createElement(dpc, d));
29: }
30:
31: XMLDPAvailable(DPContext dpc, DPRoot r, Document d, List avail) {
32: this (dpc, r, createElement(dpc, d, avail));
33: }
34:
35: public void checkType() {
36: if (!getElement().getTagName().equals(getTag())) {
37: throw new DPError(
38: "XMLDPAvailable.checkType(): wrong type tagName="
39: + getElement().getTagName());
40: }
41: }
42:
43: public String getTag() {
44: return AVAILABLE_TAG;
45: }
46:
47: public short getType() {
48: return AVAILABLE_DP;
49: }
50:
51: public DPProperty copy(DPRoot dpr, boolean deep) {
52: Element elementCopy = copyElement(dpr, deep);
53: return XMLDPFactory.getInstance().getAvailable(getContext(),
54: dpr, elementCopy);
55: }
56:
57: protected Element getMergedElement() {
58: List avail = (List) getCollectionValue().values();
59: Element e = createElement(getContext(), getDocument());
60: for (int i = 0; i < avail.size(); i++) {
61: String ref = (String) avail.get(i);
62: e.appendChild(XMLDPReference.createElement(getContext(),
63: getDocument(), ref));
64: }
65:
66: return e;
67: }
68:
69: public static Element createElement(DPContext dpc, Document d) {
70: Element e = createElement(dpc, d, AVAILABLE_TAG);
71: setDefaultsElement(e);
72:
73: return e;
74: }
75:
76: public static Element createElement(DPContext dpc, DPRoot r,
77: Document d, List avail) {
78: Element e = createElement(dpc, r, d, AVAILABLE_TAG, null, avail);
79: setDefaultsElement(e);
80:
81: return e;
82: }
83:
84: public void toXML(StringBuffer b, int indent) {
85:
86: indentBuffer(b, indent);
87: appendStartTag(b);
88: appendMergeAttr(b);
89: appendLockAttr(b);
90: appendAdvancedAttr(b);
91: b.append(">\n");
92:
93: appendReferenceList(b, indent);
94:
95: indentBuffer(b, indent);
96: appendEndTag(b);
97: }
98:
99: }
|