001 /*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2008-2017 the original author or authors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.codehaus.griffon.runtime.groovy.view;
019
020 import griffon.util.BuilderCustomizer;
021 import groovy.lang.Closure;
022 import groovy.util.Factory;
023
024 import javax.annotation.Nonnull;
025 import javax.annotation.Nullable;
026 import java.util.ArrayList;
027 import java.util.LinkedHashMap;
028 import java.util.List;
029 import java.util.Map;
030
031 import static java.util.Collections.unmodifiableList;
032 import static java.util.Collections.unmodifiableMap;
033 import static java.util.Objects.requireNonNull;
034
035 /**
036 * @author Andres Almiray
037 * @since 2.0.0
038 */
039 @SuppressWarnings("rawtypes")
040 public class AbstractBuilderCustomizer implements BuilderCustomizer {
041 private final Map<String, Object> variables = new LinkedHashMap<>();
042 private final Map<String, Factory> factories = new LinkedHashMap<>();
043 private final Map<String, Closure> methods = new LinkedHashMap<>();
044 private final Map<String, Closure[]> props = new LinkedHashMap<>();
045 private final List<Closure> attributeDelegates = new ArrayList<>();
046 private final List<Closure> preInstantiateDelegates = new ArrayList<>();
047 private final List<Closure> postInstantiateDelegates = new ArrayList<>();
048 private final List<Closure> postNodeCompletionDelegates = new ArrayList<>();
049 private final List<Closure> disposalClosures = new ArrayList<>();
050 private Closure methodMissingDelegate;
051 private Closure propertyMissingDelegate;
052
053 @Nonnull
054 public Map<String, Object> getVariables() {
055 return unmodifiableMap(variables);
056 }
057
058 public void setVariables(@Nonnull Map<String, Object> variables) {
059 requireNonNull(variables, "Argument 'variables' must not be null");
060 this.variables.clear();
061 this.variables.putAll(variables);
062 }
063
064 @Nonnull
065 public Map<String, Factory> getFactories() {
066 return unmodifiableMap(factories);
067 }
068
069 public void setFactories(@Nonnull Map<String, Factory> factories) {
070 requireNonNull(factories, "Argument 'factories' must not be null");
071 this.factories.clear();
072 this.factories.putAll(factories);
073 }
074
075 @Nonnull
076 public Map<String, Closure> getMethods() {
077 return unmodifiableMap(methods);
078 }
079
080 public void setMethods(@Nonnull Map<String, Closure> methods) {
081 requireNonNull(methods, "Argument 'methods' must not be null");
082 this.methods.clear();
083 this.methods.putAll(methods);
084 }
085
086 @Nonnull
087 public Map<String, Closure[]> getProps() {
088 return unmodifiableMap(props);
089 }
090
091 public void setProps(@Nonnull Map<String, Closure[]> props) {
092 requireNonNull(props, "Argument 'props' must not be null");
093 this.props.clear();
094 this.props.putAll(props);
095 }
096
097 @Nonnull
098 public List<Closure> getAttributeDelegates() {
099 return unmodifiableList(attributeDelegates);
100 }
101
102 public void setAttributeDelegates(@Nonnull List<Closure> attributeDelegates) {
103 requireNonNull(attributeDelegates, "Argument 'attributeDelegates' must not be null");
104 this.attributeDelegates.clear();
105 this.attributeDelegates.addAll(attributeDelegates);
106 }
107
108 @Nonnull
109 public List<Closure> getPostInstantiateDelegates() {
110 return unmodifiableList(postInstantiateDelegates);
111 }
112
113 public void setPostInstantiateDelegates(@Nonnull List<Closure> postInstantiateDelegates) {
114 requireNonNull(postInstantiateDelegates, "Argument 'postInstantiateDelegates' must not be null");
115 this.postInstantiateDelegates.clear();
116 this.postInstantiateDelegates.addAll(postInstantiateDelegates);
117 }
118
119 @Nonnull
120 public List<Closure> getPostNodeCompletionDelegates() {
121 return unmodifiableList(postNodeCompletionDelegates);
122 }
123
124 public void setPostNodeCompletionDelegates(@Nonnull List<Closure> postNodeCompletionDelegates) {
125 requireNonNull(postNodeCompletionDelegates, "Argument 'postNodeCompletionDelegates' must not be null");
126 this.postNodeCompletionDelegates.clear();
127 this.postNodeCompletionDelegates.addAll(postNodeCompletionDelegates);
128 }
129
130 @Nonnull
131 public List<Closure> getPreInstantiateDelegates() {
132 return unmodifiableList(preInstantiateDelegates);
133 }
134
135 public void setPreInstantiateDelegates(@Nonnull List<Closure> preInstantiateDelegates) {
136 requireNonNull(preInstantiateDelegates, "Argument 'preInstantiateDelegates' must not be null");
137 this.preInstantiateDelegates.clear();
138 this.preInstantiateDelegates.addAll(preInstantiateDelegates);
139 }
140
141 @Nonnull
142 public List<Closure> getDisposalClosures() {
143 return unmodifiableList(disposalClosures);
144 }
145
146 public void setDisposalClosures(@Nonnull List<Closure> disposalClosures) {
147 requireNonNull(disposalClosures, "Argument 'disposalClosures' must not be null");
148 this.disposalClosures.clear();
149 this.disposalClosures.addAll(disposalClosures);
150 }
151
152 @Nullable
153 public Closure getMethodMissingDelegate() {
154 return methodMissingDelegate;
155 }
156
157 public void setMethodMissingDelegate(@Nullable Closure methodMissingDelegate) {
158 this.methodMissingDelegate = methodMissingDelegate;
159 }
160
161 @Nullable
162 public Closure getPropertyMissingDelegate() {
163 return propertyMissingDelegate;
164 }
165
166 public void setPropertyMissingDelegate(@Nullable Closure propertyMissingDelegate) {
167 this.propertyMissingDelegate = propertyMissingDelegate;
168 }
169 }
|