001: /***************************************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others. All rights reserved. This program and the
003: * accompanying materials are made available under the terms of the Eclipse Public License v1.0
004: * which accompanies this distribution, and is available at
005: * http://www.eclipse.org/legal/epl-v10.html
006: *
007: * Contributors: IBM Corporation - initial API and implementation
008: **************************************************************************************************/package org.eclipse.ui.intro.config;
009:
010: import java.util.ArrayList;
011: import java.util.Enumeration;
012: import java.util.Hashtable;
013:
014: /**
015: * Used to provide children of the computed gruops while constructing intro content. Clients provide
016: * instances of this class from <code>IntroConfigurer</code> to dynamically complete the intro
017: * content. Attribute and element names, as well as content model must match the intro
018: * schema.
019: *
020: * @since 3.2
021: */
022: public class IntroElement {
023:
024: private String name;
025: private String value;
026: private Hashtable atts = new Hashtable();
027: private ArrayList children;
028:
029: /**
030: * Creates a new intro element with the provided name.
031: *
032: * @param name
033: * the name of the new intro element
034: */
035: public IntroElement(String name) {
036: this .name = name;
037: }
038:
039: /**
040: * Sets the value of the named attribute.
041: *
042: * @param name
043: * attribute name
044: * @param value
045: * attribute value
046: */
047: public void setAttribute(String name, String value) {
048: atts.put(name, value);
049: }
050:
051: /**
052: * Returns the value of the attribute with a given name.
053: *
054: * @param name
055: * the attribute name
056: * @return value of the attribute with a given name or <code>null</code> if not set.
057: */
058: public String getAttribute(String name) {
059: return (String) atts.get(name);
060: }
061:
062: /**
063: * Returns the names of all the attributes defined in this element.
064: *
065: * @return an enumeration of all the element names
066: */
067:
068: public Enumeration getAttributes() {
069: return atts.keys();
070: }
071:
072: /**
073: * Returns the name of the element.
074: *
075: * @return name of the element
076: */
077: public String getName() {
078: return name;
079: }
080:
081: /**
082: * Returns the value of the element.
083: *
084: * @return value of the element or <code>null</code> if not set.
085: */
086: public String getValue() {
087: return value;
088: }
089:
090: /**
091: * Sets the value of the element.
092: *
093: * @param value
094: * the value of this element
095: */
096: public void setValue(String value) {
097: this .value = value;
098: }
099:
100: /**
101: * Adds a child to this element.
102: *
103: * @param child
104: * the new child of this element
105: */
106: public void addChild(IntroElement child) {
107: if (children == null)
108: children = new ArrayList();
109: children.add(child);
110: }
111:
112: /**
113: * Returns the children of this element.
114: *
115: * @return an array of child elements or an empty array of there are no children.
116: */
117: public IntroElement[] getChildren() {
118: if (children == null)
119: return new IntroElement[0];
120: return (IntroElement[]) children
121: .toArray(new IntroElement[children.size()]);
122: }
123:
124: public boolean equals(Object obj) {
125: if (obj instanceof IntroElement) {
126: if (obj == this ) {
127: return true;
128: }
129: String id1 = (String) atts.get("id"); //$NON-NLS-1$
130: String id2 = (String) ((IntroElement) obj).atts.get("id"); //$NON-NLS-1$
131: if (id1 == null && id2 == null) {
132: return super .equals(obj);
133: }
134: if (id1 != null && id2 != null) {
135: return id1.equals(id2);
136: }
137: }
138: return false;
139: }
140: }
|