KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > Utils


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.j2ee.clientproject;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import org.netbeans.modules.j2ee.api.ejbjar.Car;
26 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties;
27 import org.netbeans.modules.j2ee.dd.api.client.AppClient;
28 import org.netbeans.modules.j2ee.dd.api.client.DDProvider;
29 import org.openide.ErrorManager;
30 import org.openide.WizardDescriptor;
31
32 /**
33  * Utility methods for the module.
34  */

35 public class Utils {
36
37     private static final String JavaDoc WIZARD_PANEL_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
38
private static final String JavaDoc WIZARD_PANEL_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; //NOI18N;
39

40     public static String JavaDoc toClasspathString(File JavaDoc[] classpathEntries) {
41         if (classpathEntries == null) {
42             return "";
43         }
44         StringBuffer JavaDoc classpath = new StringBuffer JavaDoc();
45         for (int i = 0; i < classpathEntries.length; i++) {
46             classpath.append(classpathEntries[i].getAbsolutePath());
47             if (i + 1 < classpathEntries.length) {
48                 classpath.append(':');
49             }
50         }
51         return classpath.toString();
52     }
53     
54     /**
55      * Returns {@link AppClient} associated with the given project.
56      *
57      * @returns AppClient instance or <code>null</code>.
58      */

59     public static AppClient getAppClient(final AppClientProject project) {
60         AppClient result = null;
61         try {
62             Car apiCar = project.getAPICar();
63             if (apiCar.getDeploymentDescriptor() != null
64                     || apiCar.getJ2eePlatformVersion().equals(AppClientProjectProperties.JAVA_EE_5)) {
65                 result = DDProvider.getDefault().getMergedDDRoot(apiCar);
66             }
67         } catch (IOException JavaDoc e) {
68             ErrorManager.getDefault().log(e.getLocalizedMessage());
69         }
70         return result;
71     }
72     
73 // public static void notifyError(Exception ex) {
74
// NotifyDescriptor ndd = new NotifyDescriptor.Message(ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
75
// DialogDisplayer.getDefault().notify(ndd);
76
// }
77
//
78
// public static void mergeSteps(WizardDescriptor wizard, WizardDescriptor.Panel[] panels, String[] steps) {
79
// Object prop = wizard.getProperty (WIZARD_PANEL_CONTENT_DATA);
80
// String[] beforeSteps;
81
// int offset;
82
// if (prop instanceof String[]) {
83
// beforeSteps = (String[]) prop;
84
// offset = beforeSteps.length;
85
// if (offset > 0 && ("...".equals(beforeSteps[offset - 1]))) {// NOI18N
86
// offset--;
87
// }
88
// } else {
89
// beforeSteps = null;
90
// offset = 0;
91
// }
92
// String[] resultSteps = new String[ (offset) + panels.length];
93
// for (int i = 0; i < offset; i++) {
94
// resultSteps[i] = beforeSteps[i];
95
// }
96
// setSteps(panels, steps, resultSteps, offset);
97
// }
98
//
99
private static void setSteps(WizardDescriptor.Panel[] panels, String JavaDoc[] steps, String JavaDoc[] resultSteps, int offset) {
100         int n = steps == null ? 0 : steps.length;
101         for (int i = 0; i < panels.length; i++) {
102             final JComponent JavaDoc component = (JComponent JavaDoc) panels[i].getComponent();
103             String JavaDoc step = i < n ? steps[i] : null;
104             if (step == null) {
105                 step = component.getName();
106             }
107             component.putClientProperty(WIZARD_PANEL_CONTENT_DATA, resultSteps);
108             component.putClientProperty(WIZARD_PANEL_CONTENT_SELECTED_INDEX, i);
109             component.getAccessibleContext().setAccessibleDescription(step);
110             resultSteps[i + offset] = step;
111         }
112     }
113     
114     public static void setSteps(WizardDescriptor.Panel[] panels, String JavaDoc[] steps) {
115         setSteps(panels, steps, steps, 0);
116     }
117     
118 // /**
119
// * JMI transaction must be started and JMI classpath must be set to use this method
120
// */
121
// public static void save(JavaClass jc) {
122
// if (jc == null) {
123
// return;
124
// }
125
// DataObject dataObject = null;
126
// try {
127
// DataObject.find(JavaModel.getFileObject(jc.getResource()));
128
// } catch (DataObjectNotFoundException dnfe) {
129
// }
130
// SaveCookie saveCookie = dataObject == null ? null : (SaveCookie) dataObject.getCookie(SaveCookie.class);
131
// // TODO: SaveCookie - is returned if file is not modified?
132
//// assert saveCookie != null: ("SaveCookie not found for " + jc.getName());
133
// if (saveCookie != null) {
134
// try {
135
// saveCookie.save();
136
// } catch (IOException ioe) {
137
// ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ioe);
138
// }
139
// }
140
// }
141
//
142
// /**
143
// * JMI transaction must be started and JMI classpath must be set to use this method
144
// */
145
// public static boolean isModified(JavaClass ce) {
146
// DataObject dataObject = JavaMetamodel.getManager().getDataObject(ce.getResource());
147
// assert dataObject != null: ("DataObject not found for " + ce.getName());
148
// return dataObject.isModified();
149
// }
150
//
151
// public static boolean areInSameJ2EEApp(Project p1, Project p2) {
152
// Set globalPath = GlobalPathRegistry.getDefault().getSourceRoots();
153
// Iterator iter = globalPath.iterator();
154
// while (iter.hasNext()) {
155
// FileObject sourceRoot = (FileObject)iter.next();
156
// Project project = FileOwnerQuery.getOwner(sourceRoot);
157
// if (project != null) {
158
// Object j2eeAppProvider = project.getLookup().lookup(J2eeAppProvider.class);
159
// if (j2eeAppProvider != null) { // == it is j2ee app
160
// J2eeAppProvider j2eeApp = (J2eeAppProvider)j2eeAppProvider;
161
// J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders();
162
// if ((j2eeModules != null) && (j2eeModules.length > 0)) { // == there are some modules in the j2ee app
163
// J2eeModuleProvider affectedPrjProvider1 =
164
// (J2eeModuleProvider)p1.getLookup().lookup(J2eeModuleProvider.class);
165
// J2eeModuleProvider affectedPrjProvider2 =
166
// (J2eeModuleProvider)p2.getLookup().lookup(J2eeModuleProvider.class);
167
// if (affectedPrjProvider1 != null && affectedPrjProvider2 != null) {
168
// List childModules = Arrays.asList(j2eeModules);
169
// if (childModules.contains(affectedPrjProvider1) &&
170
// childModules.contains(affectedPrjProvider2)) {
171
// return true;
172
// }
173
// }
174
// }
175
// }
176
// }
177
// }
178
// return false;
179
// }
180
//
181
// // =========================================================================
182
//
183
// // utils for ejb code synchronization
184
//
185
//
186
//
187
// /** Returns list of all EJB projects that can be called from the caller project.
188
// *
189
// * @param enterpriseProject the caller enterprise project
190
// */
191
// public static Project [] getCallableEjbProjects (Project enterpriseProject) {
192
// Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
193
//
194
// boolean isCallerEJBModule = false;
195
// J2eeModuleProvider callerJ2eeModuleProvider = (J2eeModuleProvider) enterpriseProject.getLookup().lookup(J2eeModuleProvider.class);
196
// if (callerJ2eeModuleProvider != null && callerJ2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.CAR)) {
197
// // TODO: HACK - this should be set by calling AntArtifactQuery.findArtifactsByType(p, EjbProjectConstants.ARTIFACT_TYPE_EJBJAR)
198
// // but now freeform doesn't implement this correctly
199
// isCallerEJBModule = true;
200
// }
201
// // TODO: HACK - this must be solved by freeform's own implementation of EnterpriseReferenceContainer, see issue 57003
202
// // call ejb should not make this check, all should be handled in EnterpriseReferenceContainer
203
// boolean isCallerFreeform = enterpriseProject.getClass().getName().equals("org.netbeans.modules.ant.freeform.FreeformProject");
204
//
205
// List /*<Project>*/ filteredResults = new ArrayList(allProjects.length);
206
// for (int i = 0; i < allProjects.length; i++) {
207
// boolean isEJBModule = false;
208
// J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) allProjects[i].getLookup().lookup(J2eeModuleProvider.class);
209
// if (j2eeModuleProvider != null && j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.CAR)) {
210
// isEJBModule = true;
211
// }
212
// if ((isEJBModule && !isCallerFreeform) ||
213
// (isCallerFreeform && enterpriseProject.equals(allProjects[i]))) {
214
// filteredResults.add(allProjects[i]);
215
// }
216
// }
217
// return (Project []) filteredResults.toArray(new Project[filteredResults.size()]);
218
// }
219
//
220
// // Copied from j2ee/utilities JMIUtils
221
// public static JavaClass findClass(String className) {
222
// JavaClass result = (JavaClass) resolveType(className);
223
// return result instanceof UnresolvedClass ? null : result;
224
// }
225
//
226
// // Copied from j2ee/utilities JMIUtils
227
// public static Type resolveType(String typeName) {
228
// Type type = JavaModel.getDefaultExtent().getType().resolve(typeName);
229
// if (type instanceof UnresolvedClass) {
230
// Type basicType = JavaModel.getDefaultExtent().getType().resolve("java.lang." + typeName); // NOI18N;
231
// if (!(basicType instanceof UnresolvedClass)) {
232
// return basicType;
233
// }
234
// }
235
// return type;
236
// }
237
}
238
Popular Tags