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

Namespaces

public class Namespaces extends HashMap

Description: A HashMap of packageNames and namespaces with some helper methods

author
rkumar@borland.com

Fields Summary
private int
prefixCount
Field prefixCount
private HashMap
namespacePrefixMap
Field namespacePrefixMap
Constructors Summary
public Namespaces()
Constructor Namespaces


           
      

        super();

        namespacePrefixMap = new HashMap();
    
Methods Summary
public java.lang.StringgetCreate(java.lang.String key)
Get the namespaace for the given package If there is no entry in the HashMap for this namespace, create one.

param
key String representing packagename
return
the namespace either created or existing


        Object value = super.get(key);

        if (value == null) {
            value = makeNamespaceFromPackageName(key);

            put(key, value, null);
        }

        return (String) value;
    
public java.lang.StringgetCreate(java.lang.String key, java.lang.String prefix)
Get the namespaace for the given package If there is no entry in the HashMap for this namespace, create one.

param
key String representing packagename
param
prefix the prefix to use for the generated namespace
return
the namespace either created or existing


        Object value = super.get(key);

        if (value == null) {
            value = makeNamespaceFromPackageName(key);

            put(key, value, prefix);
        }

        return (String) value;
    
public java.lang.StringgetCreatePrefix(java.lang.String namespace)
Get the prefix for the given namespace. If one exists, create one

param
namespace namespace
return
prefix String


        if (namespacePrefixMap.get(namespace) == null) {
            namespacePrefixMap.put(namespace, "tns" + prefixCount++);
        }

        return (String) namespacePrefixMap.get(namespace);
    
public java.util.IteratorgetNamespaces()
Get the list of namespaces currently registered

return
iterator

        return namespacePrefixMap.keySet().iterator();
    
public static java.lang.StringgetPackage(java.lang.String namespace)
Reverse the process. Get the package name from the namespace.

param
namespace
return

        try {
            URL url = new URL(namespace);
            StringTokenizer st = new StringTokenizer(url.getHost(), ".");
            String[] words = new String[st.countTokens()];
            for (int i = 0; i < words.length; ++i) {
                words[i] = st.nextToken();
            }
            StringBuffer sb = new StringBuffer(80);
            for (int i = words.length - 1; i >= 0; --i) {
                String word = words[i];
                // seperate with dot
                if (i != words.length - 1) {
                    sb.append('.");
                }
                sb.append(word);
            }
            String pkg = sb.toString();
            if (pkg.equals("DefaultNamespace")) {
                return "";
            }
            return pkg;
        } catch (MalformedURLException e) {
        }
        return null;
    
public static java.lang.StringmakeNamespace(java.lang.String clsName, java.lang.String protocol)
Make namespace from a fully qualified class name and the given protocol

param
clsName fully qualified class name
param
protocol protocol String
return
namespace namespace String


        if (clsName.startsWith("[L")) {
            clsName = clsName.substring(2, clsName.length() - 1);
        }

        if (clsName.lastIndexOf('.") == -1) {
            return protocol + "://" + "DefaultNamespace";
        }

        String packageName = clsName.substring(0, clsName.lastIndexOf('."));

        return makeNamespaceFromPackageName(packageName, protocol);
    
public static java.lang.StringmakeNamespace(java.lang.String clsName)
Make namespace from a fully qualified class name use the default protocol for the namespace

param
clsName fully qualified class name
return
namespace namespace String

        return makeNamespace(clsName, "http");
    
private static java.lang.StringmakeNamespaceFromPackageName(java.lang.String packageName)
Method makeNamespaceFromPackageName

param
packageName
return

        return makeNamespaceFromPackageName(packageName, "http");
    
private static java.lang.StringmakeNamespaceFromPackageName(java.lang.String packageName, java.lang.String protocol)
Method makeNamespaceFromPackageName

param
packageName
param
protocol
return


        if ((packageName == null) || packageName.equals("")) {
            return protocol + "://" + "DefaultNamespace";
        }

        StringTokenizer st = new StringTokenizer(packageName, ".");
        String[] words = new String[st.countTokens()];

        for (int i = 0; i < words.length; ++i) {
            words[i] = st.nextToken();
        }

        StringBuffer sb = new StringBuffer(80);

        for (int i = words.length - 1; i >= 0; --i) {
            String word = words[i];

            // seperate with dot
            if (i != words.length - 1) {
                sb.append('.");
            }

            sb.append(word);
        }

        return protocol + "://" + sb.toString();
    
public java.lang.Objectput(java.lang.Object key, java.lang.Object value, java.lang.String prefix)
adds an entry to the packagename/namespace HashMap. In addition, also makes an entry in the auxillary namespace/prefix HashMap if an entry doesn't already exists

param
key packageName String
param
value namespace value
param
prefix the prefix to use for the given namespace
return
old value for the specified key


        if (prefix != null) {
            namespacePrefixMap.put(value, prefix);
        } else {
            getCreatePrefix((String) value);
        }

        return super.put(key, value);
    
public voidputAll(java.util.Map map)
adds an entry to the packagename/namespace HashMap for each of the entry in the map. In addition, also add an entries in the auxillary namespace/prefix HashMap

param
map packageName/namespace map


        Iterator i = map.entrySet().iterator();

        while (i.hasNext()) {
            Map.Entry entry = (Map.Entry) i.next();

            put(entry.getKey(), entry.getValue(), null);
        }
    
public voidputAllPrefix(java.util.Map map)
adds an entry to the namespace / prefix HashMap for each of the entry in the map.

param
map packageName/namespace map


        Iterator i = map.entrySet().iterator();

        while (i.hasNext()) {
            Map.Entry entry = (Map.Entry) i.next();

            put(entry.getKey(), entry.getValue());
        }
    
public voidputPrefix(java.lang.String namespace, java.lang.String prefix)
put the gine namespace / prefix into the appropriate HashMap

param
namespace
param
prefix

        namespacePrefixMap.put(namespace, prefix);