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