001    // Copyright 2002-2006 Waterken Inc. under the terms of the MIT X license
002    // found at http://www.opensource.org/licenses/mit-license.html
003    package org.ref_send.promise;
004    
005    import org.joe_e.Struct;
006    
007    /**
008     * An eventual conditional code block.
009     * @param <P> parameter type
010     * @param <R> return type
011     */
012    public abstract class
013    Do<P,R> extends Struct {
014        
015        /**
016         * Constructs an instance.
017         */
018        protected
019        Do() {}
020    
021        /**
022         * Notification of a fulfilled argument.
023         * @param arg   argument to the code block
024         * @return code block's return value
025         * @throws Exception    any exception produced by the code block
026         */
027        public abstract R fulfill(P arg) throws Exception;
028    
029        /**
030         * Notification of a rejected argument.
031         * <p>
032         * The default implementation throws <code>reason</code>.
033         * </p>
034         * @param reason    reason the code block's argument is not known
035         * @return code block's return value
036         * @throws Exception    any exception produced by the code block
037         */
038        public R reject(final Exception reason) throws Exception { throw reason; }
039    }