KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > TestJavaPlatformProviderImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java;
20
21 import java.beans.PropertyChangeListener JavaDoc;
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.regex.Pattern JavaDoc;
30 import org.netbeans.api.java.classpath.ClassPath;
31 import org.netbeans.api.java.platform.JavaPlatform;
32 import org.netbeans.api.java.platform.Specification;
33 import org.netbeans.modules.java.platform.JavaPlatformProvider;
34 import org.netbeans.spi.java.classpath.ClassPathProvider;
35 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
36 import org.openide.ErrorManager;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileStateInvalidException;
39 import org.openide.filesystems.FileUtil;
40 import org.openide.modules.SpecificationVersion;
41
42 /**
43  *
44  * @author Jan Lahoda
45  */

46 public class TestJavaPlatformProviderImpl implements JavaPlatformProvider {
47     
48     /** Creates a new instance of TestJavaPlatformProviderImpl */
49     public TestJavaPlatformProviderImpl() {
50     }
51
52     public JavaPlatform[] getInstalledPlatforms() {
53         return new JavaPlatform[] {getDefaultPlatform()};
54     }
55
56     private static DefaultPlatform DEFAULT = new DefaultPlatform();
57
58     public JavaPlatform getDefaultPlatform() {
59         return DEFAULT;
60     }
61
62     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
63     }
64
65     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
66     }
67
68     private static final class DefaultPlatform extends JavaPlatform {
69         private static ClassPath EMPTY = ClassPathSupport.createClassPath(Collections.EMPTY_LIST);
70
71         public String JavaDoc getDisplayName() {
72             return "default";
73         }
74
75         public Map JavaDoc getProperties() {
76             return Collections.emptyMap();
77         }
78
79         private static ClassPath bootClassPath;
80         
81         private static synchronized ClassPath getBootClassPath() {
82             if (bootClassPath == null) {
83                 try {
84                     String JavaDoc cp = System.getProperty("sun.boot.class.path");
85                     List JavaDoc<URL JavaDoc> urls = new ArrayList JavaDoc<URL JavaDoc>();
86                     String JavaDoc[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
87                     
88                     for (String JavaDoc path : paths) {
89                         File JavaDoc f = new File JavaDoc(path);
90                         
91                         if (!f.canRead())
92                             continue;
93                         
94                         FileObject fo = FileUtil.toFileObject(f);
95                         
96                         if (FileUtil.isArchiveFile(fo)) {
97                             fo = FileUtil.getArchiveRoot(fo);
98                         }
99                         
100                         if (fo != null) {
101                             urls.add(fo.getURL());
102                         }
103                     }
104                     
105                     bootClassPath = ClassPathSupport.createClassPath((URL JavaDoc[])urls.toArray(new URL JavaDoc[0]));
106                 } catch (FileStateInvalidException e) {
107                     ErrorManager.getDefault().notify(e);
108                 }
109             }
110             
111             return bootClassPath;
112         }
113
114         public ClassPath getBootstrapLibraries() {
115             return getBootClassPath();
116         }
117
118         public ClassPath getStandardLibraries() {
119             return EMPTY;
120         }
121
122         public String JavaDoc getVendor() {
123             return "";
124         }
125
126         private Specification spec = new Specification("j2se", new SpecificationVersion("1.5"));
127
128         public Specification getSpecification() {
129             return spec;
130         }
131
132         public Collection JavaDoc getInstallFolders() {
133             throw new UnsupportedOperationException JavaDoc();
134         }
135
136         public FileObject findTool(String JavaDoc toolName) {
137             return null;//no tools supported.
138
}
139
140         public ClassPath getSourceFolders() {
141             return EMPTY;
142         }
143
144         public List JavaDoc getJavadocFolders() {
145             return Collections.emptyList();
146         }
147
148     }
149
150 }
151
Popular Tags