KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > moduleinstall > DataModel


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.apisupport.project.ui.wizard.moduleinstall;
21
22 import java.net.URL JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
26 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
27 import org.openide.WizardDescriptor;
28
29 /**
30  * Data model used across the <em>New Module Installer</em>.
31  */

32 final class DataModel extends BasicWizardIterator.BasicDataModel {
33
34     static final String JavaDoc OPENIDE_MODULE_INSTALL = "OpenIDE-Module-Install"; // NOI18N
35
private static final String JavaDoc INSTALLER_CLASS_NAME = "Installer"; // NOI18N
36

37     private CreatedModifiedFiles cmf;
38     
39     DataModel(final WizardDescriptor wiz) {
40         super(wiz);
41     }
42     
43     CreatedModifiedFiles getCreatedModifiedFiles() {
44         if (cmf == null) {
45             regenerate();
46         }
47         return cmf;
48     }
49     
50     private void regenerate() {
51         cmf = new CreatedModifiedFiles(getProject());
52         
53         // obtain unique class name
54
String JavaDoc className = INSTALLER_CLASS_NAME;
55         String JavaDoc path = getDefaultPackagePath(className + ".java", false); // NOI18N
56
int i = 0;
57         while (alreadyExist(path)) {
58             className = INSTALLER_CLASS_NAME + '_' + ++i;
59             path = getDefaultPackagePath(className + ".java", false); // NOI18N
60
}
61         
62         // generate .java file for ModuleInstall
63
Map JavaDoc basicTokens = new HashMap JavaDoc();
64         basicTokens.put("@@PACKAGE_NAME@@", getPackageName()); // NOI18N
65
basicTokens.put("@@CLASS_NAME@@", className); // NOI18N
66
// XXX use nbresloc URL protocol rather than
67
// DataModel.class.getResource(...) and all such a cases below
68
URL JavaDoc template = DataModel.class.getResource("moduleInstall.javx"); // NOI18N
69
cmf.add(cmf.createFileWithSubstitutions(path, template, basicTokens));
70         
71         cmf.add(cmf.addModuleDependency("org.openide.modules")); // NOI18N
72
cmf.add(cmf.addModuleDependency("org.openide.util")); // NOI18N
73

74         // add manifest attribute
75
Map JavaDoc attribs = new HashMap JavaDoc();
76         attribs.put(OPENIDE_MODULE_INSTALL, getPackageName().replace('.','/') + '/' + className + ".class"); // NOI18N
77
cmf.add(cmf.manifestModification(null, attribs));
78     }
79     
80     private void reset() {
81         cmf = null;
82     }
83     
84     public void setPackageName(String JavaDoc packageName) {
85         super.setPackageName(packageName);
86         reset();
87     }
88     
89     private boolean alreadyExist(String JavaDoc relPath) {
90         return getProject().getProjectDirectory().getFileObject(relPath) != null;
91     }
92     
93 }
94
Popular Tags