source: trunk/gli/src/org/greenstone/gatherer/msm/Metadata.java@ 8243

Last change on this file since 8243 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
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 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.msm;
38
39import java.io.*;
40import org.greenstone.gatherer.Gatherer;
41import org.greenstone.gatherer.collection.Collection;
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.valuetree.GValueModel;
44import org.greenstone.gatherer.valuetree.GValueNode;
45import org.greenstone.gatherer.util.StaticStrings;
46import org.w3c.dom.Element;
47/** Stores a mapping between a particular metadata element, and a certain value node.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.3
50 */
51public class Metadata
52 implements Comparable {
53 /** Is this an accumulating piece of metadata? */
54 private boolean accumulate = false;
55 /** Indicates what level of metadata this is, relative to the file it was retrieved for. */
56 private boolean file_level = true;
57 /** The file for which this metadata was retrieved. This allows us to determine the source of folder level metadata. */
58 private File file;
59 /** The value node this metadata maps to. */
60 private GValueNode value = null;
61 /** Used to count the number of references to this piece of metadata within the metadata table. */
62 private int count = 1;
63 /** The metadata element this metadata maps to. */
64 private ElementWrapper element = null;
65 /** Constructs a new Metadata object with no current value.
66 * @param element The <strong>ElementWrapper</strong> associated with this metadata.
67 */
68 public Metadata(ElementWrapper element) {
69 super();
70 this.element = element;
71 this.value = null;
72 }
73 /** Default constructor simply creates a new Metadata object based on the given parameters.
74 * @param element The <strong>ElementWrapper</strong> associated with this metadata.
75 * @param value The assigned value for the given element, as a <strong>GValueNode</strong>.
76 */
77 public Metadata(ElementWrapper element, GValueNode value) {
78 super();
79 this.element = element;
80 this.value = value;
81 }
82 /** Constructs a new Metadata object, given the value. The metadata element is extracted from the value tree information.
83 * @param value The assigned value for the given element, as a <strong>GValueNode</strong>.
84 * @see org.greenstone.gatherer.Gatherer
85 * @see org.greenstone.gatherer.collection.CollectionManager
86 * @see org.greenstone.gatherer.msm.MetadataSetManager
87 */
88 public Metadata(GValueNode value) {
89 super();
90 this.element = Gatherer.c_man.getCollection().msm.getElement(value.getMetadataElementName());
91 this.value = value;
92 }
93 /** Determine if this metadata overwrites or accumulates. */
94 public boolean accumulates() {
95 return accumulate;
96 }
97 /** Compares two Metadata objects for ordering purposes.
98 * @param object The other metadata as an <strong>Object</strong>.
99 * @return An <i>int</i> value as specified in java.lang.String#compareTo
100 * @see java.lang.String#compareTo
101 */
102 public int compareTo(Object object) {
103 return toString().compareTo(object.toString());
104 }
105 /** Decrease the reference count by 1. */
106 public void dec() {
107 count--;
108 }
109 /** Tests to metadata objects for equality.
110 * @param object The other metadata as an <strong>Object</strong>.
111 * @return <i>true</i> if the metadata are equal, <i>false</i> otherwise.
112 */
113 public boolean equals(Object object) {
114 if(compareTo(object) == 0) {
115 return true;
116 }
117 return false;
118 }
119 /** Determine the absolute path value of this metadata, taking into account whether this value is hierarchical. */
120 public String getAbsoluteValue() {
121 String abs_result = "";
122 if(value != null) {
123 //abs_result = value.toString(GValueNode.GREENSTONE);
124 abs_result = value.getFullPath(false);
125 }
126 return abs_result;
127 }
128
129 /** Retrieve the reference count.
130 * @return The count as an <i>int</i>.
131 */
132 public int getCount() {
133 return count;
134 }
135 /** Retrieve the element associated with this metadata.
136 * @return An <strong>ElementWrapper</strong>.
137 */
138 public ElementWrapper getElement() {
139 return element;
140 }
141
142 /** Retrieve the source file if any. */
143 public File getFile() {
144 return file;
145 }
146
147 /** Get the textual value of this metadata.
148 * @return A <strong>String</strong> representing the value of this Metadata. Note that if the value node is null, then the String returned is "".
149 */
150 public String getValue() {
151 String result = "";
152 if(value != null) {
153 result = value.toString();
154 }
155 return result;
156 }
157 /** Retrieve the value node associated with this metadata.
158 * @return A <strong>GValueNode</strong>.
159 */
160 public GValueNode getValueNode() {
161 return value;
162 }
163 /** Increase the reference count by 1. */
164 public void inc() {
165 count++;
166 }
167
168 /** Determine if this metadata is file level or folder level. */
169 public boolean isFileLevel() {
170 return file_level;
171 }
172
173 /** Inform this metadata whether it will accumulate with any other metadata of the same type. */
174 public void setAccumulate(boolean accumulate) {
175 this.accumulate = accumulate;
176 }
177 /** Sets the reference count.
178 * @param value The new value of count as an <i>int</i>.
179 */
180 public void setCount(int value) {
181 count = value;
182 }
183 /** Set the level of this metadata (whether it is associated with this file explicitly or found in some folder above this file). */
184 public void setFileLevel(boolean file_level) {
185 this.file_level = file_level;
186 }
187
188 /** Set the current source file for this metadata to the given collection. This value should not be counted are remaining valid at any time other than immediately after a getMetadata call as it is relative the the file that metadata call was for. */
189 public void setFile(File file) {
190 this.file = file;
191 }
192
193 /** Translates this object into a string representation.
194 * @return A <strong>String</strong>.
195 */
196 public String toString() {
197 return element.toString() + "=" + getValue();
198 }
199
200 /** Retrieve the value node associated with a certain value string. */
201 static final public GValueNode getDefaultValueNode(ElementWrapper element, String value) {
202 // Retrieve the GValueNode
203 GValueModel model = Gatherer.c_man.getCollection().msm.getValueTree(element);
204 GValueNode value_node;
205 if(model != null) {
206 value_node = model.getValue(value);
207 }
208 else {
209 value_node = new GValueNode(element.getName(), value);
210 }
211 model = null;
212 return value_node;
213 }
214}
Note: See TracBrowser for help on using the repository browser.