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.xml.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 Xml} annotation.
023 *
024 * <ul class='seealso'>
025 *    <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)}
026 * </ul>
027 */
028public class XmlAnnotation implements Xml {
029
030   private String
031      on = "",
032      childName = "",
033      namespace = "",
034      prefix = "";
035   private XmlFormat
036      format = XmlFormat.DEFAULT;
037
038   /**
039    * Constructor.
040    *
041    * @param on The initial value for the <c>on</c> property.
042    *    <br>See {@link Xml#on()}
043    */
044   public XmlAnnotation(String on) {
045      on(on);
046   }
047
048   /**
049    * Constructor.
050    *
051    * @param on The initial value for the <c>on</c> property.
052    *    <br>See {@link Xml#on()}
053    */
054   public XmlAnnotation(Class<?> on) {
055      on(on);
056   }
057
058   /**
059    * Constructor.
060    *
061    * @param on The initial value for the <c>on</c> property.
062    *    <br>See {@link Xml#on()}
063    */
064   public XmlAnnotation(Method on) {
065      on(on);
066   }
067
068   /**
069    * Constructor.
070    *
071    * @param on The initial value for the <c>on</c> property.
072    *    <br>See {@link Xml#on()}
073    */
074   public XmlAnnotation(Field on) {
075      on(on);
076   }
077
078   @Override
079   public Class<? extends Annotation> annotationType() {
080      return Xml.class;
081   }
082
083   @Override
084   public String childName() {
085      return childName;
086   }
087
088   /**
089    * Sets the <c>childName</c> property on this annotation.
090    *
091    * @param value The new value for this property.
092    * @return This object (for method chaining).
093    */
094   public XmlAnnotation childName(String value) {
095      this.childName = value;
096      return this;
097   }
098
099   @Override
100   public XmlFormat format() {
101      return format;
102   }
103
104   /**
105    * Sets the <c>format</c> property on this annotation.
106    *
107    * @param value The new value for this property.
108    * @return This object (for method chaining).
109    */
110   public XmlAnnotation format(XmlFormat value) {
111      this.format = value;
112      return this;
113   }
114
115   @Override
116   public String namespace() {
117      return namespace;
118   }
119
120   /**
121    * Sets the <c>namespace</c> property on this annotation.
122    *
123    * @param value The new value for this property.
124    * @return This object (for method chaining).
125    */
126   public XmlAnnotation namespace(String value) {
127      this.namespace = value;
128      return this;
129   }
130
131   @Override
132   public String on() {
133      return on;
134   }
135
136   /**
137    * Sets the <c>on</c> property on this annotation.
138    *
139    * @param value The new value for this property.
140    * @return This object (for method chaining).
141    */
142   public XmlAnnotation on(String value) {
143      this.on = value;
144      return this;
145   }
146
147
148   /**
149    * Sets the <c>on</c> property on this annotation.
150    *
151    * @param value The new value for this property.
152    * @return This object (for method chaining).
153    */
154   public XmlAnnotation on(Class<?> value) {
155      this.on = value.getName();
156      return this;
157   }
158
159   /**
160    * Sets the <c>on</c> property on this annotation.
161    *
162    * @param value The new value for this property.
163    * @return This object (for method chaining).
164    */
165   public XmlAnnotation on(Method value) {
166      this.on = MethodInfo.of(value).getFullName();
167      return this;
168   }
169
170   /**
171    * Sets the <c>on</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 XmlAnnotation on(Field value) {
177      this.on = value.getName();
178      return this;
179   }
180
181   @Override
182   public String prefix() {
183      return prefix;
184   }
185
186   /**
187    * Sets the <c>prefix</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 XmlAnnotation prefix(String value) {
193      this.prefix = value;
194      return this;
195   }
196}