~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/util/TGClassLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.util;
 
2
 
 
3
import java.io.File;
 
4
import java.net.MalformedURLException;
 
5
import java.net.URL;
 
6
import java.net.URLClassLoader;
 
7
 
 
8
public class TGClassLoader{
 
9
        
 
10
        private static TGClassLoader instance;
 
11
        
 
12
        private URLClassLoaderImpl classLoader;
 
13
        
 
14
        private TGClassLoader(){
 
15
                this.classLoader = new URLClassLoaderImpl();
 
16
        }
 
17
        
 
18
        public static TGClassLoader instance(){
 
19
                if(instance == null){
 
20
                        instance = new TGClassLoader();
 
21
                }
 
22
                return instance;
 
23
        }
 
24
        
 
25
        public ClassLoader getClassLoader(){
 
26
                return this.classLoader;
 
27
        }
 
28
        
 
29
        public Object newInstance(String loadClassName){
 
30
                Object object = null;
 
31
                try {
 
32
                        object = getClassLoader().loadClass(loadClassName).newInstance();
 
33
                } catch (InstantiationException e) {
 
34
                        e.printStackTrace();
 
35
                } catch (IllegalAccessException e) {
 
36
                        e.printStackTrace();
 
37
                } catch (ClassNotFoundException e) {
 
38
                        e.printStackTrace();
 
39
                }
 
40
                return object;
 
41
        }
 
42
        
 
43
        public void addPath(String path){
 
44
                try {
 
45
                        this.classLoader.addURL(new File(path).toURI().toURL());
 
46
                } catch (MalformedURLException e) {
 
47
                        e.printStackTrace();
 
48
                }
 
49
        }
 
50
        
 
51
        public void addPaths(File folder){
 
52
                if(folder != null && folder.exists() && folder.isDirectory()){
 
53
                        String[] files = folder.list();
 
54
                        for(int i = 0;i < files.length;i++){
 
55
                                try {
 
56
                                        this.addPath( (folder.getAbsolutePath() + File.separator + files[i]) );
 
57
                                } catch (Throwable throwable) {
 
58
                                        throwable.printStackTrace();
 
59
                                }
 
60
                        }
 
61
                }
 
62
        }
 
63
        
 
64
        private class URLClassLoaderImpl extends URLClassLoader{
 
65
                
 
66
                public URLClassLoaderImpl(){
 
67
                        super(new URL[]{},TGClassLoader.class.getClassLoader());
 
68
                }
 
69
                
 
70
                public void addURL(URL url){
 
71
                        super.addURL(url);
 
72
                }
 
73
                
 
74
        }
 
75
        
 
76
}
 
 
b'\\ No newline at end of file'