01 /*
02 * SPDX-License-Identifier: Apache-2.0
03 *
04 * Copyright 2008-2017 the original author or authors.
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.codehaus.griffon.runtime.core.configuration;
19
20 import javax.annotation.Nonnull;
21 import javax.annotation.Nullable;
22 import java.beans.PropertyEditor;
23 import java.lang.reflect.Method;
24
25 import static java.util.Objects.requireNonNull;
26
27 /**
28 * @author Andres Almiray
29 * @since 2.11.0
30 */
31 public class MethodConfigurationDescriptor extends ConfigurationDescriptor {
32 private final Method writeMethod;
33
34 public MethodConfigurationDescriptor(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class<? extends PropertyEditor> editor) {
35 super(configuration, key, defaultValue, format, editor);
36 this.writeMethod = requireNonNull(writeMethod, "Argument 'writeMethod' must not be null");
37 }
38
39 @Nonnull
40 public Method getWriteMethod() {
41 return writeMethod;
42 }
43
44 @Nonnull
45 public InjectionPoint asInjectionPoint() {
46 return new MethodInjectionPoint(writeMethod, getConfiguration(), getKey(), getFormat(), getEditor());
47 }
48
49 @Override
50 public String toString() {
51 final StringBuilder sb = new StringBuilder("MethodPreferenceDescriptor{");
52 sb.append("writeMethod=").append(writeMethod);
53 sb.append(", configuration='").append(getConfiguration()).append('\'');
54 sb.append(", key='").append(getKey()).append('\'');
55 sb.append(", defaultValue='").append(getDefaultValue()).append('\'');
56 sb.append(", format='").append(getFormat()).append('\'');
57 sb.append(", editor='").append(getEditor()).append('\'');
58 sb.append('}');
59 return sb.toString();
60 }
61 }
|