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.annotation; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021import static org.apache.juneau.internal.ArrayUtils.*; 022 023import java.lang.annotation.*; 024 025import org.apache.juneau.*; 026import org.apache.juneau.reflect.*; 027import org.apache.juneau.svl.*; 028 029/** 030 * Utility classes and methods for the {@link BeanIgnore @BeanIgnore} annotation. 031 * 032 * <h5 class='section'>See Also:</h5><ul> 033 * </ul> 034 */ 035public class BeanIgnoreAnnotation { 036 037 //----------------------------------------------------------------------------------------------------------------- 038 // Static 039 //----------------------------------------------------------------------------------------------------------------- 040 041 /** Default value */ 042 public static final BeanIgnore DEFAULT = create().build(); 043 044 /** 045 * Instantiates a new builder for this class. 046 * 047 * @return A new builder object. 048 */ 049 public static Builder create() { 050 return new Builder(); 051 } 052 053 /** 054 * Instantiates a new builder for this class. 055 * 056 * @param on The targets this annotation applies to. 057 * @return A new builder object. 058 */ 059 public static Builder create(Class<?>...on) { 060 return create().on(on); 061 } 062 063 /** 064 * Instantiates a new builder for this class. 065 * 066 * @param on The targets this annotation applies to. 067 * @return A new builder object. 068 */ 069 public static Builder create(String...on) { 070 return create().on(on); 071 } 072 073 /** 074 * Creates a copy of the specified annotation. 075 * 076 * @param a The annotation to copy. 077 * @param r The var resolver for resolving any variables. 078 * @return A copy of the specified annotation. 079 */ 080 public static BeanIgnore copy(BeanIgnore a, VarResolverSession r) { 081 return 082 create() 083 .on(r.resolve(a.on())) 084 .onClass(a.onClass()) 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 TargetedAnnotationTMFCBuilder<Builder> { 100 101 /** 102 * Constructor. 103 */ 104 protected Builder() { 105 super(BeanIgnore.class); 106 } 107 108 /** 109 * Instantiates a new {@link BeanIgnore @BeanIgnore} object initialized with this builder. 110 * 111 * @return A new {@link BeanIgnore @BeanIgnore} object. 112 */ 113 public BeanIgnore build() { 114 return new Impl(this); 115 } 116 117 } 118 119 //----------------------------------------------------------------------------------------------------------------- 120 // Implementation 121 //----------------------------------------------------------------------------------------------------------------- 122 123 private static class Impl extends TargetedAnnotationTImpl implements BeanIgnore { 124 125 Impl(Builder b) { 126 super(b); 127 postConstruct(); 128 } 129 } 130 131 //----------------------------------------------------------------------------------------------------------------- 132 // Appliers 133 //----------------------------------------------------------------------------------------------------------------- 134 135 /** 136 * Applies targeted {@link BeanIgnore} annotations to a {@link org.apache.juneau.BeanContext.Builder}. 137 */ 138 public static class Applier extends AnnotationApplier<BeanIgnore,BeanContext.Builder> { 139 140 /** 141 * Constructor. 142 * 143 * @param vr The resolver for resolving values in annotations. 144 */ 145 public Applier(VarResolverSession vr) { 146 super(BeanIgnore.class, BeanContext.Builder.class, vr); 147 } 148 149 @Override 150 public void apply(AnnotationInfo<BeanIgnore> ai, BeanContext.Builder b) { 151 BeanIgnore a = ai.inner(); 152 if (isEmptyArray(a.on(), a.onClass())) 153 return; 154 b.annotations(copy(a, vr())); 155 } 156 } 157 158 //----------------------------------------------------------------------------------------------------------------- 159 // Other 160 //----------------------------------------------------------------------------------------------------------------- 161 162 /** 163 * A collection of {@link BeanIgnore @BeanIgnore annotations}. 164 */ 165 @Documented 166 @Target({METHOD,TYPE}) 167 @Retention(RUNTIME) 168 @Inherited 169 public static @interface Array { 170 171 /** 172 * The child annotations. 173 * 174 * @return The annotation value. 175 */ 176 BeanIgnore[] value(); 177 } 178}