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

Quick Search    Search Deep

Source code: openfuture/masterdata/LDMasterDataContainer.java


1   package openfuture.masterdata;
2   
3   import java.util.*;
4   
5   /**
6    * This class implements the <tt>IMasterDataContainer</tt> interface in order to
7    * provide a container for language dependent master data.
8    * 
9    * Creation date: (10.09.00 09:32:50)
10   * @author: Markus Giebeler
11   *
12   * This library is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU Lesser General Public
14   * License as published by the Free Software Foundation; either
15   * version 2 of the License, or (at your option) any later version.<p>
16   *
17   * This library 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 GNU
20   * Lesser General Public License for more details.<p>
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA<br>
25   * http://www.gnu.org/copyleft/lesser.html"
26   */
27  public class LDMasterDataContainer implements IMasterDataContainer {
28    /** Field data (Vector) is used to hold the data */
29    private Vector data;
30    
31    /** Field language (String) is used to check which data are loaded */
32    private String language="";
33  
34  /**
35   * Constructor
36   */
37  public LDMasterDataContainer() {
38    super();
39  }
40  /**
41   * Constructor
42   * 
43   * Creation date: (10.09.00 09:34:37)
44   * @param data java.util.Vector
45   */
46  public LDMasterDataContainer(Vector data) {
47    setData(data);
48  }
49   /**
50    * Return contents of field data
51    * 
52    * @return (Vector) contents of field data
53    */
54    public final Vector getData() {
55    if(data==null) {
56      data = new Vector(); 
57    }
58    return data;
59    }  
60  /**
61   * Provides another container with master data for the given language
62   * 
63   * Creation date: (10.09.00 10:10:44)
64   * @return IMasterDataContainer
65   * @param language java.lang.String
66   */
67  public IMasterDataContainer getMasterData(String language) {
68    Vector result = new Vector();
69    
70    Enumeration allData = getData().elements();
71    while(allData.hasMoreElements()) {
72      ILanguageDependent data = (ILanguageDependent) allData.nextElement();
73      if(data.getLanguage().equalsIgnoreCase(language)) {
74        result.addElement(data);
75      }
76    }
77  
78    Object[] tData = result.toArray();
79    Arrays.sort(tData);
80    result = new Vector();
81    for(int i=0; i<tData.length; i++) {
82      result.addElement(tData[i]);
83    }
84  
85    
86    IMasterDataContainer newContainer = new LDMasterDataContainer(result);
87    newContainer.setLanguage(language);
88    return newContainer;
89  }
90  /**
91   * indicates if this container can provide data for a given language.
92   * 
93   * Creation date: (10.09.00 10:10:44)
94   * @return boolean
95   * @param language java.lang.String
96   */
97  public boolean hasMasterData(String language) {
98    return language.equals(this.language);
99  }
100  /**
101   * Set contents of field data to the given value
102   * 
103   * @param newValue (Vector) new value for field data
104   */
105   public final void setData(Vector newValue) {
106   this.data = newValue;
107   }  
108  /**
109   * Set contents of field language to the given value
110   * 
111   * @param newValue (String) new value for field language
112   */
113   public final void setLanguage(String newValue) {
114   this.language = newValue;
115   }  
116 }