1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
5 | * library suite from the New Zealand Digital Library Project at the
|
---|
6 | * University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
9 | *
|
---|
10 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | *########################################################################
|
---|
26 | */
|
---|
27 | package org.greenstone.gatherer.cdm;
|
---|
28 |
|
---|
29 | /**************************************************************************************
|
---|
30 | * Written: 16/07/03
|
---|
31 | * Revised:
|
---|
32 | **************************************************************************************/
|
---|
33 | import org.w3c.dom.*;
|
---|
34 |
|
---|
35 | /** This class represents a level (for mgpp and lucene collecitons) .
|
---|
36 | */
|
---|
37 | public class Level
|
---|
38 | implements DOMProxyListEntry {
|
---|
39 |
|
---|
40 | /** The Element this level object will source its information from. */
|
---|
41 | private Element element;
|
---|
42 |
|
---|
43 | /** Constructor used only during DOMProxyListModel initialization. */
|
---|
44 | public Level() {
|
---|
45 | }
|
---|
46 |
|
---|
47 | /** Normal constructor.
|
---|
48 | * @param element the Element this object will find its data from
|
---|
49 | */
|
---|
50 | public Level(Element element) {
|
---|
51 | this.element = element;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /** Creation of a brand new Level
|
---|
55 | * @param name the name of this type as a String
|
---|
56 | */
|
---|
57 | public Level(String level) {
|
---|
58 | this.element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LEVEL_ELEMENT);
|
---|
59 | this.element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** Compare two objects for ordering.
|
---|
63 | * @param object the other Object to compare to
|
---|
64 | * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after
|
---|
65 | * since we can only have one instance of a particular level, we don't need to look at the name when comparing.
|
---|
66 | */
|
---|
67 | public int compareTo(Object object) {
|
---|
68 | if(object == null) {
|
---|
69 | return -1;
|
---|
70 | }
|
---|
71 | // hope we never compare a Level with something that is not a Level!
|
---|
72 | return getLevel().compareTo(((Level)object).getLevel());
|
---|
73 | }
|
---|
74 |
|
---|
75 | /** Factory-like method to allow DOMProxyListModel to generate new entries.
|
---|
76 | * @param element the Element the new level should be based on
|
---|
77 | * @return a newly created DOMProxyListEntry for the given element
|
---|
78 | */
|
---|
79 | public DOMProxyListEntry create(Element element) {
|
---|
80 | return new Level(element);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /** Determine if this level is equavilent to another object.
|
---|
84 | * @param object the other Other to match against
|
---|
85 | * @return true if the two are equal, false otherwise
|
---|
86 | */
|
---|
87 | public boolean equals(Object object) {
|
---|
88 | return (compareTo(object) == 0);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
|
---|
92 | * @return the Element in question
|
---|
93 | */
|
---|
94 | public Element getElement() {
|
---|
95 | return element;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /** Retrieve the level.
|
---|
99 | * @return the level as a String
|
---|
100 | */
|
---|
101 | public String getLevel() {
|
---|
102 | return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /** Determine is this command has been assigned, either because it already existed in the collection configuration, or because it has been explicitly set by the user. Non-assigned entries imply they have been added by the GLI to ensure consistancy (and avoid NPE's!)
|
---|
106 | * @return true if this command has been assigned, false otherwise
|
---|
107 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
108 | */
|
---|
109 | public boolean isAssigned() {
|
---|
110 | return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
|
---|
111 | }
|
---|
112 |
|
---|
113 | /** Set the assigned state.
|
---|
114 | * @param assigned the desired state of assigned as a boolean
|
---|
115 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
116 | */
|
---|
117 | public void setAssigned(boolean assigned) {
|
---|
118 | if(element != null) {
|
---|
119 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | /** Set the element that this DOMProxyListEntry is base on.
|
---|
124 | * @param element the new Element that this entry should source informatin from
|
---|
125 | */
|
---|
126 | public void setElement(Element element) {
|
---|
127 | this.element = element;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /** Set the name of this level.
|
---|
131 | * @param name the new name for this level, as a String
|
---|
132 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
133 | */
|
---|
134 | public void setLevel(String level) {
|
---|
135 | if(element != null) {
|
---|
136 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Produce a text representation of this level.
|
---|
141 | * @return a String showing this level
|
---|
142 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
143 | */
|
---|
144 | public String toString() {
|
---|
145 | return getLevel();
|
---|
146 | }
|
---|
147 | }
|
---|