View Javadoc

1   package com.jamesbryangraves.bob;
2   
3   import gnu.getopt.Getopt;
4   
5   import javax.sound.midi.InvalidMidiDataException;
6   import javax.sound.midi.MidiUnavailableException;
7   
8   import org.apache.log4j.Logger;
9   import org.springframework.beans.factory.BeanFactory;
10  import org.springframework.beans.factory.xml.XmlBeanFactory;
11  import org.springframework.core.io.ClassPathResource;
12  import org.springframework.core.io.FileSystemResource;
13  
14  import com.jamesbryangraves.bob.midi.BobGenericReceiver;
15  
16  public class BobEngine {
17  	
18  	static Logger log = Logger.getLogger(BobEngine.class);
19  
20  	public static void main(String[] args) {
21  		
22  
23  		BeanFactory beanFactory = null;
24  
25  		Getopt g = new Getopt("BobEngine", args, "f:d");
26  
27  		int c;
28  		String arg;
29  		while ((c = g.getopt()) != -1) {
30  			switch (c) {
31  			case 'f':
32  				arg = g.getOptarg();
33  				beanFactory = new XmlBeanFactory(new FileSystemResource(arg));
34  				break;
35  			
36  			case 'd' :
37  				System.out.println("Device Options. . .");
38  				listDevices();
39  				System.out.println(". . .Done.");
40  				System.exit(0);
41  				break;
42  			default:
43  				System.err.print("getopt() returned " + c + "\n");
44  			}
45  		}
46  		
47  		if(beanFactory == null)
48  			beanFactory = new XmlBeanFactory(new ClassPathResource(
49  				"spring-config.xml"));
50  
51  		BobApplication app = (BobApplication) beanFactory
52  				.getBean("bobApplication");
53  
54  		try {
55  			app.init();
56  			new Thread(app).start();
57  			log.info("BobEngine is running. . .");
58  		} catch (MidiUnavailableException mue) {
59  			mue.printStackTrace();
60  		} catch (InvalidMidiDataException imde) {
61  			imde.printStackTrace();
62  		}
63  	}
64  
65  	public static void printUsage() {
66  		System.out
67  				.println("Usage: java com.jamesbryangraves.bob.BobEngine [-f configFile]");
68  	}
69  	
70  	public static void listDevices() {
71  		int i = 0;
72  		for(String deviceName : BobGenericReceiver.getDeviceNames()) {
73  			System.out.println(i + " " + deviceName);
74  			i++;
75  		}	
76  	}
77  }