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 Contact @Contact} annotation.
025 *
026 * <h5 class='section'>See Also:</h5><ul>
027 * </ul>
028 */
029public class ContactAnnotation {
030
031   //-----------------------------------------------------------------------------------------------------------------
032   // Static
033   //-----------------------------------------------------------------------------------------------------------------
034
035   /** Default value */
036   public static final Contact 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(Contact 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 email="", name="", url="";
071
072      /**
073       * Constructor.
074       */
075      protected Builder() {
076         super(Contact.class);
077      }
078
079      /**
080       * Instantiates a new {@link Contact @Contact} object initialized with this builder.
081       *
082       * @return A new {@link Contact @Contact} object.
083       */
084      public Contact build() {
085         return new Impl(this);
086      }
087
088
089      /**
090       * Sets the {@link Contact#email} property on this annotation.
091       *
092       * @param value The new value for this property.
093       * @return This object.
094       */
095      public Builder email(String value) {
096         this.email = value;
097         return this;
098      }
099
100      /**
101       * Sets the {@link Contact#name} property on this annotation.
102       *
103       * @param value The new value for this property.
104       * @return This object.
105       */
106      public Builder name(String value) {
107         this.name = value;
108         return this;
109      }
110
111      /**
112       * Sets the {@link Contact#url} property on this annotation.
113       *
114       * @param value The new value for this property.
115       * @return This object.
116       */
117      public Builder url(String value) {
118         this.url = value;
119         return this;
120      }
121
122   }
123
124   //-----------------------------------------------------------------------------------------------------------------
125   // Implementation
126   //-----------------------------------------------------------------------------------------------------------------
127
128   private static class Impl extends AnnotationImpl implements Contact {
129
130      private final String email, name, url;
131
132      Impl(Builder b) {
133         super(b);
134         this.email = b.email;
135         this.name = b.name;
136         this.url = b.url;
137         postConstruct();
138      }
139
140      @Override /* Contact */
141      public String email() {
142         return email;
143      }
144
145      @Override /* Contact */
146      public String name() {
147         return name;
148      }
149
150      @Override /* Contact */
151      public String url() {
152         return url;
153      }
154   }
155}