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.marshall; 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 Example @Example} annotation. 027 * 028 */ 029public class ExampleAnnotation { 030 031 /** 032 * Prevents instantiation. 033 */ 034 private ExampleAnnotation() {} 035 036 /** 037 * Builder class. 038 * 039 * <h5 class='section'>See Also:</h5><ul> 040 * <li class='jm'>{@link MarshallingContext.Builder#annotations(Annotation...)} 041 * </ul> 042 */ 043 public static class Builder extends AnnotationObject.Builder { 044 045 private String[] description = {}; 046 private String value = ""; 047 048 /** 049 * Constructor. 050 */ 051 protected Builder() { 052 super(Example.class); 053 } 054 055 /** 056 * Instantiates a new {@link Example @Example} object initialized with this builder. 057 * 058 * @return A new {@link Example @Example} object. 059 */ 060 public Example build() { 061 return new Object(this); 062 } 063 064 /** 065 * Sets the description property on this annotation. 066 * 067 * @param value The new value for this property. 068 * @return This object. 069 */ 070 public Builder description(String...value) { 071 description = value; 072 return this; 073 } 074 075 /** 076 * Sets the <c>value</c> property on this annotation. 077 * 078 * @param value The new value for this property. 079 * @return This object. 080 */ 081 public Builder value(String value) { 082 this.value = value; 083 return this; 084 } 085 086 } 087 088 @SuppressWarnings({ 089 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 090 }) 091 private static class Object extends AnnotationObject implements Example { 092 093 private final String[] description; 094 private final String value; 095 096 Object(ExampleAnnotation.Builder b) { 097 super(b); 098 description = cp(b.description); 099 value = b.value; 100 } 101 102 @Override /* Overridden from Example */ 103 public String value() { 104 return value; 105 } 106 107 @Override /* Overridden from annotation */ 108 public String[] description() { 109 return description; 110 } 111 } 112 113 /** Default value */ 114 public static final Example DEFAULT = create().build(); 115 116 /** 117 * Instantiates a new builder for this class. 118 * 119 * @return A new builder object. 120 */ 121 public static Builder create() { 122 return new Builder(); 123 } 124}