KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > platform > JavaPlatform


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.api.java.platform;
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.openide.filesystems.FileObject;
30
31 /**
32  * JavaPlatform describes a java platform in a way that the IDE tools may utilize. It may serve as
33  * description of the platform a java project targets, or it may provide access to tools from the
34  * particular SDK installation. It also provides information about individual platforms, for example
35  * the Java platform version implemented, vendor name or implementation version. It is also possible
36  * to enumerate services that the IDE supports, which are implemented as a part of the Platform.
37  *
38  * @author Radko Najman, Svata Dedic, Tomas Zezula
39  */

40 public abstract class JavaPlatform {
41
42     //List of names of mutable properties
43
/**
44      * Property name for displayName
45      */

46     public static final String JavaDoc PROP_DISPLAY_NAME = "displayName"; //NOI18N
47

48     /**
49      * Property name for sourceFolders
50      */

51     public static final String JavaDoc PROP_SOURCE_FOLDER = "sourceFolders"; //NOI18N
52

53     /**
54      * Property name for javadocFolders
55      */

56     public static final String JavaDoc PROP_JAVADOC_FOLDER ="javadocFolders"; //NOI18N
57

58     /**
59      * Property name for systemProperties
60      */

61     public static final String JavaDoc PROP_SYSTEM_PROPERTIES = "systemProperties"; //NOI18N
62

63     private Map JavaDoc sysproperties = Collections.EMPTY_MAP;
64     private PropertyChangeSupport JavaDoc supp;
65     
66     /** Creates a new instance of JavaPlatform */
67     protected JavaPlatform() {
68     }
69
70     /**
71      * @return a descriptive, human-readable name of the platform
72      */

73     public abstract String JavaDoc getDisplayName();
74
75     /**
76      * Registers a listener to be notified when some of the platform's properties
77      * change
78      */

79     public final void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
80         synchronized (this) {
81             if (supp == null)
82                 supp = new PropertyChangeSupport JavaDoc(this);
83         }
84         supp.addPropertyChangeListener(l);
85     }
86     
87     /**
88      * Removes a listener registered previously
89      */

90     public final void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
91         if (supp != null)
92             supp.removePropertyChangeListener(l);
93     }
94     
95     /**
96      * Gets some ad-hoc properties defined for this platform.
97      * The precise set of properties is not specified.
98      * <p class="nonnormative">
99      * Implementations are however advised to include the key
100      * <code>platform.ant.name</code> if they wish to be used in Ant builds;
101      * the value <code>default_platform</code> is conventionally associated
102      * with the default platform.
103      * </p>
104      * @return some properties
105      */

106     public abstract Map JavaDoc getProperties();
107     
108     /** Gets the java platform system properties.
109      * @return the java platform system properties
110      */

111     public final Map JavaDoc getSystemProperties() {
112         return sysproperties;
113     }
114
115     /**
116      * Returns a ClassPath, which represents bootstrap libraries for the
117      * runtime environment. The Bootstrap libraries include libraries in
118      * JRE's extension directory, if there are any.
119      * @return ClassPath representing the bootstrap libs
120      */

121     public abstract ClassPath getBootstrapLibraries();
122     
123     /**
124      * Returns libraries recognized by default by the platform. Usually
125      * it corresponds to contents of CLASSPATH environment variable.
126      */

127     public abstract ClassPath getStandardLibraries();
128
129     /**
130      * Returns the vendor of the Java SDK
131      * @return String
132      */

133     public abstract String JavaDoc getVendor ();
134
135     /**
136      * Returns specification of the Java SDK
137      * @return Specification
138      */

139     public abstract Specification getSpecification ();
140
141     /**
142      * Retrieves a collection of {@link FileObject}s of one or more folders
143      * where the Platform is installed. Typically it returns one folder, but
144      * in some cases there can be more of them.
145      */

146     public abstract Collection JavaDoc getInstallFolders();
147
148     /**
149      * Gets the platform tool executable.
150      * @param toolName the tool platform independent tool name.
151      * @return file representing the tool executable, or null if the tool can not be found
152      */

153     public abstract FileObject findTool (String JavaDoc toolName);
154
155
156     /**
157      * Returns the locations of the source of platform
158      * or empty collection when the location is not set or is invalid
159      * @return ClassPath never returns null
160      */

161     public abstract ClassPath getSourceFolders ();
162
163     /**
164      * Returns the locations of the Javadoc for this platform
165      * or empty collection if the location is not set or invalid
166      * @return List&lt;URL&gt never returns null
167      */

168     public abstract List JavaDoc getJavadocFolders ();
169
170
171     /**
172      * Get the "default platform", meaning the JDK on which NetBeans itself is running.
173      * @return the default platform, if it can be found, or null
174      * @see JavaPlatformManager#getDefaultPlatform
175      */

176     public static JavaPlatform getDefault() {
177         return JavaPlatformManager.getDefault().getDefaultPlatform();
178     }
179
180
181     //SPI methods
182

183     /** Fires PropertyChange to all registered PropertyChangeListeners
184      * @param propName
185      * @param oldValue
186      * @param newValue
187      */

188     protected final void firePropertyChange(String JavaDoc propName, Object JavaDoc oldValue, Object JavaDoc newValue) {
189         if (supp != null)
190             supp.firePropertyChange(propName, oldValue, newValue);
191     }
192
193     /** Sets the system properties of java platform.
194      * @param sysproperties the java platform system properties
195      */

196     protected final void setSystemProperties(Map JavaDoc sysproperties) {
197         this.sysproperties = Collections.unmodifiableMap(sysproperties);
198         firePropertyChange(PROP_SYSTEM_PROPERTIES, null, null); // NOI18N
199
}
200
201  }
202
Popular Tags