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.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.beans.*;
019import java.lang.annotation.*;
020
021import org.apache.juneau.*;
022import org.apache.juneau.transform.*;
023
024/**
025 * Used to tailor how beans get interpreted by the framework.
026 * 
027 * <p>
028 * This annotation can be applied to classes and interfaces.
029 * 
030 * <h5 class='section'>See Also:</h5>
031 * <ul>
032 *    <li class='link'><a class="doclink" href="../../../../overview-summary.html#juneau-marshall.BeanAnnotation">Overview &gt; juneau-marshall &gt; @Bean Annotation</a>
033 * </ul>
034 */
035@Documented
036@Target(TYPE)
037@Retention(RUNTIME)
038@Inherited
039public @interface Bean {
040
041   /**
042    * Bean dictionary.
043    * 
044    * <p>
045    * The list of classes that make up the bean dictionary for all properties in this class and all subclasses.
046    * 
047    * <h5 class='section'>See Also:</h5>
048    * <ul>
049    *    <li class='jf'>{@link BeanContext#BEAN_beanDictionary}
050    * </ul>
051    */
052   Class<?>[] beanDictionary() default {};
053   
054   /**
055    * Specifies a list of properties that should be excluded from {@link BeanMap#entrySet()}.
056    * 
057    * <h5 class='section'>Example:</h5>
058    * <p class='bcode'>
059    *    <jc>// Exclude the 'city' and 'state' properties from the Address class.</jc>
060    *    <ja>@Bean</ja>(excludeProperties=<js>"city,state"</js>})
061    *    <jk>public class</jk> Address {...}
062    * </p>
063    * 
064    * <h5 class='section'>See Also:</h5>
065    * <ul>
066    *    <li class='jf'>{@link BeanContext#BEAN_excludeProperties}
067    * </ul>
068    */
069   String excludeProperties() default "";
070
071   /**
072    * Identifies a class to be used as the interface class for this and all subclasses.
073    * 
074    * <p>
075    * When specified, only the list of properties defined on the interface class will be used during serialization.
076    * Additional properties on subclasses will be ignored.
077    * 
078    * <p class='bcode'>
079    *    <jc>// Parent class</jc>
080    *    <ja>@Bean</ja>(interfaceClass=A.<jk>class</jk>)
081    *    <jk>public abstract class</jk> A {
082    *       <jk>public</jk> String <jf>f0</jf> = <js>"f0"</js>;
083    *    }
084    * 
085    *    <jc>// Sub class</jc>
086    *    <jk>public class</jk> A1 <jk>extends</jk> A {
087    *       <jk>public</jk> String <jf>f1</jf> = <js>"f1"</js>;
088    *    }
089    * 
090    *    <jc>// Produces "{f0:'f0'}"</jc>
091    *    String json = JsonSerializer.<jsf>DEFAULT_LAX</jsf>.serialize(<jk>new</jk> A1());
092    * </p>
093    * 
094    * <p>
095    * Note that this annotation can be used on the parent class so that it filters to all child classes,
096    * or can be set individually on the child classes.
097    * 
098    * <h5 class='section'>See Also:</h5>
099    * <ul>
100    *    <li class='jf'>{@link BeanContext#BEAN_beanFilters}
101    * </ul>
102    */
103   Class<?> interfaceClass() default Object.class;
104
105   /**
106    * The set and order of names of properties associated with a bean class.
107    * 
108    * <p>
109    * The order specified is the same order that the entries will be returned by the {@link BeanMap#entrySet()} and
110    * related methods.
111    * 
112    * <p>
113    * This value is entirely optional if you simply want to expose all the getters and public fields on 
114    * a class as bean properties.
115    * <br>However, it's useful if you want certain getters to be ignored or you want the properties to be
116    * serialized in a particular order.
117    * <br>Note that on IBM JREs, the property order is the same as the order in the source code, 
118    * whereas on Oracle JREs, the order is entirely random.
119    * 
120    * <h5 class='section'>Example:</h5>
121    * <p class='bcode'>
122    *    <jc>// Address class with only street/city/state properties (in that order).</jc>
123    *    <ja>@Bean</ja>(properties=<js>"street,city,state"</js>)
124    *    <jk>public class</jk> Address {...}
125    * </p>
126    * 
127    * <h5 class='section'>See Also:</h5>
128    * <ul>
129    *    <li class='jf'>{@link BeanContext#BEAN_includeProperties}
130    * </ul>
131    */
132   String properties() default "";
133
134   /**
135    * Property filter.
136    * 
137    * <p>
138    * Property filters can be used to intercept calls to getters and setters and alter their values in transit. 
139    * 
140    * <h5 class='section'>See Also:</h5>
141    * <ul>
142    *    <li class='jc'>{@link PropertyFilter}
143    * </ul>
144    */
145   Class<? extends PropertyFilter> propertyFilter() default PropertyFilter.class;
146
147   /**
148    * Associates a {@link PropertyNamer} with this bean to tailor the names of the bean properties.
149    * 
150    * <p>
151    * Property namers are used to transform bean property names from standard form to some other form.
152    * 
153    * <h5 class='section'>Example:</h5>
154    * <p class='bcode'>
155    *    <jc>// Define a class with dashed-lowercase property names.</jc>
156    *    <ja>@Bean</ja>(propertyNamer=PropertyNamerDashedLC.<jk>class</jk>)
157    *    <jk>public class</jk> MyBean {...}
158    * </p>
159    * 
160    * <h5 class='section'>See Also:</h5>
161    * <ul>
162    *    <li class='jf'>{@link BeanContext#BEAN_propertyNamer}
163    * </ul>
164    */
165   Class<? extends PropertyNamer> propertyNamer() default PropertyNamerDefault.class;
166
167   /**
168    * Sort bean properties in alphabetical order.
169    * 
170    * <p>
171    * When <jk>true</jk>, all bean properties will be serialized and access in alphabetical order.
172    * <br>Otherwise, the natural order of the bean properties is used which is dependent on the JVM vendor.
173    * 
174    * <h5 class='section'>Example:</h5>
175    * <p class='bcode'>
176    *    <jc>// Sort bean properties alphabetically during serialization.</jc>
177    *    <ja>@Bean</ja>(sort=<jk>true</jk>)
178    *    <jk>public class</jk> MyBean {...}
179    * </p>
180    * 
181    * <h5 class='section'>See Also:</h5>
182    * <ul>
183    *    <li class='jf'>{@link BeanContext#BEAN_sortProperties}
184    * </ul>
185    */
186   boolean sort() default false;
187
188   /**
189    * Identifies a stop class for the annotated class.
190    * 
191    * <p>
192    * Identical in purpose to the stop class specified by {@link Introspector#getBeanInfo(Class, Class)}.
193    * Any properties in the stop class or in its base classes will be ignored during analysis.
194    * 
195    * <p>
196    * For example, in the following class hierarchy, instances of <code>C3</code> will include property <code>p3</code>,
197    * but not <code>p1</code> or <code>p2</code>.
198    * <p class='bcode'>
199    *    <jk>public class</jk> C1 {
200    *       <jk>public int</jk> getP1();
201    *    }
202    * 
203    *    <jk>public class</jk> C2 <jk>extends</jk> C1 {
204    *       <jk>public int</jk> getP2();
205    *    }
206    * 
207    *    <ja>@Bean</ja>(stopClass=C2.<jk>class</jk>)
208    *    <jk>public class</jk> C3 <jk>extends</jk> C2 {
209    *       <jk>public int</jk> getP3();
210    *    }
211    * </p>
212    */
213   Class<?> stopClass() default Object.class;
214
215   /**
216    * An identifying name for this class.
217    * 
218    * <p>
219    * The name is used to identify the class type during parsing when it cannot be inferred through reflection.
220    * <br>For example, if a bean property is of type <code>Object</code>, then the serializer will add the name to the
221    * output so that the class can be determined during parsing.
222    * 
223    * <p>
224    * It is also used to specify element names in XML.
225    * 
226    * <h5 class='section'>Example:</h5>
227    * <p class='bcode'>
228    *    <jc>// Use _type='mybean' to identify this bean.</jc>
229    *    <ja>@Bean</ja>(typeName=<js>"mybean"</js>)
230    *    <jk>public class</jk> MyBean {...}
231    * </p>
232    * 
233    * <h5 class='section'>See Also:</h5>
234    * <ul>
235    *    <li class='jf'>{@link BeanContext#BEAN_beanDictionary}
236    * </ul>
237    */
238   String typeName() default "";
239
240   /**
241    * The property name to use for representing the type name.
242    * 
243    * <p>
244    * This can be used to override the name used for the <js>"_type"</js> property used by the {@link #typeName()} setting.
245    * 
246    * <p>
247    * The default value if not specified is <js>"_type"</js> .
248    * 
249    * <h5 class='section'>Example:</h5>
250    * <p class='bcode'>
251    *    <jc>// Use 'type' instead of '_type' for bean names.</jc>
252    *    <ja>@Bean</ja>(typePropertyName=<js>"type"</js>)
253    *    <jk>public class</jk> MyBean {...}
254    * </p>
255    * 
256    * <h5 class='section'>See Also:</h5>
257    * <ul>
258    *    <li class='jf'>{@link BeanContext#BEAN_beanTypePropertyName}
259    * </ul>
260    */
261   String typePropertyName() default "";
262}