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 * <h5 class='section'>See Also:</h5> 032 * <ul> 033 * <li class='link'>{@doc juneau-rest-server.RestMethod.PredefinedHelperBeans} 034 * </ul> 035 */ 036@Bean(properties="name,description", fluentSetters=true) 037@Response(schema=@Schema(ignore=true)) 038public final class ResourceDescription implements Comparable<ResourceDescription> { 039 040 private String name, description; 041 042 /** 043 * Constructor. 044 * 045 * @param name The name of the child resource. 046 * @param description The description of the child resource. 047 */ 048 public ResourceDescription(String name, String description) { 049 this.name = name; 050 this.description = description; 051 } 052 053 /** No-arg constructor. Used for JUnit testing of OPTIONS pages. */ 054 public ResourceDescription() {} 055 056 /** 057 * Returns the name field on this label. 058 * 059 * @return The name. 060 */ 061 @Html(link="servlet:/{name}") 062 public String getName() { 063 return name; 064 } 065 066 /** 067 * Sets the name field on this label to a new value. 068 * 069 * @param name The new name. 070 * @return This object (for method chaining). 071 */ 072 public ResourceDescription name(String name) { 073 this.name = name; 074 return this; 075 } 076 077 /** 078 * Returns the description field on this label. 079 * 080 * @return The description. 081 */ 082 public String getDescription() { 083 return description; 084 } 085 086 /** 087 * Sets the description field on this label to a new value. 088 * 089 * @param description The new description. 090 * @return This object (for method chaining). 091 */ 092 public ResourceDescription description(String description) { 093 this.description = description; 094 return this; 095 } 096 097 098 @Override /* Comparable */ 099 public int compareTo(ResourceDescription o) { 100 return getName().toString().compareTo(o.getName().toString()); 101 } 102 103 @Override /* Object */ 104 public boolean equals(Object o) { 105 return (o instanceof ResourceDescription) && ((ResourceDescription)o).getName().equals(getName()); 106 } 107 108 @Override /* Object */ 109 public int hashCode() { 110 return getName().hashCode(); 111 } 112}