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