FileDocCategorySizeDatePackage
Namespaces.javaAPI DocApache Axis 1.47037Sat Apr 22 18:57:28 BST 2006org.apache.axis.wsdl.toJava

Namespaces

public class Namespaces extends HashMap
This class is essentially a HashMap of pairs with a few extra wizzbangs.

Fields Summary
private String
root
Field root
private String
defaultPackage
Field defaultPackage
private static final char[]
pkgSeparators
Toknens in a namespace that are treated as package name part separators.
private static final char
javaPkgSeparator
Field javaPkgSeparator
private Map
pkg2NamespacesMap
Field pkg2Namespaces : reverse mapping of Namespaces
Constructors Summary
public Namespaces(String root)
Instantiate a Namespaces object whose packages will all reside under root.

param
root


        super();

        this.root = root;
    
private Namespaces(Namespaces clone)
Instantiate a clone of an existing Namespaces object.

param
clone


        super(clone);

        this.root = clone.root;
        this.defaultPackage = clone.defaultPackage;
    
Methods Summary
public java.lang.Objectclone()
Instantiate a clone of this Namespaces object.

return

        return new Namespaces(this);
    
public java.lang.StringgetAsDir(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 "".

param
key
return


        if (defaultPackage != null) {
            return toDir(defaultPackage);
        }

        String pkg = (String) get(key);

        return toDir(pkg);
    
public java.lang.StringgetCreate(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.

param
key
return

        return getCreate(key, true);
    
java.lang.StringgetCreate(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.

param
key
param
create
return


        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.MapgetPkg2NamespacesMap()

        return pkg2NamespacesMap;
    
private java.lang.Stringjavify(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.

param
pkg
return


        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 voidmkdir(java.lang.String pkg)
Make a directory for the given package under root.

param
pkg


        String pkgDirString = toDir(pkg);
        File packageDir = new File(pkgDirString);

        packageDir.mkdirs();
    
private static java.lang.StringnormalizePackageName(java.lang.String pkg, char separator)
Method normalizePackageName

param
pkg
param
separator
return


                          
           

        for (int i = 0; i < pkgSeparators.length; i++) {
            pkg = pkg.replace(pkgSeparators[i], separator);
        }

        return pkg;
    
public java.lang.Objectput(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 voidputAll(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.

param
map


        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 voidsetDefaultPackage(java.lang.String defaultPackage)
Set a package name that overrides the namespace map

param
defaultPackage a java package name (e.g. com.foo)

        this.defaultPackage = defaultPackage;
    
public java.lang.StringtoDir(java.lang.String pkg)
Return the given package name in directory format (dots replaced by slashes). If pkg is null, "" is returned.

param
pkg
return


        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;