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;
018
019import org.apache.juneau.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 * <h5 class='section'>See Also:</h5><ul>
032 * </ul>
033 */
034@SuppressWarnings("rawtypes")
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.
044    */
045   public AnnotationWork(AnnotationInfo annotation, AnnotationApplier applier) {
046      this.annotation = annotation;
047      this.applier = applier;
048   }
049
050   /**
051    * Returns <jk>true</jk> if the annotation in this work can be applied to the specified builder.
052    *
053    * @param builder The builder.
054    * @return <jk>true</jk> if the annotation in this work can be applied to the specified builder.
055    */
056   public boolean canApply(Object builder) {
057      return applier.canApply(builder);
058   }
059
060   /**
061    * Calls {@link AnnotationApplier#apply(AnnotationInfo, Object)} on the specified builder.
062    *
063    * <p>
064    * A no-op if {@link AnnotationApplier#canApply(Object)} returns <jk>false</jk>.
065    *
066    * @param builder The builder.
067    */
068   @SuppressWarnings("unchecked")
069   public void apply(Object builder) {
070      if (canApply(builder))
071         applier.apply(annotation, builder);
072   }
073}