|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ProgramManager.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
|
|
3 |
VRMoo Server - Virtual Reality Object Oriented MUD Server
|
|
4 |
Copyright (C) 2001 - 2003 VRMoo Development Team
|
|
5 |
|
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with this program; if not, write to the Free Software
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
|
|
21 |
|
|
22 |
For information about VRMoo and its authors, please visit the website:
|
|
23 |
http://www.vrmoo.org/
|
|
24 |
|
|
25 |
*/
|
|
26 |
|
|
27 |
package org.vrmoo.server.data;
|
|
28 |
|
|
29 |
import java.io.File;
|
|
30 |
import java.util.HashMap;
|
|
31 |
import java.util.Map;
|
|
32 |
|
|
33 |
import org.vrmoo.common.util.FileUtility;
|
|
34 |
|
|
35 |
import org.vrmoo.server.vrmoopl.Parser;
|
|
36 |
import org.vrmoo.server.vrmoopl.Program;
|
|
37 |
import org.vrmoo.server.world.World;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Manager for a set of vrmoopl programs attached to a world.
|
|
41 |
*
|
|
42 |
* @author Jeff Weston
|
|
43 |
*/
|
|
44 |
public class ProgramManager |
|
45 |
{ |
|
46 |
/**
|
|
47 |
* The world that this class is managing textures for.
|
|
48 |
*/
|
|
49 |
private World world;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* The set of programs managed by this class.
|
|
53 |
*/
|
|
54 |
private Map programs;
|
|
55 |
|
|
56 |
/**
|
|
57 |
* The directory of programs we are managing.
|
|
58 |
*/
|
|
59 |
private String programDir;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Construct a new vrmoopl program manager for the specified world.
|
|
63 |
*
|
|
64 |
* @param world the world to manage programs for
|
|
65 |
*/
|
|
66 | 0 |
public ProgramManager( World world )
|
67 |
{ |
|
68 | 0 |
this.world = world;
|
69 | 0 |
programs = new HashMap( );
|
70 | 0 |
programDir = world.getWorldDataDirectory( ) + "/programs";
|
71 |
|
|
72 | 0 |
File dir = new File( programDir );
|
73 | 0 |
FileUtility.ensureDirectoryExists( dir ); |
74 |
|
|
75 | 0 |
File[ ] files = dir.listFiles( ); |
76 | 0 |
for ( int i = 0; i < files.length; i++ ) |
77 |
{ |
|
78 | 0 |
addProgram( files[ i ] ); |
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
/**
|
|
83 |
* Parse the program from the specified file and add it to the set of
|
|
84 |
* programs this class is managing.
|
|
85 |
*
|
|
86 |
* @param file a file containing a vrmoopl program
|
|
87 |
*/
|
|
88 | 0 |
private void addProgram( File file ) |
89 |
{ |
|
90 | 0 |
try
|
91 |
{ |
|
92 | 0 |
Parser parser = new Parser( );
|
93 | 0 |
parser.parse( file ); |
94 | 0 |
Program program = parser.getProgram( ); |
95 | 0 |
programs.put( program.getName( ), program ); |
96 |
} |
|
97 |
catch ( Exception e )
|
|
98 |
{ |
|
99 | 0 |
e.printStackTrace( ); |
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|