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