Commit 26aeb858c520ab44a3c018745414d5275148d18d
1 parent
1d5ee70b
Exists in
master
Injeção de ResourceBundle utilizando o ClassLoader correto. Não é
necessário fazer cache do ResourceBundle, pois a implementação padrão já se encarrega disto. Bug relatado no tracker: http://sourceforge.net/apps/mantisbt/demoiselle/view.php?id=782
Showing
3 changed files
with
22 additions
and
54 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrap.java
... | ... | @@ -36,6 +36,8 @@ |
36 | 36 | */ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | +import java.util.Locale; | |
40 | + | |
39 | 41 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
40 | 42 | import javax.enterprise.inject.spi.Extension; |
41 | 43 | |
... | ... | @@ -56,7 +58,7 @@ public class AbstractBootstrap implements Extension { |
56 | 58 | } |
57 | 59 | |
58 | 60 | protected static ResourceBundle getBundle(String baseName) { |
59 | - return bundleFactory.create(baseName); | |
61 | + return bundleFactory.create(baseName, Locale.getDefault()); | |
60 | 62 | } |
61 | 63 | |
62 | 64 | protected static Logger getLogger() { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/processor/AbstractProcessor.java
... | ... | @@ -36,6 +36,8 @@ |
36 | 36 | */ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.processor; |
38 | 38 | |
39 | +import java.util.Locale; | |
40 | + | |
39 | 41 | import javax.enterprise.inject.spi.AnnotatedCallable; |
40 | 42 | import javax.enterprise.inject.spi.Bean; |
41 | 43 | import javax.enterprise.inject.spi.BeanManager; |
... | ... | @@ -106,8 +108,10 @@ public abstract class AbstractProcessor<DC> implements Processor { |
106 | 108 | } |
107 | 109 | |
108 | 110 | protected ResourceBundle getBundle(String baseName) { |
109 | - if (bundle == null) | |
110 | - bundle = bundleFactory.create(baseName); | |
111 | + if (bundle == null) { | |
112 | + bundle = bundleFactory.create(baseName, Locale.getDefault()); | |
113 | + } | |
114 | + | |
111 | 115 | return bundle; |
112 | 116 | } |
113 | 117 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
... | ... | @@ -37,16 +37,12 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
38 | 38 | |
39 | 39 | import java.io.Serializable; |
40 | -import java.util.HashMap; | |
41 | 40 | import java.util.Locale; |
42 | -import java.util.Map; | |
43 | 41 | import java.util.MissingResourceException; |
44 | 42 | |
45 | -import javax.enterprise.context.ApplicationScoped; | |
46 | 43 | import javax.enterprise.inject.Default; |
47 | 44 | import javax.enterprise.inject.Produces; |
48 | 45 | import javax.enterprise.inject.spi.InjectionPoint; |
49 | -import javax.inject.Inject; | |
50 | 46 | |
51 | 47 | import br.gov.frameworkdemoiselle.DemoiselleException; |
52 | 48 | import br.gov.frameworkdemoiselle.annotation.Name; |
... | ... | @@ -57,38 +53,28 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
57 | 53 | * |
58 | 54 | * @author SERPRO |
59 | 55 | */ |
60 | -@ApplicationScoped | |
61 | 56 | public class ResourceBundleProducer implements Serializable { |
62 | 57 | |
63 | 58 | private static final long serialVersionUID = 1L; |
64 | 59 | |
65 | - @Inject | |
66 | - protected Locale locale; | |
67 | - | |
68 | - private final Map<String, ResourceBundle> map = new HashMap<String, ResourceBundle>(); | |
69 | - | |
70 | - public ResourceBundleProducer() { | |
71 | - this.locale = Locale.getDefault(); | |
72 | - } | |
73 | - | |
74 | - /** | |
75 | - * This constructor should be used by classes that can not inject ResourceBundle. | |
76 | - * | |
77 | - * @param Locale | |
78 | - * locale | |
79 | - */ | |
80 | - public ResourceBundleProducer(Locale locale) { | |
81 | - this.locale = locale; | |
82 | - } | |
83 | - | |
84 | 60 | /** |
85 | 61 | * This method should be used by classes that can not inject ResourceBundle, to create the ResourceBundle. |
86 | 62 | * |
87 | 63 | * @param String |
88 | 64 | * baseName |
89 | 65 | */ |
90 | - public ResourceBundle create(String baseName) { | |
91 | - return getResourceBundle(baseName); | |
66 | + public ResourceBundle create(String baseName, Locale locale) { | |
67 | + ResourceBundle bundle = null; | |
68 | + | |
69 | + try { | |
70 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
71 | + bundle = new ResourceBundle(ResourceBundle.getBundle(baseName, locale, classLoader)); | |
72 | + | |
73 | + } catch (MissingResourceException e) { | |
74 | + throw new DemoiselleException("File " + baseName + " not found!"); | |
75 | + } | |
76 | + | |
77 | + return bundle; | |
92 | 78 | } |
93 | 79 | |
94 | 80 | /** |
... | ... | @@ -98,7 +84,6 @@ public class ResourceBundleProducer implements Serializable { |
98 | 84 | @Produces |
99 | 85 | @Default |
100 | 86 | public ResourceBundle create(InjectionPoint ip, Locale locale) { |
101 | - this.locale = locale; | |
102 | 87 | String baseName; |
103 | 88 | |
104 | 89 | if (ip != null && ip.getAnnotated().isAnnotationPresent(Name.class)) { |
... | ... | @@ -107,29 +92,6 @@ public class ResourceBundleProducer implements Serializable { |
107 | 92 | baseName = "messages"; |
108 | 93 | } |
109 | 94 | |
110 | - return create(baseName); | |
95 | + return create(baseName, locale); | |
111 | 96 | } |
112 | - | |
113 | - /** | |
114 | - * This method checks if the bundle was created already. If the bundle has not been created, it creates and saves | |
115 | - * the bundle on a Map. | |
116 | - */ | |
117 | - private ResourceBundle getResourceBundle(String baseName) { | |
118 | - ResourceBundle bundle = null; | |
119 | - | |
120 | - if (map.containsKey(baseName + "-" + this.locale)) { | |
121 | - bundle = map.get(baseName + "-" + this.locale); | |
122 | - | |
123 | - } else { | |
124 | - try { | |
125 | - bundle = new ResourceBundle(ResourceBundle.getBundle(baseName, this.locale)); | |
126 | - } catch (MissingResourceException e) { | |
127 | - throw new DemoiselleException("File " + baseName + " not found!"); | |
128 | - } | |
129 | - map.put(baseName + "-" + this.locale, bundle); | |
130 | - } | |
131 | - | |
132 | - return bundle; | |
133 | - } | |
134 | - | |
135 | 97 | } | ... | ... |