KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > TestPlatformProvider


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.j2ee.clientproject;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map 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.support.ClassPathSupport;
35 import org.openide.filesystems.FileObject;
36 import org.openide.modules.SpecificationVersion;
37
38 /**
39  * @author Tomas Zezula
40  */

41 public final class TestPlatformProvider implements JavaPlatformProvider {
42     
43     private JavaPlatform defaultPlatform;
44     private JavaPlatform explicitPlatform;
45     private PropertyChangeSupport JavaDoc support;
46     private boolean hideExplicitPlatform;
47     
48     /** Default constructor for lookup. */
49     public TestPlatformProvider() {
50         this(null, null);
51     }
52     
53     public TestPlatformProvider(ClassPath defaultPlatformBootClassPath, ClassPath explicitPlatformBootClassPath) {
54         this.support = new PropertyChangeSupport JavaDoc(this);
55         this.defaultPlatform = new TestPlatform("default_platform", "1.5", defaultPlatformBootClassPath);
56         this.explicitPlatform = new TestPlatform("ExplicitPlatform", "1.4", explicitPlatformBootClassPath);
57     }
58     
59     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
60         this.support.removePropertyChangeListener(listener);
61     }
62     
63     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
64         this.support.addPropertyChangeListener(listener);
65     }
66     
67     public JavaPlatform[] getInstalledPlatforms() {
68         if (this.hideExplicitPlatform) {
69             return new JavaPlatform[] {
70                 this.defaultPlatform,
71             };
72         } else {
73             return new JavaPlatform[] {
74                 this.defaultPlatform,
75                 this.explicitPlatform,
76             };
77         }
78     }
79     
80     public JavaPlatform getDefaultPlatform() {
81         return this.defaultPlatform;
82     }
83     
84     public void setExplicitPlatformVisible(boolean value) {
85         this.hideExplicitPlatform = !value;
86         this.support.firePropertyChange(PROP_INSTALLED_PLATFORMS,null,null);
87     }
88     
89     private static class TestPlatform extends JavaPlatform {
90         
91         private final String JavaDoc systemName;
92         private final Map JavaDoc properties;
93         private final ClassPath bootClassPath;
94         private final String JavaDoc specVersion;
95         
96         public TestPlatform(String JavaDoc systemName, String JavaDoc specVersion, ClassPath bootCP) {
97             this.systemName = systemName;
98             this.specVersion = specVersion;
99             if (bootCP == null) {
100                 try {
101                     this.bootClassPath = ClassPathSupport.createClassPath(new URL JavaDoc[] {
102                         // This file does not really have to exist - just needs to have a well-known location.
103
// Cf. ClasspathsTest.
104
new URL JavaDoc("jar:file:/c:/java/" + systemName + "/jre/lib/rt.jar!/"),
105                     });
106                 } catch (MalformedURLException JavaDoc e) {
107                     throw new AssertionError JavaDoc(e);
108                 }
109             } else {
110                 this.bootClassPath = bootCP;
111             }
112             this.properties = Collections.singletonMap("platform.ant.name",this.systemName);
113         }
114         
115         public FileObject findTool(String JavaDoc toolName) {
116             return null;
117         }
118         
119         public String JavaDoc getVendor() {
120             return "me";
121         }
122         
123         public ClassPath getStandardLibraries() {
124             return null;
125         }
126         
127         public Specification getSpecification() {
128             return new Specification("j2se", new SpecificationVersion(specVersion));
129         }
130         
131         public ClassPath getSourceFolders() {
132             return null;
133         }
134         
135         public Map JavaDoc getProperties() {
136             return this.properties;
137         }
138         
139         public List JavaDoc getJavadocFolders() {
140             return null;
141         }
142         
143         public Collection JavaDoc getInstallFolders() {
144             return null;
145         }
146         
147         public String JavaDoc getDisplayName() {
148             return this.systemName;
149         }
150         
151         public ClassPath getBootstrapLibraries() {
152             return this.bootClassPath;
153         }
154     }
155 }
156
Popular Tags