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