1 | package org.greenstone.gatherer.cdm;
|
---|
2 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
3 | import org.w3c.dom.*;
|
---|
4 | /** For even more confusion this class provides a convience wrapper around an element, to allow it to appear in the <strong>JList</strong> with both name and description. However this class has nothing to do with its namesake.
|
---|
5 | * @see org.greenstone.gatherer.msm.ElementWrapper
|
---|
6 | */
|
---|
7 | public class ElementWrapper
|
---|
8 | implements Comparable {
|
---|
9 | /** The element as the data from this object. */
|
---|
10 | private Node element = null;
|
---|
11 | /** Constructor.
|
---|
12 | * @param element The <strong>Node</strong> this object is wrapped around.
|
---|
13 | */
|
---|
14 | public ElementWrapper(Node element) {
|
---|
15 | this.element = element;
|
---|
16 | }
|
---|
17 | /** Compare two objects for ordering.
|
---|
18 | * @param object The other <strong>Object</strong> to compare to.
|
---|
19 | * @return An <i>int</i> indicating the ordering as is String.compareTo
|
---|
20 | */
|
---|
21 | public int compareTo(Object object) {
|
---|
22 | if(object == null) {
|
---|
23 | return 1;
|
---|
24 | }
|
---|
25 | return toString().compareTo(object.toString());
|
---|
26 | }
|
---|
27 | /** Compare two objects for equality.
|
---|
28 | * @param object The <strong>Object</strong> to compare to.
|
---|
29 | * @return <i>true</i> if the objects are equal, <i>false</i> otherwise.
|
---|
30 | */
|
---|
31 | public boolean equals(Object object) {
|
---|
32 | if(compareTo(object) == 0) {
|
---|
33 | return true;
|
---|
34 | }
|
---|
35 | return false;
|
---|
36 | }
|
---|
37 | /** Retrieve the name of the element.
|
---|
38 | * @return The fully qualified name as a <strong>String</strong>.
|
---|
39 | * @see org.greenstone.gatherer.msm.MSMUtils
|
---|
40 | */
|
---|
41 | public String name() {
|
---|
42 | return MSMUtils.getFullName((Element)element);
|
---|
43 | }
|
---|
44 | /** Retrieve a textual representation of this object.
|
---|
45 | * @return A <strong>String</strong>.
|
---|
46 | * @see org.greenstone.gatherer.msm.MSMUtils
|
---|
47 | */
|
---|
48 | public String toString() {
|
---|
49 | return MSMUtils.getIdentifier(element) + ": " + MSMUtils.getDescription(element);
|
---|
50 | }
|
---|
51 | }
|
---|