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