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.marshall.xml;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import java.lang.annotation.*;
022
023import org.apache.juneau.commons.*;
024
025/**
026 * Utility classes and methods for the {@link Xml @Xml} annotation.
027 *
028 * <h5 class='section'>See Also:</h5><ul>
029 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/XmlSupport">XML</a>
030 * </ul>
031 */
032public class XmlAnnotation {
033
034   /**
035    * Prevents instantiation.
036    */
037   private XmlAnnotation() {}
038   /**
039    * Builder class.
040    *
041    * <h5 class='section'>See Also:</h5><ul>
042    *    <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)}
043    * </ul>
044    */
045   public static class Builder extends AnnotationObject.Builder {
046
047      private String[] description = {};
048      private String childName = "";
049      private String namespace = "";
050      private String prefix = "";
051      private XmlFormat format = XmlFormat.DEFAULT;
052
053      /**
054       * Constructor.
055       */
056      protected Builder() {
057         super(Xml.class);
058      }
059
060      /**
061       * Instantiates a new {@link Xml @Xml} object initialized with this builder.
062       *
063       * @return A new {@link Xml @Xml} object.
064       */
065      public Xml build() {
066         return new Object(this);
067      }
068
069      /**
070       * Sets the description property on this annotation.
071       *
072       * @param value The new value for this property.
073       * @return This object.
074       */
075      public Builder description(String...value) {
076         description = value;
077         return this;
078      }
079
080      /**
081       * Sets the {@link Xml#childName} property on this annotation.
082       *
083       * @param value The new value for this property.
084       * @return This object.
085       */
086      public Builder childName(String value) {
087         childName = value;
088         return this;
089      }
090
091      /**
092       * Sets the {@link Xml#format} property on this annotation.
093       *
094       * @param value The new value for this property.
095       * @return This object.
096       */
097      public Builder format(XmlFormat value) {
098         format = value;
099         return this;
100      }
101
102      /**
103       * Sets the {@link Xml#namespace} property on this annotation.
104       *
105       * @param value The new value for this property.
106       * @return This object.
107       */
108      public Builder namespace(String value) {
109         namespace = value;
110         return this;
111      }
112
113      /**
114       * Sets the {@link Xml#prefix} property on this annotation.
115       *
116       * @param value The new value for this property.
117       * @return This object.
118       */
119      public Builder prefix(String value) {
120         prefix = value;
121         return this;
122      }
123
124   }
125
126   @SuppressWarnings({
127      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
128   })
129   private static class Object extends AnnotationObject implements Xml {
130
131      private final String[] description;
132      private final String childName;
133      private final String namespace;
134      private final String prefix;
135      private final XmlFormat format;
136
137      Object(XmlAnnotation.Builder b) {
138         super(b);
139         description = cp(b.description);
140         childName = b.childName;
141         format = b.format;
142         namespace = b.namespace;
143         prefix = b.prefix;
144      }
145
146      @Override /* Overridden from Xml */
147      public String childName() {
148         return childName;
149      }
150
151      @Override /* Overridden from Xml */
152      public XmlFormat format() {
153         return format;
154      }
155
156      @Override /* Overridden from Xml */
157      public String namespace() {
158         return namespace;
159      }
160
161      @Override /* Overridden from Xml */
162      public String prefix() {
163         return prefix;
164      }
165
166      @Override /* Overridden from annotation */
167      public String[] description() {
168         return description;
169      }
170   }
171
172   /** Default value */
173   public static final Xml DEFAULT = create().build();
174
175   /**
176    * Instantiates a new builder for this class.
177    *
178    * @return A new builder object.
179    */
180   public static Builder create() {
181      return new Builder();
182   }
183}