001: /*
002: Mdarad-Toolobox is a collection of tools for Architected RAD
003: (Rapid Application Development) based on an MDA approach.
004: The toolbox contains frameworks and generators for many environments
005: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
006: applications from a design Model
007: Copyright (C) 2004-2005 Elapse Technologies Inc.
008:
009: This library is free software; you can redistribute it and/or
010: modify it under the terms of the GNU General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: General Public License for more details.
018:
019: You should have received a copy of the GNU General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023:
024: package org.mdarad.framework.facade;
025:
026: import org.dataisland.primitives.bean.Localizable;
027: import org.dataisland.primitives.bean.LocalizationContext;
028: import org.dataisland.primitives.exception.LocalizationContextNotFoundException;
029: import org.dataisland.primitives.exception.LocalizationException;
030: import org.dataisland.primitives.util.Keys;
031: import org.dataisland.primitives.util.LocalizationUtils;
032:
033: import java.util.ArrayList;
034: import java.util.Collection;
035: import java.util.List;
036:
037: /**
038: * Created by IntelliJ IDEA.
039: * User: voarsenault
040: * Date: Jun 8, 2004
041: * Time: 1:22:51 PM
042: * To change this template use File | Settings | File Templates.
043: */
044: public class LocalizationFacade {
045: private static LocalizationFacade instance = null;
046:
047: private LocalizationFacade() {
048: }
049:
050: static public LocalizationFacade getInstance() {
051: if (instance == null)
052: instance = new LocalizationFacade();
053: return instance;
054: }
055:
056: /**
057: * This method localize a Collection of LocalizableObject given a LocalizationContext and a LocalizationContext humanReadableKey <br />
058: *
059: * @param localizableObjectCollection The Collection of LocalizableObject
060: * @param clientLocalizationContext The LocalizationContext
061: * @param humanReadableKey The LocalizationContext humanReadableKey
062: * @return
063: */
064: public Collection localize(Collection localizableObjectCollection,
065: LocalizationContext clientLocalizationContext,
066: String humanReadableKey) throws LocalizationException {
067: org.dataisland.primitives.bean.LocalizationContext localizationContext = buildLocalizationContext(
068: clientLocalizationContext, humanReadableKey);
069: LocalizationUtils.localize(localizableObjectCollection,
070: localizationContext);
071: return localizableObjectCollection;
072: }
073:
074: /**
075: * @param clientLocalizationContext
076: * @param humanReadableKey
077: * @return
078: * @throws LocalizationException
079: */
080: public org.dataisland.primitives.bean.LocalizationContext buildLocalizationContext(
081: LocalizationContext clientLocalizationContext,
082: String humanReadableKey) throws LocalizationException {
083: org.dataisland.primitives.bean.LocalizationContext lOutput = null;
084: org.dataisland.primitives.bean.LocalizationContext webLocalizationContext = null;
085: org.dataisland.primitives.bean.LocalizationContext systemLocalizationContext = null;
086:
087: try {
088: webLocalizationContext = LocalizationContextDAO
089: .getInstance()
090: .fetchLocalizationContextByHumanReadableKey(
091: humanReadableKey);
092: } catch (LocalizationContextNotFoundException lcnfe) {
093: throw new LocalizationException(
094: "Could not find the web context localization context.",
095: lcnfe);
096: }
097:
098: systemLocalizationContext = getSystemLocalizationContext();
099: List localizationContextList = new ArrayList(3);
100: localizationContextList.add(clientLocalizationContext);
101: localizationContextList.add(webLocalizationContext);
102: localizationContextList.add(systemLocalizationContext);
103:
104: lOutput = org.dataisland.primitives.bean.LocalizationContext
105: .merge(localizationContextList);
106:
107: return lOutput;
108: }
109:
110: public org.dataisland.primitives.bean.LocalizationContext getSystemLocalizationContext()
111: throws LocalizationException {
112: LocalizationContext lOutput = null;
113:
114: try {
115: lOutput = LocalizationContextDAO
116: .getInstance()
117: .fetchLocalizationContextByHumanReadableKey(
118: Keys.SYSTEMLOCALIZATIONCONTEXTHUMANREADABLEKEY_KEY);
119: } catch (org.dataisland.primitives.exception.LocalizationContextNotFoundException lcnfe) {
120: throw new LocalizationException(
121: "Could not find the system localization context.",
122: lcnfe);
123: }
124:
125: return lOutput;
126: }
127:
128: /**
129: * This method localize a LocalizableObject given a LocalizationContext and a LocalizationContext humanReadableKey <br />
130: *
131: * @param localizableObject The LocalizableObject
132: * @param clientLocalizationContext A LocalizationContext
133: * @param humanReadableKey A LocalizationContext humanReadableKey
134: * @return
135: */
136: public Localizable localize(
137: Localizable localizableObject,
138: org.dataisland.primitives.bean.LocalizationContext clientLocalizationContext,
139: String humanReadableKey) throws LocalizationException {
140: org.dataisland.primitives.bean.LocalizationContext entityLocalizationContext = buildLocalizationContext(
141: clientLocalizationContext, humanReadableKey);
142: org.dataisland.primitives.util.LocalizationUtils.localize(
143: localizableObject, entityLocalizationContext);
144: return localizableObject;
145: }
146: }
|