KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > DummyJavaPlatformProvider


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
20 package org.netbeans.modules.java.freeform;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL 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 org.netbeans.api.java.classpath.ClassPath;
30 import org.netbeans.api.java.platform.JavaPlatform;
31 import org.netbeans.api.java.platform.Specification;
32 import org.netbeans.modules.java.platform.JavaPlatformProvider;
33 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
34 import org.openide.filesystems.FileObject;
35 import org.openide.modules.SpecificationVersion;
36
37 /**
38  * Testing Java platform provider, just enough to check ClassPath.BOOT usage.
39  * @author Jesse Glick
40  */

41 public final class DummyJavaPlatformProvider implements JavaPlatformProvider {
42     
43     private final JavaPlatform jdk14 = new DummyJavaPlatform("1.4");
44     private final JavaPlatform jdk15 = new DummyJavaPlatform("1.5");
45     
46     /** Default constructor for lookup. */
47     public DummyJavaPlatformProvider() {}
48     
49     public JavaPlatform getDefaultPlatform() {
50         return jdk15;
51     }
52     
53     public JavaPlatform[] getInstalledPlatforms() {
54         return new JavaPlatform[] {
55             jdk14,
56             jdk15,
57         };
58     }
59     
60     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {}
61     
62     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {}
63     
64     private static final class DummyJavaPlatform extends JavaPlatform {
65         
66         private final String JavaDoc spec;
67         private ClassPath bootcp;
68         
69         public DummyJavaPlatform(String JavaDoc spec) {
70             this.spec = spec;
71         }
72         
73         public FileObject findTool(String JavaDoc toolName) {
74             return null;
75         }
76         
77         public ClassPath getBootstrapLibraries() {
78             if (bootcp == null) {
79                 try {
80                     bootcp = ClassPathSupport.createClassPath(new URL JavaDoc[] {
81                         // This file does not really have to exist - just needs to have a well-known location.
82
// Cf. ClasspathsTest.
83
new URL JavaDoc("jar:file:/c:/java/" + spec + "/jre/lib/rt.jar!/"),
84                     });
85                 } catch (MalformedURLException JavaDoc e) {
86                     throw new AssertionError JavaDoc(e);
87                 }
88             }
89             return bootcp;
90         }
91         
92         public String JavaDoc getDisplayName() {
93             return "JDK " + spec;
94         }
95         
96         public Collection JavaDoc getInstallFolders() {
97             return Collections.EMPTY_SET;
98         }
99         
100         public List JavaDoc getJavadocFolders() {
101             return Collections.EMPTY_LIST;
102         }
103         
104         public Map JavaDoc getProperties() {
105             return Collections.EMPTY_MAP;
106         }
107         
108         public ClassPath getSourceFolders() {
109             return ClassPathSupport.createClassPath(new FileObject[0]);
110         }
111         
112         public Specification getSpecification() {
113             return new Specification("j2se", new SpecificationVersion(spec));
114         }
115         
116         public ClassPath getStandardLibraries() {
117             return ClassPathSupport.createClassPath(new FileObject[0]);
118         }
119         
120         public String JavaDoc getVendor() {
121             return "test";
122         }
123         
124     }
125     
126 }
127
Popular Tags