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 com.sun.portal.desktop.context.DPContext;
011:
012: import com.sun.portal.desktop.dp.DPError;
013: import com.sun.portal.desktop.dp.DPPropertyHolder;
014: import com.sun.portal.desktop.dp.DPRoot;
015: import com.sun.portal.desktop.dp.DPProperties;
016:
017: public abstract class XMLDPPropertyHolder extends XMLDPObject implements
018: DPPropertyHolder, XMLDPAttrs {
019:
020: //
021: // this never changes over the life of this
022: // object, so store it off so we
023: // do not need to look it up each time
024: // we access it a lot!
025: //
026: protected Element propertiesElement = null;
027:
028: XMLDPPropertyHolder(DPContext dpc, DPRoot r, Element e) {
029: super (dpc, r, e);
030: }
031:
032: public Element getPropertiesElement() {
033: if (propertiesElement == null) {
034: propertiesElement = getChildElement(getElement(),
035: PROPERTIES_TAG, null);
036:
037: if (propertiesElement == null) {
038: throw new DPError(
039: "XMLDPPropertyHolder.getPropertiesElement(): no properties element exists for node name="
040: + getName()
041: + ", element="
042: + getElement().toString()
043: + ", document="
044: + getElement().getOwnerDocument()
045: .toString());
046: }
047: }
048:
049: return propertiesElement;
050: }
051:
052: public DPProperties getPropertiesFromThis() {
053: Element pe = getPropertiesElement();
054: DPProperties dpProperties = (DPProperties) getObject(pe);
055: if (dpProperties == null) {
056: dpProperties = XMLDPFactory.getInstance().getProperties(
057: getContext(), getRoot(), pe);
058: putObject(dpProperties);
059: }
060:
061: return dpProperties;
062: }
063:
064: public DPProperties getProperties() {
065: DPProperties dpProperties = getPropertiesFromThis();
066:
067: if (dpProperties != null && dpProperties.isMerged()) {
068: // nothing
069: } else {
070: for (int i = 0; i < getMergers().size(); i++) {
071: DPPropertyHolder dpph = (DPPropertyHolder) getMergers()
072: .get(i);
073:
074: if (getType() != dpph.getType()) {
075: throw new DPError(
076: "XMLDPPropertyHolder.getProperties(): type mismatch");
077: }
078:
079: DPProperties dpp = ((XMLDPPropertyHolder) dpph)
080: .getPropertiesFromThis();
081: dpProperties.addMerger(dpp);
082: }
083: }
084:
085: return dpProperties;
086: }
087:
088: public abstract DPPropertyHolder getParentPropertyHolder();
089:
090: static Element createElement(DPContext dpc, Document d,
091: String name, Element propertiesElement) {
092: Element e = createElement(dpc, d, CHANNEL_TAG, name);
093: e.appendChild(propertiesElement);
094:
095: setDefaultsElement(e);
096:
097: return e;
098: }
099:
100: public int getDefaultMergeType() {
101: return staticGetDefaultMergeType();
102: }
103:
104: static int staticGetDefaultMergeType() {
105: return MERGE_FUSE;
106: }
107:
108: public void setMergeDefaults() {
109: setMergeDefaultsElement(getElement());
110: }
111:
112: public void setDefaults() {
113: setDefaultsElement(getElement());
114: }
115:
116: static void setMergeDefaultsElement(Element e) {
117: setMergeTypeElement(e, staticGetDefaultMergeType());
118: e.setAttribute(LOCK_KEY, FALSE_ATTR);
119:
120: Element pe = getChildElement(e, PROPERTIES_TAG, null);
121: XMLDPProperties.setMergeDefaultsElement(pe);
122: }
123:
124: static void setDefaultsElement(Element e) {
125: setMergeDefaultsElement(e);
126: e.setAttribute(ADVANCED_KEY, FALSE_ATTR);
127:
128: Element pe = getChildElement(e, PROPERTIES_TAG, null);
129: XMLDPProperties.setDefaultsElement(pe);
130: }
131: }
|