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