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