1   /**
2    * 
3    */
4   package org.melati.app.test;
5   
6   import java.io.InputStream;
7   
8   import org.melati.Melati;
9   import org.melati.MelatiConfig;
10  import org.melati.PoemContext;
11  import org.melati.app.InvalidArgumentsException;
12  import org.melati.app.PoemApp;
13  import org.melati.login.AccessHandler;
14  import org.melati.login.CommandLineAccessHandler;
15  import org.melati.login.OpenAccessHandler;
16  import org.melati.util.InstantiationPropertyException;
17  import org.melati.util.MelatiException;
18  
19  /**
20   * @author timp
21   *
22   */
23  public class ProtectedPoemApp extends PoemApp {
24  
25    InputStream in = null;
26    /**
27     * 
28     */
29    public ProtectedPoemApp() {
30      super();
31      in = null;
32    }
33    /**
34     * {@inheritDoc}
35     * @see org.melati.app.AbstractConfigApp#melatiConfig()
36     */
37    protected MelatiConfig melatiConfig() throws MelatiException {
38      MelatiConfig config = super.melatiConfig();
39      try {
40        config.setAccessHandler((AccessHandler)CommandLineAccessHandler.class
41                .newInstance());
42      } catch (Exception e) {
43        throw new InstantiationPropertyException(OpenAccessHandler.class
44                .getName(), e);
45      }
46      return config;
47      
48    }
49  
50    /**
51     * {@inheritDoc}
52     * @see org.melati.app.AbstractTemplateApp#init(java.lang.String[])
53     */
54    public Melati init(String[] args) throws MelatiException {
55      Melati melati = super.init(args);
56      if (in != null) {
57        CommandLineAccessHandler ah = (CommandLineAccessHandler)melati.getConfig().getAccessHandler();
58        ah.setInput(in);
59        ah.setOutput(System.err); // get that coverage
60      }
61      return melati;
62      
63    }
64  
65    /**
66     * {@inheritDoc}
67     * @see org.melati.app.AbstractPoemApp#prePoemSession(org.melati.Melati)
68     */
69    protected void doPoemRequest(Melati melati) throws Exception {
70      // Need to be logged in to do this
71      melati.getDatabase().getUserTable().getTableInfo().
72          setDefaultcanread(melati.getDatabase().getCanAdminister());
73      super.doPoemRequest(melati);    
74    }
75    
76    /*
77     * The main entry point.
78     * 
79     * @param args in format <code>db table troid method</code> 
80     */
81    public static void main(String[] args) throws Exception {
82      ProtectedPoemApp me = new ProtectedPoemApp();
83      me.run(args);
84    }
85    protected PoemContext poemContext(Melati melati) 
86        throws InvalidArgumentsException {
87      return poemContextWithLDB(melati,"appjunit");
88    }
89  
90    /**
91     * @param is input to set
92     */
93    public void setInput(InputStream is) { 
94      in = is;
95    }
96  }