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.Document;
008: import org.w3c.dom.Element;
009:
010: import java.util.Map;
011: import java.util.List;
012: import java.util.Iterator;
013:
014: import com.sun.portal.desktop.context.DPContext;
015:
016: import com.sun.portal.desktop.dp.DPRoot;
017: import com.sun.portal.desktop.dp.DPProperty;
018: import com.sun.portal.desktop.dp.DPConditionalProperties;
019:
020: class XMLDPConditionalProperties extends XMLDPProperties implements
021: DPConditionalProperties, XMLDPTags {
022:
023: XMLDPConditionalProperties(DPContext dpc, DPRoot r, Document d,
024: String condition, String conditionValue) {
025: this (dpc, r, createElement(dpc, d, condition, conditionValue));
026: }
027:
028: XMLDPConditionalProperties(DPContext dpc, DPRoot r, Document d,
029: String condition, String conditionValue, Map m) {
030: this (dpc, r, createElement(dpc, r, d, condition,
031: conditionValue, m));
032: }
033:
034: XMLDPConditionalProperties(DPContext dpc, DPRoot r, Element e) {
035: super (dpc, r, e);
036: }
037:
038: public short getType() {
039: return CONDITIONALPROPERTIES_DP;
040: }
041:
042: public String getTag() {
043: return CONDITIONALPROPERTIES_TAG;
044: }
045:
046: public String getCondition() {
047: return getElement().getAttribute("condition");
048: }
049:
050: public String getConditionValue() {
051: return getElement().getAttribute("value");
052: }
053:
054: protected Element getMergedElement() {
055: Map map = getCollectionValue();
056: Element e = createElement(getContext(), getRoot(),
057: getDocument(), getCondition(), getConditionValue(), map);
058:
059: return e;
060: }
061:
062: static Element createElement(DPContext dpc, Document d,
063: String condition, String conditionValue) {
064: Element e = createElement(dpc, d, CONDITIONALPROPERTIES_TAG);
065:
066: if (condition != null) {
067: e.setAttribute(CONDITION_KEY, condition);
068: }
069:
070: if (conditionValue != null) {
071: e.setAttribute(VALUE_KEY, conditionValue);
072: }
073:
074: setDefaultsElement(e);
075:
076: return e;
077: }
078:
079: private static Element createElement(DPContext dpc, DPRoot r,
080: Document d, String condition, String conditionValue, Map m) {
081: Element e = createElement(dpc, d, condition, conditionValue);
082:
083: XMLDPFactory factory = XMLDPFactory.getInstance();
084: for (Iterator i = m.keySet().iterator(); i.hasNext();) {
085: String name = (String) i.next();
086: Object o = m.get(name);
087: Element newElement = null;
088: if (isConditionalPropertiesName(name)) {
089: Iterator j = parseConditionalPropertiesName(name)
090: .iterator();
091: String type = (String) j.next();
092: String value = (String) j.next();
093: DPConditionalProperties dptp = factory
094: .createConditionalProperties(dpc, r, d, type,
095: value, (Map) o);
096: XMLDPConditionalProperties xmlDPTP = (XMLDPConditionalProperties) dptp;
097: newElement = xmlDPTP.getElement();
098: } else {
099: DPProperty dpp = XMLDPFactory.getInstance()
100: .createProperty(dpc, r, d, name, o);
101: XMLDPProperty xmlDPP = (XMLDPProperty) dpp;
102: newElement = xmlDPP.getElement();
103: }
104: e.appendChild(newElement);
105: }
106:
107: setDefaultsElement(e);
108:
109: return e;
110:
111: }
112:
113: public void appendTypeAttr(StringBuffer b) {
114: b.append(" " + CONDITION_KEY + "=\"").append(getCondition())
115: .append("\"");
116: }
117:
118: public void appendValueAttr(StringBuffer b) {
119: b.append(" " + VALUE_KEY + "=\"").append(getConditionValue())
120: .append("\"");
121: }
122:
123: public void toXML(StringBuffer b, int indent) {
124:
125: if (isDummy()) {
126: return;
127: }
128: indentBuffer(b, indent);
129:
130: appendStartTag(b);
131: appendTypeAttr(b);
132: appendValueAttr(b);
133: appendMergeAttr(b);
134: appendLockAttr(b);
135: appendAdvancedAttr(b);
136: appendPropagateAttr(b);
137: b.append(">\n");
138:
139: appendChildProperty(b, indent);
140: indentBuffer(b, indent);
141:
142: appendEndTag(b);
143: }
144:
145: }
|