1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.onami.factoryannotation; 20 21 import java.lang.annotation.Annotation; 22 import java.lang.reflect.Constructor; 23 import java.lang.reflect.Field; 24 import java.lang.reflect.Member; 25 import java.lang.reflect.Method; 26 27 import com.google.inject.TypeLiteral; 28 29 /** 30 * This interface represents the injection point of the actual provision. In addiction to the 31 * {@link FactoryAnnotationProvisionType} returned by {@link #getProvisionType()} the methods {@link #getConstructor()}, 32 * {@link #getMethod()} or {@link #getField()} methods return null or the actual {@link Member} that corresponds to the 33 * injection point. 34 * 35 * @param <T> The type to be injected 36 * @param <A> Annotation type where injection happens 37 */ 38 public interface FactoryAnnotationProvision<T, A extends Annotation> 39 { 40 41 /** 42 * The type of provision to be executed 43 */ 44 public static enum FactoryAnnotationProvisionType 45 { 46 /** 47 * A method parameter provision 48 */ 49 METHOD, 50 51 /** 52 * A constructor parameter provision 53 */ 54 CONSTRUCTOR, 55 56 /** 57 * A field (instance member) provision 58 */ 59 FIELD, 60 61 /** 62 * A static field (class member) provision 63 */ 64 STATIC 65 } 66 67 /** 68 * Returns the type of provision that happens at this injection point 69 */ 70 FactoryAnnotationProvisionType getProvisionType(); 71 72 /** 73 * If the provision type is {@link FactoryAnnotationProvisionType#CONSTRUCTOR} this returns the constructor of the 74 * injection point otherwise it returns null. 75 */ 76 Constructor<T> getConstructor(); 77 78 /** 79 * If the provision type is {@link FactoryAnnotationProvisionType#METHOD} this returns the method of the injection 80 * point otherwise it returns null. 81 */ 82 Method getMethod(); 83 84 /** 85 * If the provision type is {@link FactoryAnnotationProvisionType#CONSTRUCTOR} or 86 * {@link FactoryAnnotationProvisionType#METHOD} this returns the parameter position of the parameter to be 87 * provisioned otherwise if the provision type is a field it returns -1. 88 */ 89 int getParameterPosition(); 90 91 /** 92 * If the provision type is {@link FactoryAnnotationProvisionType#FIELD} or 93 * {@link FactoryAnnotationProvisionType#STATIC} this returns the field of the injection point otherwise it returns 94 * null. 95 */ 96 Field getField(); 97 98 /** 99 * Returns the target object to be provisioned. 100 */ 101 T getTarget(); 102 103 /** 104 * Returns the actual annotation of the bound annotation type. 105 */ 106 A getProvisionAnnotation(); 107 108 /** 109 * Returns an array of all available annotations at the actual provision position (field, method- / constructor 110 * parameter). 111 */ 112 Annotation[] getAnnotations(); 113 114 /** 115 * Returns the {@link TypeLiteral} of the provisioned type. 116 */ 117 TypeLiteral<T> getElementTypeLiteral(); 118 119 }