samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java
changeset 349 414d979b20b9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/stateful/src/org/apidesign/stateful/api/ProgressStateMachine.java	Sun May 02 14:34:48 2010 +0200
     1.3 @@ -0,0 +1,47 @@
     1.4 +package org.apidesign.stateful.api;
     1.5 +
     1.6 +import java.lang.annotation.Documented;
     1.7 +
     1.8 +/**
     1.9 + *
    1.10 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.11 + */
    1.12 +// BEGIN: progress.annotations
    1.13 +public abstract class ProgressStateMachine {
    1.14 +    /** Annotation that helps users and IDEs to understand what
    1.15 +     * is the allowed order of method calls on instances of given class.
    1.16 +     */
    1.17 +    @Documented
    1.18 +    public @interface StateChange {
    1.19 +        /** What is the required state of the object before given method
    1.20 +         * is called.
    1.21 +         * @return "*" means any state, otherwise specify the state's name
    1.22 +         */
    1.23 +        String from() default "*";
    1.24 +        /** The state object enters after the method successfully returns.
    1.25 +         * @return name of new state
    1.26 +         */
    1.27 +        String to();
    1.28 +    }
    1.29 +
    1.30 +    @StateChange(to="ready")
    1.31 +    public static ProgressStateMachine create(String name) {
    1.32 +        return createImpl(name);
    1.33 +    }
    1.34 +
    1.35 +    @StateChange(from="ready", to="started")
    1.36 +    public abstract void start(int totalAmount);
    1.37 +
    1.38 +    @StateChange(from="started", to="started")
    1.39 +    public abstract void progress(int howMuch);
    1.40 +
    1.41 +    @StateChange(to="finished")
    1.42 +    public abstract void finish();
    1.43 +    // FINISH: progress.annotations
    1.44 +
    1.45 +
    1.46 +
    1.47 +    private static ProgressStateMachine createImpl(String name) {
    1.48 +        return null; // implementation left out, similar to Progress.java
    1.49 +    }
    1.50 +}