KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > facade > LocalizationFacade


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23
24 package org.mdarad.framework.facade;
25
26 import org.dataisland.primitives.bean.Localizable;
27 import org.dataisland.primitives.bean.LocalizationContext;
28 import org.dataisland.primitives.exception.LocalizationContextNotFoundException;
29 import org.dataisland.primitives.exception.LocalizationException;
30 import org.dataisland.primitives.util.Keys;
31 import org.dataisland.primitives.util.LocalizationUtils;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.Collection JavaDoc;
35 import java.util.List JavaDoc;
36
37 /**
38  * Created by IntelliJ IDEA.
39  * User: voarsenault
40  * Date: Jun 8, 2004
41  * Time: 1:22:51 PM
42  * To change this template use File | Settings | File Templates.
43  */

44 public class LocalizationFacade {
45     private static LocalizationFacade instance = null;
46
47     private LocalizationFacade() {
48     }
49
50     static public LocalizationFacade getInstance() {
51         if (instance == null) instance = new LocalizationFacade();
52         return instance;
53     }
54
55
56     /**
57      * This method localize a Collection of LocalizableObject given a LocalizationContext and a LocalizationContext humanReadableKey <br />
58      *
59      * @param localizableObjectCollection The Collection of LocalizableObject
60      * @param clientLocalizationContext The LocalizationContext
61      * @param humanReadableKey The LocalizationContext humanReadableKey
62      * @return
63      */

64     public Collection JavaDoc localize(Collection JavaDoc localizableObjectCollection, LocalizationContext clientLocalizationContext, String JavaDoc humanReadableKey) throws LocalizationException {
65         org.dataisland.primitives.bean.LocalizationContext localizationContext = buildLocalizationContext(clientLocalizationContext, humanReadableKey);
66         LocalizationUtils.localize(localizableObjectCollection, localizationContext);
67         return localizableObjectCollection;
68     }
69
70     /**
71      * @param clientLocalizationContext
72      * @param humanReadableKey
73      * @return
74      * @throws LocalizationException
75      */

76     public org.dataisland.primitives.bean.LocalizationContext buildLocalizationContext(LocalizationContext clientLocalizationContext, String JavaDoc humanReadableKey) throws LocalizationException {
77         org.dataisland.primitives.bean.LocalizationContext lOutput = null;
78         org.dataisland.primitives.bean.LocalizationContext webLocalizationContext = null;
79         org.dataisland.primitives.bean.LocalizationContext systemLocalizationContext = null;
80
81         try {
82             webLocalizationContext = LocalizationContextDAO.getInstance().fetchLocalizationContextByHumanReadableKey(humanReadableKey);
83         } catch (LocalizationContextNotFoundException lcnfe) {
84             throw new LocalizationException("Could not find the web context localization context.", lcnfe);
85         }
86
87         systemLocalizationContext = getSystemLocalizationContext();
88         List JavaDoc localizationContextList = new ArrayList JavaDoc(3);
89         localizationContextList.add(clientLocalizationContext);
90         localizationContextList.add(webLocalizationContext);
91         localizationContextList.add(systemLocalizationContext);
92
93         lOutput = org.dataisland.primitives.bean.LocalizationContext.merge(localizationContextList);
94
95         return lOutput;
96     }
97
98     public org.dataisland.primitives.bean.LocalizationContext getSystemLocalizationContext() throws LocalizationException {
99         LocalizationContext lOutput = null;
100
101         try {
102             lOutput = LocalizationContextDAO.getInstance().fetchLocalizationContextByHumanReadableKey(Keys.SYSTEMLOCALIZATIONCONTEXTHUMANREADABLEKEY_KEY);
103         } catch (org.dataisland.primitives.exception.LocalizationContextNotFoundException lcnfe) {
104             throw new LocalizationException("Could not find the system localization context.", lcnfe);
105         }
106
107         return lOutput;
108     }
109
110     /**
111      * This method localize a LocalizableObject given a LocalizationContext and a LocalizationContext humanReadableKey <br />
112      *
113      * @param localizableObject The LocalizableObject
114      * @param clientLocalizationContext A LocalizationContext
115      * @param humanReadableKey A LocalizationContext humanReadableKey
116      * @return
117      */

118     public Localizable localize(Localizable localizableObject, org.dataisland.primitives.bean.LocalizationContext clientLocalizationContext, String JavaDoc humanReadableKey) throws LocalizationException {
119         org.dataisland.primitives.bean.LocalizationContext entityLocalizationContext = buildLocalizationContext(clientLocalizationContext, humanReadableKey);
120         org.dataisland.primitives.util.LocalizationUtils.localize(localizableObject, entityLocalizationContext);
121         return localizableObject;
122     }
123 }
124
Popular Tags