Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CoreUtils |
|
| 1.0;1 |
1 | package org.jtheque.core.utils; | |
2 | ||
3 | import org.jtheque.core.managers.Managers; | |
4 | import org.jtheque.core.managers.beans.IBeansManager; | |
5 | import org.jtheque.core.managers.language.ILanguageManager; | |
6 | import org.jtheque.core.managers.log.IJThequeLogger; | |
7 | import org.jtheque.core.managers.log.ILoggingManager; | |
8 | import org.jtheque.core.managers.view.able.IMainView; | |
9 | import org.jtheque.core.managers.view.able.IViewManager; | |
10 | ||
11 | /* | |
12 | * This file is part of JTheque. | |
13 | * | |
14 | * JTheque is free software: you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License as published by | |
16 | * the Free Software Foundation, either version 3 of the License. | |
17 | * | |
18 | * JTheque is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | * GNU General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
25 | */ | |
26 | ||
27 | /** | |
28 | * Utility class for the most used methods of the Core. | |
29 | * | |
30 | * @author Baptiste Wicht | |
31 | */ | |
32 | public final class CoreUtils { | |
33 | /** | |
34 | * Utility class, not instanciable. | |
35 | */ | |
36 | private CoreUtils(){ | |
37 | 0 | super(); |
38 | 0 | } |
39 | ||
40 | /** | |
41 | * Return the bean with a specific name. | |
42 | * | |
43 | * @param name The name of the bean. | |
44 | * @return The bean. | |
45 | */ | |
46 | public static <T> T getBean(String name){ | |
47 | 0 | return Managers.getManager(IBeansManager.class).<T>getBean(name); |
48 | } | |
49 | ||
50 | /** | |
51 | * Return the main view. | |
52 | * | |
53 | * @return the main view. | |
54 | */ | |
55 | public static IMainView getMainView(){ | |
56 | 0 | return getView().getViews().getMainView(); |
57 | } | |
58 | ||
59 | /** | |
60 | * Return the view manager. | |
61 | * | |
62 | * @return The view manager. | |
63 | */ | |
64 | public static IViewManager getView(){ | |
65 | 0 | return Managers.getManager(IViewManager.class); |
66 | } | |
67 | ||
68 | /** | |
69 | * Return the logger for a class. | |
70 | * | |
71 | * @param classz The class for which we want the logger. | |
72 | * | |
73 | * @return The appropriate logger. | |
74 | */ | |
75 | public static IJThequeLogger getLogger(Class<?> classz){ | |
76 | 0 | return Managers.getManager(ILoggingManager.class).getLogger(classz); |
77 | } | |
78 | ||
79 | /** | |
80 | * Return the message of the key. If there is no message with this key, the method return the key and | |
81 | * log the message to the log system. | |
82 | * | |
83 | * @param key The message key. | |
84 | * | |
85 | * @return The message of the key of the current locale, empty string if the key is <code>null</code> else | |
86 | * the key if there is no message for this key. | |
87 | */ | |
88 | public static String getMessage(String key){ | |
89 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(key); |
90 | } | |
91 | ||
92 | /** | |
93 | * Return the message of the key and effect the replaces. | |
94 | * | |
95 | * @param key The message key. | |
96 | * @param replaces The replacements. | |
97 | * @return The message of the current locale with the replacements. | |
98 | */ | |
99 | public static String getMessage(String key, Object... replaces){ | |
100 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(key, replaces); |
101 | } | |
102 | } |