01 /*
02 * Copyright 2008-2014 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.core.resources;
17
18 import griffon.core.resources.ResourceResolver;
19 import griffon.util.CompositeResourceBundleBuilder;
20
21 import javax.annotation.Nonnull;
22 import javax.inject.Inject;
23 import javax.inject.Provider;
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 ResourceResolverProvider implements Provider<ResourceResolver> {
33 private final String basename;
34
35 private CompositeResourceBundleBuilder resourceBundleBuilder;
36
37 public ResourceResolverProvider(@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 ResourceResolver get() {
48 return new DefaultResourceResolver(resourceBundleBuilder, basename);
49 }
50 }
|