net.sourceforge.nrl.parser.model.xsd
Class XSDModelLoader

java.lang.Object
  extended by net.sourceforge.nrl.parser.model.xsd.XSDModelLoader
All Implemented Interfaces:
IXSDUserData

public class XSDModelLoader
extends Object
implements IXSDUserData

The main XML Schema model loader class. Call load(File) to load a file and its includes and imports as an NRL model or load(Resource, File) if you already have a handle on the EMF resource containing the schema.

Author:
Christian Nentwich

Field Summary
 
Fields inherited from interface net.sourceforge.nrl.parser.model.xsd.IXSDUserData
ATTRIBUTE_KIND, CONTAINING_TYPE, JAXB_CATCH_ALL, JAXB_FLATTENED_PROPERTY, MODEL_FILE_LOCATION, NAMESPACE, RENAMED_AMBIGUOUS_ATTRIBUTE, SUBSTITUTABLE, SUBSTITUTION_FOR, XSD_ATTRIBUTE_KIND, XSD_COMPLEX_TYPE_KIND, XSD_ELEMENT_KIND, XSD_GLOBAL_ELEMENT, XSD_PATH, XSD_SIMPLE_TYPE_KIND, XSD_TYPE_KIND
 
Constructor Summary
XSDModelLoader()
           
 
Method Summary
protected  boolean areDescendantTypesUnique(org.eclipse.xsd.XSDParticle particle)
          Traverse the entire particle and check whether all descendant elements have a unique type.
protected  org.eclipse.xsd.XSDModelGroup getClosestEnclosingGroup(org.eclipse.xsd.XSDElementDeclaration elementA, org.eclipse.xsd.XSDElementDeclaration elementB)
          Assuming that two elements are contained within the same time, return the closest enclosing particular (sequence/choice, etc) that encloses both of them.
protected  XSDClassifier getComplexType(XSDPackage resultPackage, org.eclipse.xsd.XSDComplexTypeDefinition complexDef, String anonymousTypeName, boolean declaredAsGlobalElement)
          Generate a complex type from a complex type definition, registered it with the name map, add it to the result package and return it.
protected  void getComplexTypes(org.eclipse.xsd.XSDSchema schema, XSDPackage resultPackage)
          Read in all global complex type definitions and add to result package.
protected  String getCompositorAsString(org.eclipse.xsd.XSDCompositor compositor)
          Turn a sequence compositor to a string for naming purposes
protected  XSDDataType getDataType(org.eclipse.xsd.XSDComplexTypeDefinition def, XSDPackage resultPackage, String anonymousName, boolean declaredAsGlobalElement)
          Construct an XSDDataType from a complex type definition in the schema.
protected  XSDDataType getDataType(org.eclipse.xsd.XSDSimpleTypeDefinition def, XSDPackage resultPackage, String anonymousName, boolean declaredAsGlobalElement)
          Construct an XSDDataType from a simple type definition in the schema.
protected  org.eclipse.xsd.XSDParticle getDescendantElementParticle(org.eclipse.xsd.XSDParticle particle)
          Keep looking inside the nested particles until we find the first element declaration.
protected  List<org.eclipse.xsd.XSDElementDeclaration> getDirectDescendants(org.eclipse.xsd.XSDParticle particle)
          Return all element declarations in a particle, but not element declarations _within_ other element declarations, i.e.
protected  String getDisambiguated(String name, String targetNamespace)
          Return a disambiguated type name unique within the namespace.
protected  XSDDataType getEnumeration(org.eclipse.xsd.XSDSimpleTypeDefinition def, XSDPackage resultPackage, String anonymousName, boolean declaredAsGlobalElement)
          Create an enumeration type from a schema simple type.
protected  String getFlattenedJAXBPropertyName(org.eclipse.xsd.XSDParticle particle)
          Suggest a property name based on a content model of sequences and choices.
protected  void getGlobalElements(org.eclipse.xsd.XSDSchema schema, XSDPackage resultPackage)
          Read in all global element definitions, turning each into a classifier.
protected  int getNumberOfDescendantElements(org.eclipse.xsd.XSDParticle particle)
          Recursively search for elements within a repeating particle.
protected  void getSimpleTypes(org.eclipse.xsd.XSDSchema schema, XSDPackage resultPackage)
          Add anything to the result package that legitimately qualifies as a data type: simple types, derived simple types, enumerations and complex types that derive from simple types.
