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