Source code: org/acs/damsel/srvr/schema/MetaDataTag.java
1 package org.acs.damsel.srvr.schema;
2
3 import java.io.*;
4 import java.util.*;
5
6 import org.acs.damsel.srvr.*;
7 import org.apache.log4j.*;
8
9 /**
10 * <p>Title: MetaDataTag</p>
11 * <p>Description: MetaDataTag holds a name for a tag (i.e., "Title",
12 * "Description", etc) as well as a vocabulary list for tags with a controlled
13 * vocabulary (as opposed to free-form tags). The class overrides the Object
14 * equals() method with one that only compares the Tag name. Thus, tag names
15 * must be unique, even if their other properties, such as having a controlled
16 * vocabulary list, are not.</p>
17 * @version 1.0
18 */
19 public class MetaDataTag implements Serializable {
20 private String name;
21 private boolean controlledVocabulary;
22 private Vector vocabulary;
23 private static Logger log = Logger.getLogger(TestMetaDataTag.class);
24
25 /**
26 * Default constructor
27 */
28 public MetaDataTag() {
29 BasicConfigurator.resetConfiguration();
30 PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
31 controlledVocabulary = false;
32 vocabulary = new Vector();
33 name = "";
34 }
35
36 /**
37 * Method adds a word to the controlled vocabulary list of the MetaDataTag.
38 * If the word already exists in the list or the MetaDataTag is not a
39 * controlled vocabulary tag, a ControlledVocabularyException is thrown.
40 * @param word String controlled vocabulary word to be added
41 * @throws ControlledVocabularyException
42 * */
43 public void addVocabularyWord(String word) throws ControlledVocabularyException {
44 log.debug("enter addVocabularyWord");
45 if(!controlledVocabulary) {
46 log.error("Tag does not use a controlled vocabulary.");
47 throw new ControlledVocabularyException("Tag does not use a controlled vocabulary.");
48 }
49 if(isInVocabulary(word)) {
50 log.error("Word " + word + " already exists in vocabulary.");
51 throw new ControlledVocabularyException("Word " + word + " already exists in vocabulary.");
52 }
53 vocabulary.add(word);
54 log.debug("exit addVocabularyWord");
55 }
56
57 /**
58 * removeVocabularyWord is similar to addVocabularyWord, except that a
59 * ControlledVocabularyException is thrown if the word does not exist in
60 * the controlled vocabulary list or if the MetaDataTag does not have a
61 * controlled vocabulary.
62 * @param word String controlled vocabulary word to be removed
63 * @throws ControlledVocabularyException
64 * */
65 public void removeVocabularyWord(String word) throws ControlledVocabularyException {
66 log.debug("enter removeVocabularyWord");
67 if (!controlledVocabulary) {
68 log.error("Tag does not use a controlled vocabulary.");
69 throw new ControlledVocabularyException("Tag does not use a controlled vocabulary.");
70 }
71 if (!isInVocabulary(word)) {
72 log.error("Word " + word + " does not exist in vocabulary.");
73 throw new ControlledVocabularyException("Word " + word + " does not exist in vocabulary.");
74 }
75 vocabulary.remove(word);
76 log.debug("exit removeVocabularyWord");
77 }
78
79 /**
80 * Method checks if the specified word is in the vocabulary list.
81 * @param word String controlled vocabulary word to be checked for
82 * @return boolean, true if word exists in vocabulary list, false otherwise
83 */
84 public boolean isInVocabulary(String word) {
85 return vocabulary.indexOf(word) != -1 ;
86 }
87
88 /**
89 * Method returns an interator of all words in the conrolled vocabulary list.
90 * @return Iterator
91 */
92 public Iterator vocabularyIterator() {
93 return vocabulary.iterator();
94 }
95
96 /**
97 * Method returns true if the metadatatag has a controlled vocabulary list,
98 * false otherwise.
99 * @return boolean
100 */
101 public boolean isControlledVocabulary() {
102 return controlledVocabulary;
103 }
104
105 /* Getters and Setters */
106 public String getName() {
107 return name;
108 }
109 public void setName(String name) {
110 this.name = name;
111 }
112 public void setControlledVocabulary(boolean controlledVocabulary) {
113 this.controlledVocabulary = controlledVocabulary;
114 }
115 public boolean equals(Object tag){
116 return name.equals(((MetaDataTag)tag).getName());
117 }
118 public Vector getVocabulary() {
119 return vocabulary;
120 }
121 public void setVocabulary(Vector vocabulary) {
122 this.vocabulary = vocabulary;
123 }
124 }