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.rest.beans; 018 019import static org.apache.juneau.commons.utils.Utils.*; 020 021import org.apache.juneau.annotation.*; 022import org.apache.juneau.html.annotation.*; 023import org.apache.juneau.http.annotation.*; 024 025/** 026 * Shortcut label for child resources. 027 * 028 * <p> 029 * Typically used in router resources. 030 * 031 * <h5 class='section'>Example:</h5> 032 * <p class='bjava'> 033 * <jk>new</jk> ResourceDescription(<js>"httpTool"</js>, <js>"HTTP request test client"</js>); 034 * </p> 035 * 036 * <h5 class='section'>See Also:</h5><ul> 037 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/UtilityBeans">Utility Beans</a> 038 039 * </ul> 040 */ 041@Bean(properties = "name,description", findFluentSetters = true) 042@Response(schema = @Schema(ignore = true)) 043public class ResourceDescription implements Comparable<ResourceDescription> { 044 045 private String name, uri, description; 046 047 /** No-arg constructor. Used for JUnit testing of OPTIONS pages. */ 048 public ResourceDescription() {} 049 050 /** 051 * Constructor for when the name and uri are the same. 052 * 053 * @param name The name of the child resource. 054 * @param description The description of the child resource. 055 */ 056 public ResourceDescription(String name, String description) { 057 this.name = name; 058 this.uri = name; 059 this.description = description; 060 } 061 062 /** 063 * Constructor for when the name and uri are different. 064 * 065 * @param name The name of the child resource. 066 * @param uri The uri of the child resource. 067 * @param description The description of the child resource. 068 */ 069 public ResourceDescription(String name, String uri, String description) { 070 this.name = name; 071 this.uri = uri; 072 this.description = description; 073 } 074 075 @Override /* Overridden from Comparable */ 076 public int compareTo(ResourceDescription o) { 077 return getName().toString().compareTo(o.getName().toString()); 078 } 079 080 /** 081 * Sets the description field on this label to a new value. 082 * 083 * @param description The new description. 084 * @return This object. 085 */ 086 public ResourceDescription description(String description) { 087 this.description = description; 088 return this; 089 } 090 091 @Override /* Overridden from Object */ 092 public boolean equals(Object o) { 093 return (o instanceof ResourceDescription o2) && eq(this, o2, (x, y) -> eq(x.getName(), y.getName())); 094 } 095 096 /** 097 * Returns the description field on this label. 098 * 099 * @return The description. 100 */ 101 public String getDescription() { return description; } 102 103 /** 104 * Returns the name field on this label. 105 * 106 * @return The name. 107 */ 108 @Html(link = "servlet:/{uri}") 109 public String getName() { return name; } 110 111 /** 112 * Returns the uri on this label. 113 * 114 * @return The name. 115 */ 116 public String getUri() { return uri == null ? name : uri; } 117 118 @Override /* Overridden from Object */ 119 public int hashCode() { 120 return getName().hashCode(); 121 } 122 123 /** 124 * Sets the name field on this label to a new value. 125 * 126 * @param name The new name. 127 * @return This object. 128 */ 129 public ResourceDescription name(String name) { 130 this.name = name; 131 return this; 132 } 133 134 /** 135 * Sets the uri field on this label to a new value. 136 * 137 * @param uri The new uri. 138 * @return This object. 139 */ 140 public ResourceDescription uri(String uri) { 141 this.uri = uri; 142 return this; 143 } 144}