protected  String getSuggestedAnonymousTypeName(String namespace, String assignedToElement)
          Suggest a type name for an anonymous sub type, based on the element it has been assigned to.
 List<String> getWarnings()
          Return the list of warning strings created during the last load operation.
 IPackage load(File file)
          Deprecated. Use the IModelLoader interface to load models.
 IPackage load(org.eclipse.emf.ecore.resource.Resource res, File file)
          Deprecated. Use the IModelLoader interface to load models.
 IPackage load(org.eclipse.emf.ecore.resource.Resource res, File file, Map<?,?> options)
          Deprecated. Use the IModelLoader interface to load models, or load(Resource, Map) if you must.
 IPackage load(org.eclipse.emf.ecore.resource.Resource res, Map<?,?> options)
           
protected  void resolve(XSDPackage pkg)
          Resolve attribute types, parent references.
protected  void traverseParticle(XSDPackage resultPackage, XSDClassifier result, org.eclipse.xsd.XSDParticle particle, boolean ancestorOptional, boolean ancestorUnbounded, String targetNamespace)
          Recursive method that traverses a schema particle content model and adds attributes to a classifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XSDModelLoader

public XSDModelLoader()
Method Detail

areDescendantTypesUnique

protected boolean areDescendantTypesUnique(org.eclipse.xsd.XSDParticle particle)
Traverse the entire particle and check whether all descendant elements have a unique type.

Parameters:
particle - the particle
Returns:
true only if all have a unique type

getClosestEnclosingGroup

protected org.eclipse.xsd.XSDModelGroup getClosestEnclosingGroup(org.eclipse.xsd.XSDElementDeclaration elementA,
                                                                 org.eclipse.xsd.XSDElementDeclaration elementB)
Assuming that two elements are contained within the same time, return the closest enclosing particular (sequence/choice, etc) that encloses both of them.

Parameters:
elementA - the first element
elementB - the second element
Returns:
the closest particle or null if they have no common parent

getComplexType

protected XSDClassifier getComplexType(XSDPackage resultPackage,
                                       org.eclipse.xsd.XSDComplexTypeDefinition complexDef,
                                       String anonymousTypeName,
                                       boolean declaredAsGlobalElement)
Generate a complex type from a complex type definition, registered it with the name map, add it to the result package and return it.

Parameters:
resultPackage - the package to add to
complexDef - the type definition
anonymousTypeName - a name suggestion if the type is anonymous (has no name)
declaredAsGlobalElement - if true, this is a global element with an anonymous type
Returns:
the complex type classifier

getComplexTypes

protected void getComplexTypes(org.eclipse.xsd.XSDSchema schema,
                               XSDPackage resultPackage)
Read in all global complex type definitions and add to result package.

Parameters:
schema - the schema to read from
resultPackage - package to add to

getCompositorAsString

protected String getCompositorAsString(org.eclipse.xsd.XSDCompositor compositor)
Turn a sequence compositor to a string for naming purposes

Parameters:
compositor - the compositor (choice/sequence/all)
Returns:
the string "Or" or "And"

getDataType

protected XSDDataType getDataType(org.eclipse.xsd.XSDComplexTypeDefinition def,
                                  XSDPackage resultPackage,
                                  String anonymousName,
                                  boolean declaredAsGlobalElement)
Construct an XSDDataType from a complex type definition in the schema. The complex type must have ultimately inherited from a simple type to make this a valid operation.

Parameters:
def - the definition
resultPackage - the package to add to
anonymousName - name to use if the type has no name
declaredAsGlobalElement - if true, this is a global element declaration with an anoymous type

getDataType

protected XSDDataType getDataType(org.eclipse.xsd.XSDSimpleTypeDefinition def,
                                  XSDPackage resultPackage,
                                  String anonymousName,
                                  boolean declaredAsGlobalElement)
Construct an XSDDataType from a simple type definition in the schema.

Parameters:
def - the definition
resultPackage - the package to add to
anonymousName - name to use if the type has no name
declaredAsGlobalElement - if true, this is a global element with an anoymous type

getDescendantElementParticle

protected org.eclipse.xsd.XSDParticle getDescendantElementParticle(org.eclipse.xsd.XSDParticle particle)
Keep looking inside the nested particles until we find the first element declaration. The return it. Returns null if none found.

Parameters:
particle - the particle to search
Returns:
the element

getDirectDescendants

protected List<org.eclipse.xsd.XSDElementDeclaration> getDirectDescendants(org.eclipse.xsd.XSDParticle particle)
Return all element declarations in a particle, but not element declarations _within_ other element declarations, i.e. complex anonymous types.

