1 19 20 package org.netbeans.modules.websvc.jaxrpc; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.StringTokenizer ; 25 import org.openide.WizardDescriptor; 26 27 31 public final class Utilities { 32 33 private Utilities() { 34 } 35 36 41 public static String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 42 int diff = 0; 45 if (before == null) { 46 before = new String [0]; 47 } else if (before.length > 0) { 48 diff = ("...".equals(before[before.length - 1])) ? 1 : 0; } 50 String [] res = new String [ (before.length - diff) + panels.length]; 51 for (int i = 0; i < res.length; i++) { 52 if (i < (before.length - diff)) { 53 res[i] = before[i]; 54 } else { 55 res[i] = panels[i - before.length + diff].getComponent().getName(); 56 } 57 } 58 return res; 59 } 60 61 63 public static boolean isJavaIdentifier(String id) { 64 boolean result = true; 65 66 if(id == null || id.length() == 0 || !Character.isJavaIdentifierStart(id.charAt(0))) { 67 result = false; 68 } else { 69 for(int i = 1, idlength = id.length(); i < idlength; i++) { 70 if(!Character.isJavaIdentifierPart(id.charAt(i))) { 71 result = false; 72 break; 73 } 74 } 75 } 76 77 return result; 78 } 79 80 82 public static boolean isJavaPackage(String pkg) { 83 boolean result = false; 84 85 if(pkg != null && pkg.length() > 0) { 86 int state = 0; 87 for(int i = 0, pkglength = pkg.length(); i < pkglength && state < 2; i++) { 88 switch(state) { 89 case 0: 90 if(Character.isJavaIdentifierStart(pkg.charAt(i))) { 91 state = 1; 92 } else { 93 state = 2; 94 } 95 break; 96 case 1: 97 if(pkg.charAt(i) == '.') { 98 state = 0; 99 } else if(!Character.isJavaIdentifierPart(pkg.charAt(i))) { 100 state = 2; 101 } 102 break; 103 } 104 } 105 106 if(state == 1) { 107 result = true; 108 } 109 } 110 111 return result; 112 } 113 114 117 public static File getCanonicalFile(File f) { 118 File f1; 119 try { 120 f1 = f.getCanonicalFile(); 121 } catch (IOException e) { 122 f1 = null; 123 } 124 return f1; 125 } 126 127 public static String removeSpacesFromServiceName(String serviceName) { 128 if (serviceName!=null) { 129 String result = ""; if (serviceName.indexOf(" ") > -1) { StringTokenizer serviceNameTokenizer = new StringTokenizer (serviceName, " ", false); while (serviceNameTokenizer.hasMoreTokens()) { 133 StringBuffer token = new StringBuffer (serviceNameTokenizer.nextToken()); 134 if (token != null) { 135 token.setCharAt(0, Character.toUpperCase(token.charAt(0))); 136 result = result.concat(token.toString()); 137 } 138 } 139 return result; 140 } else if (serviceName.length()>0) { 141 result = Character.toUpperCase(serviceName.charAt(0))+serviceName.substring(1); 142 } 143 StringBuffer buf = new StringBuffer (result); 145 for (int i=0;i<buf.length();i++) { 146 if (Character.isDigit(buf.charAt(i))) { 147 if ((i+1)<buf.length() && !Character.isDigit(buf.charAt(i+1))) { 148 buf.setCharAt(i+1, Character.toUpperCase(buf.charAt(i+1))); 149 ++i; 150 } 151 } 152 result = buf.toString(); 153 } 154 return result; 155 } 156 return null; 157 } 158 } 159 | Popular Tags |