View Javadoc

1   /**
2    *  MicroEmulator
3    *  Copyright (C) 2006-2007 Bartek Teodorczyk <barteo@barteo.net>
4    *  Copyright (C) 2006-2007 Vlad Skarzhevskyy
5    *
6    *  It is licensed under the following two licenses as alternatives:
7    *    1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
8    *    2. Apache License (the "AL") Version 2.0
9    *
10   *  You may not use this file except in compliance with at least one of
11   *  the above two licenses.
12   *
13   *  You may obtain a copy of the LGPL at
14   *      http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
15   *
16   *  You may obtain a copy of the AL at
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   *
19   *  Unless required by applicable law or agreed to in writing, software
20   *  distributed under the License is distributed on an "AS IS" BASIS,
21   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   *  See the LGPL or the AL for the specific language governing permissions and
23   *  limitations.
24   *
25   *  @version $Id: MIDletClassLoaderConfig.java 1881 2008-12-18 15:09:07Z vlads $
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 }