KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > platformdefinition > DefaultPlatformImpl


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.java.j2seplatform.platformdefinition;
21
22 import java.io.*;
23 import java.net.URL JavaDoc;
24 import java.util.*;
25 import java.net.MalformedURLException JavaDoc;
26
27 import org.openide.util.NbBundle;
28 import org.openide.util.Utilities;
29 import org.openide.ErrorManager;
30 import org.openide.filesystems.FileUtil;
31 import org.netbeans.api.java.platform.*;
32 import org.netbeans.api.java.classpath.*;
33
34 /**
35  * Implementation of the "Default" platform. The information here is extracted
36  * from the NetBeans' own runtime.
37  *
38  * @author Svata Dedic
39  */

40 public class DefaultPlatformImpl extends J2SEPlatformImpl {
41
42
43     public static final String JavaDoc DEFAULT_PLATFORM_ANT_NAME = "default_platform"; //NOI18N
44

45     private ClassPath standardLibs;
46     
47     static JavaPlatform create(Map properties, List sources, List javadoc) {
48         if (properties == null) {
49             properties = new HashMap ();
50         }
51         File javaHome = FileUtil.normalizeFile(new File(System.getProperty("jdk.home"))); //NOI18N
52
List installFolders = new ArrayList ();
53         try {
54             installFolders.add (javaHome.toURI().toURL());
55         } catch (MalformedURLException JavaDoc mue) {
56             ErrorManager.getDefault().notify (mue);
57         }
58         if (sources == null) {
59             sources = getSources (javaHome);
60         }
61         if (javadoc == null) {
62             javadoc = getJavadoc (javaHome);
63         }
64         return new DefaultPlatformImpl(installFolders, properties, new HashMap(System.getProperties()), sources,javadoc);
65     }
66     
67     private DefaultPlatformImpl(List installFolders, Map platformProperties, Map systemProperties, List sources, List javadoc) {
68         super(null,DEFAULT_PLATFORM_ANT_NAME,
69               installFolders, platformProperties, systemProperties, sources, javadoc);
70     }
71
72     public void setAntName(String JavaDoc antName) {
73         throw new UnsupportedOperationException JavaDoc (); //Default platform ant name can not be changed
74
}
75     
76     public String JavaDoc getDisplayName () {
77         String JavaDoc displayName = super.getDisplayName();
78         if (displayName == null) {
79             displayName = NbBundle.getMessage(DefaultPlatformImpl.class,"TXT_DefaultPlatform", getSpecification().getVersion().toString());
80             this.internalSetDisplayName (displayName);
81         }
82         return displayName;
83     }
84     
85     public void setDisplayName(String JavaDoc name) {
86         throw new UnsupportedOperationException JavaDoc (); //Default platform name can not be changed
87
}
88
89     public ClassPath getStandardLibraries() {
90         if (standardLibs != null)
91             return standardLibs;
92         String JavaDoc s = System.getProperty(SYSPROP_JAVA_CLASS_PATH); //NOI18N
93
if (s == null) {
94             s = ""; // NOI18N
95
}
96         return standardLibs = Util.createClassPath (s);
97     }
98
99     static List getSources (File javaHome) {
100         if (javaHome != null) {
101             try {
102                 File f;
103                 //On VMS, the root of the "src.zip" is "src", and this causes
104
//problems with NetBeans 4.0. So use the modified "src.zip" shipped
105
//with the OpenVMS NetBeans 4.0 kit.
106
if (Utilities.getOperatingSystem() == Utilities.OS_VMS) {
107                     String JavaDoc srcHome =
108                         System.getProperty("netbeans.openvms.j2seplatform.default.srcdir");
109                     if (srcHome != null)
110                         f = new File(srcHome, "src.zip");
111                     else
112                         f = new File (javaHome, "src.zip");
113                 } else {
114                     f = new File (javaHome, "src.zip"); //NOI18N
115
//If src.zip does not exist, try src.jar (it is on some platforms)
116
if (!f.exists()) {
117                         f = new File (javaHome, "src.jar"); //NOI18N
118
}
119                 }
120                 if (f.exists() && f.canRead()) {
121                     URL JavaDoc url = FileUtil.getArchiveRoot(f.toURI().toURL());
122                     return Collections.singletonList (url);
123                 }
124             } catch (MalformedURLException JavaDoc e) {
125                 ErrorManager.getDefault().notify (e);
126             }
127         }
128         return null;
129     }
130     
131     
132     static List getJavadoc (File javaHome) {
133         if (javaHome != null ) {
134             File f = new File (javaHome,"docs"); //NOI18N
135
if (f.isDirectory() && f.canRead()) {
136                 try {
137                     return Collections.singletonList(f.toURI().toURL());
138                 } catch (MalformedURLException JavaDoc mue) {
139                     ErrorManager.getDefault().notify (mue);
140                 }
141             }
142         }
143         return null;
144     }
145
146 }
Popular Tags