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 */ 019 020package org.apache.wiki.event; 021 022import org.apache.wiki.WikiEngine; 023 024/** 025 * WikiEngineEvent indicates a change in the state of the WikiEngine. 026 * 027 * @see org.apache.wiki.event.WikiEvent 028 * @since 2.4.20 029 */ 030public class WikiEngineEvent extends WikiEvent { 031 032 private static final long serialVersionUID = 1829433967558773970L; 033 034 /** Indicates a WikiEngine initialization event, fired as the 035 * wiki service is being initialized (in progress). */ 036 public static final int INITIALIZING = -1; 037 038 /** Indicates a WikiEngine initialized event, fired after the 039 * wiki service is fully available. */ 040 public static final int INITIALIZED = 0; 041 042 /** Indicates a WikiEngine closing event, fired as a signal that 043 * the wiki service is shutting down. */ 044 public static final int SHUTDOWN = 1; 045 046 /** Indicates a WikiEngine stopped event, fired after halting the wiki service. 047 * A WikiEngine in this state is not expected to provide further services. 048 */ 049 public static final int STOPPED = 2; 050 051 private WikiEngine m_engine; 052 053 /** 054 * Constructs an instance of this event. 055 * @param eventSource the Object that is the source of the event, 056 * which <b>must</b> be the WikiEngine. If it is not, this 057 * method thows a ClassCastException 058 * @param type the event type 059 */ 060 public WikiEngineEvent( Object eventSource, int type ) { 061 super( eventSource, type ); 062 m_engine = (WikiEngine)eventSource; 063 } 064 065 /** 066 * Sets the type of this event. 067 * 068 * @param type the type of this WikiEngineEvent. 069 */ 070 protected void setType( int type ) { 071 if ( type >= INITIALIZING && type <= STOPPED ) { 072 super.setType(type); 073 } else { 074 super.setType(ERROR); 075 } 076 } 077 078 /** 079 * Returns the WikiEngine that spawned this event. 080 * 081 * @return the WikiEngine that spawned this event. 082 */ 083 public WikiEngine getEngine() 084 { 085 return m_engine; 086 } 087 088 /** 089 * Returns <code>true</code> if the int value is a WikiPageEvent type. 090 * @param type the event type 091 * @return the result 092 */ 093 public static boolean isValidType( int type ) 094 { 095 return type >= INITIALIZING && type <= STOPPED; 096 } 097 098 /** 099 * Returns a textual representation of the event type. 100 * 101 * @return a String representation of the type 102 */ 103 public final String eventName() { 104 switch ( getType() ) { 105 case INITIALIZING: return "INITIALIZING"; 106 case INITIALIZED: return "INITIALIZED"; 107 case SHUTDOWN: return "SHUTDOWN"; 108 case STOPPED: return "STOPPED"; 109 default: return super.eventName(); 110 } 111 } 112 113 /** 114 * Returns a human-readable description of the event type. 115 * 116 * @return a String description of the type 117 */ 118 public final String getTypeDescription() { 119 switch ( getType() ) { 120 case INITIALIZING: return "wiki engine initializing"; 121 case INITIALIZED: return "wiki engine initialized"; 122 case SHUTDOWN: return "wiki engine shutting down"; 123 case STOPPED: return "wiki engine stopped"; 124 default: return super.getTypeDescription(); 125 } 126 } 127 128}