KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > wizard > Util


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
21 package org.netbeans.modules.java.ui.wizard;
22
23 import java.util.ResourceBundle JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 import org.openide.src.*;
27 import org.openide.loaders.TemplateWizard;
28 import org.openide.util.Utilities;
29
30 public class Util {
31     static String JavaDoc getString(String JavaDoc key) {
32         return org.openide.util.NbBundle.getMessage(Util.class, key);
33     }
34
35     /** Returns true, if the passed string can be used as a qualified identifier.
36      * it does not check for semantic, only for syntax.
37      * The function returns true for any sequence of identifiers separated by
38      * dots.
39      */

40     static boolean isValidPackageName(String JavaDoc str) {
41         if (str.length() > 0 && str.charAt(0) == '.') return false;
42         StringTokenizer JavaDoc tukac = new StringTokenizer JavaDoc(str, "."); // NOI18N
43
while (tukac.hasMoreTokens()) {
44             String JavaDoc token = tukac.nextToken();
45             if ("".equals(token))
46                 return false;
47             if (!Utilities.isJavaIdentifier(token))
48                 return false;
49         }
50         return true;
51     }
52     
53     static boolean isValidTypeIdentifier(String JavaDoc ident) {
54         if (ident == null || "".equals(ident))
55             return false;
56         try {
57             Type t = Type.parse(ident);
58             return t.isClass();
59         } catch (IllegalArgumentException JavaDoc e) {
60             return false;
61         }
62     }
63     
64     static boolean implementsInterface(ClassElement clazz, Identifier id) {
65         Identifier[] implemented = clazz.getInterfaces();
66         for (int i = 0; i < implemented.length; i++) {
67             if (implemented[i].equals(id)) {
68                 return true;
69             }
70         }
71         return false;
72     }
73     
74     static TemplateWizard.Iterator packageIt;
75     
76     public static TemplateWizard.Iterator createPackageIterator() {
77         if (packageIt == null)
78             packageIt = JavaPackageIterator.create();
79         return packageIt;
80     }
81 }
82
Popular Tags