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 package org.microemu.app.util;
26
27 import java.io.File;
28 import java.net.MalformedURLException;
29 import java.net.URL;
30
31 import org.microemu.EmulatorContext;
32 import org.microemu.app.Common;
33 import org.microemu.app.Config;
34 import org.microemu.log.Logger;
35
36 import com.barteo.emulator.device.Device;
37
38 public class DeviceEntry {
39
40 private String name;
41
42 private String fileName;
43
44 private String descriptorLocation;
45
46 private boolean defaultDevice;
47
48 private boolean canRemove;
49
50
51
52
53 private String className;
54
55
56
57
58 private EmulatorContext emulatorContext;
59
60 public DeviceEntry(String name, String fileName, String descriptorLocation, boolean defaultDevice) {
61 this(name, fileName, descriptorLocation, defaultDevice, true);
62 }
63
64 public DeviceEntry(String name, String fileName, String descriptorLocation, boolean defaultDevice, boolean canRemove) {
65 this.name = name;
66 this.fileName = fileName;
67 this.descriptorLocation = descriptorLocation;
68 this.defaultDevice = defaultDevice;
69 this.canRemove = canRemove;
70 }
71
72
73
74
75 public DeviceEntry(String name, String fileName, boolean defaultDevice, String className,
76 EmulatorContext emulatorContext) {
77 this(name, fileName, null, defaultDevice, true);
78
79 this.className = className;
80 this.emulatorContext = emulatorContext;
81 }
82
83 public boolean canRemove() {
84 return canRemove;
85 }
86
87 public String getDescriptorLocation() {
88 if (descriptorLocation == null) {
89 URL[] urls = new URL[1];
90 try {
91 urls[0] = new File(Config.getConfigPath(), fileName).toURI().toURL();
92 ClassLoader classLoader = Common.createExtensionsClassLoader(urls);
93 Class deviceClass = Class.forName(className, true, classLoader);
94 Device device = (Device) deviceClass.newInstance();
95
96 com.barteo.emulator.EmulatorContext oldContext = new com.barteo.emulator.EmulatorContext(emulatorContext);
97
98 device.init(oldContext);
99 descriptorLocation = device.getDescriptorLocation();
100 } catch (MalformedURLException ex) {
101 Logger.error(ex);
102 } catch (ClassNotFoundException ex) {
103 Logger.error(ex);
104 } catch (InstantiationException ex) {
105 Logger.error(ex);
106 } catch (IllegalAccessException ex) {
107 Logger.error(ex);
108 }
109
110 }
111
112 return descriptorLocation;
113 }
114
115 public String getFileName() {
116 return fileName;
117 }
118
119
120
121
122 public void setFileName(String fileName) {
123 this.fileName = fileName;
124 }
125
126 public String getName() {
127 return name;
128 }
129
130 public boolean isDefaultDevice() {
131 return defaultDevice;
132 }
133
134 public void setDefaultDevice(boolean b) {
135 defaultDevice = b;
136 }
137
138 public boolean equals(DeviceEntry test) {
139 if (test == null) {
140 return false;
141 }
142 if (test.getDescriptorLocation().equals(getDescriptorLocation())) {
143 return true;
144 }
145
146 return false;
147 }
148
149 public String toString() {
150 if (defaultDevice) {
151 return name + " (default)";
152 } else {
153 return name;
154 }
155 }
156
157 }