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 022/** 023 * <p> 024 * WorkflowEvent indicates that a state change to a Workflow: started, running, waiting, completed, aborted. 025 * These correspond exactly to the states described in the {@link org.apache.wiki.workflow.Workflow}. All events 026 * are logged with priority INFO. 027 * </p> 028 * 029 * @since 2.3.79 030 */ 031public final class WorkflowEvent extends WikiEvent { 032 033 private static final long serialVersionUID = 1L; 034 035 /** After Workflow instantiation. */ 036 public static final int CREATED = 0; 037 038 /** 039 * After the Workflow has been instantiated, but before it has been started 040 * using the {@link org.apache.wiki.workflow.Workflow#start()} method. 041 */ 042 public static final int STARTED = 10; 043 044 /** 045 * After the Workflow has been started (or re-started) using the 046 * {@link org.apache.wiki.workflow.Workflow#start()} method, 047 * but before it has finished processing all Steps. 048 */ 049 public static final int RUNNING = 20; 050 051 /** When the Workflow has temporarily paused, for example because of a pending Decision. */ 052 public static final int WAITING = 30; 053 054 /** After the Workflow has finished processing all Steps, without errors. */ 055 public static final int COMPLETED = 40; 056 057 /** If a Step has elected to abort the Workflow. */ 058 public static final int ABORTED = 50; 059 060 /** When the workflow wishes to add a Decision to the DecisionQueue */ 061 public static final int DQ_ADDITION = 60; 062 063 /** When the workflow wishes to remove a Decision from the DecisionQueue */ 064 public static final int DQ_REMOVAL = 70; 065 066 /** When the decision queue decides the outcome of a Decision */ 067 public static final int DQ_DECIDE = 80; 068 069 /** When the decision queue reassigns a Decision */ 070 public static final int DQ_REASSIGN = 90; 071 072 /** 073 * Constructs a new instance of this event type, which signals a security event has occurred. 074 * The <code>source</code> parameter is required, and may not be <code>null</code>. When the 075 * WikiSecurityEvent is constructed, the security logger {@link WikiSecurityEvent#log} is notified. 076 * 077 * @param src the source of the event, which can be any object: a wiki page, group or authentication/authentication/group manager. 078 * @param type the type of event 079 */ 080 public WorkflowEvent( final Object src, final int type ) { 081 super( src, type ); 082 } 083 084 /** 085 * Constructs a new instance of this event type, which signals a security event has occurred. 086 * The <code>source</code> parameter is required, and may not be <code>null</code>. When the 087 * WikiSecurityEvent is constructed, the security logger {@link WikiSecurityEvent#log} is notified. 088 * 089 * @param src the source of the event, which can be any object: a wiki page, group or authentication/authentication/group manager. 090 * @param type the type of event 091 */ 092 public WorkflowEvent( final Object src, final int type, final Object... args ) { 093 super( src, type, args ); 094 } 095 096 /** 097 * Prints a String (human-readable) representation of this object. 098 * 099 * @see java.lang.Object#toString() 100 */ 101 public String toString() { 102 final StringBuilder msg = new StringBuilder(); 103 msg.append( "WorkflowEvent." ); 104 msg.append( eventName( getType() ) ); 105 final Object obj = getSrc(); // cfr. https://forums.oracle.com/forums/thread.jspa?threadID=1184115 106 msg.append( " [source=" ).append( obj.toString() ); 107 msg.append( "]" ); 108 return msg.toString(); 109 } 110 111 /** 112 * Returns a textual representation of an event type. 113 * 114 * @param type the type 115 * @return the string representation 116 */ 117 public String eventName( final int type ) { 118 switch( type ) { 119 case CREATED: return "CREATED"; 120 case ABORTED: return "ABORTED"; 121 case COMPLETED: return "COMPLETED"; 122 case RUNNING: return "RUNNING"; 123 case STARTED: return "STARTED"; 124 case WAITING: return "WAITING"; 125 case DQ_REMOVAL: return "DQ_REMOVAL"; 126 default: return super.eventName(); 127 } 128 } 129 130}