01 /*
02 * Copyright 2009-2012 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
17 package org.codehaus.griffon.runtime.core;
18
19
20 import griffon.core.GriffonApplication;
21 import griffon.core.MVCGroup;
22 import griffon.core.MVCGroupConfiguration;
23
24 import java.util.Collections;
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27
28 /**
29 * Base implementation of the {@code MVCGroupConfiguration} interface
30 *
31 * @author Andres Almiray
32 * @since 0.9.4
33 */
34 public abstract class AbstractMVCGroupConfiguration implements MVCGroupConfiguration {
35 protected final Map<String, String> members = new LinkedHashMap<String, String>();
36 protected final Map<String, Object> config = new LinkedHashMap<String, Object>();
37 protected final String mvcType;
38 protected final GriffonApplication app;
39
40 public AbstractMVCGroupConfiguration(GriffonApplication app, String mvcType, Map<String, String> members, Map<String, Object> config) {
41 this.app = app;
42 this.mvcType = mvcType;
43 this.members.putAll(members);
44 this.config.putAll(config);
45 }
46
47 public final GriffonApplication getApp() {
48 return app;
49 }
50
51 public final String getMvcType() {
52 return mvcType;
53 }
54
55 public final Map<String, String> getMembers() {
56 return Collections.unmodifiableMap(members);
57 }
58
59 public final Map<String, Object> getConfig() {
60 return Collections.unmodifiableMap(config);
61 }
62
63 public final MVCGroup create() {
64 return create(null, Collections.<String, Object>emptyMap());
65 }
66
67 public final MVCGroup create(String mvcId) {
68 return create(mvcId, Collections.<String, Object>emptyMap());
69 }
70
71 public final MVCGroup create(Map<String, Object> args) {
72 return create(null, args);
73 }
74
75 public final MVCGroup create(String mvcId, Map<String, Object> args) {
76 return instantiateMVCGroup(mvcId, args);
77 }
78
79 protected abstract MVCGroup instantiateMVCGroup(String mvcId, Map<String, Object> args);
80
81 @Override
82 public String toString() {
83 return "MVCGroupConfiguration{" +
84 "mvcType='" + mvcType + '\'' +
85 ", members=" + members +
86 ", config=" + config +
87 '}';
88 }
89 }
|