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.uon.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.annotation.*; 024import org.apache.juneau.reflect.*; 025import org.apache.juneau.svl.*; 026 027/** 028 * Utility classes and methods for the {@link Uon @Uon} annotation. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="../../../../../index.html#jm.UonDetails">UON Details</a> 032 * </ul> 033 */ 034public class UonAnnotation { 035 036 //----------------------------------------------------------------------------------------------------------------- 037 // Static 038 //----------------------------------------------------------------------------------------------------------------- 039 040 /** Default value */ 041 public static final Uon DEFAULT = create().build(); 042 043 /** 044 * Instantiates a new builder for this class. 045 * 046 * @return A new builder object. 047 */ 048 public static Builder create() { 049 return new Builder(); 050 } 051 052 /** 053 * Instantiates a new builder for this class. 054 * 055 * @param on The targets this annotation applies to. 056 * @return A new builder object. 057 */ 058 public static Builder create(Class<?>...on) { 059 return create().on(on); 060 } 061 062 /** 063 * Instantiates a new builder for this class. 064 * 065 * @param on The targets this annotation applies to. 066 * @return A new builder object. 067 */ 068 public static Builder create(String...on) { 069 return create().on(on); 070 } 071 072 /** 073 * Creates a copy of the specified annotation. 074 * 075 * @param a The annotation to copy.s 076 * @param r The var resolver for resolving any variables. 077 * @return A copy of the specified annotation. 078 */ 079 public static Uon copy(Uon a, VarResolverSession r) { 080 return 081 create() 082 .on(r.resolve(a.on())) 083 .onClass(a.onClass()) 084 .build(); 085 } 086 087 //----------------------------------------------------------------------------------------------------------------- 088 // Builder 089 //----------------------------------------------------------------------------------------------------------------- 090 091 /** 092 * Builder class. 093 * 094 * <h5 class='section'>See Also:</h5><ul> 095 * <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)} 096 * </ul> 097 */ 098 public static class Builder extends TargetedAnnotationTMFBuilder { 099 100 /** 101 * Constructor. 102 */ 103 protected Builder() { 104 super(Uon.class); 105 } 106 107 /** 108 * Instantiates a new {@link Uon @Uon} object initialized with this builder. 109 * 110 * @return A new {@link Uon @Uon} object. 111 */ 112 public Uon build() { 113 return new Impl(this); 114 } 115 116 // <FluentSetters> 117 118 @Override /* GENERATED - TargetedAnnotationBuilder */ 119 public Builder on(String...values) { 120 super.on(values); 121 return this; 122 } 123 124 @Override /* GENERATED - TargetedAnnotationTBuilder */ 125 public Builder on(java.lang.Class<?>...value) { 126 super.on(value); 127 return this; 128 } 129 130 @Override /* GENERATED - TargetedAnnotationTBuilder */ 131 public Builder onClass(java.lang.Class<?>...value) { 132 super.onClass(value); 133 return this; 134 } 135 136 @Override /* GENERATED - TargetedAnnotationTMFBuilder */ 137 public Builder on(Field...value) { 138 super.on(value); 139 return this; 140 } 141 142 @Override /* GENERATED - TargetedAnnotationTMFBuilder */ 143 public Builder on(Method...value) { 144 super.on(value); 145 return this; 146 } 147 148 // </FluentSetters> 149 } 150 151 //----------------------------------------------------------------------------------------------------------------- 152 // Implementation 153 //----------------------------------------------------------------------------------------------------------------- 154 155 private static class Impl extends TargetedAnnotationTImpl implements Uon { 156 157 Impl(Builder b) { 158 super(b); 159 postConstruct(); 160 } 161 } 162 163 //----------------------------------------------------------------------------------------------------------------- 164 // Appliers 165 //----------------------------------------------------------------------------------------------------------------- 166 167 /** 168 * Applies targeted {@link Uon} annotations to a {@link org.apache.juneau.Context.Builder}. 169 */ 170 public static class Apply extends AnnotationApplier<Uon,Context.Builder> { 171 172 /** 173 * Constructor. 174 * 175 * @param vr The resolver for resolving values in annotations. 176 */ 177 public Apply(VarResolverSession vr) { 178 super(Uon.class, Context.Builder.class, vr); 179 } 180 181 @Override 182 public void apply(AnnotationInfo<Uon> ai, Context.Builder b) { 183 Uon a = ai.inner(); 184 if (isEmptyArray(a.on(), a.onClass())) 185 return; 186 b.annotations(copy(a, vr())); 187 } 188 } 189 190 //----------------------------------------------------------------------------------------------------------------- 191 // Other 192 //----------------------------------------------------------------------------------------------------------------- 193 194 /** 195 * A collection of {@link Uon @Uon annotations}. 196 */ 197 @Documented 198 @Target({METHOD,TYPE}) 199 @Retention(RUNTIME) 200 @Inherited 201 public static @interface Array { 202 203 /** 204 * The child annotations. 205 * 206 * @return The annotation value. 207 */ 208 Uon[] value(); 209 } 210}