Parameters:
particle - the particle
Returns:
all elements declared in the particle

getDisambiguated

protected String getDisambiguated(String name,
                                  String targetNamespace)
Return a disambiguated type name unique within the namespace. Searches the name mapping and adds disambiguator at the end.

Parameters:
name - the name
targetNamespace - the namespace
Returns:
the unique name

getEnumeration

protected XSDDataType getEnumeration(org.eclipse.xsd.XSDSimpleTypeDefinition def,
                                     XSDPackage resultPackage,
                                     String anonymousName,
                                     boolean declaredAsGlobalElement)
Create an enumeration type from a schema simple type. This normally instatiates a classifier with static attributes.

Parameters:
def - the the type
resultPackage - the package to add to
anonymousName - name to use if the type has no name
declaredAsGlobalElement - if true, this is a global element with an anonymous type

getFlattenedJAXBPropertyName

protected String getFlattenedJAXBPropertyName(org.eclipse.xsd.XSDParticle particle)
Suggest a property name based on a content model of sequences and choices. This should only be called if the full extent of the content model has at least two elements in it.

It will create a suggested name based on the JAXB convention, for example elementAAndElementB, if the elements are in a sequence.

Parameters:
particle - the particle
Returns:
a name or null if it was not possible to determine the property name

getGlobalElements

protected void getGlobalElements(org.eclipse.xsd.XSDSchema schema,
                                 XSDPackage resultPackage)
Read in all global element definitions, turning each into a classifier.

Parameters:
schema - the schema to read from
resultPackage - the result package to add to

getNumberOfDescendantElements

protected int getNumberOfDescendantElements(org.eclipse.xsd.XSDParticle particle)
Recursively search for elements within a repeating particle. Return the number found.

Parameters:
particle - the particle to search
Returns:
the number of elements found

getSimpleTypes

protected void getSimpleTypes(org.eclipse.xsd.XSDSchema schema,
                              XSDPackage resultPackage)
Add anything to the result package that legitimately qualifies as a data type: simple types, derived simple types, enumerations and complex types that derive from simple types.

Parameters:
schema - the schema to scan
resultPackage - the package to add to

getSuggestedAnonymousTypeName

protected String getSuggestedAnonymousTypeName(String namespace,
                                               String assignedToElement)
Suggest a type name for an anonymous sub type, based on the element it has been assigned to.

Parameters:
assignedToElement - the element name
Returns:
the type name, which will have to be unique

getWarnings

public List<String> getWarnings()
Return the list of warning strings created during the last load operation.

Returns:
the warnings

load

@Deprecated
public IPackage load(File file)
              throws Exception
Deprecated. Use the IModelLoader interface to load models.

Load a model contained in the specified file. This will break up the model into an NRL model.

The method currently also ignores all ClassNotFoundException and PackageNotFoundException errors, to ignore problems where a profile is not found.

Parameters:
file - the file to load
Returns:
the model
Throws:
Exception

load

@Deprecated
public IPackage load(org.eclipse.emf.ecore.resource.Resource res,
                                File file)
              throws Exception
Deprecated. Use the IModelLoader interface to load models.

Load with no options.

Throws:
Exception

load

@Deprecated
public IPackage load(org.eclipse.emf.ecore.resource.Resource res,
                                File file,
                                Map<?,?> options)
              throws Exception
Deprecated. Use the IModelLoader interface to load models, or load(Resource, Map) if you must.

Load using an ECore resource and an option map. Used for testing.

Throws:
Exception

load

public IPackage load(org.eclipse.emf.ecore.resource.Resource res,
                     Map<?,?> options)
              throws Exception
Throws:
Exception

resolve

protected void resolve(XSDPackage pkg)
Resolve attribute types, parent references.


traverseParticle

protected void traverseParticle(XSDPackage resultPackage,
                                XSDClassifier result,
                                org.eclipse.xsd.XSDParticle particle,
                                boolean ancestorOptional,
                                boolean ancestorUnbounded,
                                String targetNamespace)
Recursive method that traverses a schema particle content model and adds attributes to a classifier.

Parameters:
result - the classifier to add to
particle - the particle
ancestorOptional - if true, an ancestor particle was optional; everything from here on will be optional
ancestorUnbounded - if true, an ancestor was unbounded; everything from here on will be unbounded


Copyright © 2006-2013. All Rights Reserved.