API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jottools. JOTConfigurator View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.jottools;

import net.jot.utils.JOTUtilities;
import net.jot.web.server.impl.JOTMiniServer;
import net.jottools.actions.ConfigView;

/**
 *
 * @author thibautc
 */
public class JOTConfigurator {
    private final static int DEFAULT_PORT=8033;
    private JOTMiniServer server=null;
    
    public JOTConfigurator(Integer port)
    {
        server=new JOTMiniServer();
        try
        {
            server.start(port.intValue(), JOTConfiguratorHandler.class,null);        
        }
        catch(Exception e)
        {
            System.err.println("Failed starting server: "+e);
            e.printStackTrace();
        }
    }
    
    /**
     * TODO: option to accept connection only from localhost
     * TODO: provide/use a password ?
     * @param args
     */
    public static void main(String[] args)
    {
        Integer port=new Integer(DEFAULT_PORT);
        if (args.length < 1)
        {
            System.out.println("Using default port: "+DEFAULT_PORT);
        }
        else
        {
            String p = args[1];
            port = new Integer(p.trim());
        }
        new JOTConfigurator(port);
    }

    public void finalyze() throws Throwable
    {
        if(server!=null)
        {
            server.finalyze();
        }
        super.finalize();
    }
    
 
    private ConfigView getViewClass(String path)
    {
        Object view=null;
        try
        {
        if(path.startsWith("/"))
            path=path.substring(1,path.length());
        if(path.length()==0)
            path="home";
        Class c=Class.forName("net.jottools.actions.Config"+JOTUtilities.upperFirst(path.toLowerCase()));
        if(c!=null)
        {
            view=c.newInstance();
            if (! (view instanceof ConfigView))
            {
                view=null;
            }
        }
        }
        catch(Exception e){e.printStackTrace();view=null;}
        return (ConfigView)view;
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar