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; 014 015import org.apache.juneau.reflect.*; 016 017/** 018 * A unit of work for applying an annotation to a context builder. 019 * 020 * <p> 021 * Consists of a pair of objects: 022 * <ul> 023 * <li>{@link AnnotationInfo} - The annotation being applied. 024 * <li>{@link AnnotationApplier} - The applier for that annotation. 025 * </ul> 026 * 027 * <h5 class='section'>See Also:</h5><ul> 028 * </ul> 029 */ 030@SuppressWarnings("rawtypes") 031public class AnnotationWork { 032 final AnnotationInfo annotation; 033 final AnnotationApplier applier; 034 035 /** 036 * Constructor. 037 * 038 * @param annotation The annotation being applied. 039 * @param applier The applier for that annotation. 040 */ 041 public AnnotationWork(AnnotationInfo annotation, AnnotationApplier applier) { 042 this.annotation = annotation; 043 this.applier = applier; 044 } 045 046 /** 047 * Returns <jk>true</jk> if the annotation in this work can be applied to the specified builder. 048 * 049 * @param builder The builder. 050 * @return <jk>true</jk> if the annotation in this work can be applied to the specified builder. 051 */ 052 public boolean canApply(Object builder) { 053 return applier.canApply(builder); 054 } 055 056 /** 057 * Calls {@link AnnotationApplier#apply(AnnotationInfo, Object)} on the specified builder. 058 * 059 * <p> 060 * A no-op if {@link AnnotationApplier#canApply(Object)} returns <jk>false</jk>. 061 * 062 * @param builder The builder. 063 */ 064 @SuppressWarnings("unchecked") 065 public void apply(Object builder) { 066 if (canApply(builder)) 067 applier.apply(annotation, builder); 068 } 069}