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.rest.helper;
014
015import org.apache.juneau.annotation.*;
016import org.apache.juneau.html.annotation.*;
017import org.apache.juneau.http.annotation.*;
018import org.apache.juneau.jsonschema.annotation.Schema;
019
020/**
021 * Shortcut label for child resources.
022 *
023 * <p>
024 * Typically used in router resources.
025 *
026 * <h5 class='section'>Example:</h5>
027 * <p class='bcode w800'>
028 *    <jk>new</jk> ResourceLink(<js>"httpTool"</js>, <js>"HTTP request test client"</js>);
029 * </p>
030 *
031 * <ul class='seealso'>
032 *    <li class='link'>{@doc juneau-rest-server.RestMethod.PredefinedHelperBeans}
033 * </ul>
034 */
035@Bean(properties="name,description", fluentSetters=true)
036@Response(schema=@Schema(ignore=true))
037public final class ResourceDescription implements Comparable<ResourceDescription> {
038
039   private String name, description;
040
041   /**
042    * Constructor.
043    *
044    * @param name The name of the child resource.
045    * @param description The description of the child resource.
046    */
047   public ResourceDescription(String name, String description) {
048      this.name = name;
049      this.description = description;
050   }
051
052   /** No-arg constructor.  Used for JUnit testing of OPTIONS pages. */
053   public ResourceDescription() {}
054
055   /**
056    * Returns the name field on this label.
057    *
058    * @return The name.
059    */
060   @Html(link="servlet:/{name}")
061   public String getName() {
062      return name;
063   }
064
065   /**
066    * Sets the name field on this label to a new value.
067    *
068    * @param name The new name.
069    * @return This object (for method chaining).
070    */
071   public ResourceDescription name(String name) {
072      this.name = name;
073      return this;
074   }
075
076   /**
077    * Returns the description field on this label.
078    *
079    * @return The description.
080    */
081   public String getDescription() {
082      return description;
083   }
084
085   /**
086    * Sets the description field on this label to a new value.
087    *
088    * @param description The new description.
089    * @return This object (for method chaining).
090    */
091   public ResourceDescription description(String description) {
092      this.description = description;
093      return this;
094   }
095
096
097   @Override /* Comparable */
098   public int compareTo(ResourceDescription o) {
099      return getName().toString().compareTo(o.getName().toString());
100   }
101
102   @Override /* Object */
103   public boolean equals(Object o) {
104      return (o instanceof ResourceDescription) && ((ResourceDescription)o).getName().equals(getName());
105   }
106
107   @Override /* Object */
108   public int hashCode() {
109      return getName().hashCode();
110   }
111}