    001/*
    002    Licensed to the Apache Software Foundation (ASF) under one
    003    or more contributor license agreements.  See the NOTICE file
    004    distributed with this work for additional information
    005    regarding copyright ownership.  The ASF licenses this file
    006    to you under the Apache License, Version 2.0 (the
    007    "License"); you may not use this file except in compliance
    008    with the License.  You may obtain a copy of the License at
    009
    010       http://www.apache.org/licenses/LICENSE-2.0
    011
    012    Unless required by applicable law or agreed to in writing,
    013    software distributed under the License is distributed on an
    014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015    KIND, either express or implied.  See the License for the
    016    specific language governing permissions and limitations
    017    under the License.
    018 */
    019package org.apache.wiki.event;
    020
    021/**
    022  * WikiEngineEvent indicates a change in the state of the Engine.
    023  *
    024  * @see     org.apache.wiki.event.WikiEvent
    025  * @since   2.4.20
    026  */
    027public class WikiEngineEvent extends WikiEvent {
    028
    029    private static final long serialVersionUID = 1829433967558773970L;
    030
    031    /** Indicates a Engine initialization event, fired as the  wiki service is being initialized (in progress). */
    032    public static final int INITIALIZING   = -1;
    033
    034    /** Indicates a Engine initialized event, fired after the  wiki service is fully available. */
    035    public static final int INITIALIZED    = 0;
    036
    037    /** Indicates a Engine closing event, fired as a signal that the wiki service is shutting down. */
    038    public static final int SHUTDOWN       = 1;
    039
    040    /**
    041     * Indicates a Engine stopped event, fired after halting the wiki service. A Engine in this state is not expected to provide further
    042     * services.
    043     */
    044    public static final int STOPPED        = 2;
    045
    046     /**
    047      *  Constructs an instance of this event.
    048      *
    049      * @param eventSource the Object that is the source of the event, which <b>must</b> be the Engine. If it is not, this method thows
    050      *                    a ClassCastException
    051      * @param type the event type
    052      */
    053    public WikiEngineEvent( final Object eventSource, final int type ) {
    054        super( eventSource, type );
    055    }
    056
    057    /**
    058     *  Sets the type of this event.
    059     *
    060     * @param type the type of this WikiEngineEvent.
    061     */
    062    @Override
    063    protected void setType( final int type ) {
    064        if( type >= INITIALIZING && type <= STOPPED ) {
    065            super.setType( type );
    066        } else {
    067            super.setType( ERROR );
    068        }
    069    }
    070
    071    /**
    072     * Returns <code>true</code> if the int value is a WikiPageEvent type.
    073     *
    074     * @param type the event type
    075     * @return the result
    076     */
    077    public static boolean isValidType( final int type ) {
    078        return type >= INITIALIZING && type <= STOPPED;
    079    }
    080
    081    /**
    082     *  Returns a textual representation of the event type.
    083     *
    084     * @return a String representation of the type
    085     */
    086    @Override
    087    public final String eventName() {
    088        switch ( getType() ) {
    089            case INITIALIZING: return "INITIALIZING";
    090            case INITIALIZED:  return "INITIALIZED";
    091            case SHUTDOWN:     return "SHUTDOWN";
    092            case STOPPED:      return "STOPPED";
    093            default:           return super.eventName();
    094        }
    095    }
    096
    097    /**
    098     *  Returns a human-readable description of the event type.
    099     *
    100     * @return a String description of the type
    101     */
    102    @Override
    103    public final String getTypeDescription() {
    104        switch ( getType() ) {
    105            case INITIALIZING: return "wiki engine initializing";
    106            case INITIALIZED:  return "wiki engine initialized";
    107            case SHUTDOWN:     return "wiki engine shutting down";
    108            case STOPPED:      return "wiki engine stopped";
    109            default:           return super.getTypeDescription();
    110        }
    111    }
    112
    113}