1 55 package org.jboss.axis.wsdl.toJava; 56 57 import org.jboss.axis.utils.JavaUtils; 58 59 import java.io.File ; 60 import java.util.HashMap ; 61 import java.util.Iterator ; 62 import java.util.Map ; 63 import java.util.StringTokenizer ; 64 65 69 public class Namespaces extends HashMap 70 { 71 private String root; 72 private String defaultPackage = null; 73 74 77 private static final char[] pkgSeparators = {'.', ':'}; 78 private static final char javaPkgSeparator = pkgSeparators[0]; 79 80 private static String normalizePackageName(String pkg, char separator) 81 { 82 for (int i = 0; i < pkgSeparators.length; i++) 83 pkg = pkg.replace(pkgSeparators[i], separator); 84 return pkg; 85 } 86 87 90 public Namespaces(String root) 91 { 92 super(); 93 this.root = root; 94 } 96 99 private Namespaces(Namespaces clone) 100 { 101 super(clone); 102 this.root = clone.root; 103 this.defaultPackage = clone.defaultPackage; 104 } 106 109 public Object clone() 110 { 111 return new Namespaces(this); 112 } 114 118 public String getCreate(String key) 119 { 120 if (defaultPackage != null) 121 { 122 return defaultPackage; 123 } 124 String value = (String )super.get(key); 125 if (value == null) 126 { 127 value = normalizePackageName((String )Utils.makePackageName(key), 128 javaPkgSeparator); 129 put(key, value); 130 } 131 return (String )value; 132 } 134 138 public String getAsDir(String key) 139 { 140 if (defaultPackage != null) 141 { 142 return toDir(defaultPackage); 143 } 144 String pkg = (String )get(key); 145 return toDir(pkg); 146 } 148 152 public String toDir(String pkg) 153 { 154 String dir = null; 155 if (pkg != null) 156 { 157 pkg = normalizePackageName(pkg, File.separatorChar); 158 } 159 if (root == null) 160 { 161 dir = pkg; 162 } 163 else 164 { 165 dir = root + File.separatorChar + pkg; 166 } 167 168 return dir == null ? "" : dir + File.separatorChar; 169 } 171 175 public void putAll(Map map) 176 { 177 Iterator i = map.entrySet().iterator(); 178 while (i.hasNext()) 179 { 180 Map.Entry entry = (Map.Entry )i.next(); 181 Object key = entry.getKey(); 182 String pkg = (String )entry.getValue(); 183 pkg = javify(pkg); 184 put(key, pkg); 185 } 186 } 188 192 private String javify(String pkg) 193 { 194 StringTokenizer st = new StringTokenizer (pkg, "."); 195 pkg = ""; 196 while (st.hasMoreTokens()) 197 { 198 String token = st.nextToken(); 199 if (JavaUtils.isJavaKeyword(token)) 200 { 201 token = JavaUtils.makeNonJavaKeyword(token); 202 } 203 pkg = pkg + token; 204 if (st.hasMoreTokens()) 205 { 206 pkg = pkg + '.'; 207 } 208 } 209 return pkg; 210 } 212 215 public void mkdir(String pkg) 216 { 217 String pkgDirString = toDir(pkg); 218 File packageDir = new File (pkgDirString); 219 packageDir.mkdirs(); 220 } 222 227 public void setDefaultPackage(String defaultPackage) 228 { 229 this.defaultPackage = defaultPackage; 230 } 231 232 } | Popular Tags |