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.http; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.commons.*; 024 025/** 026 * Utility classes and methods for the {@link Contact @Contact} annotation. 027 * 028 */ 029public class ContactAnnotation { 030 031 /** 032 * Prevents instantiation. 033 */ 034 private ContactAnnotation() {} 035 036 /** 037 * Builder class. 038 * 039 * <h5 class='section'>See Also:</h5><ul> 040 * <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)} 041 * </ul> 042 */ 043 public static class Builder extends AnnotationObject.Builder { 044 045 private String[] description = {}; 046 private String email = ""; 047 private String name = ""; 048 private String url = ""; 049 050 /** 051 * Constructor. 052 */ 053 protected Builder() { 054 super(Contact.class); 055 } 056 057 /** 058 * Instantiates a new {@link Contact @Contact} object initialized with this builder. 059 * 060 * @return A new {@link Contact @Contact} object. 061 */ 062 public Contact build() { 063 return new Instance(this); 064 } 065 066 /** 067 * Sets the description property on this annotation. 068 * 069 * @param value The new value for this property. 070 * @return This object. 071 */ 072 public Builder description(String...value) { 073 description = value; 074 return this; 075 } 076 077 /** 078 * Sets the {@link Contact#email} property on this annotation. 079 * 080 * @param value The new value for this property. 081 * @return This object. 082 */ 083 public Builder email(String value) { 084 email = value; 085 return this; 086 } 087 088 /** 089 * Sets the {@link Contact#name} property on this annotation. 090 * 091 * @param value The new value for this property. 092 * @return This object. 093 */ 094 public Builder name(String value) { 095 name = value; 096 return this; 097 } 098 099 /** 100 * Sets the {@link Contact#url} property on this annotation. 101 * 102 * @param value The new value for this property. 103 * @return This object. 104 */ 105 public Builder url(String value) { 106 url = value; 107 return this; 108 } 109 } 110 111 @SuppressWarnings({ 112 "ClassExplicitlyAnnotation", // IntelliJ / SonarLint: Instance implements @Contact (AnnotationObject runtime proxy pattern) 113 "all", // Eclipse JDT: AnnotationTypeUsedAsSuperInterface has no dedicated @SuppressWarnings token (JLS 9.6) 114 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 115 }) 116 private static class Instance extends AnnotationObject implements Contact { 117 118 private final String[] description; 119 private final String email; 120 private final String name; 121 private final String url; 122 123 Instance(ContactAnnotation.Builder b) { 124 super(b); 125 description = cp(b.description); 126 email = b.email; 127 name = b.name; 128 url = b.url; 129 } 130 131 @Override /* Overridden from Contact */ 132 public String email() { 133 return email; 134 } 135 136 @Override /* Overridden from Contact */ 137 public String name() { 138 return name; 139 } 140 141 @Override /* Overridden from Contact */ 142 public String url() { 143 return url; 144 } 145 146 @Override /* Overridden from annotation */ 147 public String[] description() { 148 return cp(description); 149 } 150 } 151 152 /** Default value */ 153 public static final Contact DEFAULT = create().build(); 154 155 /** 156 * Instantiates a new builder for this class. 157 * 158 * @return A new builder object. 159 */ 160 public static Builder create() { 161 return new Builder(); 162 } 163 164 /** 165 * Returns <jk>true</jk> if the specified annotation contains all default values. 166 * 167 * @param a The annotation to check. 168 * @return <jk>true</jk> if the specified annotation contains all default values. 169 */ 170 public static boolean empty(Contact a) { 171 return a == null || DEFAULT.equals(a); 172 } 173}