ResourceBundleProvider.java
01 /*
02  * Copyright 2008-2016 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
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 org.codehaus.griffon.runtime.util;
17 
18 import griffon.util.CompositeResourceBundleBuilder;
19 
20 import javax.annotation.Nonnull;
21 import javax.inject.Inject;
22 import javax.inject.Provider;
23 import java.util.ResourceBundle;
24 
25 import static griffon.util.GriffonNameUtils.requireNonBlank;
26 import static java.util.Objects.requireNonNull;
27 
28 /**
29  @author Andres Almiray
30  @since 2.0.0
31  */
32 public class ResourceBundleProvider implements Provider<ResourceBundle> {
33     private final String basename;
34 
35     private CompositeResourceBundleBuilder resourceBundleBuilder;
36 
37     public ResourceBundleProvider(@Nonnull String basename) {
38         this.basename = requireNonBlank(basename, "Argument 'basename' must not be blank");
39     }
40 
41     @Inject
42     public void setResourceBundleBuilder(@Nonnull CompositeResourceBundleBuilder resourceBundleBuilder) {
43         this.resourceBundleBuilder = requireNonNull(resourceBundleBuilder, "Argument 'resourceBundleBuilder' must not be null");
44     }
45 
46     @Override
47     public ResourceBundle get() {
48         return resourceBundleBuilder.create(basename);
49     }
50 }