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.lang.annotation.*;
019
020/**
021 * Identifies examples for POJOs.
022 *
023 * <p>
024 * Can be used in the following locations:
025 * <ul>
026 *    <li>Static method that returns an example of the POJO.
027 *    <li>Static field that contains an example of the POJO.
028 *    <li>On a class.
029 *    <li><ja>@Rest</ja>-annotated classes and <ja>@RestOp</ja>-annotated methods when an {@link #on()} value is specified.
030 * </ul>
031 *
032 * <h5 class='figure'>Examples:</h5>
033 * <p class='bjava'>
034 *    <jc>// On a static method.</jc>
035 *    <jk>public class</jk> A {
036 *
037 *       <ja>@Example</ja>
038 *       <jk>public static</jk> A example() {
039 *          <jk>return new</jk> A().foo(<js>"bar"</js>).baz(123);
040 *       }
041 *
042 *       ...
043 *    }
044 *
045 *    <jc>// On a static field.</jc>
046 *    <jk>public class</jk> B {
047 *
048 *       <ja>@Example</ja>
049 *       <jk>public static</jk> B EXAMPLE = <jk>new</jk> B().foo(<js>"bar"</js>).baz(123);
050 *
051 *       ...
052 *    }
053 *
054 *    <jc>// On a class.</jc>
055 *    <ja>@Example</ja>(<js>"{foo:'bar',baz:123}"</js>)
056 *    <jk>public class</jk> C {...}
057 * </p>
058 *
059 * <h5 class='section'>See Also:</h5><ul>
060
061 * </ul>
062 */
063@Documented
064@Target({FIELD,METHOD,TYPE})
065@Retention(RUNTIME)
066@Inherited
067@Repeatable(ExampleAnnotation.Array.class)
068@ContextApply(ExampleAnnotation.Applier.class)
069public @interface Example {
070
071   /**
072    * Dynamically apply this annotation to the specified classes/methods/fields.
073    *
074    * <p>
075    * Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class/method/field.
076    * It is ignored when the annotation is applied directly to classes/methods/fields.
077    *
078    * <h5 class='section'>Valid patterns:</h5>
079    * <ul class='spaced-list'>
080    *  <li>Classes:
081    *       <ul>
082    *          <li>Fully qualified:
083    *             <ul>
084    *                <li><js>"com.foo.MyClass"</js>
085    *             </ul>
086    *          <li>Fully qualified inner class:
087    *             <ul>
088    *                <li><js>"com.foo.MyClass$Inner1$Inner2"</js>
089    *             </ul>
090    *          <li>Simple:
091    *             <ul>
092    *                <li><js>"MyClass"</js>
093    *             </ul>
094    *          <li>Simple inner:
095    *             <ul>
096    *                <li><js>"MyClass$Inner1$Inner2"</js>
097    *                <li><js>"Inner1$Inner2"</js>
098    *                <li><js>"Inner2"</js>
099    *             </ul>
100    *       </ul>
101    *    <li>Methods:
102    *       <ul>
103    *          <li>Fully qualified with args:
104    *             <ul>
105    *                <li><js>"com.foo.MyClass.myMethod(String,int)"</js>
106    *                <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js>
107    *                <li><js>"com.foo.MyClass.myMethod()"</js>
108    *             </ul>
109    *          <li>Fully qualified:
110    *             <ul>
111    *                <li><js>"com.foo.MyClass.myMethod"</js>
112    *             </ul>
113    *          <li>Simple with args:
114    *             <ul>
115    *                <li><js>"MyClass.myMethod(String,int)"</js>
116    *                <li><js>"MyClass.myMethod(java.lang.String,int)"</js>
117    *                <li><js>"MyClass.myMethod()"</js>
118    *             </ul>
119    *          <li>Simple:
120    *             <ul>
121    *                <li><js>"MyClass.myMethod"</js>
122    *             </ul>
123    *          <li>Simple inner class:
124    *             <ul>
125    *                <li><js>"MyClass$Inner1$Inner2.myMethod"</js>
126    *                <li><js>"Inner1$Inner2.myMethod"</js>
127    *                <li><js>"Inner2.myMethod"</js>
128    *             </ul>
129    *       </ul>
130    *    <li>Fields:
131    *       <ul>
132    *          <li>Fully qualified:
133    *             <ul>
134    *                <li><js>"com.foo.MyClass.myField"</js>
135    *             </ul>
136    *          <li>Simple:
137    *             <ul>
138    *                <li><js>"MyClass.myField"</js>
139    *             </ul>
140    *          <li>Simple inner class:
141    *             <ul>
142    *                <li><js>"MyClass$Inner1$Inner2.myField"</js>
143    *                <li><js>"Inner1$Inner2.myField"</js>
144    *                <li><js>"Inner2.myField"</js>
145    *             </ul>
146    *       </ul>
147    *    <li>A comma-delimited list of anything on this list.
148    * </ul>
149    *
150    * <h5 class='section'>See Also:</h5><ul>
151    *    <li class='link'><a class="doclink" href="../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
152    * </ul>
153    *
154    * @return The annotation value.
155    */
156   String[] on() default {};
157
158   /**
159    * Dynamically apply this annotation to the specified classes.
160    *
161    * <p>
162    * Identical to {@link #on()} except allows you to specify class objects instead of a strings.
163    *
164    * <h5 class='section'>See Also:</h5><ul>
165    *    <li class='link'><a class="doclink" href="../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
166    * </ul>
167    *
168    * @return The annotation value.
169    */
170   Class<?>[] onClass() default {};
171
172   /**
173    * An example of a POJO class.
174    *
175    * <p>
176    * Format is Lax-JSON.
177    *
178    * <p>
179    * This value is only used when the annotation is used on a type.
180    *
181    * @return The annotation value.
182    */
183   String value() default "";
184}