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.rest.server; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023 024import jakarta.servlet.*; 025 026/** 027 * Identifies a method that gets called immediately after servlet initialization. 028 * 029 * <p> 030 * This method is called from within the {@link Servlet#init(ServletConfig)} method after the {@link RestContext} 031 * object has been created. 032 * 033 * <p> 034 * The only valid parameter type for this method is {@link RestContext} which can be used to retrieve information 035 * about the servlet. 036 * 037 * <h5 class='section'>Notes:</h5><ul> 038 * <li class='note'> 039 * The method should return <jk>void</jk> although if it does return any value, the value will be ignored. 040 * <li class='note'> 041 * The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it. 042 * <li class='note'> 043 * Static methods can be used. 044 * <li class='note'> 045 * Multiple post-init methods can be defined on a class. 046 * <br>Post-init methods on parent classes are invoked before post-init methods on child classes unless {@link #childFirst()} is specified. 047 * <br>The order of Post-init method invocations within a class is alphabetical, then by parameter count, then by parameter types. 048 * <li class='note'> 049 * The method can throw any exception causing initialization of the servlet to fail. 050 * <li class='note'> 051 * Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>. 052 * <br>The method is still considered part of the parent class for ordering purposes even though it's 053 * overridden by the child class. 054 * </ul> 055 */ 056@Target({ METHOD }) 057@Retention(RUNTIME) 058@Inherited 059public @interface RestPostInit { 060 061 /** 062 * Execute in child-first order. 063 * 064 * <p> 065 * Use this annotation if you need to perform any kind of initialization on child resources before the parent resource. 066 * 067 * <p> 068 * This method is called from within the {@link Servlet#init(ServletConfig)} method after the {@link RestContext} 069 * object has been created and after the non-child-first methods have been called. 070 * 071 * @return The annotation value. 072 */ 073 boolean childFirst() default false; 074 075 /** 076 * Optional description for the exposed API. 077 * 078 * @return The annotation value. 079 * @since 9.2.0 080 */ 081 String[] description() default {}; 082}