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 during servlet destroy.
030 *
031 * <p>
032 * This method is called from within the {@link Servlet#destroy()}.
033 *
034 * <p>
035 * The only valid parameter type for this method is {@link RestContext}, although typically no arguments will
036 * be specified.
037 *
038 * <h5 class='figure'>Example:</h5>
039 * <p class='bjava'>
040 *    <ja>@Rest</ja>(...)
041 *    <jk>public class</jk> PetStoreResource <jk>extends</jk> BasicRestServlet <jk>implements</jk> BasicUniversalJenaConfig {
042 *
043 *       <jc>// Our database.</jc>
044 *       <jk>private</jk> Map&lt;Integer,Pet&gt; <jf>petDB</jf>;
045 *
046 *       <ja>@RestDestroy</ja>
047 *       <jk>public void</jk> onDestroy() {
048 *          <jf>petDB</jf> = <jk>null</jk>;
049 *       }
050 *    }
051 * </p>
052 *
053 * <h5 class='section'>Notes:</h5><ul>
054 *    <li class='note'>
055 *       The method should return <jk>void</jk> although if it does return any value, the value will be ignored.
056 *    <li class='note'>
057 *       The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it.
058 *    <li class='note'>
059 *       Static methods can be used.
060 *    <li class='note'>
061 *       Multiple destroy methods can be defined on a class.
062 *       <br>Destroy methods on child classes are invoked before destroy methods on parent classes.
063 *       <br>The order of destroy method invocations within a class is alphabetical, then by parameter count, then by parameter types.
064 *    <li class='note'>
065 *       In general, destroy methods should not throw any exceptions, although if any are thrown, the stack trace will be
066 *       printed to <c>System.err</c>.
067 *    <li class='note'>
068 *       Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>.
069 *       <br>The method is still considered part of the parent class for ordering purposes even though it's
070 *       overridden by the child class.
071 * </ul>
072 *
073 * <h5 class='section'>See Also:</h5><ul>
074 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/LifecycleHooks">Lifecycle Hooks</a>
075 * </ul>
076 */
077@Target({METHOD,TYPE})
078@Retention(RUNTIME)
079@Inherited
080@Repeatable(RestDestroyAnnotation.Array.class)
081public @interface RestDestroy {
082
083    /**
084     * Optional description for the exposed API.
085     *
086     * @return The annotation value.
087     * @since 9.2.0
088     */
089    String[] description() default {};
090
091    /**
092    * Dynamically apply this annotation to the specified methods.
093    *
094    * <h5 class='section'>See Also:</h5><ul>
095    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
096    * </ul>
097    *
098    * @return The annotation value.
099    */
100   String[] on() default {};
101}