001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.gsfpath.api.platform;
043:
044: import java.beans.PropertyChangeListener;
045: import java.beans.PropertyChangeSupport;
046: import java.net.URL;
047: import java.util.Collection;
048: import java.util.Collections;
049: import java.util.List;
050: import java.util.Map;
051: import org.netbeans.modules.gsfpath.api.classpath.ClassPath;
052: import org.openide.filesystems.FileObject;
053:
054: /**
055: * JavaPlatform describes a java platform in a way that the IDE tools may utilize. It may serve as
056: * description of the platform a java project targets, or it may provide access to tools from the
057: * particular SDK installation. It also provides information about individual platforms, for example
058: * the Java platform version implemented, vendor name or implementation version. It is also possible
059: * to enumerate services that the IDE supports, which are implemented as a part of the Platform.
060: *
061: * @author Radko Najman, Svata Dedic, Tomas Zezula
062: */
063: public abstract class JavaPlatform {
064:
065: //List of names of mutable properties
066: /**
067: * Property name for displayName
068: */
069: public static final String PROP_DISPLAY_NAME = "displayName"; //NOI18N
070:
071: /**
072: * Property name for sourceFolders
073: */
074: public static final String PROP_SOURCE_FOLDER = "sourceFolders"; //NOI18N
075:
076: /**
077: * Property name for javadocFolders
078: */
079: public static final String PROP_JAVADOC_FOLDER = "javadocFolders"; //NOI18N
080:
081: /**
082: * Property name for systemProperties
083: */
084: public static final String PROP_SYSTEM_PROPERTIES = "systemProperties"; //NOI18N
085:
086: private Map<String, String> sysproperties = Collections.emptyMap();
087: private PropertyChangeSupport supp;
088:
089: /** Creates a new instance of JavaPlatform */
090: protected JavaPlatform() {
091: }
092:
093: /**
094: * @return a descriptive, human-readable name of the platform
095: */
096: public abstract String getDisplayName();
097:
098: /**
099: * Registers a listener to be notified when some of the platform's properties
100: * change
101: */
102: public final void addPropertyChangeListener(PropertyChangeListener l) {
103: synchronized (this ) {
104: if (supp == null)
105: supp = new PropertyChangeSupport(this );
106: }
107: supp.addPropertyChangeListener(l);
108: }
109:
110: /**
111: * Removes a listener registered previously
112: */
113: public final void removePropertyChangeListener(
114: PropertyChangeListener l) {
115: if (supp != null)
116: supp.removePropertyChangeListener(l);
117: }
118:
119: /**
120: * Gets some ad-hoc properties defined for this platform.
121: * The precise set of properties is not specified.
122: * <p class="nonnormative">
123: * Implementations are however advised to include the key
124: * <code>platform.ant.name</code> if they wish to be used in Ant builds;
125: * the value <code>default_platform</code> is conventionally associated
126: * with the default platform.
127: * </p>
128: * @return some properties
129: */
130: public abstract Map<String, String> getProperties();
131:
132: /** Gets the java platform system properties.
133: * @return the java platform system properties
134: */
135: public final Map<String, String> getSystemProperties() {
136: return sysproperties;
137: }
138:
139: /**
140: * Returns a ClassPath, which represents bootstrap libraries for the
141: * runtime environment. The Bootstrap libraries include libraries in
142: * JRE's extension directory, if there are any.
143: * @return ClassPath representing the bootstrap libs
144: */
145: public abstract ClassPath getBootstrapLibraries();
146:
147: /**
148: * Returns libraries recognized by default by the platform. Usually
149: * it corresponds to contents of CLASSPATH environment variable.
150: */
151: public abstract ClassPath getStandardLibraries();
152:
153: /**
154: * Returns the vendor of the Java SDK
155: * @return String
156: */
157: public abstract String getVendor();
158:
159: /**
160: * Returns specification of the Java SDK
161: * @return Specification
162: */
163: public abstract Specification getSpecification();
164:
165: /**
166: * Retrieves a collection of {@link FileObject}s of one or more folders
167: * where the Platform is installed. Typically it returns one folder, but
168: * in some cases there can be more of them.
169: * @return collection of installation folders (should be nonempty unless platform is broken)
170: */
171: public abstract Collection<FileObject> getInstallFolders();
172:
173: /**
174: * Gets the platform tool executable.
175: * @param toolName the tool platform independent tool name.
176: * @return file representing the tool executable, or null if the tool can not be found
177: */
178: public abstract FileObject findTool(String toolName);
179:
180: /**
181: * Returns the locations of the source of platform
182: * or empty collection when the location is not set or is invalid
183: * @return ClassPath never returns null
184: */
185: public abstract ClassPath getSourceFolders();
186:
187: /**
188: * Returns the locations of the Javadoc for this platform
189: * or empty collection if the location is not set or invalid
190: * @return (non-null) list of locations
191: */
192: public abstract List<URL> getJavadocFolders();
193:
194: /**
195: * Get the "default platform", meaning the JDK on which NetBeans itself is running.
196: * @return the default platform, if it can be found, or null
197: * @see JavaPlatformManager#getDefaultPlatform
198: */
199: public static JavaPlatform getDefault() {
200: return JavaPlatformManager.getDefault().getDefaultPlatform();
201: }
202:
203: //SPI methods
204:
205: /** Fires PropertyChange to all registered PropertyChangeListeners
206: * @param propName
207: * @param oldValue
208: * @param newValue
209: */
210: protected final void firePropertyChange(String propName,
211: Object oldValue, Object newValue) {
212: if (supp != null)
213: supp.firePropertyChange(propName, oldValue, newValue);
214: }
215:
216: /** Sets the system properties of java platform.
217: * @param sysproperties the java platform system properties
218: */
219: protected final void setSystemProperties(
220: Map<String, String> sysproperties) {
221: this .sysproperties = Collections.unmodifiableMap(sysproperties);
222: firePropertyChange(PROP_SYSTEM_PROPERTIES, null, null); // NOI18N
223: }
224:
225: }
|