|
Juno |
|
1 // joi/6/juno/Juno.java
2 //
3 //
4 // Copyright 2003 Bill Campbell and Ethan Bolker
5
6 import java.io.*;
7 import java.util.*;
8 import java.lang.*;
9
10 /**
11 * Juno (Juno's Unix NOt) mimics a command line operating system
12 * like Unix.
13 * <p>
14 * A Juno system has a name, a set of Users, a JFile system,
15 * a login process and a set of shell commands.
16 *
17 * @see User
18 * @see JFile
19 * @see ShellCommand
20 *
21 * @version 6
22 */
23
24 public class Juno
25 {
26 private final static String os = "Juno";
27 private final static String version = "6";
28
29 private String hostName; // host machine name
30 private Map users; // lookup table for Users
31 private Terminal console; // for input and output
32
33 private Directory slash; // root of JFile system
34 private Directory userHomes; // for home directories
35
36 private ShellCommandTable commandTable; // shell commands
37
38 /**
39 * Construct a Juno (operating system) object.
40 *
41 * @param hostName the name of the host on which it's running.
42 * @param echoInput should all input be echoed as output?
43 */
44
45 public Juno( String hostName, boolean echoInput )
46 {
47 // initialize the Juno environment ...
48
49 this.hostName = hostName;
50 console = new Terminal( echoInput );
51 users = new TreeMap(); // for registered Users
52 commandTable = new ShellCommandTable(); // for shell commands
53
54 // the file system
55
56 slash = new Directory( "", null, null );
57 User root = new User( "root", slash, "Rick Martin" );
58 users.put( "root", root );
59 slash.setOwner(root);
60 userHomes = new Directory( "users", root, slash );
61
62 // create, then start a command line login interpreter
63
64 LoginInterpreter interpreter
65 = new LoginInterpreter( this, console );
66 interpreter.CLILogin();
67 }
68
69 /**
70 * The name of the host computer on which this system
71 * is running.
72 *
73 * @return the host computer name.
74 */
75
76 public String getHostName()
77 {
78 return hostName;
79 }
80
81 /**
82 * The name of this operating system.
83 *
84 * @return the operating system name.
85 */
86
87 public String getOS()
88 {
89 return os;
90 }
91
92 /**
93 * The version number for this system.
94 *
95 * @return the version number.
96 */
97
98 public String getVersion()
99 {
100 return version;
101 }
102
103 /**
104 * The directory containing all user homes for this system.
105 *
106 * @return the directory containing user homes.
107 */
108
109 public Directory getUserHomes()
110 {
111 return userHomes;
112 }
113
114 /**
115 * The shell command table for this system.
116 *
117 * @return the shell command table.
118 */
119
120 public ShellCommandTable getCommandTable()
121 {
122 return commandTable;
123 }
124
125 /**
126 * Look up a user by user name.
127 *
128 * @param username the user's name.
129 * @return the appropriate User object.
130 */
131
132 public User lookupUser( String username )
133 {
134 return (User) users.get( username );
135 }
136
137 /**
138 * Create a new User.
139 *
140 * @param userName the User's login name.
141 * @param home her home Directory.
142 * @param realName her real name.
143 * @return newly created User.
144 */
145
146 public User createUser( String userName, Directory home,
147 String realName )
148 {
149 User newUser = new User( userName, home, realName );
150 users.put( userName, newUser );
151 return newUser;
152 }
153
154 /**
155 * The Juno system may be given the following command line
156 * arguments.
157 * <pre>
158 *
159 * -e: Echo all input (useful for testing).
160 *
161 * -version: Report the version number and exit.
162 *
163 * [hostname]: The name of the host on which
164 * Juno is running (optional).
165 * </pre>
166 */
167
168 public static void main( String[] args )
169 {
170 // Parse command line options
171
172 boolean echoInput = false;
173 String hostName = "mars";
174
175 for (int i=0; i < args.length; i++) {
176 if (args[i].equals("-version")) {
177 System.out.println( os + " version " + version );
178 System.exit(0);
179 }
180 if (args[i].equals("-e")) {
181 echoInput = true;
182 }
183 else {
184 hostName = args[i];
185 }
186 }
187
188 // create a Juno instance, which will start itself
189
190 new Juno( hostName, echoInput );
191 }
192 }
193
|
Juno |
|