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
26
27 package org.microemu.app.classloader;
28
29 import java.util.List;
30 import java.util.Vector;
31
32 import org.microemu.app.ConfigurationException;
33
34 public class MIDletClassLoaderConfig {
35
36 public static final int DELEGATION_STRICT = 0;
37
38 public static final int DELEGATION_RELAXED = 1;
39
40 public static final int DELEGATION_DELEGATING = 2;
41
42 public static final int DELEGATION_SYSTEM = 3;
43
44 private int delegationType;
45
46 private boolean delegationSelected;
47
48 List appclasses = new Vector();
49
50 List appclasspath = new Vector();
51
52 public MIDletClassLoaderConfig() {
53 delegationSelected = false;
54 delegationType = DELEGATION_STRICT;
55 }
56
57 public void setDelegationType(String delegationType) throws ConfigurationException {
58 if ("strict".equalsIgnoreCase(delegationType)) {
59 this.delegationType = DELEGATION_STRICT;
60 } else if ("relaxed".equalsIgnoreCase(delegationType)) {
61 this.delegationType = DELEGATION_RELAXED;
62 } else if ("delegating".equalsIgnoreCase(delegationType)) {
63 this.delegationType = DELEGATION_DELEGATING;
64 } else if ("system".equalsIgnoreCase(delegationType)) {
65 if ((appclasses.size() != 0) || (appclasspath.size() != 0)) {
66 throw new ConfigurationException("Can't extend system CLASSPATH");
67 }
68 this.delegationType = DELEGATION_SYSTEM;
69 } else {
70 throw new ConfigurationException("Unknown delegationType [" + delegationType + "]");
71 }
72 delegationSelected = true;
73 }
74
75 public int getDelegationType(boolean forJad) {
76 if ((!delegationSelected) && (!forJad)) {
77 return DELEGATION_RELAXED;
78 } else {
79 return delegationType;
80 }
81 }
82
83 public boolean isClassLoaderDisabled() {
84 return (this.delegationType == DELEGATION_SYSTEM);
85 }
86
87 public void addAppClassPath(String path) throws ConfigurationException {
88 if (this.delegationType == DELEGATION_SYSTEM) {
89 throw new ConfigurationException("Can't extend system CLASSPATH");
90 }
91 appclasspath.add(path);
92 }
93
94 public void addAppClass(String className) throws ConfigurationException {
95 if (this.delegationType == DELEGATION_SYSTEM) {
96 throw new ConfigurationException("Can't extend system CLASSPATH");
97 }
98 appclasses.add(className);
99 }
100
101 }