Class DomParser
- java.lang.Object
-
- de.iip_ecosphere.platform.configuration.opcua.parser.DomParser
-
public class DomParser extends java.lang.ObjectXML parser for OPC UA companion spec files.- Author:
- Jan-Hendrik Cepok, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDomParser.DescriptionOrDocumentationResults instance forgetDescriptionOrDocumentation(String, Element).private static classDomParser.TypeListAndType
-
Field Summary
Fields Modifier and Type Field Description private org.w3c.dom.NodeListaliasListprivate java.lang.StringbaseNameSpaceprivate org.w3c.dom.NodeListdataTypeListprivate org.w3c.dom.Document[]documentsprivate java.util.ArrayList<org.w3c.dom.NodeList>externAliasListsprivate java.util.ArrayList<BaseType>hierarchyprivate static java.util.Set<java.lang.String>IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPEprivate org.w3c.dom.NodeListmethodListprivate org.w3c.dom.NodeListobjectListprivate org.w3c.dom.NodeListobjectTypeListprivate static java.lang.StringusingIvmlFolderprivate org.w3c.dom.NodeListvariableListprivate org.w3c.dom.NodeListvariableTypeListprivate booleanverboseprivate static booleanverboseDefault
-
Constructor Summary
Constructors Modifier Constructor Description privateDomParser(org.w3c.dom.NodeList objectTypeList, org.w3c.dom.NodeList objectList, org.w3c.dom.NodeList variableList, org.w3c.dom.NodeList methodList, org.w3c.dom.NodeList dataTypeList, org.w3c.dom.NodeList variableTypeList, org.w3c.dom.NodeList aliasList, java.util.ArrayList<BaseType> hierarchy)Creates a DOM parser/translator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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 java.lang.StringchangeVariableDataTypes(java.lang.String dataType)Turns OPC UA type names to IIP-Ecosphere meta model type names.private java.lang.StringcheckForExternDataType(java.lang.String dataType)Checks for an extern data type.private java.lang.StringcheckForInternDataType(java.lang.String dataTypeNodeId)Checks for intern data type.private booleancheckRedundancy(java.lang.String varName, java.util.ArrayList<FieldType> list)Checks for redundant/duplicate variable names inhierarchy.private static org.w3c.dom.ElementcheckRelation(java.lang.String currentNodeId, org.w3c.dom.NodeList nodes)Checks the relations and returns a node with NodeIdcurrentNodeId.private static java.io.File[]checkRequiredModels(DomParser parser, java.lang.String modelName, java.lang.String path, java.lang.String fileName, org.w3c.dom.NodeList nameSpaceUris)Checks for required models.private voidcreateElement(ElementType type, org.w3c.dom.Element element, java.lang.String id, java.lang.String displayName, java.lang.String description, java.lang.String documentation, java.util.ArrayList<FieldType> subFields, java.util.ArrayList<FieldType> objectFields, java.util.ArrayList<EnumLiteral> literals, java.util.ArrayList<DataLiteral> dataLiterals, java.lang.String typeDef, boolean optional)Creates an element.private voidcreateIvmlModel(java.lang.String fileName, java.io.File ivmlFile)Creates the IVML model in the givenfileName.private static DomParsercreateParser(java.lang.String path, java.io.File compSpec, boolean verbose)Creates the parser.private DomParser.DescriptionOrDocumentationgetDescriptionOrDocumentation(java.lang.String reference, org.w3c.dom.Element refElement)Extracts information about description or documentation fromrefElement.private static java.lang.StringgetFieldDescription(org.w3c.dom.Element fieldNode)Returns the field description offieldNode.private static org.w3c.dom.ElementgetNextNodeElement(org.w3c.dom.NodeList nodes, int iterator)Returns the next node element.private DomParser.TypeListAndTypegetTypeListAndTypeRootNs(java.lang.String refId, java.lang.String reference, ElementType type)Extracts the type list and type for a given root namespacerefId.private java.util.ArrayList<FieldType>identifyFields(org.w3c.dom.Node childNode)Identifies the fields ofchildNode.private java.lang.StringidentifySpecificReference(java.lang.String reference, org.w3c.dom.Node node, ElementType type)Identifies a specific reference.static voidmain(java.lang.String[] args)Executes the parser, per default in verbose mode.private static voidnop()Does nothing, just allows for code convention compliance while bugfixing.private voidparseFile()Parses a file by retrieving all root elements of the objects inobjectListand retriving all data types indataTypeList.private voidprintln(java.lang.String text)Prints out information in verbose mode.static voidprocess(java.io.File xmlIn, java.lang.String outName, java.io.File ivmlOut, boolean verbose)Processes an OPC XML file.private voidretrieveAttributes(org.w3c.dom.Element element, java.util.ArrayList<FieldType> subFields, ElementType type, java.lang.String externNodeId)Retrieves the attributes and creates respective elements.private java.lang.StringretrieveAttributesForExternDataType(java.lang.String nodeId)Retrieves attributes fromdocumentsfor extern data types.private voidretrieveAttributesForRefElement(java.util.ArrayList<FieldType> fields, java.lang.String refId, org.w3c.dom.Element refElement, ElementType elementType)Retrieves attribute for a reference element.private voidretrieveElementTypes()Retrieves the element types and nested attributes via#retrieveAttributes(Element, ArrayList, ElementType).private java.lang.StringretrieveParent(java.lang.String parentNodeId, org.w3c.dom.NodeList list)Retrieves the displayName of given parentNodeId.private voidretrieveRelatedSubElements(java.util.ArrayList<FieldType> subElements)Retrieves the related sub elements.private voidretrieveRootElement(org.w3c.dom.Element object, ElementType type)Retrieves the root element.private static java.lang.StringsearchVarName(BaseType uaElement, java.util.ArrayList<BaseType> hierarchy)Searches for a field type variable name.voidsetBaseNameSpace(java.lang.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(org.w3c.dom.Document[] documents)Defines the OPC UA document collection.voidsetExternAliasLists(java.util.ArrayList<org.w3c.dom.NodeList> externAliasLists)Defines the OPC UA core alias list.static voidsetUsingIvmlFolder(java.lang.String folder)Sets the folder where to generate example using IVML models.private static java.lang.StringtoOsPath(java.io.File file)Turns a file into an operating-system dependent string path.private static java.lang.StringtoOsPath(java.lang.String path)Turns a string (assumed to be a path) into an operating-system dependent string path.
-
-
-
Field Detail
-
verboseDefault
private static boolean verboseDefault
-
usingIvmlFolder
private static java.lang.String usingIvmlFolder
-
IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPE
private static final java.util.Set<java.lang.String> IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPE
-
documents
private org.w3c.dom.Document[] documents
-
objectTypeList
private org.w3c.dom.NodeList objectTypeList
-
objectList
private org.w3c.dom.NodeList objectList
-
variableList
private org.w3c.dom.NodeList variableList
-
methodList
private org.w3c.dom.NodeList methodList
-
dataTypeList
private org.w3c.dom.NodeList dataTypeList
-
variableTypeList
private org.w3c.dom.NodeList variableTypeList
-
aliasList
private org.w3c.dom.NodeList aliasList
-
hierarchy
private java.util.ArrayList<BaseType> hierarchy
-
verbose
private boolean verbose
-
baseNameSpace
private java.lang.String baseNameSpace
-
externAliasLists
private java.util.ArrayList<org.w3c.dom.NodeList> externAliasLists
-
-
Constructor Detail
-
DomParser
private DomParser(org.w3c.dom.NodeList objectTypeList, org.w3c.dom.NodeList objectList, org.w3c.dom.NodeList variableList, org.w3c.dom.NodeList methodList, org.w3c.dom.NodeList dataTypeList, org.w3c.dom.NodeList variableTypeList, org.w3c.dom.NodeList aliasList, java.util.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 Detail
-
setExternAliasLists
public void setExternAliasLists(java.util.ArrayList<org.w3c.dom.NodeList> externAliasLists)
Defines the OPC UA core alias list.- Parameters:
externAliasLists- the list of OPC UA core aliases.
-
setDocuments
public void setDocuments(org.w3c.dom.Document[] documents)
Defines the OPC UA document collection.- Parameters:
documents- the collection of documents.
-
setBaseNameSpace
public void setBaseNameSpace(java.lang.String baseNameSpace)
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
private static java.lang.String searchVarName(BaseType uaElement, java.util.ArrayList<BaseType> hierarchy)
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
private java.lang.String changeVariableDataTypes(java.lang.String dataType)
Turns OPC UA type names to IIP-Ecosphere meta model type names.- Parameters:
dataType- the data type- Returns:
- the translated data type
-
adaptDatatypesToModel
private void adaptDatatypesToModel(ObjectType uaObject, MethodType uaMethod)
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
private static org.w3c.dom.Element checkRelation(java.lang.String currentNodeId, org.w3c.dom.NodeList nodes)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
private static org.w3c.dom.Element getNextNodeElement(org.w3c.dom.NodeList nodes, int iterator)Returns the next node element.- Parameters:
nodes- the nodes to search foriterator- the 0-based index into nodes- Returns:
- the next node element
-
retrieveParent
private java.lang.String retrieveParent(java.lang.String parentNodeId, org.w3c.dom.NodeList list)Retrieves the displayName of given parentNodeId.- Parameters:
parentNodeId- the parent node idlist- the node list to check- Returns:
- the root parent
-
checkForInternDataType
private java.lang.String checkForInternDataType(java.lang.String dataTypeNodeId)
Checks for intern data type.- Parameters:
dataTypeNodeId- the referenced node id of a data type- Returns:
- the identified data type
-
checkForExternDataType
private java.lang.String checkForExternDataType(java.lang.String dataType)
Checks for an extern data type.- Parameters:
dataType- the data type to look for- Returns:
- the data type
-
retrieveAttributesForExternDataType
private java.lang.String retrieveAttributesForExternDataType(java.lang.String nodeId)
Retrieves attributes fromdocumentsfor extern data types.- Parameters:
nodeId- the node id of the node to retrieve the attributes for- Returns:
- the data type
-
identifySpecificReference
private java.lang.String identifySpecificReference(java.lang.String reference, org.w3c.dom.Node node, ElementType type)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(java.lang.String refId, java.lang.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(java.lang.String reference, org.w3c.dom.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
private java.util.ArrayList<FieldType> identifyFields(org.w3c.dom.Node childNode)
Identifies the fields ofchildNode.- Parameters:
childNode- the child node to analyze- Returns:
- the identified fields
-
retrieveAttributesForRefElement
private void retrieveAttributesForRefElement(java.util.ArrayList<FieldType> fields, java.lang.String refId, org.w3c.dom.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
private void retrieveRootElement(org.w3c.dom.Element object, ElementType type)Retrieves the root element.- Parameters:
object- the element to start withtype- the type
-
retrieveRelatedSubElements
private void retrieveRelatedSubElements(java.util.ArrayList<FieldType> subElements)
Retrieves the related sub elements.- Parameters:
subElements- the sub elements to analyze
-
retrieveAttributes
private void retrieveAttributes(org.w3c.dom.Element element, java.util.ArrayList<FieldType> subFields, ElementType type, java.lang.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
private static java.lang.String getFieldDescription(org.w3c.dom.Element fieldNode)
Returns the field description offieldNode.- Parameters:
fieldNode- the field node- Returns:
- the field description
-
createElement
private void createElement(ElementType type, org.w3c.dom.Element element, java.lang.String id, java.lang.String displayName, java.lang.String description, java.lang.String documentation, java.util.ArrayList<FieldType> subFields, java.util.ArrayList<FieldType> objectFields, java.util.ArrayList<EnumLiteral> literals, java.util.ArrayList<DataLiteral> dataLiterals, java.lang.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
private void addElement(BaseType element, ElementType type)
Adds an element to the hierarchy.- Parameters:
element- the elementtype- the element type
-
checkRedundancy
private boolean checkRedundancy(java.lang.String varName, java.util.ArrayList<FieldType> list)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 via#retrieveAttributes(Element, ArrayList, ElementType).
-
toOsPath
private static java.lang.String toOsPath(java.io.File file)
Turns a file into an operating-system dependent string path.- Parameters:
file- the file- Returns:
- the path
-
toOsPath
private static java.lang.String toOsPath(java.lang.String path)
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 java.io.File[] checkRequiredModels(DomParser parser, java.lang.String modelName, java.lang.String path, java.lang.String fileName, org.w3c.dom.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
private static DomParser createParser(java.lang.String path, java.io.File compSpec, boolean verbose)
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
public static void setUsingIvmlFolder(java.lang.String folder)
Sets the folder where to generate example using IVML models.- Parameters:
folder- the folder name (by default "src/test/easy")
-
createIvmlModel
private void createIvmlModel(java.lang.String fileName, java.io.File ivmlFile)Creates the IVML model in the givenfileName.- Parameters:
fileName- the file name for the IVML modelivmlFile- the output file
-
println
private void println(java.lang.String text)
Prints out information in verbose mode.- Parameters:
text- the text to print
-
process
public static void process(java.io.File xmlIn, java.lang.String outName, java.io.File ivmlOut, boolean verbose)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
public static void main(java.lang.String[] args)
Executes the parser, per default in verbose mode.- Parameters:
args- command line arguments (ignored)
-
-