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 java.lang.annotation.*;
016import java.lang.reflect.*;
017
018import org.apache.juneau.*;
019import org.apache.juneau.reflect.*;
020
021/**
022 * A concrete implementation of the {@link Beanp} annotation.
023 *
024 * <ul class='seealso'>
025 *    <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)}
026 * </ul>
027 */
028public class BeanpAnnotation implements Beanp {
029
030   private String
031      on = "",
032      name = "",
033      value = "",
034      properties = "",
035      format = "",
036      ro = "",
037      wo = "";
038   private Class<?>
039      type = Object.class;
040   private Class<?>[]
041      params = new Class[0],
042      dictionary = new Class[0];
043
044   /**
045    * Constructor.
046    *
047    * @param on The initial value for the <c>on</c> property.
048    *    <br>See {@link Beanp#on()}
049    */
050   public BeanpAnnotation(String on) {
051      on(on);
052   }
053
054   /**
055    * Constructor.
056    *
057    * @param on The initial value for the <c>on</c> property.
058    *    <br>See {@link Beanp#on()}
059    */
060   public BeanpAnnotation(Method on) {
061      on(on);
062   }
063
064   /**
065    * Constructor.
066    *
067    * @param on The initial value for the <c>on</c> property.
068    *    <br>See {@link Beanp#on()}
069    */
070   public BeanpAnnotation(Field on) {
071      on(on);
072   }
073
074   @Override
075   public Class<? extends Annotation> annotationType() {
076      return Beanp.class;
077   }
078
079   @Override
080   public String name() {
081      return name;
082   }
083
084   /**
085    * Sets the <c>name</c> property on this annotation.
086    *
087    * @param value The new value for this property.
088    * @return This object (for method chaining).
089    */
090   public BeanpAnnotation name(String value) {
091      this.name = value;
092      return this;
093   }
094
095   @Override
096   public String value() {
097      return value;
098   }
099
100   /**
101    * Sets the <c>value</c> property on this annotation.
102    *
103    * @param value The new value for this property.
104    * @return This object (for method chaining).
105    */
106   public BeanpAnnotation value(String value) {
107      this.value = value;
108      return this;
109   }
110
111   @Override
112   public Class<?> type() {
113      return type;
114   }
115
116   /**
117    * Sets the <c>type</c> property on this annotation.
118    *
119    * @param value The new value for this property.
120    * @return This object (for method chaining).
121    */
122   public BeanpAnnotation type(Class<?> value) {
123      this.type = value;
124      return this;
125   }
126
127   @Override
128   public String on() {
129      return on;
130   }
131
132   /**
133    * Sets the <c>on</c> property on this annotation.
134    *
135    * @param value The new value for this property.
136    * @return This object (for method chaining).
137    */
138   public BeanpAnnotation on(String value) {
139      this.on = value;
140      return this;
141   }
142
143   /**
144    * Sets the <c>on</c> property on this annotation.
145    *
146    * @param value The new value for this property.
147    * @return This object (for method chaining).
148    */
149   public BeanpAnnotation on(Method value) {
150      this.on = MethodInfo.of(value).getFullName();
151      return this;
152   }
153
154   /**
155    * Sets the <c>on</c> property on this annotation.
156    *
157    * @param value The new value for this property.
158    * @return This object (for method chaining).
159    */
160   public BeanpAnnotation on(Field value) {
161      this.on = value.getName();
162      return this;
163   }
164
165   @Override
166   public Class<?>[] params() {
167      return params;
168   }
169
170   /**
171    * Sets the <c>params</c> property on this annotation.
172    *
173    * @param value The new value for this property.
174    * @return This object (for method chaining).
175    */
176   public BeanpAnnotation params(Class<?>...value) {
177      this.params = value;
178      return this;
179   }
180
181   @Override
182   public String properties() {
183      return properties;
184   }
185
186   /**
187    * Sets the <c>properties</c> property on this annotation.
188    *
189    * @param value The new value for this property.
190    * @return This object (for method chaining).
191    */
192   public BeanpAnnotation properties(String value) {
193      this.properties = value;
194      return this;
195   }
196
197   @Override
198   public Class<?>[] dictionary() {
199      return dictionary;
200   }
201
202   /**
203    * Sets the <c>dictionary</c> property on this annotation.
204    *
205    * @param value The new value for this property.
206    * @return This object (for method chaining).
207    */
208   public BeanpAnnotation dictionary(Class<?>...value) {
209      this.dictionary = value;
210      return this;
211   }
212
213   @Override
214   public String format() {
215      return format;
216   }
217
218   /**
219    * Sets the <c>format</c> property on this annotation.
220    *
221    * @param value The new value for this property.
222    * @return This object (for method chaining).
223    */
224   public BeanpAnnotation format(String value) {
225      this.format = value;
226      return this;
227   }
228
229   @Override
230   public String ro() {
231      return ro;
232   }
233
234   /**
235    * Sets the <c>ro</c> property on this annotation.
236    *
237    * @param value The new value for this property.
238    * @return This object (for method chaining).
239    */
240   public BeanpAnnotation ro(String value) {
241      this.ro = value;
242      return this;
243   }
244
245   @Override
246   public String wo() {
247      return wo;
248   }
249
250   /**
251    * Sets the <c>wo</c> property on this annotation.
252    *
253    * @param value The new value for this property.
254    * @return This object (for method chaining).
255    */
256   public BeanpAnnotation wo(String value) {
257      this.wo = value;
258      return this;
259   }
260}