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.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("rawtypes")
033public class AnnotationWork {
034   final AnnotationInfo annotation;
035   final AnnotationApplier applier;
036
037   /**
038    * Constructor.
039    *
040    * @param annotation The annotation being applied.
041    * @param applier The applier for that annotation.
042    */
043   public AnnotationWork(AnnotationInfo annotation, AnnotationApplier applier) {
044      this.annotation = annotation;
045      this.applier = applier;
046   }
047
048   /**
049    * Calls {@link AnnotationApplier#apply(AnnotationInfo, Object)} on the specified builder.
050    *
051    * <p>
052    * A no-op if {@link AnnotationApplier#canApply(Object)} returns <jk>false</jk>.
053    *
054    * @param builder The builder.
055    */
056   @SuppressWarnings("unchecked")
057   public void apply(Object builder) {
058      if (canApply(builder))
059         applier.apply(annotation, builder);
060   }
061
062   /**
063    * Returns <jk>true</jk> if the annotation in this work can be applied to the specified builder.
064    *
065    * @param builder The builder.
066    * @return <jk>true</jk> if the annotation in this work can be applied to the specified builder.
067    */
068   public boolean canApply(Object builder) {
069      return applier.canApply(builder);
070   }
071}