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