Methods Summary |
---|
public java.lang.Object | clone()Instantiate a clone of this Namespaces object.
return new Namespaces(this);
|
public java.lang.String | getAsDir(java.lang.String key)Get the package name in directory format (dots replaced by slashes). If the package name
doesn't exist in the HashMap, return "".
if (defaultPackage != null) {
return toDir(defaultPackage);
}
String pkg = (String) get(key);
return toDir(pkg);
|
public java.lang.String | getCreate(java.lang.String key)Get the package name for the given namespace. If there is no entry in the HashMap for
this namespace, create one.
return getCreate(key, true);
|
java.lang.String | getCreate(java.lang.String key, boolean create)Get the package name for the given namespace. If there is no entry in the HashMap for
this namespace, create one if create flag is on, return null otherwise.
if (defaultPackage != null) {
put(key, defaultPackage);
return defaultPackage;
}
String value = (String) super.get(key);
if ((value == null) && create) {
value = normalizePackageName((String) Utils.makePackageName(key),
javaPkgSeparator);
put(key, value);
}
return (String) value;
|
public java.util.Map | getPkg2NamespacesMap()
return pkg2NamespacesMap;
|
private java.lang.String | javify(java.lang.String pkg)Make sure each package name doesn't conflict with a Java keyword.
Ie., org.apache.import.test becomes org.apache.import_.test.
StringTokenizer st = new StringTokenizer(pkg, ".");
pkg = "";
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (JavaUtils.isJavaKeyword(token)) {
token = JavaUtils.makeNonJavaKeyword(token);
}
pkg = pkg + token;
if (st.hasMoreTokens()) {
pkg = pkg + '.";
}
}
return pkg;
|
public void | mkdir(java.lang.String pkg)Make a directory for the given package under root.
String pkgDirString = toDir(pkg);
File packageDir = new File(pkgDirString);
packageDir.mkdirs();
|
private static java.lang.String | normalizePackageName(java.lang.String pkg, char separator)Method normalizePackageName
for (int i = 0; i < pkgSeparators.length; i++) {
pkg = pkg.replace(pkgSeparators[i], separator);
}
return pkg;
|
public java.lang.Object | put(java.lang.Object key, java.lang.Object value)
// Store pakcage->namespaces vector mapping
Vector v = null;
if (!pkg2NamespacesMap.containsKey(value)) {
v = new Vector();
} else {
v = (Vector)pkg2NamespacesMap.get(value);
}
// NOT need to add an input key (namespace value) to v (package vector)
if (!v.contains(key)) {
v.add(key);
}
pkg2NamespacesMap.put(value, v);
return super.put(key, value);
|
public void | putAll(java.util.Map map)Like HashMap's putAll, this adds the given map's contents to this map. But it
also makes sure the value strings are javified.
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
Object key = entry.getKey();
String pkg = (String) entry.getValue();
pkg = javify(pkg);
put(key, pkg);
}
|
public void | setDefaultPackage(java.lang.String defaultPackage)Set a package name that overrides the namespace map
this.defaultPackage = defaultPackage;
|
public java.lang.String | toDir(java.lang.String pkg)Return the given package name in directory format (dots replaced by slashes). If pkg is null,
"" is returned.
String dir = null;
if (pkg != null) {
pkg = normalizePackageName(pkg, File.separatorChar);
}
if (root == null) {
dir = pkg;
} else {
dir = root + File.separatorChar + pkg;
}
return (dir == null)
? ""
: dir + File.separatorChar;
|