KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > 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.web.project;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import org.netbeans.api.java.classpath.ClassPath;
29 import org.netbeans.api.java.platform.JavaPlatform;
30 import org.netbeans.api.java.platform.Specification;
31 import org.netbeans.modules.java.platform.JavaPlatformProvider;
32 import org.openide.filesystems.FileObject;
33 import org.openide.modules.SpecificationVersion;
34
35 /**
36  *
37  * @author Tomas Zezula
38  */

39 public final class TestPlatformProvider implements JavaPlatformProvider {
40
41     private JavaPlatform defaultPlatform;
42     private JavaPlatform explicitPlatform;
43     private PropertyChangeSupport JavaDoc support;
44     private boolean hideExplicitPlatform;
45
46     public TestPlatformProvider (ClassPath defaultPlatformBootClassPath, ClassPath explicitPlatformBootClassPath) {
47         this.support = new PropertyChangeSupport JavaDoc (this);
48         this.defaultPlatform = new TestPlatform("default_platform", defaultPlatformBootClassPath);
49         this.explicitPlatform = new TestPlatform("ExplicitPlatform", explicitPlatformBootClassPath);
50     }
51
52     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
53         this.support.removePropertyChangeListener (listener);
54     }
55
56     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
57         this.support.addPropertyChangeListener(listener);
58     }
59
60     public JavaPlatform[] getInstalledPlatforms() {
61         if (this.hideExplicitPlatform) {
62             return new JavaPlatform[] {
63                 this.defaultPlatform,
64             };
65         }
66         else {
67             return new JavaPlatform[] {
68                 this.defaultPlatform,
69                 this.explicitPlatform,
70             };
71         }
72     }
73
74     public JavaPlatform getDefaultPlatform () {
75         return this.defaultPlatform;
76     }
77
78     public void setExplicitPlatformVisible (boolean value) {
79         this.hideExplicitPlatform = !value;
80         this.support.firePropertyChange(PROP_INSTALLED_PLATFORMS,null,null);
81     }
82
83     private static class TestPlatform extends JavaPlatform {
84
85         private String JavaDoc systemName;
86         private Map JavaDoc properties;
87         private ClassPath bootClassPath;
88
89         public TestPlatform (String JavaDoc systemName, ClassPath bootCP) {
90             this.systemName = systemName;
91             this.bootClassPath = bootCP;
92             this.properties = Collections.singletonMap("platform.ant.name",this.systemName);
93         }
94
95         public FileObject findTool(String JavaDoc toolName) {
96             return null;
97         }
98
99         public String JavaDoc getVendor() {
100             return "me";
101         }
102
103         public ClassPath getStandardLibraries() {
104             return null;
105         }
106
107         public Specification getSpecification() {
108             return new Specification ("j2se", new SpecificationVersion ("1.5"));
109         }
110
111         public ClassPath getSourceFolders() {
112             return null;
113         }
114
115         public Map JavaDoc getProperties() {
116             return this.properties;
117         }
118
119         public List JavaDoc getJavadocFolders() {
120             return null;
121         }
122
123         public Collection JavaDoc getInstallFolders() {
124             return null;
125         }
126
127         public String JavaDoc getDisplayName() {
128             return this.systemName;
129         }
130
131         public ClassPath getBootstrapLibraries() {
132             return this.bootClassPath;
133         }
134     }
135 }
136
Popular Tags