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