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.http.annotation;
014
015import java.lang.annotation.*;
016
017import org.apache.juneau.annotation.*;
018
019/**
020 * Utility classes and methods for the {@link License @License} annotation.
021 *
022 * <h5 class='section'>See Also:</h5><ul>
023 * </ul>
024 */
025public class LicenseAnnotation {
026
027   //-----------------------------------------------------------------------------------------------------------------
028   // Static
029   //-----------------------------------------------------------------------------------------------------------------
030
031   /** Default value */
032   public static final License DEFAULT = create().build();
033
034   /**
035    * Instantiates a new builder for this class.
036    *
037    * @return A new builder object.
038    */
039   public static Builder create() {
040      return new Builder();
041   }
042
043   /**
044    * Returns <jk>true</jk> if the specified annotation contains all default values.
045    *
046    * @param a The annotation to check.
047    * @return <jk>true</jk> if the specified annotation contains all default values.
048    */
049   public static boolean empty(License a) {
050      return a == null || DEFAULT.equals(a);
051   }
052
053   //-----------------------------------------------------------------------------------------------------------------
054   // Builder
055   //-----------------------------------------------------------------------------------------------------------------
056
057   /**
058    * Builder class.
059    *
060    * <h5 class='section'>See Also:</h5><ul>
061    *    <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)}
062    * </ul>
063    */
064   public static class Builder extends AnnotationBuilder {
065
066      String name="", url="";
067
068      /**
069       * Constructor.
070       */
071      protected Builder() {
072         super(License.class);
073      }
074
075      /**
076       * Instantiates a new {@link License @License} object initialized with this builder.
077       *
078       * @return A new {@link License @License} object.
079       */
080      public License build() {
081         return new Impl(this);
082      }
083
084
085      /**
086       * Sets the {@link License#name} property on this annotation.
087       *
088       * @param value The new value for this property.
089       * @return This object.
090       */
091      public Builder name(String value) {
092         this.name = value;
093         return this;
094      }
095
096      /**
097       * Sets the {@link License#url} property on this annotation.
098       *
099       * @param value The new value for this property.
100       * @return This object.
101       */
102      public Builder url(String value) {
103         this.url = value;
104         return this;
105      }
106
107      // <FluentSetters>
108
109      // </FluentSetters>
110   }
111
112   //-----------------------------------------------------------------------------------------------------------------
113   // Implementation
114   //-----------------------------------------------------------------------------------------------------------------
115
116   private static class Impl extends AnnotationImpl implements License {
117
118      private final String name, url;
119
120      Impl(Builder b) {
121         super(b);
122         this.name = b.name;
123         this.url = b.url;
124         postConstruct();
125      }
126
127      @Override /* License */
128      public String name() {
129         return name;
130      }
131
132      @Override /* License */
133      public String url() {
134         return url;
135      }
136   }
137}