Opc.Ua.Server.CoreNodeManager.CreateObjectType C# (CSharp) Method

CreateObjectType() public method

Creates an ObjectType node in the address space.
public CreateObjectType ( NodeId parentId, NodeId nodeId, QualifiedName browseName, ObjectTypeAttributes attributes ) : NodeId
parentId NodeId
nodeId NodeId
browseName QualifiedName
attributes ObjectTypeAttributes
return NodeId
        public NodeId CreateObjectType(
            NodeId               parentId,
            NodeId               nodeId,
            QualifiedName        browseName,
            ObjectTypeAttributes attributes)
        {
            try
            {
                m_lock.Enter();

                // validate browse name.
                if (QualifiedName.IsNull(browseName))
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "BrowseName must not be empty.");
                }

                // check for null node id.
                if (NodeId.IsNull(nodeId))
                {
                    nodeId = CreateUniqueNodeId();
                }

                // check if node id exists.
                if (m_nodes.Exists(nodeId))
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId);
                }

                // set the BaseObjectType as the default.
                if (parentId == null)
                {
                    parentId = ObjectTypes.BaseObjectType;
                }

                // find parent.
                IObjectType parent = GetManagerHandle(parentId) as IObjectType;

                if (parent == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist or is not an ObjectType.", parentId);
                }
                
                // validate reference.
                ValidateReference(parent, ReferenceTypeIds.HasSubtype, false, NodeClass.ObjectType);
                           
                // create node.
                ObjectTypeNode node = new ObjectTypeNode();
                
                node.NodeId     = nodeId;
                node.NodeClass  = NodeClass.ObjectType;
                node.BrowseName = browseName;

                UpdateAttributes(node, attributes);

                // IsAbstract    
                if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.IsAbstract) != 0)
                {
                    node.IsAbstract = attributes.IsAbstract;
                }
                else
                {
                    node.IsAbstract = false;
                }    

                // add reference from parent.
                AddReference(parent, ReferenceTypeIds.HasSubtype, false, node, true);
                
                // add the node.
                AddNode(node);
                
                // return the new node id.
                return node.NodeId;
            }
            finally
            {
                m_lock.Exit();
            } 
        }