View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau;
18  
19  import org.apache.juneau.commons.reflect.*;
20  
21  /**
22   * A unit of work for applying an annotation to a context builder.
23   *
24   * <p>
25   * Consists of a pair of objects:
26   * <ul>
27   * 	<li>{@link AnnotationInfo} - The annotation being applied.
28   * 	<li>{@link AnnotationApplier} - The applier for that annotation.
29   * </ul>
30   *
31   */
32  @SuppressWarnings("rawtypes")
33  public class AnnotationWork {
34  	final AnnotationInfo annotation;
35  	final AnnotationApplier applier;
36  
37  	/**
38  	 * Constructor.
39  	 *
40  	 * @param annotation The annotation being applied.
41  	 * @param applier The applier for that annotation.
42  	 */
43  	public AnnotationWork(AnnotationInfo annotation, AnnotationApplier applier) {
44  		this.annotation = annotation;
45  		this.applier = applier;
46  	}
47  
48  	/**
49  	 * Calls {@link AnnotationApplier#apply(AnnotationInfo, Object)} on the specified builder.
50  	 *
51  	 * <p>
52  	 * A no-op if {@link AnnotationApplier#canApply(Object)} returns <jk>false</jk>.
53  	 *
54  	 * @param builder The builder.
55  	 */
56  	@SuppressWarnings("unchecked")
57  	public void apply(Object builder) {
58  		if (canApply(builder))
59  			applier.apply(annotation, builder);
60  	}
61  
62  	/**
63  	 * Returns <jk>true</jk> if the annotation in this work can be applied to the specified builder.
64  	 *
65  	 * @param builder The builder.
66  	 * @return <jk>true</jk> if the annotation in this work can be applied to the specified builder.
67  	 */
68  	public boolean canApply(Object builder) {
69  		return applier.canApply(builder);
70  	}
71  }