Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acs/damsel/srvr/schema/Schema.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: Schema</p>
11   * <p>Description: Schema holds a name for the schema (i.e., "Dublin Core",
12   * "Realia", etc) and a list of MetaDataTags that compose the Schema.  Random
13   * access to tags is provided by isInSchema() and getTag(), sequential access
14   * by using the Iterator from tagsIterator().  Like MetaDataTags, Schemas are
15   * uniquely identified by name, even if their other properties are different.</p>
16   * @version 1.0
17   */
18  public class Schema implements Serializable {
19    private Vector tags;
20    private String name;
21    private String ownerName;
22    private String permissionID;
23    private String groupName;
24    private static Logger log = Logger.getLogger(TestMetaDataTag.class);
25  
26    /**
27     * Default constructor.  Initializes the vector of schema tags.
28     */
29    public Schema() {
30      BasicConfigurator.resetConfiguration();
31      PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
32      tags = new Vector();
33    }
34  
35    /**
36     * Method adds a MetaDataTag to the schema.  A SchemaException is thrown if a
37     * tag with the same name already exists in the Schema.
38     * @param tag MetaDataTag to be added
39     * @throws SchemaException
40     */
41    public void addTag(MetaDataTag tag) throws SchemaException {
42      log.debug("enter addTag");
43      if (isInSchema(tag.getName())) {
44        log.error("Tag " + tag.getName() + " already in schema " + name);
45        throw new SchemaException("tag " + tag.getName() + " already in schema " +
46                                  name);
47      }
48      this.tags.add(tag);
49      log.debug("enter addTag");
50    }
51  
52    /**
53     * Method removes a MetaDataTag from the schema.  A SchemaException is thrown
54     * if a tag with the same name does not exist in the Schema.
55     * @param tagName String containing the name to the tag to be removed
56     * @throws SchemaException
57     */
58    public void removeTag(String tagName) throws SchemaException {
59      log.debug("enter removeTag");
60      MetaDataTag searchTag = new MetaDataTag();
61      searchTag.setName(tagName);
62      if (!isInSchema(tagName)) {
63        log.error("tag " + tagName + " not in schema " + name);
64        throw new SchemaException("tag " + tagName + " not in schema " + name);
65      }
66      tags.remove(searchTag);
67      log.debug("exit removeTag");
68    }
69  
70    /**
71     * Method returns the MetaDataTag with the given name.  If no such MetaDataTag
72     * exists in the Schema, a SchemaException is thrown.
73     * @param tagName String containing the tag name
74     * @return MetaDataTag
75     * @throws SchemaException
76     */
77    public MetaDataTag getTag(String tagName) throws SchemaException {
78      log.debug("enter getTag");
79      MetaDataTag searchTag = new MetaDataTag();
80      searchTag.setName(tagName);
81      if (!isInSchema(tagName)) {
82        log.error("tag " + tagName + " not in schema " + name);
83        throw new SchemaException("tag " + tagName + " not in schema " + name);
84      }
85      log.debug("exit getTag");
86      return (MetaDataTag) tags.get(tags.indexOf(searchTag));
87    }
88  
89    /**
90     * Method returns true if the specified metadata tag is included in the
91     * current schema object, false otherwise.
92     * @param tagName String containing the name of the tag to check for
93     * @return boolean
94     */
95    public boolean isInSchema(String tagName) {
96      MetaDataTag searchTag = new MetaDataTag();
97      searchTag.setName(tagName);
98      return tags.indexOf(searchTag) != -1;
99    }
100 
101   /**
102    * Method returns true if there are no tags in the schema, false otherwise
103    * @return boolean
104    */
105   public boolean isEmpty() {
106     if (this.tags.size() == 0) {
107       return true;
108     }
109     return false;
110   }
111 
112   /**
113    * Method returns an iterator of all tags in the schema.
114    * @return Iterator
115    */
116   public Iterator tagsIterator() {
117     return tags.iterator();
118   }
119 
120   /* Getters and Setters */
121   public String getName() {
122     return name;
123   }
124   public void setName(String name) {
125     this.name = name;
126   }
127   public boolean equals(Object sch) {
128     return this.getName().equals(((Schema) sch).getName());
129   }
130   public Vector getTags() {
131     return tags;
132   }
133   public void setTags(Vector tags) {
134     this.tags = tags;
135   }
136   public String getGroupName() {
137     return groupName;
138   }
139   public void setGroupName(String groupName) {
140     this.groupName = groupName;
141   }
142   public String getOwnerName() {
143     return ownerName;
144   }
145   public String getPermissionID() {
146     return permissionID;
147   }
148   public void setOwnerName(String ownerName) {
149     this.ownerName = ownerName;
150   }
151   public void setPermissionID(String permissionID) {
152     this.permissionID = permissionID;
153   }
154 }