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.bean.hal;
018
019import org.apache.juneau.marshall.*;
020import org.apache.juneau.marshall.marshaller.*;
021
022/**
023 * Represents a HAL Link Object as defined by
024 * <a href="https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-08#section-5">draft-kelly-json-hal-08 &#167; 5</a>.
025 *
026 * <p>
027 * A Link Object describes a hyperlink from the containing resource to another resource. The {@code href} property is
028 * the only required field; all other fields are optional.
029 *
030 * <h5 class='section'>See Also:</h5><ul>
031 *   <li class='link'><a href="https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-08#section-5">HAL Link Object</a>
032 *   <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHal">juneau-bean-hal</a>
033 * </ul>
034 */
035@Marshalled
036@SuppressWarnings({
037   "java:S116" // Field names mirror HAL spec.
038})
039public class HalLink {
040
041   private String href;
042   private Boolean templated;
043   private String type;
044   private String deprecation;
045   private String name;
046   private String profile;
047   private String title;
048   private String hreflang;
049
050   /**
051    * Default constructor.
052    */
053   public HalLink() {}
054
055   /**
056    * Convenience constructor with the required {@code href} field.
057    *
058    * @param href The link URI or URI template.  Can be <jk>null</jk> to leave the property unset.
059    */
060   public HalLink(String href) {
061      this.href = href;
062   }
063
064   /**
065    * Bean property getter:  <property>href</property>.
066    *
067    * <p>
068    * The link's target URI or URI template (per RFC 6570). This is the only required HAL Link field.
069    *
070    * @return The value of the <property>href</property> property, or <jk>null</jk> if it is not set.
071    */
072   public String getHref() { return href; }
073
074   /**
075    * Bean property setter:  <property>href</property>.
076    *
077    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
078    * @return This object.
079    */
080   public HalLink setHref(String value) {
081      href = value;
082      return this;
083   }
084
085   /**
086    * Bean property getter:  <property>templated</property>.
087    *
088    * <p>
089    * Indicates whether {@link #getHref() href} is a URI template per RFC 6570.
090    *
091    * @return The value of the <property>templated</property> property, or <jk>null</jk> if it is not set.
092    */
093   public Boolean getTemplated() { return templated; }
094
095   /**
096    * Bean property setter:  <property>templated</property>.
097    *
098    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
099    * @return This object.
100    */
101   public HalLink setTemplated(Boolean value) {
102      templated = value;
103      return this;
104   }
105
106   /**
107    * Bean property getter:  <property>type</property>.
108    *
109    * <p>
110    * A hint about the media type expected when dereferencing the target resource.
111    *
112    * @return The value of the <property>type</property> property, or <jk>null</jk> if it is not set.
113    */
114   public String getType() { return type; }
115
116   /**
117    * Bean property setter:  <property>type</property>.
118    *
119    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
120    * @return This object.
121    */
122   public HalLink setType(String value) {
123      type = value;
124      return this;
125   }
126
127   /**
128    * Bean property getter:  <property>deprecation</property>.
129    *
130    * <p>
131    * A URL providing information about deprecation of the link.
132    *
133    * @return The value of the <property>deprecation</property> property, or <jk>null</jk> if it is not set.
134    */
135   public String getDeprecation() { return deprecation; }
136
137   /**
138    * Bean property setter:  <property>deprecation</property>.
139    *
140    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
141    * @return This object.
142    */
143   public HalLink setDeprecation(String value) {
144      deprecation = value;
145      return this;
146   }
147
148   /**
149    * Bean property getter:  <property>name</property>.
150    *
151    * <p>
152    * A secondary key for selecting a link from a set sharing the same relation.
153    *
154    * @return The value of the <property>name</property> property, or <jk>null</jk> if it is not set.
155    */
156   public String getName() { return name; }
157
158   /**
159    * Bean property setter:  <property>name</property>.
160    *
161    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
162    * @return This object.
163    */
164   public HalLink setName(String value) {
165      name = value;
166      return this;
167   }
168
169   /**
170    * Bean property getter:  <property>profile</property>.
171    *
172    * <p>
173    * A URI hint about the profile (additional semantics) of the target resource.
174    *
175    * @return The value of the <property>profile</property> property, or <jk>null</jk> if it is not set.
176    */
177   public String getProfile() { return profile; }
178
179   /**
180    * Bean property setter:  <property>profile</property>.
181    *
182    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
183    * @return This object.
184    */
185   public HalLink setProfile(String value) {
186      profile = value;
187      return this;
188   }
189
190   /**
191    * Bean property getter:  <property>title</property>.
192    *
193    * <p>
194    * A human-readable identifier for the link, suitable for display.
195    *
196    * @return The value of the <property>title</property> property, or <jk>null</jk> if it is not set.
197    */
198   public String getTitle() { return title; }
199
200   /**
201    * Bean property setter:  <property>title</property>.
202    *
203    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
204    * @return This object.
205    */
206   public HalLink setTitle(String value) {
207      title = value;
208      return this;
209   }
210
211   /**
212    * Bean property getter:  <property>hreflang</property>.
213    *
214    * <p>
215    * The language of the target resource (RFC 5646 language tag).
216    *
217    * @return The value of the <property>hreflang</property> property, or <jk>null</jk> if it is not set.
218    */
219   public String getHreflang() { return hreflang; }
220
221   /**
222    * Bean property setter:  <property>hreflang</property>.
223    *
224    * @param value The new value for this property.  Can be <jk>null</jk> to unset the property.
225    * @return This object.
226    */
227   public HalLink setHreflang(String value) {
228      hreflang = value;
229      return this;
230   }
231
232   @Override /* Overridden from Object */
233   public String toString() {
234      return Json.of(this);
235   }
236}