01 /*
02 * Copyright 2008-2017 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.core.configuration;
17
18 import javax.annotation.Nonnull;
19 import java.lang.reflect.Method;
20
21 import static java.util.Objects.requireNonNull;
22
23 /**
24 * @author Andres Almiray
25 * @since 2.11.0
26 */
27 public class MethodConfigurationDescriptor extends ConfigurationDescriptor {
28 private final Method writeMethod;
29
30 public MethodConfigurationDescriptor(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nonnull String defaultValue, @Nonnull String format) {
31 super(configuration, key, defaultValue, format);
32 this.writeMethod = requireNonNull(writeMethod, "Argument 'writeMethod' must not be null");
33 }
34
35 @Nonnull
36 public Method getWriteMethod() {
37 return writeMethod;
38 }
39
40 @Nonnull
41 public InjectionPoint asInjectionPoint() {
42 return new MethodInjectionPoint(writeMethod, getConfiguration(), getKey(), getFormat());
43 }
44
45 @Override
46 public String toString() {
47 final StringBuilder sb = new StringBuilder("MethodPreferenceDescriptor{");
48 sb.append("writeMethod=").append(writeMethod);
49 sb.append(", configuration='").append(getConfiguration()).append('\'');
50 sb.append(", key='").append(getKey()).append('\'');
51 sb.append(", defaultValue='").append(getDefaultValue()).append('\'');
52 sb.append(", format='").append(getFormat()).append('\'');
53 sb.append('}');
54 return sb.toString();
55 }
56 }
|