DefaultGroovyAwareResourceResolver.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.groovy.resources;
17 
18 import griffon.core.resources.GroovyAwareResourceResolver;
19 import griffon.core.resources.NoSuchResourceException;
20 import griffon.core.resources.ResourceResolver;
21 import org.codehaus.griffon.runtime.core.resources.ResourceResolverDecorator;
22 
23 import javax.annotation.Nonnull;
24 import java.util.ArrayList;
25 import java.util.List;
26 
27 import static griffon.util.GriffonClassUtils.requireNonEmpty;
28 
29 /**
30  @author Andres Almiray
31  @since 2.4.0
32  */
33 public class DefaultGroovyAwareResourceResolver extends ResourceResolverDecorator implements GroovyAwareResourceResolver {
34     public DefaultGroovyAwareResourceResolver(@Nonnull ResourceResolver delegate) {
35         super(delegate);
36     }
37 
38     @Nonnull
39     @Override
40     public Object getAt(@Nonnull String keythrows NoSuchResourceException {
41         return resolveResource(key);
42     }
43 
44     @Nonnull
45     @Override
46     public Object getAt(@Nonnull List<?> keyAndArgsthrows NoSuchResourceException {
47         requireNonEmpty(keyAndArgs, "Argument 'keyAndArgs' must not be null");
48         String key = String.valueOf(keyAndArgs.get(0));
49         List<Object> args = new ArrayList<>();
50         if (keyAndArgs.size() 1) {
51             args.addAll(keyAndArgs.subList(1, keyAndArgs.size()));
52         }
53         return resolveResource(key, args);
54     }
55 }