001: /*
002: * Message.java
003: *
004: * Version: $Revision: 1.3 $
005: *
006: * Date: $Date: 2006/06/02 21:48:19 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.xmlui.wing;
041:
042: /**
043: *
044: * This class represents an i18n message, which is composed of three parts: a
045: * catalogue, a key, and a set of dictionary parameters. The catalogue tells
046: * the translater where to find the key, the key tells the transformer which
047: * specific text should be used, and the parameters provide for non translated
048: * data to be inserted into the resulting string.
049: *
050: * This class design such that the Message object can be made static my any
051: * class that needs to use it. If dicionary parameters are used then a new
052: * instance is created specificaly for those parameters, this prevents
053: * concurent threads from over writting parameters of each other.
054: *
055: * @author Scott Phillips
056: */
057:
058: public class Message {
059: /** What catalogue this key is to be found in. */
060: protected final String catalogue;
061:
062: /** The key to look up in the catalogue. */
063: protected final String key;
064:
065: /**
066: * Create a new translatable element.
067: *
068: * @param catalogue
069: * The catalogue were this key is to be found.
070: * @param key
071: * The key to look up in the catalogue.
072: */
073: public Message(String catalogue, String key) {
074: this .catalogue = catalogue;
075: this .key = key;
076: }
077:
078: /**
079: *
080: * @return The catalogue this key is to be found in.
081: */
082: public String getCatalogue() {
083: return this .catalogue;
084: }
085:
086: /**
087: *
088: * @return The key to look-up in the catalogue.
089: */
090: public String getKey() {
091: return this .key;
092: }
093:
094: /**
095: *
096: * Parameterize this translate key by specifying
097: * dictionary parameters. This will not modify the
098: * current translate object but instead create a
099: * cloned copy that has been parameterized.
100: *
101: * @param object The dictionary parameters
102: */
103: public Message parameterize(Object... dictionaryParameters) {
104: return new ParameterizedMessage(catalogue, key,
105: dictionaryParameters);
106: }
107:
108: /**
109: * Return any dictionary parameters that are used by this
110: * translation message.
111: *
112: * Since this is the basic implementation it does not support
113: * parameters we just return an empty array.
114: *
115: * @return Any parameters to the catalogue key
116: */
117: public Object[] getDictionaryParameters() {
118: return new Object[0];
119: }
120:
121: /**
122: *
123: * Specialized translate class that handles parameterized messages.
124: * Parameterized messages contain a catalogue and key like normal but
125: * also add the ability for extra parameters to be added to the
126: * message. These parameters are inserted into the final translated
127: * string based upon the key's definition.
128: *
129: * No one out side of this class should even know this class exists,
130: * hence the privacy, but haveing two implementations allows us to
131: * sepearete all the functionality for paramaterization into this
132: * one place. Since most of the messages used are unparameterized
133: * this is not wasted on them and is only invoked when needed. There
134: * may be some performance increase by doing this but i doubt it is
135: * of much consequence, instead the main reason is to be able to create
136: * a new instance when messages are parameterized so that concurrent
137: * threads do not step on each other.
138: *
139: */
140: private static class ParameterizedMessage extends Message {
141: /**
142: * Parameters to the dictionary key, they may be filled into places in the
143: * final translated version
144: */
145: private final Object[] dictionaryParameters;
146:
147: /**
148: * Create a new translatable element.
149: *
150: * @param catalogue
151: * The catalogue were this key is to be found.
152: * @param key
153: * The key to look up in the catalogue.
154: */
155: public ParameterizedMessage(String catalogue, String key,
156: Object... dictionaryParameters) {
157: super (catalogue, key);
158: this .dictionaryParameters = dictionaryParameters;
159: }
160:
161: /**
162: * Return the dicionary parameters for this message.
163: *
164: * @return Any parameters to the catalogue key
165: */
166: public Object[] getDictionaryParameters() {
167: return dictionaryParameters;
168: }
169: }
170:
171: }
|