com.ibm.di.fc.emf
Class ModelParser

java.lang.Object
  extended by com.ibm.di.fc.emf.ModelParser

public class ModelParser
extends Object

Utility class providing a set functions related to working with the Ecore model used by EMF XMLToSDO and SDOToXML Function Components.


Field Summary
static String DOCROOT_CLASSNAME
          The name of the classes used in the Ecore models for the document root classes.
static String ROOT_NAME
          The name of the XML root object.
static String XMLNSPREFIX_FEATURE_NAME
          The name of the feature used in the Ecore models for the namespaces maps.
 
Constructor Summary
ModelParser(ResourceHash resHash)
          Initializing the class instances.
 
Method Summary
 void checkPackagesForConformity(Collection packageCollection, boolean isNamespaceAware)
          Checks if the packages conform to the restrictions set by the EMF XMLToSDO and SDOToXML Function Components.
static org.eclipse.emf.ecore.sdo.EDataObject createRootObject(org.eclipse.emf.ecore.EPackage epackage)
          Creates a Data Object of type the root class of the epackage package.
 org.eclipse.emf.ecore.sdo.EDataObject createRootObject(String xsdFile)
          Creates a root object according to the XML Schema specified by the xsdFile file.
 org.eclipse.emf.ecore.EStructuralFeature getFeature(org.eclipse.emf.ecore.EClass eclass, String name, Map prefixToURIMap)
          Searches an EClass features for a feature which represents an XML element or attribute with specified name.
static String getFeatureName(org.eclipse.emf.ecore.EStructuralFeature feature)
          Returns the name as specified in the XML Schema of an XML element or attribute represented by the feature object.
static String getFeatureNamespace(org.eclipse.emf.ecore.EStructuralFeature feature)
          Returns the namespace URI of the XML element or attribute represented by the feature object.
 Collection getPackageCollection(String xsdFile)
          Reads an XML Schema file and creates an Ecore model corresponding to it.
static org.eclipse.emf.ecore.EClass getRootClass(org.eclipse.emf.ecore.EPackage epackage)
          Returns the root class of the specified package.
static org.eclipse.emf.ecore.EPackage getRootPackage(Collection packageCollection)
          Searches the package collection for a package that defines a root class.
static int getSeparatorPosition(String path)
          Searches for a separator in the feature path and returns the position of the first separator or -1 if there are no separators.
static boolean isAttribute(org.eclipse.emf.ecore.EStructuralFeature feature)
          Checks if the specified feature object represents an XML attribute.
static boolean isElement(org.eclipse.emf.ecore.EStructuralFeature feature)
          Checks if the specified feature object represents an XML element.
static boolean isIgnored(String name)
          Checks if the specified string is a ignored feature name.
static boolean isSeparator(char c)
          Checks if the specified character is a feature path separator.
static String makeFeaturePath(org.eclipse.emf.ecore.EStructuralFeature feature, String path, Map uriToPrefixMap, boolean alwaysPrefix)
          Appends an XML element or attribute name to the current path.
 Map parseNamespaces(String namespaces, boolean isPrefixToURIMap)
          Parses a string that describes a mapping between prefixes and namespace URIs.
static void updateFactoryInstances(Collection packageCollection)
          Sets the factory instances of all EPackages in the collection to factory instances compliant to the EDataObject interface.
static void updatePackageRegistry(Collection packageCollection, org.eclipse.emf.ecore.EPackage.Registry packageRegistry)
          Traverses a collection of EPackages and adds them to a package registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_NAME

public static final String ROOT_NAME
The name of the XML root object. The name is used in the path expressions.

See Also:
Constant Field Values

XMLNSPREFIX_FEATURE_NAME

public static final String XMLNSPREFIX_FEATURE_NAME
The name of the feature used in the Ecore models for the namespaces maps.

See Also:
Constant Field Values

DOCROOT_CLASSNAME

public static final String DOCROOT_CLASSNAME
The name of the classes used in the Ecore models for the document root classes.

See Also:
Constant Field Values
Constructor Detail

ModelParser

public ModelParser(ResourceHash resHash)
Initializing the class instances.

Method Detail

isIgnored

public static boolean isIgnored(String name)
Checks if the specified string is a ignored feature name.


isSeparator

public static boolean isSeparator(char c)
Checks if the specified character is a feature path separator.


getFeatureName

public static String getFeatureName(org.eclipse.emf.ecore.EStructuralFeature feature)
Returns the name as specified in the XML Schema of an XML element or attribute represented by the feature object.


getFeatureNamespace

public static String getFeatureNamespace(org.eclipse.emf.ecore.EStructuralFeature feature)
Returns the namespace URI of the XML element or attribute represented by the feature object.


isAttribute

public static boolean isAttribute(org.eclipse.emf.ecore.EStructuralFeature feature)
Checks if the specified feature object represents an XML attribute.


isElement

public static boolean isElement(org.eclipse.emf.ecore.EStructuralFeature feature)
Checks if the specified feature object represents an XML element.


makeFeaturePath

public static String makeFeaturePath(org.eclipse.emf.ecore.EStructuralFeature feature,
                                     String path,
                                     Map uriToPrefixMap,
                                     boolean alwaysPrefix)
