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