samples/exceptions/src/org/apidesign/exceptions/trycatchredo/usage/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 16:27:41 +0100
changeset 311 cb8db49f9d1c
permissions -rw-r--r--
Rearranged to support test as well as interactive modes
jtulach@311
     1
package org.apidesign.exceptions.trycatchredo.usage;
jtulach@311
     2
jtulach@311
     3
import java.awt.EventQueue;
jtulach@311
     4
import java.awt.event.ActionEvent;
jtulach@311
     5
import java.net.URL;
jtulach@311
     6
import javax.swing.Action;
jtulach@311
     7
import org.apidesign.exceptions.trycatchredo.api.IOManager;
jtulach@311
     8
import org.apidesign.exceptions.trycatchredo.api.UserQuestionException;
jtulach@311
     9
jtulach@311
    10
/** Sample usage showing interactive storage capabilities of the
jtulach@311
    11
 * {@link UserQuestionException}
jtulach@311
    12
 *
jtulach@311
    13
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@311
    14
 */
jtulach@311
    15
public class Main {
jtulach@311
    16
    public static void main(String[] args) throws Exception {
jtulach@311
    17
        MemoryURL.initialize();
jtulach@311
    18
        
jtulach@311
    19
        for (int cnt = 0; cnt < 10; cnt++) {
jtulach@311
    20
            URL u = new URL("memory://" + cnt + "/queryEncoding.txt");
jtulach@311
    21
            MemoryURL.registerURL(u.toExternalForm(), "", new QueryStream());
jtulach@311
    22
            final Action a = IOManager.createSaveAction(u, "Ask a Question");
jtulach@311
    23
            EventQueue.invokeAndWait(new Runnable() {
jtulach@311
    24
                public void run() {
jtulach@311
    25
                    a.actionPerformed(new ActionEvent(this, 0, ""));
jtulach@311
    26
                }
jtulach@311
    27
            });
jtulach@311
    28
            String out = MemoryURL.getOutputForURL(u.toExternalForm());
jtulach@311
    29
jtulach@311
    30
            System.err.println(cnt + " output: " + out);
jtulach@311
    31
        }
jtulach@311
    32
jtulach@311
    33
        System.exit(0);
jtulach@311
    34
    }
jtulach@311
    35
}