001    package org.codehaus.groovy.sandbox.ui;
002    
003    import java.io.InputStream;
004    import java.io.PrintStream;
005    
006    /**
007     * Factory to build a command line prompt.  Should build the most featureful
008     * prompt available.
009     * <p/>
010     * Currently readline prompt will be looked up dynamically, and defaults to
011     * normal System.in prompt.
012     */
013    public class PromptFactory
014    {
015        public static Prompt buildPrompt(InputStream in, PrintStream out, PrintStream err)
016        {
017            try
018            {
019                return (Prompt) Class.forName("org.codehaus.groovy.sandbox.ui.ReadlinePrompt").newInstance();
020            }
021            catch (ClassNotFoundException e)
022            {
023                return new JavaPrompt(in, out, err);
024            }
025            catch (Exception e)
026            {
027                e.printStackTrace();
028                return new JavaPrompt(in, out, err);
029            }
030        }
031    }