001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.dp.xml;
006:
007: import org.w3c.dom.Element;
008: import org.w3c.dom.Document;
009:
010: import java.util.List;
011:
012: import com.sun.portal.desktop.context.DPContext;
013: import com.sun.portal.desktop.dp.DPError;
014: import com.sun.portal.desktop.dp.DPSelected;
015: import com.sun.portal.desktop.dp.DPProperty;
016: import com.sun.portal.desktop.dp.DPRoot;
017:
018: class XMLDPSelected extends XMLDPReferenceList implements DPSelected,
019: XMLDPTags {
020:
021: XMLDPSelected(DPContext dpc, DPRoot r, Element e) {
022: super (dpc, r, e);
023: }
024:
025: XMLDPSelected(DPContext dpc, DPRoot r, Document d) {
026: this (dpc, r, createElement(dpc, d));
027: }
028:
029: XMLDPSelected(DPContext dpc, DPRoot r, Document d, List sel) {
030: this (dpc, r, createElement(dpc, d, sel));
031: }
032:
033: public void checkType() {
034: if (!getElement().getTagName().equals(getTag())) {
035: throw new DPError(
036: "XMLDPSelected.checkType(): wrong type tagName="
037: + getElement().getTagName());
038: }
039: }
040:
041: public String getTag() {
042: return SELECTED_TAG;
043: }
044:
045: public short getType() {
046: return SELECTED_DP;
047: }
048:
049: public DPProperty copy(DPRoot dpr, boolean deep) {
050: Element elementCopy = copyElement(dpr, deep);
051: return XMLDPFactory.getInstance().getSelected(getContext(),
052: dpr, elementCopy);
053: }
054:
055: protected Element getMergedElement() {
056: List sel = (List) getCollectionValue().values();
057: Element e = createElement(getContext(), getDocument());
058: for (int i = 0; i < sel.size(); i++) {
059: String ref = (String) sel.get(i);
060: e.appendChild(XMLDPReference.createElement(getContext(),
061: getDocument(), ref));
062: }
063:
064: return e;
065: }
066:
067: public static Element createElement(DPContext dpc, Document d) {
068: Element e = createElement(dpc, d, SELECTED_TAG);
069: setDefaultsElement(e);
070:
071: return e;
072: }
073:
074: public static Element createElement(DPContext dpc, DPRoot r,
075: Document d, List sel) {
076: Element e = createElement(dpc, r, d, SELECTED_TAG, null, sel);
077: setDefaultsElement(e);
078:
079: return e;
080: }
081:
082: public void toXML(StringBuffer b, int indent) {
083:
084: indentBuffer(b, indent);
085:
086: b.append("<").append(XMLDPTags.SELECTED_TAG);
087:
088: appendMergeAttr(b);
089: appendLockAttr(b);
090: appendAdvancedAttr(b);
091:
092: b.append(">\n");
093:
094: appendReferenceList(b, indent);
095:
096: indentBuffer(b, indent);
097:
098: b.append("</").append(SELECTED_TAG).append(">\n");
099: }
100: }
|