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