Exemplo n.º 1
0
        private DamlRestriction[] GetRestrictions(string strOwnerName)
        {
            ArrayList lstRestrictions = new ArrayList();

            XmlNode root = m_doc.DocumentElement;

            string strXPath = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + strOwnerName + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "/" + DamlConstants.DAML_RESTRICTION;

            XmlNodeList lstNodes = root.SelectNodes(strXPath, m_mgr);

            if (lstNodes.Count == 0)
            {
                return((DamlRestriction[])lstRestrictions.ToArray(typeof(DamlRestriction)));
            }

            foreach (XmlNode restrictionNode in lstNodes)
            {
                // Create a daml restriction
                DamlRestriction res = GetRestrictionNodeData(restrictionNode);

                res.Owner = strOwnerName;
                // Add it to our list of restrictions
                lstRestrictions.Add(res);
            }

            return((DamlRestriction[])lstRestrictions.ToArray(typeof(DamlRestriction)));
        }
Exemplo n.º 2
0
        private DamlRestriction GetRestrictionNodeData(XmlNode restrictionNode)
        {
            if (restrictionNode == null)
            {
                throw new ArgumentNullException("restriction", "Node cannnot be null");
            }

            DamlRestriction res = new DamlRestriction();

            // Restriction nodes may specify a cardinality
            if (restrictionNode.Attributes.Count > 0)
            {
                XmlAttribute cardinalityAtt = restrictionNode.Attributes[DamlConstants.DAML_CARDINALITY];
                if (cardinalityAtt != null)
                {
                    res.Cardinality = int.Parse(cardinalityAtt.Value);
                }
            }

            // Find the property which this restriction applies to
            XmlNode onPropertyNode = restrictionNode.SelectSingleNode(DamlConstants.DAML_ON_PROPERTY, m_mgr);

            if (onPropertyNode != null)
            {
                res.OnProperty = onPropertyNode.Attributes[DamlConstants.RDF_RESOURCE].Value;
            }

            XmlNode hasValueNode = restrictionNode.SelectSingleNode(DamlConstants.DAML_HAS_VALUE, m_mgr);

            if (hasValueNode != null)
            {
                res.HasValue = hasValueNode.Attributes[DamlConstants.RDF_ID].Value;
            }

            return(res);
        }
        /// <summary>
        /// Function compares 2 DamlRestriction instances. The OnProperty property
        /// is used for comparisons.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>0 (equal), -1 (less than this instance)
        /// or 1 (greater than this instance)</returns>
        public int CompareTo(object obj)
        {
            DamlRestriction temp = (DamlRestriction)obj;

            return(this.m_strOnProperty.ToLower().CompareTo(temp.m_strOnProperty.ToLower()));
        }