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 * <h5 class='section'>See Also:</h5><ul> 064 065 * </ul> 066 */ 067@Documented 068@Target({FIELD,METHOD,TYPE}) 069@Retention(RUNTIME) 070@Inherited 071@Repeatable(ExampleAnnotation.Array.class) 072@ContextApply(ExampleAnnotation.Applier.class) 073public @interface Example { 074 075 /** 076 * Optional description for the exposed API. 077 * 078 * @return The annotation value. 079 * @since 9.2.0 080 */ 081 String[] description() default {}; 082 083 /** 084 * Dynamically apply this annotation to the specified classes/methods/fields. 085 * 086 * <p> 087 * Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class/method/field. 088 * It is ignored when the annotation is applied directly to classes/methods/fields. 089 * 090 * <h5 class='section'>Valid patterns:</h5> 091 * <ul class='spaced-list'> 092 * <li>Classes: 093 * <ul> 094 * <li>Fully qualified: 095 * <ul> 096 * <li><js>"com.foo.MyClass"</js> 097 * </ul> 098 * <li>Fully qualified inner class: 099 * <ul> 100 * <li><js>"com.foo.MyClass$Inner1$Inner2"</js> 101 * </ul> 102 * <li>Simple: 103 * <ul> 104 * <li><js>"MyClass"</js> 105 * </ul> 106 * <li>Simple inner: 107 * <ul> 108 * <li><js>"MyClass$Inner1$Inner2"</js> 109 * <li><js>"Inner1$Inner2"</js> 110 * <li><js>"Inner2"</js> 111 * </ul> 112 * </ul> 113 * <li>Methods: 114 * <ul> 115 * <li>Fully qualified with args: 116 * <ul> 117 * <li><js>"com.foo.MyClass.myMethod(String,int)"</js> 118 * <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js> 119 * <li><js>"com.foo.MyClass.myMethod()"</js> 120 * </ul> 121 * <li>Fully qualified: 122 * <ul> 123 * <li><js>"com.foo.MyClass.myMethod"</js> 124 * </ul> 125 * <li>Simple with args: 126 * <ul> 127 * <li><js>"MyClass.myMethod(String,int)"</js> 128 * <li><js>"MyClass.myMethod(java.lang.String,int)"</js> 129 * <li><js>"MyClass.myMethod()"</js> 130 * </ul> 131 * <li>Simple: 132 * <ul> 133 * <li><js>"MyClass.myMethod"</js> 134 * </ul> 135 * <li>Simple inner class: 136 * <ul> 137 * <li><js>"MyClass$Inner1$Inner2.myMethod"</js> 138 * <li><js>"Inner1$Inner2.myMethod"</js> 139 * <li><js>"Inner2.myMethod"</js> 140 * </ul> 141 * </ul> 142 * <li>Fields: 143 * <ul> 144 * <li>Fully qualified: 145 * <ul> 146 * <li><js>"com.foo.MyClass.myField"</js> 147 * </ul> 148 * <li>Simple: 149 * <ul> 150 * <li><js>"MyClass.myField"</js> 151 * </ul> 152 * <li>Simple inner class: 153 * <ul> 154 * <li><js>"MyClass$Inner1$Inner2.myField"</js> 155 * <li><js>"Inner1$Inner2.myField"</js> 156 * <li><js>"Inner2.myField"</js> 157 * </ul> 158 * </ul> 159 * <li>A comma-delimited list of anything on this list. 160 * </ul> 161 * 162 * <h5 class='section'>See Also:</h5><ul> 163 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 164 * </ul> 165 * 166 * @return The annotation value. 167 */ 168 String[] on() default {}; 169 170 /** 171 * Dynamically apply this annotation to the specified classes. 172 * 173 * <p> 174 * Identical to {@link #on()} except allows you to specify class objects instead of a strings. 175 * 176 * <h5 class='section'>See Also:</h5><ul> 177 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 178 * </ul> 179 * 180 * @return The annotation value. 181 */ 182 Class<?>[] onClass() default {}; 183 184 /** 185 * An example of a POJO class. 186 * 187 * <p> 188 * Format is Lax-JSON. 189 * 190 * <p> 191 * This value is only used when the annotation is used on a type. 192 * 193 * @return The annotation value. 194 */ 195 String value() default ""; 196}