View Javadoc
1   package org.codehaus.classworlds;
2   
3   /*
4    * Copyright 2001-2010 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Collection;
20  import java.util.Vector;
21  
22  /**
23   * An adapter for ClassWorlds
24   *
25   * @author Andrew Williams
26   */
27  @Deprecated
28  public class ClassWorldAdapter extends ClassWorld {
29  
30      public static ClassWorldAdapter getInstance(org.codehaus.plexus.classworlds.ClassWorld newWorld) {
31          return new ClassWorldAdapter(newWorld);
32      }
33  
34      private org.codehaus.plexus.classworlds.ClassWorld world;
35  
36      private ClassWorldAdapter(org.codehaus.plexus.classworlds.ClassWorld newWorld) {
37          super(false);
38          this.world = newWorld;
39      }
40  
41      public ClassRealm newRealm(String id) throws DuplicateRealmException {
42          try {
43              return ClassRealmAdapter.getInstance(world.newRealm(id));
44          } catch (org.codehaus.plexus.classworlds.realm.DuplicateRealmException e) {
45              throw new DuplicateRealmException(this, e.getId());
46          }
47      }
48  
49      public ClassRealm newRealm(String id, ClassLoader classLoader) throws DuplicateRealmException {
50          try {
51              return ClassRealmAdapter.getInstance(world.newRealm(id, classLoader));
52          } catch (org.codehaus.plexus.classworlds.realm.DuplicateRealmException e) {
53              throw new DuplicateRealmException(this, e.getId());
54          }
55      }
56  
57      public void disposeRealm(String id) throws NoSuchRealmException {
58          try {
59              world.disposeRealm(id);
60          } catch (org.codehaus.plexus.classworlds.realm.NoSuchRealmException e) {
61              throw new NoSuchRealmException(this, e.getId());
62          }
63      }
64  
65      public ClassRealm getRealm(String id) throws NoSuchRealmException {
66          try {
67              return ClassRealmAdapter.getInstance(world.getRealm(id));
68          } catch (org.codehaus.plexus.classworlds.realm.NoSuchRealmException e) {
69              throw new NoSuchRealmException(this, e.getId());
70          }
71      }
72  
73      public Collection getRealms() {
74          Collection<org.codehaus.plexus.classworlds.realm.ClassRealm> realms = world.getRealms();
75          Vector<ClassRealmAdapter> ret = new Vector<>();
76          for (org.codehaus.plexus.classworlds.realm.ClassRealm classRealm : realms) {
77              ret.add(ClassRealmAdapter.getInstance(classRealm));
78          }
79  
80          return ret;
81      }
82  }