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.dto.swagger;
014
015import static org.apache.juneau.common.internal.StringUtils.*;
016import static org.apache.juneau.internal.CollectionUtils.*;
017import static org.apache.juneau.internal.ConverterUtils.*;
018
019import java.net.*;
020import java.util.*;
021
022import org.apache.juneau.annotation.*;
023import org.apache.juneau.internal.*;
024
025/**
026 * Contact information for the exposed API.
027 *
028 * <h5 class='section'>Example:</h5>
029 * <p class='bjava'>
030 *    <jc>// Construct using SwaggerBuilder.</jc>
031 *    Contact <jv>contact</jv> = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>);
032 *
033 *    <jc>// Serialize using JsonSerializer.</jc>
034 *    String <jv>json</jv> = JsonSerializer.<jsf>DEFAULT</jsf>.toString(<jv>contact</jv>);
035 *
036 *    <jc>// Or just use toString() which does the same as above.</jc>
037 *    <jv>json</jv> = <jv>contact</jv>.toString();
038 * </p>
039 * <p class='bjson'>
040 *    <jc>// Output</jc>
041 *    {
042 *       <js>"name"</js>: <js>"API Support"</js>,
043 *       <js>"url"</js>: <js>"http://www.swagger.io/support"</js>,
044 *       <js>"email"</js>: <js>"support@swagger.io"</js>
045 *    }
046 * </p>
047 *
048 * <h5 class='section'>See Also:</h5><ul>
049 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Swagger">Overview &gt; juneau-rest-server &gt; Swagger</a>
050 * </ul>
051 */
052@Bean(properties="name,url,email,*")
053@FluentSetters
054public class Contact extends SwaggerElement {
055
056   private String name;
057   private URI url;
058   private String email;
059
060   /**
061    * Default constructor.
062    */
063   public Contact() {}
064
065   /**
066    * Copy constructor.
067    *
068    * @param copyFrom The object to copy.
069    */
070   public Contact(Contact copyFrom) {
071      super(copyFrom);
072
073      this.email = copyFrom.email;
074      this.name = copyFrom.name;
075      this.url = copyFrom.url;
076   }
077
078   /**
079    * Make a deep copy of this object.
080    *
081    * @return A deep copy of this object.
082    */
083   public Contact copy() {
084      return new Contact(this);
085   }
086
087   //-----------------------------------------------------------------------------------------------------------------
088   // Properties
089   //-----------------------------------------------------------------------------------------------------------------
090
091   /**
092    * Bean property getter:  <property>email</property>.
093    *
094    * <p>
095    * The email address of the contact person/organization.
096    *
097    * @return The property value, or <jk>null</jk> if it is not set.
098    */
099   public String getEmail() {
100      return email;
101   }
102
103   /**
104    * Bean property setter:  <property>email</property>.
105    *
106    * <p>
107    * The email address of the contact person/organization.
108    *
109    * @param value
110    *    The new value for this property.
111    *    <br>MUST be in the format of an email address.
112    *    <br>Can be <jk>null</jk> to unset the property.
113    * @return This object.
114    */
115   public Contact setEmail(String value) {
116      email = value;
117      return this;
118   }
119
120   /**
121    * Bean property getter:  <property>name</property>.
122    *
123    * <p>
124    * The identifying name of the contact person/organization.
125    *
126    * @return The property value, or <jk>null</jk> if it is not set.
127    */
128   public String getName() {
129      return name;
130   }
131
132   /**
133    * Bean property setter:  <property>name</property>.
134    *
135    * <p>
136    * The identifying name of the contact person/organization.
137    *
138    * @param value
139    *    The new value for this property.
140    *    <br>Can be <jk>null</jk> to unset the property.
141    * @return This object.
142    */
143   public Contact setName(String value) {
144      name = value;
145      return this;
146   }
147
148   /**
149    * Bean property getter:  <property>url</property>.
150    *
151    * <p>
152    * The URL pointing to the contact information.
153    *
154    * @return The property value, or <jk>null</jk> if it is not set.
155    */
156   public URI getUrl() {
157      return url;
158   }
159
160   /**
161    * Bean property setter:  <property>url</property>.
162    *
163    * <p>
164    * The URL pointing to the contact information.
165    *
166    * @param value
167    *    The new value for this property.
168    *    <br>Can be <jk>null</jk> to unset the property.
169    * @return This object.
170    */
171   public Contact setUrl(URI value) {
172      url = value;
173      return this;
174   }
175
176   // <FluentSetters>
177
178   // </FluentSetters>
179
180   @Override /* SwaggerElement */
181   public <T> T get(String property, Class<T> type) {
182      if (property == null)
183         return null;
184      switch (property) {
185         case "email": return toType(getEmail(), type);
186         case "name": return toType(getName(), type);
187         case "url": return toType(getUrl(), type);
188         default: return super.get(property, type);
189      }
190   }
191
192   @Override /* SwaggerElement */
193   public Contact set(String property, Object value) {
194      if (property == null)
195         return this;
196      switch (property) {
197         case "email": return setEmail(stringify(value));
198         case "name": return setName(stringify(value));
199         case "url": return setUrl(toURI(value));
200         default:
201            super.set(property, value);
202            return this;
203      }
204   }
205
206   @Override /* SwaggerElement */
207   public Set<String> keySet() {
208      Set<String> s = setBuilder(String.class)
209         .addIf(email != null, "email")
210         .addIf(name != null, "name")
211         .addIf(url != null, "url")
212         .build();
213      return new MultiSet<>(s, super.keySet());
214   }
215}