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