1 package org.wcb.autohome;
2 /***
3 * Copyright (C) 1999 Walter Bogaardt
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 *
19 * Project: Home Automation Server
20 * Filename: $Id: JHomeServer.java,v 1.4 2004/02/25 21:38:32 wbogaardt Exp $
21 * Abstract: Server start portion for a remote capablility.
22 *
23 * $Log: JHomeServer.java,v $
24 * Revision 1.4 2004/02/25 21:38:32 wbogaardt
25 * added javadocs and fixed formating for checkstyle report
26 *
27 * Revision 1.3 2004/02/03 21:02:24 wbogaardt
28 * moved DeviceFactory away from rmi creation and simplified interface between gateway
29 *
30 * Revision 1.2 2003/10/09 23:55:21 wbogaardt
31 * code clean up of formating and adding revision history to comments
32 *
33 */
34 import java.rmi.Naming;
35 import org.wcb.autohome.factories.HAGateway;
36 import org.wcb.autohome.interfaces.IHAGateway;
37 import java.util.Properties;
38 import java.rmi.RMISecurityManager;
39
40 /***
41 * This is old, but is used to start the server for a client server application.
42 * This is now more of a web application.
43 */
44 public class JHomeServer {
45
46 /***
47 * This class is used to start an rmi version of the jhome server.
48 * @param loc location of the properties file
49 * @param host the address of the server.
50 */
51 public JHomeServer(String loc, String host)
52 {
53 Properties prop = System.getProperties();
54 prop.put("java.rmi.server.codebase", "file://" + loc);
55 System.setProperties(prop);
56 if (System.getSecurityManager() == null)
57 {
58 System.out.print("Setting up security manager . . .");
59 System.setSecurityManager(new RMISecurityManager());
60 System.out.println("Security Enabled!");
61 }
62 try
63 {
64 IHAGateway gw = new HAGateway();
65 Naming.rebind("rmi://" + host + ":1099/GatewayServer", gw);
66 }
67 catch (Exception e)
68 {
69 System.out.println("Error trouble: " + e);
70 }
71 System.out.println("Server started");
72 }
73
74 /***
75 * Main method to start the application
76 * @param args Two arguments should be passed file location and hostname
77 */
78 public static void main(String[] args)
79 {
80 if (args.length < 2)
81 {
82 System.out.println("Usage: JHomeServer [file location] [hostname] ");
83 System.exit(0);
84 }
85 new JHomeServer(args[0], args[1]);
86 }
87 }