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