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.json.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 Json} annotation.
023 *
024 * <ul class='seealso'>
025 *    <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)}
026 * </ul>
027 */
028public class JsonAnnotation implements Json {
029
030   private String on = "";
031   private String wrapperAttr = "";
032
033   /**
034    * Constructor.
035    *
036    * @param on The initial value for the <c>on</c> property.
037    *    <br>See {@link Json#on()}
038    */
039   public JsonAnnotation(String on) {
040      on(on);
041   }
042
043   /**
044    * Constructor.
045    *
046    * @param on The initial value for the <c>on</c> property.
047    *    <br>See {@link Json#on()}
048    */
049   public JsonAnnotation(Class<?> on) {
050      on(on);
051   }
052
053   /**
054    * Constructor.
055    *
056    * @param on The initial value for the <c>on</c> property.
057    *    <br>See {@link Json#on()}
058    */
059   public JsonAnnotation(Method on) {
060      on(on);
061   }
062
063   /**
064    * Constructor.
065    *
066    * @param on The initial value for the <c>on</c> property.
067    *    <br>See {@link Json#on()}
068    */
069   public JsonAnnotation(Field on) {
070      on(on);
071   }
072
073   @Override
074   public Class<? extends Annotation> annotationType() {
075      return Json.class;
076   }
077
078   @Override
079   public String on() {
080      return on;
081   }
082
083   /**
084    * Sets the <c>on</c> property on this annotation.
085    *
086    * @param value The new value for this property.
087    * @return This object (for method chaining).
088    */
089   public JsonAnnotation on(String value) {
090      this.on = value;
091      return this;
092   }
093
094   /**
095    * Sets the <c>on</c> property on this annotation.
096    *
097    * @param value The new value for this property.
098    * @return This object (for method chaining).
099    */
100   public JsonAnnotation on(Class<?> value) {
101      this.on = value.getName();
102      return this;
103   }
104
105   /**
106    * Sets the <c>on</c> property on this annotation.
107    *
108    * @param value The new value for this property.
109    * @return This object (for method chaining).
110    */
111   public JsonAnnotation on(Method value) {
112      this.on = MethodInfo.of(value).getFullName();
113      return this;
114   }
115
116   /**
117    * Sets the <c>on</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 JsonAnnotation on(Field value) {
123      this.on = value.getName();
124      return this;
125   }
126
127   @Override
128   public String wrapperAttr() {
129      return wrapperAttr;
130   }
131
132   /**
133    * Sets the <c>wrapperAttr</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 JsonAnnotation wrapperAttr(String value) {
139      this.wrapperAttr = value;
140      return this;
141   }
142
143}