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 javax.xml.parsers.*;
008: import org.xml.sax.*;
009: import org.xml.sax.helpers.*;
010: import org.w3c.dom.*;
011:
012: import java.util.Map;
013: import java.util.HashMap;
014: import java.util.Iterator;
015: import java.util.List;
016: import java.util.ArrayList;
017:
018: import com.sun.portal.desktop.context.DPContext;
019:
020: import com.sun.portal.desktop.dp.DPError;
021: import com.sun.portal.desktop.dp.DPReferenceList;
022: import com.sun.portal.desktop.dp.DPContainerChannel;
023: import com.sun.portal.desktop.dp.DPTypes;
024: import com.sun.portal.desktop.dp.DPRoot;
025: import com.sun.portal.desktop.dp.DPProperty;
026:
027: public abstract class XMLDPReferenceList extends XMLDPCollection
028: implements DPReferenceList, DPTypes {
029:
030: XMLDPReferenceList(DPContext dpc, DPRoot r, Element e) {
031: super (dpc, r, e);
032: }
033:
034: public DPProperty getParentProperty() {
035: return null;
036: }
037:
038: public DPContainerChannel getContainer() {
039: Node parentNode = getElement().getParentNode();
040:
041: if (parentNode == null) {
042: throw new DPError(
043: "XMLDPReferenceList.getContainer(): could not find parent node");
044: }
045:
046: if (parentNode.getNodeType() != Node.ELEMENT_NODE) {
047: throw new DPError(
048: "XMLDPReferenceList.getContainer(): parent node was not an element");
049: }
050:
051: Element parentElement = (Element) parentNode;
052:
053: return (DPContainerChannel) XMLDPFactory.getInstance()
054: .getChannel(getContext(), getRoot(), parentElement);
055: }
056:
057: public DPProperty add(DPProperty dp) {
058: switch (dp.getType()) {
059: case REFERENCE_DP:
060: break;
061:
062: default:
063: throw new DPError(
064: "XMLDPReferenceList.add(): cannot add to list, "
065: + "wrong type=" + dp.getType());
066: }
067:
068: return super .add(dp);
069: }
070:
071: DPProperty createProperty(String name, Object o) {
072: DPProperty dpp = XMLDPFactory.getInstance().createReference(
073: getContext(), getRoot(), getDocument(), name);
074:
075: return dpp;
076: }
077:
078: static Element createElement(DPContext dpc, Document d, List l) {
079: return null;
080: }
081:
082: public void setMergeDefaults() {
083: setMergeDefaultsElement(getElement());
084: }
085:
086: public void setDefaults() {
087: setDefaultsElement(getElement());
088: }
089:
090: static void setMergeDefaultsElement(Element e) {
091: setMergeTypeElement(e, staticGetDefaultMergeType());
092: e.setAttribute(LOCK_KEY, FALSE_ATTR);
093: }
094:
095: static void setDefaultsElement(Element e) {
096: setMergeDefaultsElement(e);
097: e.setAttribute(ADVANCED_KEY, FALSE_ATTR);
098: }
099:
100: public void appendReferenceList(StringBuffer b, int indent) {
101: if (isDummy()) {
102: return;
103: }
104:
105: for (Iterator i = getNamesFromThis().iterator(); i.hasNext();) {
106: String name = (String) i.next();
107: DPProperty prop = getFromThis(name);
108: prop.toXML(b, indent + 1);
109: }
110: }
111: }
|