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.Enumeration;
20  import java.net.URL;
21  import java.io.IOException;
22  import java.io.InputStream;
23  
24  /**
25   * A reverse adapter for ClassRealms
26   *
27   * @author Andrew Williams
28   */
29  @Deprecated
30  public class ClassRealmReverseAdapter
31      extends org.codehaus.plexus.classworlds.realm.ClassRealm
32  {
33  
34      public static ClassRealmReverseAdapter getInstance( ClassRealm oldRealm )
35      {
36          ClassRealmReverseAdapter adapter = new ClassRealmReverseAdapter( oldRealm );
37  
38          return adapter;
39      }
40  
41      private ClassRealm realm;
42  
43      private ClassRealmReverseAdapter( ClassRealm oldRealm )
44      {
45          super( ClassWorldReverseAdapter.getInstance( oldRealm.getWorld() ),
46                 oldRealm.getId(), oldRealm.getClassLoader() );
47          this.realm = oldRealm;
48      }
49  
50      public String getId()
51      {
52          return realm.getId();
53      }
54  
55      public org.codehaus.plexus.classworlds.ClassWorld getWorld()
56      {
57          return ClassWorldReverseAdapter.getInstance( realm.getWorld() );
58      }
59  
60      public void importFrom( String realmId,
61                              String pkgName )
62          throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException
63      {
64          try
65          {
66              realm.importFrom( realmId, pkgName );
67          }
68          catch ( NoSuchRealmException e )
69          {
70              throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( getWorld(), e.getId() );
71          }
72      }
73  
74      public void addURL( URL constituent )
75      {
76          realm.addConstituent( constituent );
77      }
78  
79      public org.codehaus.plexus.classworlds.realm.ClassRealm locateSourceRealm( String className )
80      {
81          return getInstance( realm.locateSourceRealm(
82              className ) );
83      }
84  
85      public void setParentRealm( org.codehaus.plexus.classworlds.realm.ClassRealm classRealm )
86      {
87          realm.setParent( ClassRealmAdapter.getInstance( classRealm ) );
88      }
89  
90      public org.codehaus.plexus.classworlds.realm.ClassRealm createChildRealm( String id )
91          throws org.codehaus.plexus.classworlds.realm.DuplicateRealmException
92      {
93          try
94          {
95              return getInstance( realm.createChildRealm( id ) );
96          }
97          catch ( DuplicateRealmException e )
98          {
99              throw new org.codehaus.plexus.classworlds.realm.DuplicateRealmException( getWorld(), e.getId() );
100         }
101     }
102 
103     public ClassLoader getClassLoader()
104     {
105         return realm.getClassLoader();
106     }
107 
108     public org.codehaus.plexus.classworlds.realm.ClassRealm getParentRealm()
109     {
110         return getInstance( realm.getParent() );
111     }
112 
113     public URL[] getURLs()
114     {
115         return realm.getConstituents();
116     }
117 
118     public Class loadClass( String name )
119         throws ClassNotFoundException
120     {
121         return realm.loadClass( name );
122     }
123 
124     public URL getResource( String name )
125     {
126         return realm.getResource( name );
127     }
128 
129     public Enumeration findResources( String name )
130         throws IOException
131     {
132         return realm.findResources( name );
133     }
134 
135     public InputStream getResourceAsStream( String name )
136     {
137         return realm.getResourceAsStream( name );
138     }
139 
140     public void display()
141     {
142         realm.display();
143     }
144 
145     public boolean equals(Object o)
146     {
147         if ( !( o instanceof ClassRealm ) )
148             return false;
149 
150         return getId().equals( ( (ClassRealm) o ).getId() );
151     }
152 }