001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.html; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.commons.*; 024import org.apache.juneau.commons.reflect.*; 025import org.apache.juneau.commons.svl.*; 026import org.apache.juneau.marshall.*; 027 028/** 029 * Utility classes and methods for the {@link HtmlLinkApply @HtmlLinkApply} annotation. 030 * 031 */ 032public class HtmlLinkApplyAnnotation { 033 034 /** 035 * Prevents instantiation. 036 */ 037 private HtmlLinkApplyAnnotation() {} 038 039 /** 040 * Applies targeted {@link HtmlLinkApply} annotations to a {@link org.apache.juneau.marshall.Context.Builder Context.Builder}. 041 */ 042 @SuppressWarnings({ 043 "rawtypes" // Raw types required for reflective annotation application. 044 }) 045 public static class Applier extends AnnotationApplier<HtmlLinkApply,Context.Builder> { 046 047 /** 048 * Constructor. 049 * 050 * @param vr The resolver for resolving values in annotations. 051 * <br>Must not be <jk>null</jk>. 052 */ 053 public Applier(VarResolverSession vr) { 054 super(HtmlLinkApply.class, Context.Builder.class, vr); 055 } 056 057 @Override 058 public void apply(AnnotationInfo<HtmlLinkApply> ai, Context.Builder b) { 059 HtmlLinkApply a = ai.inner(); 060 if (isEmptyArray(a.on()) && isEmptyArray(a.onClass())) 061 return; 062 b.annotations(a); 063 } 064 } 065 066 /** 067 * Builder class. 068 * 069 * <h5 class='section'>See Also:</h5><ul> 070 * <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...) MarshallingContext.Builder#annotations(Annotation...)} 071 * </ul> 072 */ 073 public static class Builder extends AppliedAnnotationObject.BuilderT { 074 075 HtmlLink value = HtmlLinkAnnotation.DEFAULT; 076 077 /** 078 * Constructor. 079 */ 080 protected Builder() { 081 super(HtmlLinkApply.class); 082 } 083 084 /** 085 * Sets the {@link HtmlLinkApply#value()} property on this annotation. 086 * 087 * @param value The new value for this property. 088 * @return This object. 089 */ 090 public Builder value(HtmlLink value) { 091 this.value = value; 092 return this; 093 } 094 095 @Override /* Overridden from AppliedAnnotationObject.Builder */ 096 public Builder on(String...value) { 097 super.on(value); 098 return this; 099 } 100 101 @Override /* Overridden from AppliedAnnotationObject.BuilderT */ 102 public Builder on(Class<?>...value) { 103 super.on(value); 104 return this; 105 } 106 107 @Override /* Overridden from AppliedOnClassAnnotationObject.Builder */ 108 public Builder onClass(Class<?>...value) { 109 super.onClass(value); 110 return this; 111 } 112 113 @Override /* Overridden from AppliedAnnotationObject.BuilderT */ 114 public Builder on(ClassInfo...value) { 115 super.on(value); 116 return this; 117 } 118 119 @Override /* Overridden from AppliedAnnotationObject.BuilderT */ 120 public Builder onClass(ClassInfo...value) { 121 super.onClass(value); 122 return this; 123 } 124 125 /** 126 * Instantiates a new {@link HtmlLinkApply @HtmlLinkApply} object initialized with this builder. 127 * 128 * @return A new {@link HtmlLinkApply} object. 129 */ 130 public HtmlLinkApply build() { 131 return new Object(this); 132 } 133 } 134 135 @SuppressWarnings({ 136 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 137 }) 138 private static class Object extends AppliedOnClassAnnotationObject implements HtmlLinkApply { 139 140 private final HtmlLink value; 141 142 Object(HtmlLinkApplyAnnotation.Builder b) { 143 super(b); 144 value = b.value; 145 } 146 147 @Override /* Overridden from HtmlLinkApply */ 148 public HtmlLink value() { 149 return value; 150 } 151 } 152 153 /** Default value */ 154 public static final HtmlLinkApply DEFAULT = create().build(); 155 156 /** 157 * Instantiates a new builder for this class. 158 * 159 * @return A new builder object. 160 */ 161 public static Builder create() { 162 return new Builder(); 163 } 164 165 /** 166 * Instantiates a new builder for this class. 167 * 168 * @param on The targets this annotation applies to. 169 * @return A new builder object. 170 */ 171 public static Builder create(Class<?>...on) { 172 return create().on(on); 173 } 174 175 /** 176 * Instantiates a new builder for this class. 177 * 178 * @param on The targets this annotation applies to. 179 * @return A new builder object. 180 */ 181 public static Builder create(String...on) { 182 return create().on(on); 183 } 184 185 /** 186 * Returns <jk>true</jk> if the specified annotation contains all default values. 187 * 188 * @param a The annotation to check. 189 * <br>Can be <jk>null</jk> (returns <jk>true</jk>). 190 * @return <jk>true</jk> if the specified annotation contains all default values. 191 */ 192 public static boolean empty(HtmlLinkApply a) { 193 return a == null || DEFAULT.equals(a); 194 } 195}