KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > intro > config > IntroElement


1 /***************************************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others. All rights reserved. This program and the
3  * accompanying materials are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors: IBM Corporation - initial API and implementation
8  **************************************************************************************************/

9
10 package org.eclipse.ui.intro.config;
11
12 import java.util.ArrayList JavaDoc;
13 import java.util.Enumeration JavaDoc;
14 import java.util.Hashtable JavaDoc;
15
16 /**
17  * Used to provide children of the computed gruops while constructing intro content. Clients provide
18  * instances of this class from <code>IntroConfigurer</code> to dynamically complete the intro
19  * content. Attribute and element names, as well as content model must match the intro
20  * schema.
21  *
22  * @since 3.2
23  */

24 public class IntroElement {
25
26     private String JavaDoc name;
27     private String JavaDoc value;
28     private Hashtable JavaDoc atts = new Hashtable JavaDoc();
29     private ArrayList JavaDoc children;
30
31     /**
32      * Creates a new intro element with the provided name.
33      *
34      * @param name
35      * the name of the new intro element
36      */

37     public IntroElement(String JavaDoc name) {
38         this.name = name;
39     }
40
41     /**
42      * Sets the value of the named attribute.
43      *
44      * @param name
45      * attribute name
46      * @param value
47      * attribute value
48      */

49     public void setAttribute(String JavaDoc name, String JavaDoc value) {
50         atts.put(name, value);
51     }
52
53     /**
54      * Returns the value of the attribute with a given name.
55      *
56      * @param name
57      * the attribute name
58      * @return value of the attribute with a given name or <code>null</code> if not set.
59      */

60     public String JavaDoc getAttribute(String JavaDoc name) {
61         return (String JavaDoc) atts.get(name);
62     }
63
64     /**
65      * Returns the names of all the attributes defined in this element.
66      *
67      * @return an enumeration of all the element names
68      */

69
70     public Enumeration JavaDoc getAttributes() {
71         return atts.keys();
72     }
73
74     /**
75      * Returns the name of the element.
76      *
77      * @return name of the element
78      */

79     public String JavaDoc getName() {
80         return name;
81     }
82
83     /**
84      * Returns the value of the element.
85      *
86      * @return value of the element or <code>null</code> if not set.
87      */

88     public String JavaDoc getValue() {
89         return value;
90     }
91
92     /**
93      * Sets the value of the element.
94      *
95      * @param value
96      * the value of this element
97      */

98     public void setValue(String JavaDoc value) {
99         this.value = value;
100     }
101
102     /**
103      * Adds a child to this element.
104      *
105      * @param child
106      * the new child of this element
107      */

108     public void addChild(IntroElement child) {
109         if (children == null)
110             children = new ArrayList JavaDoc();
111         children.add(child);
112     }
113
114     /**
115      * Returns the children of this element.
116      *
117      * @return an array of child elements or an empty array of there are no children.
118      */

119     public IntroElement[] getChildren() {
120         if (children == null)
121             return new IntroElement[0];
122         return (IntroElement[]) children.toArray(new IntroElement[children.size()]);
123     }
124     
125     public boolean equals(Object JavaDoc obj) {
126         if (obj instanceof IntroElement) {
127             if (obj == this) {
128                 return true;
129             }
130             String JavaDoc id1 = (String JavaDoc)atts.get("id"); //$NON-NLS-1$
131
String JavaDoc id2 = (String JavaDoc)((IntroElement)obj).atts.get("id"); //$NON-NLS-1$
132
if (id1 == null && id2 == null) {
133                 return super.equals(obj);
134             }
135             if (id1 != null && id2 != null) {
136                 return id1.equals(id2);
137             }
138         }
139         return false;
140     }
141 }
Popular Tags