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.http;
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 License @License} annotation.
027 *
028 */
029public class LicenseAnnotation {
030
031   /**
032    * Prevents instantiation.
033    */
034   private LicenseAnnotation() {}
035
036   /**
037    * Builder class.
038    *
039    * <h5 class='section'>See Also:</h5><ul>
040    *    <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)}
041    * </ul>
042    */
043   public static class Builder extends AnnotationObject.Builder {
044
045      private String[] description = {};
046      private String name = "";
047      private String url = "";
048
049      /**
050       * Constructor.
051       */
052      protected Builder() {
053         super(License.class);
054      }
055
056      /**
057       * Instantiates a new {@link License @License} object initialized with this builder.
058       *
059       * @return A new {@link License @License} object.
060       */
061      public License build() {
062         return new Instance(this);
063      }
064
065      /**
066       * Sets the description property on this annotation.
067       *
068       * @param value The new value for this property.
069       * @return This object.
070       */
071      public Builder description(String...value) {
072         description = value;
073         return this;
074      }
075
076      /**
077       * Sets the {@link License#name} property on this annotation.
078       *
079       * @param value The new value for this property.
080       * @return This object.
081       */
082      public Builder name(String value) {
083         name = value;
084         return this;
085      }
086
087      /**
088       * Sets the {@link License#url} property on this annotation.
089       *
090       * @param value The new value for this property.
091       * @return This object.
092       */
093      public Builder url(String value) {
094         url = value;
095         return this;
096      }
097
098   }
099
100   @SuppressWarnings({
101      "ClassExplicitlyAnnotation", // IntelliJ / SonarLint: Instance implements @License (AnnotationObject runtime proxy pattern)
102      "all", // Eclipse JDT: AnnotationTypeUsedAsSuperInterface has no dedicated @SuppressWarnings token (JLS 9.6)
103      "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods
104   })
105   private static class Instance extends AnnotationObject implements License {
106
107      private final String[] description;
108      private final String name;
109      private final String url;
110
111      Instance(LicenseAnnotation.Builder b) {
112         super(b);
113         description = cp(b.description);
114         name = b.name;
115         url = b.url;
116      }
117
118      @Override /* Overridden from License */
119      public String name() {
120         return name;
121      }
122
123      @Override /* Overridden from License */
124      public String url() {
125         return url;
126      }
127
128      @Override /* Overridden from annotation */
129      public String[] description() {
130         return cp(description);
131      }
132   }
133
134   /** Default value */
135   public static final License DEFAULT = create().build();
136
137   /**
138    * Instantiates a new builder for this class.
139    *
140    * @return A new builder object.
141    */
142   public static Builder create() {
143      return new Builder();
144   }
145
146   /**
147    * Returns <jk>true</jk> if the specified annotation contains all default values.
148    *
149    * @param a The annotation to check.
150    * @return <jk>true</jk> if the specified annotation contains all default values.
151    */
152   public static boolean empty(License a) {
153      return a == null || DEFAULT.equals(a);
154   }
155}