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.urlencoding.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 UrlEncoding} annotation. 023 * 024 * <ul class='seealso'> 025 * <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)} 026 * </ul> 027 */ 028public class UrlEncodingAnnotation implements UrlEncoding { 029 030 private String 031 on = ""; 032 private boolean 033 expandedParams = false; 034 035 /** 036 * Constructor. 037 * 038 * @param on The initial value for the <c>on</c> property. 039 * <br>See {@link UrlEncoding#on()} 040 */ 041 public UrlEncodingAnnotation(String on) { 042 on(on); 043 } 044 045 /** 046 * Constructor. 047 * 048 * @param on The initial value for the <c>on</c> property. 049 * <br>See {@link UrlEncoding#on()} 050 */ 051 public UrlEncodingAnnotation(Class<?> on) { 052 on(on); 053 } 054 055 /** 056 * Constructor. 057 * 058 * @param on The initial value for the <c>on</c> property. 059 * <br>See {@link UrlEncoding#on()} 060 */ 061 public UrlEncodingAnnotation(Method on) { 062 on(on); 063 } 064 065 /** 066 * Constructor. 067 * 068 * @param on The initial value for the <c>on</c> property. 069 * <br>See {@link UrlEncoding#on()} 070 */ 071 public UrlEncodingAnnotation(Field on) { 072 on(on); 073 } 074 075 @Override 076 public Class<? extends Annotation> annotationType() { 077 return UrlEncoding.class; 078 } 079 080 @Override 081 public boolean expandedParams() { 082 return expandedParams; 083 } 084 085 /** 086 * Sets the <c>expandedParams</c> property on this annotation. 087 * 088 * @param value The new value for this property. 089 * @return This object (for method chaining). 090 */ 091 public UrlEncodingAnnotation expandedParams(boolean value) { 092 this.expandedParams = value; 093 return this; 094 } 095 096 @Override 097 public String on() { 098 return on; 099 } 100 101 /** 102 * Sets the <c>on</c> property on this annotation. 103 * 104 * @param value The new value for this property. 105 * @return This object (for method chaining). 106 */ 107 public UrlEncodingAnnotation on(String value) { 108 this.on = value; 109 return this; 110 } 111 112 /** 113 * Sets the <c>on</c> property on this annotation. 114 * 115 * @param value The new value for this property. 116 * @return This object (for method chaining). 117 */ 118 public UrlEncodingAnnotation on(Class<?> value) { 119 this.on = value.getName(); 120 return this; 121 } 122 123 /** 124 * Sets the <c>on</c> property on this annotation. 125 * 126 * @param value The new value for this property. 127 * @return This object (for method chaining). 128 */ 129 public UrlEncodingAnnotation on(Method value) { 130 this.on = MethodInfo.of(value).getFullName(); 131 return this; 132 } 133 134 /** 135 * Sets the <c>on</c> property on this annotation. 136 * 137 * @param value The new value for this property. 138 * @return This object (for method chaining). 139 */ 140 public UrlEncodingAnnotation on(Field value) { 141 this.on = value.getName(); 142 return this; 143 } 144}