View Javadoc

1   /*
2    * Copyright 2007-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.exceptions.i18n;
17  
18  import java.util.Locale;
19  import java.util.ResourceBundle;
20  
21  import de.smartics.exceptions.i18n.message.MessageType;
22  
23  /**
24   * The message composer creates messages from message templates by replacing the
25   * place holders with localized parameter values.
26   */
27  public interface MessageComposer
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    // ****************************** Inner Classes *****************************
34  
35    // ********************************* Methods ********************************
36  
37    // --- get&set --------------------------------------------------------------
38  
39    // --- business -------------------------------------------------------------
40  
41    /**
42     * Creates the message from the message template.
43     *
44     * @param bean the instance with the values for the message template's
45     *          parameters.
46     * @param locale the locale to use to format the arguments within the
47     *          template.
48     * @param bundle the resource bundle to fetch the message from.
49     * @param keyPrefix the prefix to the key to fetch the message from the
50     *          bundle. The suffix is provided by the message type.
51     * @param messageType the type of message to format. This allows to access the
52     *          correct index of the exception's value within the template.
53     * @return the message constructed from the template and the exception's
54     *         member values.
55     * @throws NullPointerException if {@code messageType} is <code>null</code>.
56     * @throws IllegalArgumentException if {@code messageType} is blank.
57     */
58    String composeMessage(Object bean, Locale locale, ResourceBundle bundle,
59        String keyPrefix, MessageType messageType) throws NullPointerException,
60      IllegalArgumentException;
61  
62    // --- object basics --------------------------------------------------------
63  }