View Javadoc

1   /**
2    *  MicroEmulator
3    *  Copyright (C) 2006-2007 Bartek Teodorczyk <barteo@barteo.net>
4    *  Copyright (C) 2006-2007 Vlad Skarzhevskyy
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   *  @version $Id: MIDletClassLoaderConfig.java 1306 2007-07-04 21:01:29Z vlads $
21   */
22  package org.microemu.app.classloader;
23  
24  import java.util.List;
25  import java.util.Vector;
26  
27  import org.microemu.app.ConfigurationException;
28  
29  public class MIDletClassLoaderConfig {
30  
31  	public static final int DELEGATION_STRICT = 0;
32  	
33  	public static final int DELEGATION_DELEGATING = 1;
34  	
35  	public static final int DELEGATION_SYSTEM = 2;
36  	
37  	int delegationType = DELEGATION_STRICT;
38  	
39  	List appclasses = new Vector();
40  	
41  	List appclasspath = new Vector();
42  
43  	public void setDelegationType(String delegationType) throws ConfigurationException {
44  		if ("strict".equalsIgnoreCase(delegationType)) {
45  			this.delegationType = DELEGATION_STRICT;
46  		} else if ("delegating".equalsIgnoreCase(delegationType)) {
47  			this.delegationType = DELEGATION_DELEGATING;
48  		} else if ("system".equalsIgnoreCase(delegationType)) {
49  			if ((appclasses.size() != 0) || (appclasspath.size() != 0)) {
50  				throw new ConfigurationException("Can't extend system CLASSPATH");
51  			}
52  			this.delegationType = DELEGATION_SYSTEM;
53  		} else {
54  			throw new ConfigurationException("Unknown delegationType [" + delegationType + "]");
55  		}
56  	}
57  	
58  	public boolean isClassLoaderDisabled() {
59  		return (this.delegationType == DELEGATION_SYSTEM);
60  	}
61  	
62  	public void addAppClassPath(String path) throws ConfigurationException {
63  		if (this.delegationType == DELEGATION_SYSTEM) {
64  			throw new ConfigurationException("Can't extend system CLASSPATH");
65  		}
66  		appclasspath.add(path);
67  	}
68  	
69  	public void addAppClass(String className) throws ConfigurationException {
70  		if (this.delegationType == DELEGATION_SYSTEM) {
71  			throw new ConfigurationException("Can't extend system CLASSPATH");
72  		}
73  		appclasses.add(className);
74  	}
75  	
76  }