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