org.jibx.schema.codegen
Class PackageOrganizer

java.lang.Object
  extended by org.jibx.schema.codegen.PackageOrganizer

public class PackageOrganizer
extends java.lang.Object

Organizer for package information. This handles the conversions from namespace URIs to package names, and organizes the packages in a tree structure.

Author:
Dennis M. Sosnoski

Field Summary
private  java.lang.String[] m_authorityDiscards
          Array of case-insensitive strings to be discarded from start of authority component of URI when converting to package name.
private  java.io.File m_generateDirectory
          Base directory for code generation.
private  InsertionOrderedMap m_namePackageMap
          Map from package name to package information.
private  java.lang.String[] m_namespaceLeadMatches
          Leading URI text to be matched (paired with replacement values).
private  java.lang.String[] m_namespaceLeadReplaces
          Replacement text for URI matches (paired with leading URI texts).
private  java.util.Map m_namespacePackageMap
          Map from schema namespace URI to package (empty if unused).
private  java.lang.String m_noNamespacePackage
          Package to use for no-namespace schema components.
private  java.util.Map m_packageDirectoryMap
          Map from package to base directory for code generation (empty if unused).
private  java.util.Map m_uriPackageMap
          Map from namespace URI to package information.
 
Constructor Summary
PackageOrganizer(java.io.File basedir, java.lang.String npkg)
          Constructor.
 
Method Summary
 PackageHolder getPackage(java.lang.String pname)
          Get package information based on package name.
 PackageHolder getPackageForUri(java.lang.String uri)
          Get the information for a package.
 java.util.ArrayList getPackages()
          Get the defined packages.
private  int hexValue(char chr)
          Get value of character as hex digit.
private static boolean isAsciiAlpha(char chr)
          Check if a character is an ASCII alpha character.
private static boolean isAsciiAlphaNum(char chr)
          Check if a character is an ASCII alpha or numeric character.
private static boolean isAsciiNum(char chr)
          Check if a character is an ASCII numeric character.
private  boolean isHexChar(char chr)
          Check if a character is a hex digit.
 void setNamespaceLeadReplaces(java.lang.String[] leads, java.lang.String[] repls)
          Set the namespace lead replacement patterns.
 void setNSPackageMap(java.util.Map map)
          Set map from namespace URIs to packages.
 void setPackageDirMap(java.util.Map map)
          Set map from package to base generation directory.
 java.lang.String uriToPackage(java.lang.String uri)
          Convert namespace URI to package name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_generateDirectory

private final java.io.File m_generateDirectory
Base directory for code generation.


m_namespaceLeadMatches

private java.lang.String[] m_namespaceLeadMatches
Leading URI text to be matched (paired with replacement values). These values are matched using case-insensitive comparisons.


m_namespaceLeadReplaces

private java.lang.String[] m_namespaceLeadReplaces
Replacement text for URI matches (paired with leading URI texts).


m_namespacePackageMap

private java.util.Map m_namespacePackageMap
Map from schema namespace URI to package (empty if unused).


m_packageDirectoryMap

private java.util.Map m_packageDirectoryMap
Map from package to base directory for code generation (empty if unused).


m_authorityDiscards

private java.lang.String[] m_authorityDiscards
Array of case-insensitive strings to be discarded from start of authority component of URI when converting to package name. The default is the string "www."


m_uriPackageMap

private java.util.Map m_uriPackageMap
Map from namespace URI to package information. This is used in combination with the name-package map, since multiple URIs may be converted to the same package name.


m_namePackageMap

private InsertionOrderedMap m_namePackageMap
Map from package name to package information. This is used in combination with the URI-package map.


m_noNamespacePackage

private java.lang.String m_noNamespacePackage
Package to use for no-namespace schema components.

Constructor Detail

PackageOrganizer

public PackageOrganizer(java.io.File basedir,
                        java.lang.String npkg)
Constructor.

Parameters:
basedir - default base directory for code generation
npkg - default package for no-namespace schema components
Method Detail

setNamespaceLeadReplaces

public void setNamespaceLeadReplaces(java.lang.String[] leads,
                                     java.lang.String[] repls)
Set the namespace lead replacement patterns. This consists of lead texts to be matches and paired replacement texts. When a particular lead text is found in a URI the replacement text is substituted.

Parameters:
leads -
repls -

setNSPackageMap

public void setNSPackageMap(java.util.Map map)
Set map from namespace URIs to packages.

Parameters:
map - String-to-String map

setPackageDirMap

public void setPackageDirMap(java.util.Map map)
Set map from package to base generation directory. If this is unset all packages are generated under the default base directory, as are any packages not covered by this map. All subpackages of a package go under the parent package unless otherwise specified by this map.

Parameters:
map - String-to-File map

isHexChar

private boolean isHexChar(char chr)
Check if a character is a hex digit.

Parameters:
chr -
Returns:
hex digit flag

hexValue

private int hexValue(char chr)
Get value of character as hex digit.

Parameters:
chr -
Returns:
hex digit value

isAsciiAlpha

private static boolean isAsciiAlpha(char chr)
Check if a character is an ASCII alpha character.

Parameters:
chr -
Returns:
alpha character flag

isAsciiNum

private static boolean isAsciiNum(char chr)
Check if a character is an ASCII numeric character.

Parameters:
chr -
Returns:
numeric character flag

isAsciiAlphaNum

private static boolean isAsciiAlphaNum(char chr)
Check if a character is an ASCII alpha or numeric character.

Parameters:
chr -
Returns:
alpha or numeric character flag

uriToPackage

public java.lang.String uriToPackage(java.lang.String uri)
Convert namespace URI to package name.

Parameters:
uri -
Returns:
package name

getPackage

public PackageHolder getPackage(java.lang.String pname)
Get package information based on package name.

Parameters:
pname -
Returns:
package information

getPackageForUri

public PackageHolder getPackageForUri(java.lang.String uri)
Get the information for a package.

Parameters:
uri - corresponding namespace URI (non-null, empty string for no namespace)
Returns:
package information

getPackages

public java.util.ArrayList getPackages()
Get the defined packages. The returned list is guaranteed to be ordered such that parent packages precede child packages.

Returns:
packages


Project Web Site