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.annotation; 014 015import java.lang.annotation.*; 016import java.lang.reflect.*; 017 018import org.apache.juneau.*; 019import org.apache.juneau.reflect.*; 020 021/** 022 * A concrete implementation of the {@link Swap} annotation. 023 * 024 * <ul class='seealso'> 025 * <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)} 026 * </ul> 027 */ 028public class SwapAnnotation implements Swap { 029 030 private String 031 on = "", 032 template = ""; 033 private Class<?> 034 impl = Null.class, 035 value = Null.class; 036 private String[] 037 mediaTypes = new String[0]; 038 039 /** 040 * Constructor. 041 * 042 * @param on The initial value for the <c>on</c> property. 043 * <br>See {@link Swap#on()} 044 */ 045 public SwapAnnotation(String on) { 046 on(on); 047 } 048 049 /** 050 * Constructor. 051 * 052 * @param on The initial value for the <c>on</c> property. 053 * <br>See {@link Swap#on()} 054 */ 055 public SwapAnnotation(Class<?> on) { 056 on(on); 057 } 058 059 /** 060 * Constructor. 061 * 062 * @param on The initial value for the <c>on</c> property. 063 * <br>See {@link Swap#on()} 064 */ 065 public SwapAnnotation(Method on) { 066 on(on); 067 } 068 069 /** 070 * Constructor. 071 * 072 * @param on The initial value for the <c>on</c> property. 073 * <br>See {@link Swap#on()} 074 */ 075 public SwapAnnotation(Field on) { 076 on(on); 077 } 078 079 @Override 080 public Class<? extends Annotation> annotationType() { 081 return Swap.class; 082 } 083 084 @Override 085 public Class<?> impl() { 086 return impl; 087 } 088 089 /** 090 * Sets the <c>impl</c> property on this annotation. 091 * 092 * @param value The new value for this property. 093 * @return This object (for method chaining). 094 */ 095 public SwapAnnotation impl(Class<?> value) { 096 this.impl = value; 097 return this; 098 } 099 100 @Override 101 public String[] mediaTypes() { 102 return mediaTypes; 103 } 104 105 /** 106 * Sets the <c>mediaTypes</c> property on this annotation. 107 * 108 * @param value The new value for this property. 109 * @return This object (for method chaining). 110 */ 111 public SwapAnnotation mediaTypes(String...value) { 112 this.mediaTypes = value; 113 return this; 114 } 115 116 @Override 117 public String on() { 118 return on; 119 } 120 121 /** 122 * Sets the <c>on</c> property on this annotation. 123 * 124 * @param value The new value for this property. 125 * @return This object (for method chaining). 126 */ 127 public SwapAnnotation on(String value) { 128 this.on = value; 129 return this; 130 } 131 132 /** 133 * Sets the <c>on</c> property on this annotation. 134 * 135 * @param value The new value for this property. 136 * @return This object (for method chaining). 137 */ 138 public SwapAnnotation on(Class<?> value) { 139 this.on = value.getName(); 140 return this; 141 } 142 143 /** 144 * Sets the <c>on</c> property on this annotation. 145 * 146 * @param value The new value for this property. 147 * @return This object (for method chaining). 148 */ 149 public SwapAnnotation on(Method value) { 150 this.on = MethodInfo.of(value).getFullName(); 151 return this; 152 } 153 154 /** 155 * Sets the <c>on</c> property on this annotation. 156 * 157 * @param value The new value for this property. 158 * @return This object (for method chaining). 159 */ 160 public SwapAnnotation on(Field value) { 161 this.on = value.getName(); 162 return this; 163 } 164 165 @Override 166 public String template() { 167 return template; 168 } 169 170 /** 171 * Sets the <c>template</c> property on this annotation. 172 * 173 * @param value The new value for this property. 174 * @return This object (for method chaining). 175 */ 176 public SwapAnnotation template(String value) { 177 this.template = value; 178 return this; 179 } 180 181 @Override 182 public Class<?> value() { 183 return value; 184 } 185 186 /** 187 * Sets the <c>value</c> property on this annotation. 188 * 189 * @param value The new value for this property. 190 * @return This object (for method chaining). 191 */ 192 public SwapAnnotation value(Class<?> value) { 193 this.value = value; 194 return this; 195 } 196}