001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017import static org.apache.juneau.internal.ArrayUtils.*; 018 019import java.lang.annotation.*; 020import java.lang.reflect.*; 021 022import org.apache.juneau.*; 023import org.apache.juneau.reflect.*; 024import org.apache.juneau.svl.*; 025 026/** 027 * Utility classes and methods for the {@link NameProperty @NameProperty} annotation. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * </ul> 031 */ 032public class NamePropertyAnnotation { 033 034 //----------------------------------------------------------------------------------------------------------------- 035 // Static 036 //----------------------------------------------------------------------------------------------------------------- 037 038 /** Default value */ 039 public static final NameProperty DEFAULT = create().build(); 040 041 /** 042 * Instantiates a new builder for this class. 043 * 044 * @return A new builder object. 045 */ 046 public static Builder create() { 047 return new Builder(); 048 } 049 050 /** 051 * Instantiates a new builder for this class. 052 * 053 * @param on The targets this annotation applies to. 054 * @return A new builder object. 055 */ 056 public static Builder create(String...on) { 057 return create().on(on); 058 } 059 060 /** 061 * Creates a copy of the specified annotation. 062 * 063 * @param a The annotation to copy.s 064 * @param r The var resolver for resolving any variables. 065 * @return A copy of the specified annotation. 066 */ 067 public static NameProperty copy(NameProperty a, VarResolverSession r) { 068 return 069 create() 070 .on(r.resolve(a.on())) 071 .build(); 072 } 073 074 //----------------------------------------------------------------------------------------------------------------- 075 // Builder 076 //----------------------------------------------------------------------------------------------------------------- 077 078 /** 079 * Builder class. 080 * 081 * <h5 class='section'>See Also:</h5><ul> 082 * <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)} 083 * </ul> 084 */ 085 public static class Builder extends TargetedAnnotationMFBuilder { 086 087 /** 088 * Constructor. 089 */ 090 protected Builder() { 091 super(NameProperty.class); 092 } 093 094 /** 095 * Instantiates a new {@link NameProperty @NameProperty} object initialized with this builder. 096 * 097 * @return A new {@link NameProperty @NameProperty} object. 098 */ 099 public NameProperty build() { 100 return new Impl(this); 101 } 102 103 // <FluentSetters> 104 105 @Override /* GENERATED - TargetedAnnotationBuilder */ 106 public Builder on(String...values) { 107 super.on(values); 108 return this; 109 } 110 111 @Override /* GENERATED - TargetedAnnotationMFBuilder */ 112 public Builder on(Field...value) { 113 super.on(value); 114 return this; 115 } 116 117 @Override /* GENERATED - TargetedAnnotationMFBuilder */ 118 public Builder on(Method...value) { 119 super.on(value); 120 return this; 121 } 122 123 // </FluentSetters> 124 } 125 126 //----------------------------------------------------------------------------------------------------------------- 127 // Implementation 128 //----------------------------------------------------------------------------------------------------------------- 129 130 private static class Impl extends TargetedAnnotationImpl implements NameProperty { 131 132 Impl(Builder b) { 133 super(b); 134 postConstruct(); 135 } 136 } 137 138 //----------------------------------------------------------------------------------------------------------------- 139 // Appliers 140 //----------------------------------------------------------------------------------------------------------------- 141 142 /** 143 * Applies targeted {@link NameProperty} annotations to a {@link org.apache.juneau.BeanContext.Builder}. 144 */ 145 public static class Applier extends AnnotationApplier<NameProperty,BeanContext.Builder> { 146 147 /** 148 * Constructor. 149 * 150 * @param vr The resolver for resolving values in annotations. 151 */ 152 public Applier(VarResolverSession vr) { 153 super(NameProperty.class, BeanContext.Builder.class, vr); 154 } 155 156 @Override 157 public void apply(AnnotationInfo<NameProperty> ai, BeanContext.Builder b) { 158 NameProperty a = ai.inner(); 159 if (isEmptyArray(a.on())) 160 return; 161 b.annotations(copy(a, vr())); 162 } 163 } 164 165 //----------------------------------------------------------------------------------------------------------------- 166 // Other 167 //----------------------------------------------------------------------------------------------------------------- 168 169 /** 170 * A collection of {@link NameProperty @NameProperty annotations}. 171 */ 172 @Documented 173 @Target({METHOD,TYPE}) 174 @Retention(RUNTIME) 175 @Inherited 176 public static @interface Array { 177 178 /** 179 * The child annotations. 180 * 181 * @return The annotation value. 182 */ 183 NameProperty[] value(); 184 } 185}