KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > 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.earproject;
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  * @author Tomas Zezula
37  */

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