Package org.xmlet.xsdparser.core
Class XsdParserCore
- java.lang.Object
-
- org.xmlet.xsdparser.core.XsdParserCore
-
- Direct Known Subclasses:
XsdParser,XsdParserJar
public abstract class XsdParserCore extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcurrentFilejava.util.Map<java.lang.String,java.util.List<ReferenceBase>>parseElementsAListwhich contains all the top elements parsed by this class.(package private) static java.util.Map<java.lang.String,ConfigEntryData>parseMappersAMapobject that contains a parse function to eachXsdAbstractElementconcrete type supported by this mapper, this way based on the concreteXsdAbstractElementtag the according parse method can be invoked.private java.util.List<UnsolvedReferenceItem>parserUnsolvedElementsMapAListcontaining all the elements that even after parsing all the elements on the file, don't have a suitable object to replace the reference.(package private) java.util.List<java.lang.String>schemaLocationsAListcontaining the paths of files that were present in eitherXsdIncludeorXsdImportobjects that are present in the original or subsequent files.(package private) java.util.Map<java.lang.String,java.lang.String>schemaLocationsMapprivate java.util.Map<java.lang.String,java.util.List<UnsolvedReference>>unsolvedElementsAListofUnsolvedReferenceelements that weren't solved.private static java.util.Map<java.lang.String,java.lang.String>xsdTypesToJavaAMapobject that contains the all the XSD types and their respective types in the Java language.
-
Constructor Summary
Constructors Constructor Description XsdParserCore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFileToParse(java.lang.String schemaLocation)Adds a new file to the parsing queue.voidaddParsedElement(ReferenceBase wrappedElement)voidaddUnsolvedReference(UnsolvedReference unsolvedReference)Adds anUnsolvedReferenceobject to theunsolvedElementslist which should be solved at a later time in the parsing process.private java.lang.StringcleanPath(java.lang.String pathValue)Clean the path by useless ../ example /A/B/..protected javax.xml.parsers.DocumentBuildergetDocumentBuilder()static java.util.Map<java.lang.String,ConfigEntryData>getParseMappers()java.util.stream.Stream<XsdElement>getResultXsdElements()java.util.stream.Stream<XsdSchema>getResultXsdSchemas()java.util.List<UnsolvedReferenceItem>getUnsolvedReferences()static java.util.Map<java.lang.String,java.lang.String>getXsdTypesToJava()protected booleanisRelativePath(java.lang.String filePath)(package private) booleanisXsdSchema(org.w3c.dom.Node node)Verifies if a givenNodeobject, i.e.private voidreplaceUnsolvedImportedReference(java.util.Map<java.lang.String,java.util.List<NamedConcreteElement>> concreteElementsMap, UnsolvedReference unsolvedReference, java.lang.String fileName)private voidreplaceUnsolvedReference(java.util.Map<java.lang.String,java.util.List<NamedConcreteElement>> concreteElementsMap, UnsolvedReference unsolvedReference, java.lang.String fileName)Replaces a singleUnsolvedReferenceobject, with the respectiveNamedConcreteElementobject.private voidresolveInnerRefs()private voidresolveOtherNamespaceRefs()(package private) voidresolveRefs()This method resolves all the remainingUnsolvedReferenceobjects present after all the elements are parsed.private voidstoreUnsolvedItem(UnsolvedReference unsolvedReference)Saves an occurrence of an element which couldn't be resolved in thereplaceUnsolvedReference(java.util.Map<java.lang.String, java.util.List<org.xmlet.xsdparser.xsdelements.elementswrapper.NamedConcreteElement>>, org.xmlet.xsdparser.xsdelements.elementswrapper.UnsolvedReference, java.lang.String)method, which can be accessed at the end of the parsing process in order to verify if were there were any references that couldn't be solved.(package private) static voidupdateConfig(ParserConfig config)
-
-
-
Field Detail
-
parseMappers
static java.util.Map<java.lang.String,ConfigEntryData> parseMappers
AMapobject that contains a parse function to eachXsdAbstractElementconcrete type supported by this mapper, this way based on the concreteXsdAbstractElementtag the according parse method can be invoked.
-
xsdTypesToJava
private static java.util.Map<java.lang.String,java.lang.String> xsdTypesToJava
AMapobject that contains the all the XSD types and their respective types in the Java language.
-
parseElements
public java.util.Map<java.lang.String,java.util.List<ReferenceBase>> parseElements
AListwhich contains all the top elements parsed by this class.
-
unsolvedElements
private java.util.Map<java.lang.String,java.util.List<UnsolvedReference>> unsolvedElements
AListofUnsolvedReferenceelements that weren't solved. This list is consulted after all the elements are parsed in order to find if there is any suitable parsed element to replace the unsolved element.
-
parserUnsolvedElementsMap
private java.util.List<UnsolvedReferenceItem> parserUnsolvedElementsMap
AListcontaining all the elements that even after parsing all the elements on the file, don't have a suitable object to replace the reference. This list can be consulted after the parsing process to assert if there is any missing information in the XSD file.
-
schemaLocations
java.util.List<java.lang.String> schemaLocations
AListcontaining the paths of files that were present in eitherXsdIncludeorXsdImportobjects that are present in the original or subsequent files. These paths are stored to be parsed as well, the parsing process only ends when all the files present in thisListare parsed.
-
schemaLocationsMap
java.util.Map<java.lang.String,java.lang.String> schemaLocationsMap
-
currentFile
protected java.lang.String currentFile
-
-
Method Detail
-
isXsdSchema
boolean isXsdSchema(org.w3c.dom.Node node)
Verifies if a givenNodeobject, i.e.nodeis a xsd:schema node.- Parameters:
node- The node to verify.- Returns:
- True if the node is a xsd:schema or xs:schema. False otherwise.
-
resolveRefs
void resolveRefs()
This method resolves all the remainingUnsolvedReferenceobjects present after all the elements are parsed. It starts by iterating allparseElementsand inserting all the parsed elements with a name attribute in the concreteElementsMap variable. After that it iterates on theunsolvedElementslist in order to find if any of the unsolvedReferences can be solved by replacing the unsolvedElement by its matchingNamedConcreteElementobject, present in the concreteElementsMap. TheUnsolvedReferenceobjects matches aNamedConcreteElementobject by having its ref attribute with the same value as the name attribute of theNamedConcreteElement.
-
resolveOtherNamespaceRefs
private void resolveOtherNamespaceRefs()
-
replaceUnsolvedImportedReference
private void replaceUnsolvedImportedReference(java.util.Map<java.lang.String,java.util.List<NamedConcreteElement>> concreteElementsMap, UnsolvedReference unsolvedReference, java.lang.String fileName)
-
cleanPath
private java.lang.String cleanPath(java.lang.String pathValue)
Clean the path by useless ../ example /A/B/../B/C into /A/B/C
-
resolveInnerRefs
private void resolveInnerRefs()
-
replaceUnsolvedReference
private void replaceUnsolvedReference(java.util.Map<java.lang.String,java.util.List<NamedConcreteElement>> concreteElementsMap, UnsolvedReference unsolvedReference, java.lang.String fileName)
Replaces a singleUnsolvedReferenceobject, with the respectiveNamedConcreteElementobject. If there isn't aNamedConcreteElementobject to replace theUnsolvedReferenceobject, information is stored informing the user of this Project of the occurrence.- Parameters:
concreteElementsMap- The map containing all named concreteElements.unsolvedReference- The unsolved reference to solve.
-
storeUnsolvedItem
private void storeUnsolvedItem(UnsolvedReference unsolvedReference)
Saves an occurrence of an element which couldn't be resolved in thereplaceUnsolvedReference(java.util.Map<java.lang.String, java.util.List<org.xmlet.xsdparser.xsdelements.elementswrapper.NamedConcreteElement>>, org.xmlet.xsdparser.xsdelements.elementswrapper.UnsolvedReference, java.lang.String)method, which can be accessed at the end of the parsing process in order to verify if were there were any references that couldn't be solved.- Parameters:
unsolvedReference- The unsolved reference which couldn't be resolved.
-
getUnsolvedReferences
public java.util.List<UnsolvedReferenceItem> getUnsolvedReferences()
- Returns:
- The
ListofUnsolvedReferenceItemthat represent all the objects with a reference that couldn't be solved.
-
getResultXsdElements
public java.util.stream.Stream<XsdElement> getResultXsdElements()
- Returns:
- A list of all the top level parsed xsd:elements by this class. It doesn't return any other elements apart
from xsd:elements. To access the whole element tree use
getResultXsdSchemas()
-
getResultXsdSchemas
public java.util.stream.Stream<XsdSchema> getResultXsdSchemas()
-
addUnsolvedReference
public void addUnsolvedReference(UnsolvedReference unsolvedReference)
Adds anUnsolvedReferenceobject to theunsolvedElementslist which should be solved at a later time in the parsing process.- Parameters:
unsolvedReference- The unsolvedReference to add to the unsolvedElements list.
-
addFileToParse
public void addFileToParse(java.lang.String schemaLocation)
Adds a new file to the parsing queue. This new file appears by having xsd:import or xsd:include tags in the original file to parse.- Parameters:
schemaLocation- A new file path of another XSD file to parse.
-
getXsdTypesToJava
public static java.util.Map<java.lang.String,java.lang.String> getXsdTypesToJava()
-
getParseMappers
public static java.util.Map<java.lang.String,ConfigEntryData> getParseMappers()
-
addParsedElement
public void addParsedElement(ReferenceBase wrappedElement)
-
updateConfig
static void updateConfig(ParserConfig config)
-
isRelativePath
protected boolean isRelativePath(java.lang.String filePath)
-
getDocumentBuilder
protected javax.xml.parsers.DocumentBuilder getDocumentBuilder() throws javax.xml.parsers.ParserConfigurationException- Throws:
javax.xml.parsers.ParserConfigurationException
-
-