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