AliasedMetaComponentFactory.groovy
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 griffon.builder.core.factory
17 
18 /**
19  * Enables MVC groups to be used as component nodes
20  *
21  @author Andres Almiray
22  @author Alexander Klein
23  */
24 @SuppressWarnings("rawtypes")
25 class AliasedMetaComponentFactory extends MetaComponentFactory {
26     final String mvcType
27     final Map<String, Object> attributes = [:]
28 
29     AliasedMetaComponentFactory(String mvcType, Map<String, Object> attributes = [:]) {
30         this.mvcType = mvcType
31         this.attributes.putAll(attributes ?: [:])
32     }
33 
34     @Override
35     boolean isLeaf() {
36         return true
37     }
38 
39     @Override
40     protected Map resolveAttributes(Map attributes) {
41         println this.attributes
42         println attributes
43         Map defaultMvcArgs = this.attributes.mvcArgs ?: [:]
44         Map mvcArgs = attributes.mvcArgs ?: [:]
45         Map attrs = [:]
46         attrs.putAll(this.attributes)
47         attrs.putAll(attributes)
48         Map args = [:]
49         args.putAll(defaultMvcArgs)
50         args.putAll(mvcArgs)
51         attrs.mvcArgs = args
52         return attrs
53     }
54 
55     @Override
56     protected String resolveMvcId(Object name, Object value, Map attributes) {
57         return attributes.containsKey('mvcId') ? attributes.remove('mvcId') : mvcType
58     }
59 }