001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import jakarta.servlet.*;
021
022import org.apache.juneau.rest.*;
023
024/**
025 * Identifies a method that gets called immediately after servlet initialization.
026 *
027 * <p>
028 * This method is called from within the {@link Servlet#init(ServletConfig)} method after the {@link RestContext}
029 * object has been created.
030 *
031 * <p>
032 * The only valid parameter type for this method is {@link RestContext} which can be used to retrieve information
033 * about the servlet.
034 *
035 * <h5 class='section'>Notes:</h5><ul>
036 *    <li class='note'>
037 *       The method should return <jk>void</jk> although if it does return any value, the value will be ignored.
038 *    <li class='note'>
039 *       The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it.
040 *    <li class='note'>
041 *       Static methods can be used.
042 *    <li class='note'>
043 *       Multiple post-init methods can be defined on a class.
044 *       <br>Post-init methods on parent classes are invoked before post-init methods on child classes unless {@link #childFirst()} is specified.
045 *       <br>The order of Post-init method invocations within a class is alphabetical, then by parameter count, then by parameter types.
046 *    <li class='note'>
047 *       The method can throw any exception causing initialization of the servlet to fail.
048 *    <li class='note'>
049 *       Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>.
050 *       <br>The method is still considered part of the parent class for ordering purposes even though it's
051 *       overridden by the child class.
052 * </ul>
053 */
054@Target({METHOD,TYPE})
055@Retention(RUNTIME)
056@Inherited
057@Repeatable(RestPostInitAnnotation.Array.class)
058public @interface RestPostInit {
059
060   /**
061    * Execute in child-first order.
062    *
063    * <p>
064    * Use this annotation if you need to perform any kind of initialization on child resources before the parent resource.
065    *
066    * <p>
067    * This method is called from within the {@link Servlet#init(ServletConfig)} method after the {@link RestContext}
068    * object has been created and after the non-child-first methods have been called.
069    *
070    * @return The annotation value.
071    */
072   boolean childFirst() default false;
073
074   /**
075    * Dynamically apply this annotation to the specified methods.
076    *
077    * <h5 class='section'>See Also:</h5><ul>
078    *    <li class='link'><a class="doclink" href="../../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
079    * </ul>
080    *
081    * @return The annotation value.
082    */
083   String[] on() default {};
084}