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