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  import java.util.Iterator;
22  
23  /**
24   * An adapter for ClassWorlds
25   *
26   * @author Andrew Williams
27   */
28  @Deprecated
29  public class ClassWorldAdapter
30      extends ClassWorld
31  {
32  
33      public static ClassWorldAdapter getInstance( org.codehaus.plexus.classworlds.ClassWorld newWorld )
34      {
35          ClassWorldAdapter adapter = new ClassWorldAdapter( newWorld );
36  
37          return adapter;
38      }
39  
40      private org.codehaus.plexus.classworlds.ClassWorld world;
41  
42      private ClassWorldAdapter( org.codehaus.plexus.classworlds.ClassWorld newWorld )
43      {
44          super( false );
45          this.world = newWorld;
46      }
47  
48      public ClassRealm newRealm( String id )
49          throws DuplicateRealmException
50      {
51          try
52          {
53              return ClassRealmAdapter.getInstance( world.newRealm( id ) );
54          }
55          catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
56          {
57              throw new DuplicateRealmException( this, e.getId() );
58          }
59      }
60  
61      public ClassRealm newRealm( String id,
62                                  ClassLoader classLoader )
63          throws DuplicateRealmException
64      {
65          try
66          {
67              return ClassRealmAdapter.getInstance( world.newRealm( id,
68                                                                    classLoader ) );
69          }
70          catch ( org.codehaus.plexus.classworlds.realm.DuplicateRealmException e )
71          {
72              throw new DuplicateRealmException( this, e.getId() );
73          }
74      }
75  
76      public void disposeRealm( String id )
77          throws NoSuchRealmException
78      {
79          try
80          {
81              world.disposeRealm( id );
82          }
83          catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
84          {
85              throw new NoSuchRealmException( this, e.getId() );
86          }
87      }
88  
89      public ClassRealm getRealm( String id )
90          throws NoSuchRealmException
91      {
92          try
93          {
94              return ClassRealmAdapter.getInstance( world.getRealm( id ) );
95          }
96          catch ( org.codehaus.plexus.classworlds.realm.NoSuchRealmException e )
97          {
98              throw new NoSuchRealmException( this, e.getId() );
99          }            
100     }
101 
102     public Collection getRealms()
103     {
104         Collection realms = world.getRealms();
105         Vector ret = new Vector();
106 
107         Iterator it = realms.iterator();
108         while ( it.hasNext() )
109         {
110             org.codehaus.plexus.classworlds.realm.ClassRealm realm =
111                 (org.codehaus.plexus.classworlds.realm.ClassRealm) it.next();
112             ret.add( ClassRealmAdapter.getInstance( realm ) );
113         }
114 
115         return ret;
116     }
117 }