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.*;
023import org.apache.juneau.annotation.*;
024import org.apache.juneau.common.internal.*;
025import org.apache.juneau.internal.*;
026
027/**
028 * License information for the exposed API.
029 *
030 * <h5 class='section'>Example:</h5>
031 * <p class='bjava'>
032 *    <jc>// Construct using SwaggerBuilder.</jc>
033 *    License <jv>license</jv> = <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>);
034 *
035 *    <jc>// Serialize using JsonSerializer.</jc>
036 *    String <jv>json</jv> = JsonSerializer.<jsf>DEFAULT</jsf>.toString(<jv>license</jv>);
037 *
038 *    <jc>// Or just use toString() which does the same as above.</jc>
039 *    <jv>json</jv> = <jv>license</jv>.toString();
040 * </p>
041 * <p class='bjson'>
042 *    <jc>// Output</jc>
043 *    {
044 *       <js>"name"</js>: <js>"Apache 2.0"</js>,
045 *       <js>"url"</js>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>
046 *    }
047 * </p>
048 *
049 * <h5 class='section'>See Also:</h5><ul>
050 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Swagger">Overview &gt; juneau-rest-server &gt; Swagger</a>
051 * </ul>
052 */
053@Bean(properties="name,url,*")
054@FluentSetters
055public class License extends SwaggerElement {
056
057   private String name;
058   private URI url;
059
060   /**
061    * Default constructor.
062    */
063   public License() {}
064
065   /**
066    * Copy constructor.
067    *
068    * @param copyFrom The object to copy.
069    */
070   public License(License copyFrom) {
071      super(copyFrom);
072
073      this.name = copyFrom.name;
074      this.url = copyFrom.url;
075   }
076
077   /**
078    * Make a deep copy of this object.
079    *
080    * @return A deep copy of this object.
081    */
082   public License copy() {
083      return new License(this);
084   }
085
086   //-----------------------------------------------------------------------------------------------------------------
087   // Properties
088   //-----------------------------------------------------------------------------------------------------------------
089
090   /**
091    * Bean property getter:  <property>name</property>.
092    *
093    * <p>
094    * The license name used for the API.
095    *
096    * @return The property value, or <jk>null</jk> if it is not set.
097    */
098   public String getName() {
099      return name;
100   }
101
102   /**
103    * Bean property setter:  <property>name</property>.
104    *
105    * <p>
106    * The license name used for the API.
107    *
108    * @param value
109    *    The new value for this property.
110    *    <br>Property value is required.
111    * @return This object.
112    */
113   public License setName(String value) {
114      name = value;
115      return this;
116   }
117
118   /**
119    * Bean property getter:  <property>url</property>.
120    *
121    * <p>
122    * A URL to the license used for the API.
123    *
124    * @return The property value, or <jk>null</jk> if it is not set.
125    */
126   public URI getUrl() {
127      return url;
128   }
129
130   /**
131    * Bean property setter:  <property>url</property>.
132    *
133    * <p>
134    * A URL to the license used for the API.
135    *
136    * @param value
137    *    The new value for this property.
138    *    <br>URIs defined by {@link UriResolver} can be used for values.
139    *    <br>Can be <jk>null</jk> to unset the property.
140    * @return This object.
141    */
142   public License setUrl(URI value) {
143      url = value;
144      return this;
145   }
146
147   // <FluentSetters>
148
149   // </FluentSetters>
150
151   @Override /* SwaggerElement */
152   public <T> T get(String property, Class<T> type) {
153      if (property == null)
154         return null;
155      switch (property) {
156         case "name": return toType(getName(), type);
157         case "url": return toType(getUrl(), type);
158         default: return super.get(property, type);
159      }
160   }
161
162   @Override /* SwaggerElement */
163   public License set(String property, Object value) {
164      if (property == null)
165         return this;
166      switch (property) {
167         case "name": return setName(stringify(value));
168         case "url": return setUrl(StringUtils.toURI(value));
169         default:
170            super.set(property, value);
171            return this;
172      }
173   }
174
175   @Override /* SwaggerElement */
176   public Set<String> keySet() {
177      Set<String> s = setBuilder(String.class)
178         .addIf(name != null, "name")
179         .addIf(url != null, "url")
180         .build();
181      return new MultiSet<>(s, super.keySet());
182   }
183}