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

Quick Search    Search Deep

Source code: openfuture/util/masterdata/MRMasterDataSource.java


1   package openfuture.util.masterdata;
2   
3   /*
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.<p>
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.<p>
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
17   * http://www.gnu.org/copyleft/lesser.html
18   */
19  
20  import java.util.Locale;
21  import openfuture.masterdata.IMasterDataContainer;
22  import openfuture.masterdata.IMasterDataSource;
23  import openfuture.masterdata.LDMasterData;
24  import org.apache.struts.util.MessageResources;
25  import java.util.LinkedList;
26  import java.util.Iterator;
27  import java.util.Vector;
28  
29  // Configuration Management Information: 
30  // -------------------------------------
31  // $Id: MRMasterDataSource.java,v 1.4 2001/10/26 20:32:03 wreissen Exp $
32  //
33  // Version History:
34  // ----------------
35  // $Log: MRMasterDataSource.java,v $
36  // Revision 1.4  2001/10/26 20:32:03  wreissen
37  // javadoc bugs fixed.
38  //
39  // Revision 1.3  2001/07/01 06:46:30  wreissen
40  // fixed errors in DOS/Unix-translation.
41  //
42  // Revision 1.1  2001/05/29 18:26:18  wreissen
43  // initial version
44  //
45  
46  // ***********************************************************************************
47  /**
48   * Masterdata source using 
49   * {@link org.apache.struts.util.MessageResources MessageResources}
50   * in order to retrieve localized master data.<p>
51   *
52   *
53   * Created: Mon May 28 06:36:47 2001
54   *
55   * @author <a href="wolfgang@openfuture.de">Wolfgang Reissenberger</a>
56   * @version $Revision: 1.4 $
57   */
58  
59  public class MRMasterDataSource implements IMasterDataSource {
60  
61      private String type;
62      private LocalizedMasterDataContainer container;
63  
64      /**
65       * Creates a new <code>RBMasterDataSource</code> instance. For
66       * each given {@link java.util.Locale Locale},
67       * a vector of {@link openfuture.masterdata.LDMasterData LDMasterData}
68       * is added, one for each of the given keys. The description is
69       * retreived from the given 
70       * {@link org.apache.struts.util.MessageResources message resources}.
71       * The given search string in the resources is the concatenation
72       * of the given prefix and the respective key.<p>
73       * <emph>Special case</emph>: If the key is <code>null</code> or
74       * an empty string, the empty string is added as key and as value
75       * for each resource bundle.
76       *
77       * @param type type of master data
78       * @param resources Struts message resources
79       * @param locales list of {@link java.util.Locale Locale}
80       *                objects.
81       * @param keys vector of {@link java.lang.String String} objects.
82       * @param prefix prefix of the resource bundle entries.
83       */
84      public MRMasterDataSource (String type, MessageResources resources,
85               LinkedList locales, LinkedList keys,
86               String prefix){
87    
88    // create the master data container
89    setContainer(new LocalizedMasterDataContainer());
90  
91    // iterate over all resource bundles
92    Iterator it = locales.iterator();
93  
94    while (it.hasNext()) {
95        Locale locale = (Locale) it.next();
96        String lang = locale.toString();
97  
98        // vector storing the single master data entries
99        Vector data = new Vector();
100 
101       // iterate over all keys
102       Iterator keysIt = keys.iterator();
103       while(keysIt.hasNext()) {
104     String key = (String) keysIt.next();
105 
106     if (key == null || key.equals("")) {
107         data.add(new LDMasterData("", lang, ""));
108     } else {
109         String text = resources.getMessage(locale, prefix + key);
110 
111         if (text != null) {
112       data.add(new LDMasterData(key, lang, text));
113         }
114     }
115       }
116       // add master data for the actual language
117       getContainer().addMasterData(lang, data);
118   }
119 
120     }
121 
122     /**
123      * If {@link #getType()} returns <code>null</code> or is equal to
124      * <code>type</code>, the container with master data is
125      * returned. Otherwise, <code>null</code> will be returned.
126      *
127      * @param type master data type
128      * @return a master data container.
129      */
130     public IMasterDataContainer getMasterData(String type) {
131 
132   if (getType() == null) return (getContainer());
133 
134   if (type == null || (! type.equals(getType()))) return null;
135 
136   return (getContainer());
137     }
138 
139     
140     /**
141      * Get the value of type.
142      * @return value of type.
143      */
144     public String getType() {
145   return type;
146     }
147     
148     /**
149      * Set the value of type.
150      * @param v  Value to assign to type.
151      */
152     protected void setType(String  v) {
153   this.type = v;
154     }
155 
156 
157     /**
158      * Get the value of container.
159      * @return value of container.
160      */
161     protected LocalizedMasterDataContainer getContainer() {
162   return container;
163     }
164     
165     /**
166      * Set the value of container.
167      * @param v  Value to assign to container.
168      */
169     protected void setContainer(LocalizedMasterDataContainer  v) {
170   this.container = v;
171     }
172     
173     
174    
175 }// MRMasterDataSource