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