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 * </ul>
030 *
031 * <h5 class='figure'>Examples:</h5>
032 * <p class='bcode w800'>
033 *    <jc>// On a static method.</jc>
034 *    <jk>public class</jk> A {
035 *
036 *       <ja>@Example</ja>
037 *       <jk>public static</jk> A example() {
038 *          <jk>return new</jk> A().foo(<js>"bar"</js>).baz(123);
039 *       }
040 *
041 *       ...
042 *    }
043 *
044 *    <jc>// On a static field.</jc>
045 *    <jk>public class</jk> B {
046 *
047 *       <ja>@Example</ja>
048 *       <jk>public static</jk> B EXAMPLE = <jk>new</jk> B().foo(<js>"bar"</js>).baz(123);
049 *
050 *       ...
051 *    }
052 *
053 *    <jc>// On a class.</jc>
054 *    <ja>@Example</ja>(<js>"{foo:'bar',baz:123}"</js>)
055 *    <jk>public class</jk> C {...}
056 * </p>
057 */
058@Documented
059@Target({FIELD,METHOD,TYPE})
060@Retention(RUNTIME)
061@Inherited
062public @interface Example {
063
064   /**
065    * Dynamically apply this annotation to the specified classes/methods/fields.
066    *
067    * <p>
068    * Used in conjunction with the {@link BeanConfig#applyExample()}.
069    * It is ignored when the annotation is applied directly to classes/methods/fields.
070    *
071    * <h5 class='section'>Valid patterns:</h5>
072    * <ul class='spaced-list'>
073    *  <li>Classes:
074    *       <ul>
075    *          <li>Fully qualified:
076    *             <ul>
077    *                <li><js>"com.foo.MyClass"</js>
078    *             </ul>
079    *          <li>Fully qualified inner class:
080    *             <ul>
081    *                <li><js>"com.foo.MyClass$Inner1$Inner2"</js>
082    *             </ul>
083    *          <li>Simple:
084    *             <ul>
085    *                <li><js>"MyClass"</js>
086    *             </ul>
087    *          <li>Simple inner:
088    *             <ul>
089    *                <li><js>"MyClass$Inner1$Inner2"</js>
090    *                <li><js>"Inner1$Inner2"</js>
091    *                <li><js>"Inner2"</js>
092    *             </ul>
093    *       </ul>
094    *    <li>Methods:
095    *       <ul>
096    *          <li>Fully qualified with args:
097    *             <ul>
098    *                <li><js>"com.foo.MyClass.myMethod(String,int)"</js>
099    *                <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js>
100    *                <li><js>"com.foo.MyClass.myMethod()"</js>
101    *             </ul>
102    *          <li>Fully qualified:
103    *             <ul>
104    *                <li><js>"com.foo.MyClass.myMethod"</js>
105    *             </ul>
106    *          <li>Simple with args:
107    *             <ul>
108    *                <li><js>"MyClass.myMethod(String,int)"</js>
109    *                <li><js>"MyClass.myMethod(java.lang.String,int)"</js>
110    *                <li><js>"MyClass.myMethod()"</js>
111    *             </ul>
112    *          <li>Simple:
113    *             <ul>
114    *                <li><js>"MyClass.myMethod"</js>
115    *             </ul>
116    *          <li>Simple inner class:
117    *             <ul>
118    *                <li><js>"MyClass$Inner1$Inner2.myMethod"</js>
119    *                <li><js>"Inner1$Inner2.myMethod"</js>
120    *                <li><js>"Inner2.myMethod"</js>
121    *             </ul>
122    *       </ul>
123    *    <li>Fields:
124    *       <ul>
125    *          <li>Fully qualified:
126    *             <ul>
127    *                <li><js>"com.foo.MyClass.myField"</js>
128    *             </ul>
129    *          <li>Simple:
130    *             <ul>
131    *                <li><js>"MyClass.myField"</js>
132    *             </ul>
133    *          <li>Simple inner class:
134    *             <ul>
135    *                <li><js>"MyClass$Inner1$Inner2.myField"</js>
136    *                <li><js>"Inner1$Inner2.myField"</js>
137    *                <li><js>"Inner2.myField"</js>
138    *             </ul>
139    *       </ul>
140    *    <li>A comma-delimited list of anything on this list.
141    * </ul>
142    *
143    * <ul class='seealso'>
144    *    <li class='link'>{@doc DynamicallyAppliedAnnotations}
145    * </ul>
146    */
147   String on() default "";
148
149   /**
150    * An example of a POJO class.
151    *
152    * <p>
153    * Format is Lax-JSON.
154    *
155    * <p>
156    * This value is only used when the annotation is used on a type.
157    */
158   String value() default "";
159}