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