Class DomParser
java.lang.Object
de.iip_ecosphere.platform.configuration.opcua.parser.DomParser
XML parser for OPC UA companion spec files.
- Author:
- Jan-Hendrik Cepok, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classResults instance forgetDescriptionOrDocumentation(String, Element).private static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidadaptDatatypesToModel(ObjectType uaObject, MethodType uaMethod) Adapts the OPC UA data types to IIP-Ecosphere meta model type names.private voidaddElement(BaseType element, ElementType type) Adds an element to the hierarchy.private StringchangeVariableDataTypes(String dataType) Turns OPC UA type names to IIP-Ecosphere meta model type names.private StringcheckForExternDataType(String dataType) Checks for an extern data type.private StringcheckForInternDataType(String dataTypeNodeId) Checks for intern data type.private booleancheckRedundancy(String varName, ArrayList<FieldType> list) Checks for redundant/duplicate variable names inhierarchy.private static ElementcheckRelation(String currentNodeId, NodeList nodes) Checks the relations and returns a node with NodeIdcurrentNodeId.private static File[]checkRequiredModels(DomParser parser, String modelName, String path, String fileName, NodeList nameSpaceUris) Checks for required models.private voidcreateElement(ElementType type, Element element, String id, String displayName, String description, String documentation, ArrayList<FieldType> subFields, ArrayList<FieldType> objectFields, ArrayList<EnumLiteral> literals, ArrayList<DataLiteral> dataLiterals, String typeDef, boolean optional) Creates an element.private voidcreateIvmlModel(String fileName, File ivmlFile) Creates the IVML model in the givenfileName.private static DomParsercreateParser(String path, File compSpec, boolean verbose) Creates the parser.getDescriptionOrDocumentation(String reference, Element refElement) Extracts information about description or documentation fromrefElement.private static StringgetFieldDescription(Element fieldNode) Returns the field description offieldNode.private static ElementgetNextNodeElement(NodeList nodes, int iterator) Returns the next node element.private DomParser.TypeListAndTypegetTypeListAndTypeRootNs(String refId, String reference, ElementType type) Extracts the type list and type for a given root namespacerefId.identifyFields(Node childNode) Identifies the fields ofchildNode.private StringidentifySpecificReference(String reference, Node node, ElementType type) Identifies a specific reference.static voidExecutes the parser, per default in verbose mode.private static voidnop()Does nothing, just allows for code convention compliance while bugfixing.private voidParses a file by retrieving all root elements of the objects inobjectListand retriving all data types indataTypeList.private voidPrints out information in verbose mode.static voidProcesses an OPC XML file.private voidretrieveAttributes(Element element, ArrayList<FieldType> subFields, ElementType type, String externNodeId) Retrieves the attributes and creates respective elements.private StringRetrieves attributes fromdocumentsfor extern data types.private voidretrieveAttributesForRefElement(ArrayList<FieldType> fields, String refId, Element refElement, ElementType elementType) Retrieves attribute for a reference element.private voidRetrieves the element types and nested attributes viaretrieveAttributes(Element, ArrayList, ElementType, String).private StringretrieveParent(String parentNodeId, NodeList list) Retrieves the displayName of given parentNodeId.private voidretrieveRelatedSubElements(ArrayList<FieldType> subElements) Retrieves the related sub elements.private voidretrieveRootElement(Element object, ElementType type) Retrieves the root element.private static StringsearchVarName(BaseType uaElement, ArrayList<BaseType> hierarchy) Searches for a field type variable name.voidsetBaseNameSpace(String baseNameSpace) Defines the name space of the basic OPC UA Spec.static voidsetDefaultVerbose(boolean verbose) Changes the default verbose mode used when instantiating a parser.voidsetDocuments(Document[] documents) Defines the OPC UA document collection.voidsetExternAliasLists(ArrayList<NodeList> externAliasLists) Defines the OPC UA core alias list.static voidsetUsingIvmlFolder(String folder) Sets the folder where to generate example using IVML models.private static StringTurns a file into an operating-system dependent string path.private static StringTurns a string (assumed to be a path) into an operating-system dependent string path.
-
Field Details
-
verboseDefault
private static boolean verboseDefault -
usingIvmlFolder
-
IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPE
-
documents
-
objectTypeList
-
objectList
-
variableList
-
methodList
-
dataTypeList
-
variableTypeList
-
aliasList
-
hierarchy
-
verbose
private boolean verbose -
baseNameSpace
-
externAliasLists
-
-
Constructor Details
-
DomParser
private DomParser(NodeList objectTypeList, NodeList objectList, NodeList variableList, NodeList methodList, NodeList dataTypeList, NodeList variableTypeList, NodeList aliasList, ArrayList<BaseType> hierarchy) Creates a DOM parser/translator.- Parameters:
objectTypeList- the already parsed object type listobjectList- the already parsed object listvariableList- the already parsed variable listmethodList- the already parsed method listdataTypeList- the already parsed data type listvariableTypeList- the already parsed variable type listaliasList- the already parsed alias listhierarchy- the base type hierarchy
-
-
Method Details
-
setExternAliasLists
Defines the OPC UA core alias list.- Parameters:
externAliasLists- the list of OPC UA core aliases.
-
setDocuments
Defines the OPC UA document collection.- Parameters:
documents- the collection of documents.
-
setBaseNameSpace
Defines the name space of the basic OPC UA Spec.- Parameters:
baseNameSpace- the base name space
-
setDefaultVerbose
public static void setDefaultVerbose(boolean verbose) Changes the default verbose mode used when instantiating a parser.- Parameters:
verbose- verbose or non verbose mode
-
searchVarName
Searches for a field type variable name.- Parameters:
uaElement- the UA element delivering the node Id to search forhierarchy- the type hierarchy to search within- Returns:
- the variable name of the found field type
-
changeVariableDataTypes
Turns OPC UA type names to IIP-Ecosphere meta model type names.- Parameters:
dataType- the data type- Returns:
- the translated data type
-
adaptDatatypesToModel
Adapts the OPC UA data types to IIP-Ecosphere meta model type names.- Parameters:
uaObject- the UA object to adapt the types foruaMethod- the UA method to adapt the types for
-
nop
private static void nop()Does nothing, just allows for code convention compliance while bugfixing. -
checkRelation
Checks the relations and returns a node with NodeIdcurrentNodeId.- Parameters:
currentNodeId- the node id to search fornodes- the nodes to search- Returns:
- the found element
-
getNextNodeElement
Returns the next node element.- Parameters:
nodes- the nodes to search foriterator- the 0-based index into nodes- Returns:
- the next node element
-
retrieveParent
Retrieves the displayName of given parentNodeId.- Parameters:
parentNodeId- the parent node idlist- the node list to check- Returns:
- the root parent
-
checkForInternDataType
Checks for intern data type.- Parameters:
dataTypeNodeId- the referenced node id of a data type- Returns:
- the identified data type
-
checkForExternDataType
Checks for an extern data type.- Parameters:
dataType- the data type to look for- Returns:
- the data type
-
retrieveAttributesForExternDataType
Retrieves attributes fromdocumentsfor extern data types.- Parameters:
nodeId- the node id of the node to retrieve the attributes for- Returns:
- the data type
-
identifySpecificReference
Identifies a specific reference.- Parameters:
reference- the reference type to look fornode- the node to analyze the childrentype- the type to look for- Returns:
- the reference value
-
getTypeListAndTypeRootNs
private DomParser.TypeListAndType getTypeListAndTypeRootNs(String refId, String reference, ElementType type) Extracts the type list and type for a given root namespacerefId.- Parameters:
refId- the ref idreference- the reference typetype- the actual element type- Returns:
- the extracted result
-
getDescriptionOrDocumentation
private DomParser.DescriptionOrDocumentation getDescriptionOrDocumentation(String reference, Element refElement) Extracts information about description or documentation fromrefElement.- Parameters:
reference- the actual reference being processedrefElement- the reference element to take the data from- Returns:
- result instance carrying the extracted information
-
identifyFields
Identifies the fields ofchildNode.- Parameters:
childNode- the child node to analyze- Returns:
- the identified fields
-
retrieveAttributesForRefElement
private void retrieveAttributesForRefElement(ArrayList<FieldType> fields, String refId, Element refElement, ElementType elementType) Retrieves attribute for a reference element.- Parameters:
fields- the fields to retrieve the attributes forrefId- the ref idrefElement- the ref elementelementType- the elementType
-
retrieveRootElement
Retrieves the root element.- Parameters:
object- the element to start withtype- the type
-
retrieveRelatedSubElements
Retrieves the related sub elements.- Parameters:
subElements- the sub elements to analyze
-
retrieveAttributes
private void retrieveAttributes(Element element, ArrayList<FieldType> subFields, ElementType type, String externNodeId) Retrieves the attributes and creates respective elements.- Parameters:
element- the element to analyze the child nodes forsubFields- the sub fields for the creation of output forelementtype- the element typeexternNodeId- the element type
-
getFieldDescription
Returns the field description offieldNode.- Parameters:
fieldNode- the field node- Returns:
- the field description
-
createElement
private void createElement(ElementType type, Element element, String id, String displayName, String description, String documentation, ArrayList<FieldType> subFields, ArrayList<FieldType> objectFields, ArrayList<EnumLiteral> literals, ArrayList<DataLiteral> dataLiterals, String typeDef, boolean optional) Creates an element.- Parameters:
type- the element type.element- the actual elementid- the iddisplayName- the display namedescription- the descriptiondocumentation- the documentationsubFields- the sub fieldsobjectFields- the object fieldsliterals- the literalsdataLiterals- the data literalstypeDef- the type defoptional- whether the type is optional
-
addElement
Adds an element to the hierarchy.- Parameters:
element- the elementtype- the element type
-
checkRedundancy
Checks for redundant/duplicate variable names inhierarchy.- Parameters:
varName- the variable name to check forlist- the list of fields to check- Returns:
trueif there are duplicates,falseelse
-
retrieveElementTypes
private void retrieveElementTypes()Retrieves the element types and nested attributes viaretrieveAttributes(Element, ArrayList, ElementType, String). -
toOsPath
Turns a file into an operating-system dependent string path.- Parameters:
file- the file- Returns:
- the path
-
toOsPath
Turns a string (assumed to be a path) into an operating-system dependent string path.- Parameters:
path- the path to be translated- Returns:
- the path
-
checkRequiredModels
private static File[] checkRequiredModels(DomParser parser, String modelName, String path, String fileName, NodeList nameSpaceUris) Checks for required models.- Parameters:
parser- the parser instancemodelName- the model name to check forpath- the path to check forfileName- the file name to check fornameSpaceUris- the OPC namespace URIs- Returns:
- the found/required model files
-
parseFile
private void parseFile()Parses a file by retrieving all root elements of the objects inobjectListand retriving all data types indataTypeList. -
createParser
Creates the parser.- Parameters:
path- the path to the OPC UA nodeset modelscompSpec- the companion spec to be parsedverbose- verbose output- Returns:
- the DOM parser after parsing
-
setUsingIvmlFolder
Sets the folder where to generate example using IVML models.- Parameters:
folder- the folder name (by default "src/test/easy")
-
createIvmlModel
Creates the IVML model in the givenfileName.- Parameters:
fileName- the file name for the IVML modelivmlFile- the output file
-
println
Prints out information in verbose mode.- Parameters:
text- the text to print
-
process
Processes an OPC XML file. [public for testing]- Parameters:
xmlIn- the input fileoutName- the output file/model nameivmlOut- the full output file nameverbose- verbose output
-
main
Executes the parser, per default in verbose mode.- Parameters:
args- command line arguments (ignored)
-