samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 02 May 2010 14:34:48 +0200
changeset 349 414d979b20b9
permissions -rw-r--r--
Sample @StateChange annotation
jtulach@349
     1
package org.apidesign.stateful.api;
jtulach@349
     2
jtulach@349
     3
import java.lang.annotation.Documented;
jtulach@349
     4
jtulach@349
     5
/**
jtulach@349
     6
 *
jtulach@349
     7
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@349
     8
 */
jtulach@349
     9
// BEGIN: progress.annotations
jtulach@349
    10
public abstract class ProgressStateMachine {
jtulach@349
    11
    /** Annotation that helps users and IDEs to understand what
jtulach@349
    12
     * is the allowed order of method calls on instances of given class.
jtulach@349
    13
     */
jtulach@349
    14
    @Documented
jtulach@349
    15
    public @interface StateChange {
jtulach@349
    16
        /** What is the required state of the object before given method
jtulach@349
    17
         * is called.
jtulach@349
    18
         * @return "*" means any state, otherwise specify the state's name
jtulach@349
    19
         */
jtulach@349
    20
        String from() default "*";
jtulach@349
    21
        /** The state object enters after the method successfully returns.
jtulach@349
    22
         * @return name of new state
jtulach@349
    23
         */
jtulach@349
    24
        String to();
jtulach@349
    25
    }
jtulach@349
    26
jtulach@349
    27
    @StateChange(to="ready")
jtulach@349
    28
    public static ProgressStateMachine create(String name) {
jtulach@349
    29
        return createImpl(name);
jtulach@349
    30
    }
jtulach@349
    31
jtulach@349
    32
    @StateChange(from="ready", to="started")
jtulach@349
    33
    public abstract void start(int totalAmount);
jtulach@349
    34
jtulach@349
    35
    @StateChange(from="started", to="started")
jtulach@349
    36
    public abstract void progress(int howMuch);
jtulach@349
    37
jtulach@349
    38
    @StateChange(to="finished")
jtulach@349
    39
    public abstract void finish();
jtulach@349
    40
    // FINISH: progress.annotations
jtulach@349
    41
jtulach@349
    42
jtulach@349
    43
jtulach@349
    44
    private static ProgressStateMachine createImpl(String name) {
jtulach@349
    45
        return null; // implementation left out, similar to Progress.java
jtulach@349
    46
    }
jtulach@349
    47
}