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

Quick Search    Search Deep

Source code: org/acs/damsel/srvr/asset/AssetDescriptorCollection.java


1   package org.acs.damsel.srvr.asset;
2   
3   import java.io.*;
4   import java.util.*;
5   import org.acs.damsel.srvr.*;
6   import org.apache.log4j.*;
7   
8   /**
9    * <p>Title: AssetDescriptorCollection </p>
10   * <p>Description: This class uses the Vector class to provide methods to manage
11   *  AssetDescriptor objects. This is a collection of AssetDescriptors. </p>
12   * @version 1.0
13   */
14  
15  public class AssetDescriptorCollection implements Serializable{
16    /* myCollection is the collection */
17    private Vector myCollection;
18    private static Logger log = Logger.getLogger(AssetDescriptorCollection.class);
19  
20  
21    /**
22     * Default constructor: initializes an empty collection
23     */
24    public AssetDescriptorCollection() {
25      myCollection = new Vector();
26      BasicConfigurator.resetConfiguration();
27      PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
28    }
29  
30    /**
31     * Adds an AssetDescriptor to our collection
32     * @param AssetDescriptor ad
33     */
34    public void addAssetDescriptor(AssetDescriptor ad) {
35      log.debug("entered addAssetDescriptor method");
36      myCollection.addElement(ad);
37      log.debug("exited addAssetDescriptor method");
38    }
39  
40    /**
41     * Removes the specified AssetDescriptor from this collection
42     * @param AssetDescriptor ad
43     * @return true if removed, false otherwise
44     */
45    public boolean removeAssetDescriptor(AssetDescriptor ad)  {
46      log.debug("enter/exit removeAssetDescriptor method");
47      return myCollection.remove(ad);
48    }
49  
50    /**
51     * @return size of collection
52     */
53    public int size() {
54      return myCollection.size();
55    }
56  
57    /**
58     *  @return an Iterator with all the elements in this collection
59     */
60    public Iterator iterator() {
61      return myCollection.iterator();
62    }
63  
64    /**
65     * getTag searches through this AssetDescriptor collection and returns the
66     * tag associated with the given value
67     * @param value String
68     * @return tag associated with the passed in value, null if not found
69     */
70    public String getTag(String values) {
71      log.debug("entered getTag method");
72      AssetDescriptor temp;
73      Iterator it = this.iterator();
74      /* Search for the desired value through the entire collection */
75      while(it.hasNext()){
76        temp = (AssetDescriptor)it.next();
77        if(temp.getValue() != null) {
78          if (temp.getValue().equalsIgnoreCase(values))
79            return temp.getTag();
80        }
81      }
82      log.debug("exited getTag method");
83      return null; //desired value wasn't found
84    }
85  
86    /**
87     * getValue searches through this AssetDescriptor collection and returns the
88     * value associated with the given tag
89     * @param String tag
90     * @return value associated with the passed in tag, null if not found
91     */
92    public String getValue(String tag) {
93      log.debug("entered getValue method");
94      AssetDescriptor temp;
95      Iterator it = this.iterator();
96      //finds the asset descriptor value with the tag of tags
97      while (it.hasNext()) {
98        temp = (AssetDescriptor)it.next();
99        if (temp.getTag() != null)
100         if (temp.getTag().equalsIgnoreCase(tag))
101           return temp.getValue();
102     }
103     log.debug("exited getValue method");
104     return null;
105   }
106 
107   public AssetDescriptor getAssetDescriptor(String tag) {
108     AssetDescriptor ad = new AssetDescriptor();
109     for (Iterator i = myCollection.iterator(); i.hasNext(); ) {
110       ad = (AssetDescriptor)i.next();
111       if (ad.getTag().equals(tag))
112         return ad;
113     }
114     return ad;
115   }
116 
117   /**
118    * Returns a string value of the collection
119    * @return String
120    */
121   public String toString() {
122     return myCollection.toString();
123   }
124 }