java.lang.Object
de.iip_ecosphere.platform.configuration.opcua.parser.DomParser

public class DomParser extends Object
XML parser for OPC UA companion spec files.
Author:
Jan-Hendrik Cepok, SSE
  • Field Details

    • verboseDefault

      private static boolean verboseDefault
    • usingIvmlFolder

      private static String usingIvmlFolder
    • IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPE

      private static final Set<String> IDENTIFY_FIELDS_PERMITTED_REFERENCE_TYPE
    • documents

      private Document[] documents
    • objectTypeList

      private NodeList objectTypeList
    • objectList

      private NodeList objectList
    • variableList

      private NodeList variableList
    • methodList

      private NodeList methodList
    • dataTypeList

      private NodeList dataTypeList
    • variableTypeList

      private NodeList variableTypeList
    • aliasList

      private NodeList aliasList
    • hierarchy

      private ArrayList<BaseType> hierarchy
    • verbose

      private boolean verbose
    • baseNameSpace

      private String baseNameSpace
    • externAliasLists

      private ArrayList<NodeList> 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 list
      objectList - the already parsed object list
      variableList - the already parsed variable list
      methodList - the already parsed method list
      dataTypeList - the already parsed data type list
      variableTypeList - the already parsed variable type list
      aliasList - the already parsed alias list
      hierarchy - the base type hierarchy
  • Method Details

    • setExternAliasLists

      public void setExternAliasLists(ArrayList<NodeList> externAliasLists)
      Defines the OPC UA core alias list.
      Parameters:
      externAliasLists - the list of OPC UA core aliases.
    • setDocuments

      public void setDocuments(Document[] documents)
      Defines the OPC UA document collection.
      Parameters:
      documents - the collection of documents.
    • setBaseNameSpace

      public void setBaseNameSpace(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 String searchVarName(BaseType uaElement, ArrayList<BaseType> hierarchy)
      Searches for a field type variable name.
      Parameters:
      uaElement - the UA element delivering the node Id to search for
      hierarchy - the type hierarchy to search within
      Returns:
      the variable name of the found field type
    • changeVariableDataTypes

      private String changeVariableDataTypes(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 for
      uaMethod - 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 Element checkRelation(String currentNodeId, NodeList nodes)
      Checks the relations and returns a node with NodeId currentNodeId.
      Parameters:
      currentNodeId - the node id to search for
      nodes - the nodes to search
      Returns:
      the found element
    • getNextNodeElement

      private static Element getNextNodeElement(NodeList nodes, int iterator)
      Returns the next node element.
      Parameters:
      nodes - the nodes to search for
      iterator - the 0-based index into nodes
      Returns:
      the next node element
    • retrieveParent

      private String retrieveParent(String parentNodeId, NodeList list)
      Retrieves the displayName of given parentNodeId.
      Parameters:
      parentNodeId - the parent node id
      list - the node list to check
      Returns:
      the root parent
    • checkForInternDataType

      private String checkForInternDataType(String dataTypeNodeId)
      Checks for intern data type.
      Parameters:
      dataTypeNodeId - the referenced node id of a data type
      Returns:
      the identified data type
    • checkForExternDataType

      private String checkForExternDataType(String dataType)
      Checks for an extern data type.
      Parameters:
      dataType - the data type to look for
      Returns:
      the data type
    • retrieveAttributesForExternDataType

      private String retrieveAttributesForExternDataType(String nodeId)
      Retrieves attributes from documents for extern data types.
      Parameters:
      nodeId - the node id of the node to retrieve the attributes for
      Returns:
      the data type
    • identifySpecificReference

      private String identifySpecificReference(String reference, Node node, ElementType type)
      Identifies a specific reference.
      Parameters:
      reference - the reference type to look for
      node - the node to analyze the children
      type - 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 namespace refId.
      Parameters:
      refId - the ref id
      reference - the reference type
      type - the actual element type
      Returns:
      the extracted result
    • getDescriptionOrDocumentation

      private DomParser.DescriptionOrDocumentation getDescriptionOrDocumentation(String reference, Element refElement)
      Extracts information about description or documentation from refElement.
      Parameters:
      reference - the actual reference being processed
      refElement - the reference element to take the data from
      Returns:
      result instance carrying the extracted information
    • identifyFields

      private ArrayList<FieldType> identifyFields(Node childNode)
      Identifies the fields of childNode.
      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 for
      refId - the ref id
      refElement - the ref element
      elementType - the elementType
    • retrieveRootElement

      private void retrieveRootElement(Element object, ElementType type)
      Retrieves the root element.
      Parameters:
      object - the element to start with
      type - the type
    • retrieveRelatedSubElements

      private void retrieveRelatedSubElements(ArrayList<FieldType> subElements)
      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 for
      subFields - the sub fields for the creation of output for element
      type - the element type
      externNodeId - the element type
    • getFieldDescription

      private static String getFieldDescription(Element fieldNode)
      Returns the field description of fieldNode.
      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 element
      id - the id
      displayName - the display name
      description - the description
      documentation - the documentation
      subFields - the sub fields
      objectFields - the object fields
      literals - the literals
      dataLiterals - the data literals
      typeDef - the type def
      optional - whether the type is optional
    • addElement

      private void addElement(BaseType element, ElementType type)
      Adds an element to the hierarchy.
      Parameters:
      element - the element
      type - the element type
    • checkRedundancy

      private boolean checkRedundancy(String varName, ArrayList<FieldType> list)
      Checks for redundant/duplicate variable names in hierarchy.
      Parameters:
      varName - the variable name to check for
      list - the list of fields to check
      Returns:
      true if there are duplicates, false else
    • retrieveElementTypes

      private void retrieveElementTypes()
      Retrieves the element types and nested attributes via retrieveAttributes(Element, ArrayList, ElementType, String).
    • toOsPath

      private static String toOsPath(File file)
      Turns a file into an operating-system dependent string path.
      Parameters:
      file - the file
      Returns:
      the path
    • toOsPath

      private static String toOsPath(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 File[] checkRequiredModels(DomParser parser, String modelName, String path, String fileName, NodeList nameSpaceUris)
      Checks for required models.
      Parameters:
      parser - the parser instance
      modelName - the model name to check for
      path - the path to check for
      fileName - the file name to check for
      nameSpaceUris - 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 in objectList and retriving all data types in dataTypeList.
    • createParser

      private static DomParser createParser(String path, File compSpec, boolean verbose)
      Creates the parser.
      Parameters:
      path - the path to the OPC UA nodeset models
      compSpec - the companion spec to be parsed
      verbose - verbose output
      Returns:
      the DOM parser after parsing
    • setUsingIvmlFolder

      public static void setUsingIvmlFolder(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(String fileName, File ivmlFile)
      Creates the IVML model in the given fileName.
      Parameters:
      fileName - the file name for the IVML model
      ivmlFile - the output file
    • println

      private void println(String text)
      Prints out information in verbose mode.
      Parameters:
      text - the text to print
    • process

      public static void process(File xmlIn, String outName, File ivmlOut, boolean verbose)
      Processes an OPC XML file. [public for testing]
      Parameters:
      xmlIn - the input file
      outName - the output file/model name
      ivmlOut - the full output file name
      verbose - verbose output
    • main

      public static void main(String[] args)
      Executes the parser, per default in verbose mode.
      Parameters:
      args - command line arguments (ignored)