001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2018 microBean. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 014 * implied. See the License for the specific language governing 015 * permissions and limitations under the License. 016 */ 017package org.microbean.kubernetes.controller.cdi.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import java.lang.reflect.ParameterizedType; // for javadoc only 026 027import java.util.Optional; // for javadoc only 028 029import javax.inject.Qualifier; 030 031import javax.enterprise.util.AnnotationLiteral; 032 033import io.fabric8.kubernetes.api.model.HasMetadata; // for javadoc only 034 035/** 036 * <strong>An extraordinarily special-purpose {@link Qualifier} 037 * annotation</strong> that may be used <em>only</em> to qualify a 038 * parameter in an observer method that meets the following criteria: 039 * 040 * <ol> 041 * 042 * <li>The observer method's <a 043 * href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#events">observed 044 * event type</a> is an instance of {@link HasMetadata}.</li> 045 * 046 * <li>The observer method's <a 047 * href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#events">observed 048 * event type</a> parameter is qualified with an annotation on which 049 * {@link KubernetesEventSelector} and {@link Qualifier} appear.</li> 050 * 051 * <li>The type of the parameter in question is a parameterized type 052 * whose {@linkplain ParameterizedType#getRawType() raw type} is 053 * {@link Optional Optional} and whose sole {@linkplain 054 * ParameterizedType#getActualTypeArguments() actual type argument} is 055 * <em>identical</em> to the observer method's <a 056 * href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#events">observed 057 * event type</a>.</li> 058 * 059 * </ol> 060 * 061 * @author <a href="https://about.me/lairdnelson" 062 * target="_parent">Laird Nelson</a> 063 */ 064@Documented 065@Qualifier 066@Retention(value = RetentionPolicy.RUNTIME) 067@Target({ ElementType.PARAMETER }) 068public @interface Prior { 069 070 public static final class Literal extends AnnotationLiteral<Prior> implements Prior { 071 072 private static final long serialVersionUID = 1L; 073 074 public static final Prior INSTANCE = new Literal(); 075 076 } 077 078}