FileDocCategorySizeDatePackage
NamespaceMapping.javaAPI DocApache Axis 1.45292Sat Apr 22 18:57:28 BST 2006org.apache.axis.tools.ant.wsdl

NamespaceMapping

public class NamespaceMapping extends Object implements Mapper
Used for nested package definitions. The file format used for storing mappings is a list of package=namespace

Fields Summary
private String
namespace
private String
packageName
private File
mappingFile
Constructors Summary
public NamespaceMapping()
pass in the namespace to map to


                
      
    
Methods Summary
public voidexecute(org.apache.tools.ant.ProjectComponent owner, java.util.HashMap map, boolean packageIsKey)
execute the mapping

param
owner owner object
param
map map to map to
param
packageIsKey if the package is to be the key for the map
throws
BuildException in case of emergency

        validate();
        if (mappingFile != null) {
            mapFile(owner, map,packageIsKey);
        } else {
            map(owner, map, packageName, namespace, packageIsKey);
        }
    
private java.util.PropertiesloadMappingPropertiesFile()
load a file containing properties

return
a properties file with zero or more mappings
throws
BuildException if the load failed

        Properties props = new Properties();
        FileInputStream instr = null;
        try {
            instr = new FileInputStream(mappingFile);
            props.load(new BufferedInputStream(instr));
        } catch (IOException e) {
            throw new BuildException("Failed to load " + mappingFile, e);
        } finally {
            if (instr != null) {
                try {
                    instr.close();
                } catch (IOException e) {
                }
            }
        }
        return props;
    
protected voidmap(org.apache.tools.ant.ProjectComponent owner, java.util.HashMap map, java.lang.String packName, java.lang.String nspace, boolean packageIsKey)
map a namespace to a package

param
owner owning project component (For logging)
param
map map to assign to
param
packName package name
param
nspace namespace
param
packageIsKey if the package is to be the key for the map

        owner.log("mapping "+nspace+" to "+packName, Project.MSG_VERBOSE);
        if(packageIsKey) {
            map.put(packName,nspace);
        } else {
            map.put(nspace, packName);
        }
    
protected voidmapFile(org.apache.tools.ant.ProjectComponent owner, java.util.HashMap map, boolean packageIsKey)
Load a mapping file and save it to the map

param
owner owner component
param
map target map file
param
packageIsKey if the package is to be the key for the map
throws
BuildException if an IOException needed swallowing

        Properties props = loadMappingPropertiesFile();
        Enumeration keys = props.keys();
        while (keys.hasMoreElements()) {
            String packageName = (String) keys.nextElement();
            String namespace = props.getProperty(packageName);
            map(owner, map, packageName, namespace, packageIsKey);
        }
    
public voidsetFile(java.io.File file)
name of a property file that contains mappings in package=namespace format

param
file file to load

        mappingFile = file;
    
public voidsetNamespace(java.lang.String value)
the namespace in the WSDL. Required.

param
value new uri of the mapping

        namespace = value;
    
public voidsetPackage(java.lang.String value)
the Java package to bind to. Required.

param
value java package name

        packageName = value;
    
private voidvalidate()
validate the option set

        if (mappingFile != null) {
            if (namespace != null || packageName != null) {
                throw new BuildException(
                        "Namespace or Package cannot be used with a File attribute");
            }
        } else {
            if (namespace == null) {
                throw new BuildException("namespace must be defined");
            }
            if (packageName == null) {
                throw new BuildException("package must be defined");
            }
        }