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 055 056 /** 057 * Constructs an instance of this event. 058 * @param eventSource the Object that is the source of the event, 059 * which <b>must</b> be the WikiEngine. If it is not, this 060 * method thows a ClassCastException 061 * @param type the event type 062 */ 063 public WikiEngineEvent( Object eventSource, int type ) 064 { 065 super( eventSource, type ); 066 m_engine = (WikiEngine)eventSource; 067 } 068 069 070 /** 071 * Sets the type of this event. 072 * 073 * @param type the type of this WikiEngineEvent. 074 */ 075 protected void setType( int type ) 076 { 077 if ( type >= INITIALIZING && type <= STOPPED ) 078 { 079 super.setType(type); 080 } 081 else 082 { 083 super.setType(ERROR); 084 } 085 } 086 087 088 /** 089 * Returns the WikiEngine that spawned this event. 090 * 091 * @return the WikiEngine that spawned this event. 092 */ 093 public WikiEngine getEngine() 094 { 095 return m_engine; 096 } 097 098 099 /** 100 * Returns the WikiEngine that spawned this event. 101 * 102 * @return the WikiEngine that spawned this event. 103 * @deprecated use {@link #getEngine()} instead. 104 */ 105 public WikiEngine getWikiEngine() 106 { 107 return m_engine; 108 } 109 110 111 /** 112 * Returns <code>true</code> if the int value is a WikiPageEvent type. 113 * @param type the event type 114 * @return the result 115 */ 116 public static boolean isValidType( int type ) 117 { 118 return type >= INITIALIZING && type <= STOPPED; 119 } 120 121 122 /** 123 * Returns a textual representation of the event type. 124 * 125 * @return a String representation of the type 126 */ 127 public final String eventName() 128 { 129 switch ( getType() ) 130 { 131 case INITIALIZING: return "INITIALIZING"; 132 case INITIALIZED: return "INITIALIZED"; 133 case SHUTDOWN: return "SHUTDOWN"; 134 case STOPPED: return "STOPPED"; 135 default: return super.eventName(); 136 } 137 } 138 139 140 /** 141 * Returns a human-readable description of the event type. 142 * 143 * @return a String description of the type 144 */ 145 public final String getTypeDescription() 146 { 147 switch ( getType() ) 148 { 149 case INITIALIZING: return "wiki engine initializing"; 150 case INITIALIZED: return "wiki engine initialized"; 151 case SHUTDOWN: return "wiki engine shutting down"; 152 case STOPPED: return "wiki engine stopped"; 153 default: return super.getTypeDescription(); 154 } 155 } 156 157} // end class org.apache.wiki.event.WikiEngineEvent