jtulach@349: package org.apidesign.stateful.api; jtulach@349: jtulach@349: import java.lang.annotation.Documented; jtulach@349: jtulach@349: /** jtulach@349: * jtulach@349: * @author Jaroslav Tulach jtulach@349: */ jtulach@349: // BEGIN: progress.annotations jtulach@349: public abstract class ProgressStateMachine { jtulach@349: /** Annotation that helps users and IDEs to understand what jtulach@349: * is the allowed order of method calls on instances of given class. jtulach@349: */ jtulach@349: @Documented jtulach@349: public @interface StateChange { jtulach@349: /** What is the required state of the object before given method jtulach@349: * is called. jtulach@349: * @return "*" means any state, otherwise specify the state's name jtulach@349: */ jtulach@349: String from() default "*"; jtulach@349: /** The state object enters after the method successfully returns. jtulach@349: * @return name of new state jtulach@349: */ jtulach@349: String to(); jtulach@349: } jtulach@349: jtulach@349: @StateChange(to="ready") jtulach@349: public static ProgressStateMachine create(String name) { jtulach@349: return createImpl(name); jtulach@349: } jtulach@349: jtulach@349: @StateChange(from="ready", to="started") jtulach@349: public abstract void start(int totalAmount); jtulach@349: jtulach@349: @StateChange(from="started", to="started") jtulach@349: public abstract void progress(int howMuch); jtulach@349: jtulach@349: @StateChange(to="finished") jtulach@349: public abstract void finish(); jtulach@349: // FINISH: progress.annotations jtulach@349: jtulach@349: jtulach@349: jtulach@349: private static ProgressStateMachine createImpl(String name) { jtulach@349: return null; // implementation left out, similar to Progress.java jtulach@349: } jtulach@349: }