Appends an XML element or attribute name to the current path. The method qualifies the name with namespace prefix if such exists in the uriToPrefixMap parameter, or with a namespace URI if a prefix does not exist and the alwaysPrefix parameter is true.

Parameters:
feature - EStructuralFeature object that represents an XML element or attribute.
path - the path expression from the root till the current XML element or attribute.
uriToPrefixMap - namespace URI to prefix map.
alwaysPrefix - if true and no prefix is defined for the namespace of the XML element or attribute, for prefix is used the namespace URI.

getSeparatorPosition

public static int getSeparatorPosition(String path)
Searches for a separator in the feature path and returns the position of the first separator or -1 if there are no separators.


getRootPackage

public static org.eclipse.emf.ecore.EPackage getRootPackage(Collection packageCollection)
Searches the package collection for a package that defines a root class.

Parameters:
packageCollection - collection of EPackage objects
Returns:
a package that defines a root class

createRootObject

public static org.eclipse.emf.ecore.sdo.EDataObject createRootObject(org.eclipse.emf.ecore.EPackage epackage)
Creates a Data Object of type the root class of the epackage package.

Parameters:
epackage - specifies the package which root class is used in the object creation
Returns:
Data Object of type the root class of the epackage package. If the package has no root class null is returned.

updatePackageRegistry

public static void updatePackageRegistry(Collection packageCollection,
                                         org.eclipse.emf.ecore.EPackage.Registry packageRegistry)
Traverses a collection of EPackages and adds them to a package registry.

Parameters:
packageCollection - a collection of EPackages
packageRegistry - a package registry

updateFactoryInstances

public static void updateFactoryInstances(Collection packageCollection)
Sets the factory instances of all EPackages in the collection to factory instances compliant to the EDataObject interface.

Parameters:
packageCollection - collection of EPackage objects

getRootClass

public static org.eclipse.emf.ecore.EClass getRootClass(org.eclipse.emf.ecore.EPackage epackage)
Returns the root class of the specified package.


checkPackagesForConformity

public void checkPackagesForConformity(Collection packageCollection,
                                       boolean isNamespaceAware)
                                throws Exception
Checks if the packages conform to the restrictions set by the EMF XMLToSDO and SDOToXML Function Components. At this moment the only restriction checked is for case-insensitive equality in names of sibling XML elements or attributes.

Parameters:
packageCollection - the Ecore model package collection.
isNamespaceAware - if true siblings with case-insensitive equality in names but from different namespaces will be considered different.
Throws:
Exception - if there are siblings with case-insenstive equal names and the XML elements or attributes are in the same namespace.
Exception - if there are siblings with case-insensitive equal names and the XML elements or attributes are in different namespaces but the isNamespaceAware is false.

parseNamespaces

public Map parseNamespaces(String namespaces,
                           boolean isPrefixToURIMap)
                    throws Exception
Parses a string that describes a mapping between prefixes and namespace URIs. Then creates a prefix to URI or URI to prefix map, depending on the isPrefixToURIMap parameter.

Parameters:
namespaces - string object describing a mapping between prefixes and namespace URIs. Each mapping is delimited by an end-of-line character. On each line the prefix is delimited from the namespace URI by an equal sign.
isPrefixToURIMap - if true the created map is prefix to URI map, otherwise it is a URI to prefix map.
Returns:
prefix to URI map or URI to prefix map created by parsing the namespaces attribute.
Throws:
Exception - if the namespace mapping format (prefix=namespaceURI) is not obeyed.

getPackageCollection

public Collection getPackageCollection(String xsdFile)
                                throws Exception
Reads an XML Schema file and creates an Ecore model corresponding to it. Then returns a Collection containing all packages in the model.

Parameters:
xsdFile - specifies the location of the XML Schema File.
Throws:
Exception - if the XML Schema file is not found or is not valid XML Schema.

createRootObject

public org.eclipse.emf.ecore.sdo.EDataObject createRootObject(String xsdFile)
                                                       throws Exception
Creates a root object according to the XML Schema specified by the xsdFile file.

Parameters:
xsdFile - specifies an XML Schema file.
Returns:
Data Object corresponding to the root object defined in the XML Schema
Throws:
Exception - if the specified file does not exist or contains an invalid XML Schema.
Exception - if the XML Schema does not define a root element

getFeature

public org.eclipse.emf.ecore.EStructuralFeature getFeature(org.eclipse.emf.ecore.EClass eclass,
                                                           String name,
                                                           Map prefixToURIMap)
                                                    throws Exception
Searches an EClass features for a feature which represents an XML element or attribute with specified name. The function searches for a feature with matching name and namespace and if found it is returned. If only a feature with matching name is found it is also returned. If no feature matches the specified name an exception is thrown. Note: XML attributes are not considered namespace qualified, the prefix is regarded as part of the name.

Parameters:
eclass - the EClass object which features are searched.
name - the name of the XML element or attribute, probably with namespace prefix.
prefixToURIMap - prefix to namespace URI map.
Returns:
feature representing the XML element or attribute with the specified name and namespace by the name parameter.
Throws:
Exception - if no feature matches the specified name.