KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > wizard > J2SEWizardIterator


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.wizard;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Properties JavaDoc;
36 import java.util.Set JavaDoc;
37 import javax.swing.event.ChangeListener JavaDoc;
38 import org.netbeans.api.java.platform.JavaPlatform;
39 import org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl;
40 import org.netbeans.modules.java.j2seplatform.platformdefinition.PlatformConvertor;
41 import org.netbeans.modules.java.j2seplatform.platformdefinition.Util;
42 import org.openide.ErrorManager;
43 import org.openide.WizardDescriptor;
44 import org.openide.filesystems.FileObject;
45 import org.openide.filesystems.FileUtil;
46 import org.openide.filesystems.Repository;
47 import org.openide.loaders.DataFolder;
48 import org.openide.loaders.DataObject;
49 import org.openide.modules.InstalledFileLocator;
50 import org.openide.util.NbBundle;
51
52 /**
53  * Wizard Iterator for standard J2SE platforms. It assumes that there is a
54  * 'bin{/}java[.exe]' underneath the platform's directory, which can be run to
55  * produce the target platform's VM environment.
56  *
57  * @author Svata Dedic, Tomas Zezula
58  */

59 public class J2SEWizardIterator implements WizardDescriptor.InstantiatingIterator {
60     
61     private static final String JavaDoc[] SOLARIS_64_FOLDERS = {"sparcv9","amd64"}; //NOI18N
62

63     DataFolder installFolder;
64     DetectPanel.WizardPanel detectPanel;
65     Collection JavaDoc listeners;
66     NewJ2SEPlatform platform;
67     NewJ2SEPlatform secondaryPlatform;
68     WizardDescriptor wizard;
69     int currentIndex;
70
71     public J2SEWizardIterator(FileObject installFolder) throws IOException JavaDoc {
72         this.installFolder = DataFolder.findFolder(installFolder);
73         this.platform = NewJ2SEPlatform.create (installFolder);
74         String JavaDoc archFolder = null;
75         for (int i = 0; i< SOLARIS_64_FOLDERS.length; i++) {
76             if (Util.findTool("java",Collections.singleton(installFolder),SOLARIS_64_FOLDERS[i]) != null) {
77                 archFolder = SOLARIS_64_FOLDERS[i];
78                 break;
79             }
80         }
81         if (archFolder != null) {
82             this.secondaryPlatform = NewJ2SEPlatform.create (installFolder);
83             this.secondaryPlatform.setArchFolder(archFolder);
84         }
85     }
86
87     FileObject getInstallFolder() {
88         return installFolder.getPrimaryFile();
89     }
90
91     public void addChangeListener(ChangeListener JavaDoc l) {
92         listeners.add(l);
93     }
94
95     public WizardDescriptor.Panel current() {
96         switch (this.currentIndex) {
97             case 0:
98                 return this.detectPanel;
99             default:
100                 throw new IllegalStateException JavaDoc();
101         }
102     }
103
104     public boolean hasNext() {
105         return false;
106     }
107
108     public boolean hasPrevious() {
109         return false;
110     }
111
112     public void initialize(WizardDescriptor wiz) {
113         this.wizard = wiz;
114         this. detectPanel = new DetectPanel.WizardPanel(this);
115         this.currentIndex = 0;
116     }
117
118     /**
119      * This finally produces the java platform's XML that represents the basic
120      * platform's properties. The XML is returned in the resulting Set.
121      * @return singleton Set with java platform's instance DO inside.
122      */

123     public java.util.Set JavaDoc instantiate() throws IOException JavaDoc {
124         //Workaround #44444
125
this.detectPanel.storeSettings (this.wizard);
126         Set JavaDoc result = new HashSet JavaDoc ();
127         for (Iterator JavaDoc it = getPlatforms().iterator(); it.hasNext();) {
128             NewJ2SEPlatform platform = (NewJ2SEPlatform) it.next();
129             if (platform.isValid()) {
130                 final String JavaDoc systemName = platform.getAntName();
131                 FileObject platformsFolder = Repository.getDefault().getDefaultFileSystem().findResource(
132                         "Services/Platforms/org-netbeans-api-java-Platform"); //NOI18N
133
if (platformsFolder.getFileObject(systemName,"xml")!=null) { //NOI18N
134
String JavaDoc msg = NbBundle.getMessage(J2SEWizardIterator.class,"ERROR_InvalidName");
135                     throw (IllegalStateException JavaDoc)ErrorManager.getDefault().annotate(
136                         new IllegalStateException JavaDoc(msg), ErrorManager.USER, null, msg,null, null);
137                 }
138                 DataObject dobj = PlatformConvertor.create(platform, DataFolder.findFolder(platformsFolder),systemName);
139                 result.add((JavaPlatform) dobj.getNodeDelegate().getLookup().lookup(JavaPlatform.class));
140             }
141         }
142         return Collections.unmodifiableSet(result);
143         
144     }
145
146     public String JavaDoc name() {
147         return NbBundle.getMessage(J2SEWizardIterator.class, "TITLE_PlatformName");
148     }
149
150     public void nextPanel() {
151         this.currentIndex++;
152     }
153
154     public void previousPanel() {
155         this.currentIndex--;
156     }
157
158     public void removeChangeListener(ChangeListener JavaDoc l) {
159         listeners.add(l);
160     }
161
162     public void uninitialize(WizardDescriptor wiz) {
163         this.wizard = null;
164         this.detectPanel = null;
165     }
166
167     public NewJ2SEPlatform getPlatform() {
168         return this.platform;
169     }
170     
171     public NewJ2SEPlatform getSecondaryPlatform () {
172         return this.secondaryPlatform;
173     }
174     
175     private List JavaDoc getPlatforms () {
176         List JavaDoc result = new ArrayList JavaDoc ();
177         result.add(this.platform);
178         if (this.secondaryPlatform != null) {
179             result.add(this.secondaryPlatform);
180         }
181         return result;
182     }
183 }
184
Popular Tags