public void ClearRestrictionMap(enuIOPEType restrictionType)
 {
     if (this.m_restrictionMap.Contains(restrictionType))
     {
         this.m_restrictionMap.Remove(restrictionType);
     }
 }
        private void AddRdfProperties(ref XmlDocument doc, RdfProperty[] arrData, enuIOPEType restrictionType)
        {
            XmlNode root = doc.DocumentElement;

            for (int i = 0; i < arrData.Length; i++)
            {
                RdfProperty prop    = (RdfProperty)arrData[i];
                XmlDocument propDoc = new XmlDocument();
                propDoc.LoadXml(prop.ToXml());
                XmlNode propDocRoot  = propDoc.DocumentElement;
                XmlNode propertyNode = doc.ImportNode(propDocRoot.FirstChild, true);

                // Get restrictions on property (if any)
                DamlRestriction[] arrRestrictions = this.GetRestrictions(restrictionType);

                for (int j = 0; j < arrRestrictions.Length; j++)
                {
                    if (arrRestrictions[j].Owner == prop.Name)
                    {
                        // Create subClassOf node
                        XmlNode subClassOfNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.RDFS_SUBCLASSOF, DamlConstants.RDFS_NS_URI);
                        // Create a node for each restriction (child of subClassOfNode)
                        XmlNode restrictionNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.DAML_RESTRICTION, DamlConstants.DAML_NS_URI);
                        // Fill in restrictionNode data

                        // Add cardinality attribute if value has been set
                        if (arrRestrictions[j].Cardinality != DamlRestriction.NO_CARDINALITY)
                        {
                            // Create attribute
                            XmlAttribute cardinalityAtt = doc.CreateAttribute(DamlConstants.DAML_CARDINALITY, DamlConstants.DAML_NS_URI);
                            // Set attribute value
                            cardinalityAtt.Value = arrRestrictions[j].Cardinality.ToString();
                            // Add attribute to node
                            restrictionNode.Attributes.Append(cardinalityAtt);
                        }

                        // Create onPropertyNode
                        XmlNode onPropertyNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.DAML_ON_PROPERTY, DamlConstants.DAML_NS_URI);
                        // Create onProperty attribute
                        XmlAttribute onPropertyAtt = doc.CreateAttribute(DamlConstants.RDF_RESOURCE, DamlConstants.RDF_NS_URI);
                        // Set attribute value
                        onPropertyAtt.Value = arrRestrictions[j].OnProperty;
                        // Add attribute to node
                        onPropertyNode.Attributes.Append(onPropertyAtt);

                        // Add onPropertyNode to restrictionNode
                        restrictionNode.AppendChild(onPropertyNode);
                        // Add restrictionNode to subClassOfNode
                        subClassOfNode.AppendChild(restrictionNode);
                        //Add subClassOfNode to root
                        propertyNode.AppendChild(subClassOfNode);
                    }
                }

                // Add rdf:Property to root of document
                root.AppendChild(propertyNode);
            }
        }
        public static IIOPEXPathExprBuilder CreateInstance(enuIOPEType builderType)
        {
            switch (builderType)
            {
            case enuIOPEType.Input: return(new InputXPathExprBuilder());

            case enuIOPEType.Output: return(new OutputXPathExprBuilder());

            case enuIOPEType.Precondition: return(new PreconditionXPathExprBuilder());

            case enuIOPEType.Effect: return(new EffectXPathExprBuilder());

            default: throw new ArgumentException("Invalid/Unrecognized filter type");
            }
            ;
        }
        public DamlRestriction[] GetRestrictions(enuIOPEType restrictionType)
        {
            ArrayList lstRestrict = new ArrayList();

            Hashtable innerMap = (Hashtable)this.m_restrictionMap[restrictionType];

            if (innerMap != null)
            {
                IDictionaryEnumerator it = innerMap.GetEnumerator();

                while (it.MoveNext())
                {
                    lstRestrict.Add(it.Value);
                }
            }

            return((DamlRestriction[])lstRestrict.ToArray(typeof(DamlRestriction)));
        }
        public void AddRestriction(enuIOPEType restrictionType, DamlRestriction[] arrRestrict)
        {
            if (arrRestrict == null || arrRestrict.Length == 0)
            {
                return;
            }

            // Based on type determine if there is an entry for this type of restriction
            // first

            if (!this.m_restrictionMap.ContainsKey(restrictionType))
            {
                Hashtable newInnerMap = new Hashtable();

                for (int i = 0; i < arrRestrict.Length; i++)
                {
                    if (!newInnerMap.Contains(arrRestrict[i].OnProperty))
                    {
                        newInnerMap.Add(arrRestrict[i].OnProperty, arrRestrict[i]);
                    }
                }

                m_restrictionMap.Add(restrictionType, newInnerMap);
            }
            else             // There is an inner map for this type of restriction
            {
                Hashtable innerMap = (Hashtable)m_restrictionMap[restrictionType];

                for (int i = 0; i < arrRestrict.Length; i++)
                {
                    if (!innerMap.Contains(arrRestrict[i].OnProperty))
                    {
                        innerMap.Add(arrRestrict[i].OnProperty, arrRestrict[i]);
                    }
                }
            }
        }
Beispiel #6
0
        /* Function retrieves all the interesting data about a process given its name and
         * type.
         *
         * Interesting data:
         * Inputs, Outputs, Preconditions, Effects, Parameters, ConditionalOutputs,
         * Co-Conditions, Sub Processes (if process is a composite process)
         *
         * Inputs: strProcessName - named process
         *		   processType - process type (atomic, simple, composite)
         *
         * Return value: DamlProcess containing all the relevant data
         */
        public DamlProcess GetProcessData(string strProcessName, enuProcessType processType)
        {
            DamlProcess retVal = new DamlProcess();

            XmlNode root       = m_doc.DocumentElement;
            string  strBaseUri = GetNamespaceBaseUri(DamlConstants.PROCESS_NS);
            string  strUri     = "";

            strUri = strBaseUri;

            switch (processType)
            {
            case enuProcessType.AtomicProcess: strUri += DamlConstants.DAML_ATOMIC_PROCESS;
                break;

            case enuProcessType.CompositeProcess: strUri += DamlConstants.DAML_COMPOSITE_PROCESS;
                break;

            case enuProcessType.SimpleProcess: strUri += DamlConstants.DAML_SIMPLE_PROCESS;
                break;

            default:  throw new ArgumentException("Invalid processType value");
            }
            ;

            string strXPath = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + strProcessName + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strUri + "']";

            XmlNode processNode = root.SelectSingleNode(strXPath, m_mgr).ParentNode;

            if (processNode == null)
            {
                throw new Exception("Process node found");
            }

            // Set process name
            retVal.Name = processNode.Attributes[DamlConstants.RDF_ID].Value;
            // Set process type
            retVal.ProcessType = processType;

            // Get Process restrictions - these are actually input restrictions on
            // the process
            DamlRestriction[] arrProcessRestrict = this.GetRestrictions(strProcessName);
            retVal.AddRestriction(enuIOPEType.Input, arrProcessRestrict);

            // Get inputs from querying RdfProperty nodes in document
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.INPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            XmlNodeList lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddInput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Input;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get additional inputs from the process node itself
            // they may be hidden under restictions tagged with
            // daml:sameValueAs
            strXPath = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + retVal.Name + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "/" + DamlConstants.DAML_RESTRICTION + "/" + DamlConstants.DAML_ON_PROPERTY + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.INPUT + "']" + "/" + "following-sibling::" + DamlConstants.DAML_SAMEVALUESAS;
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                string strSameValueAs = node.Attributes[DamlConstants.RDF_RESOURCE].Value;
                strSameValueAs = strSameValueAs.Trim(new char[] { '#' });

                // Go get RdfProperty data
                strXPath = DamlConstants.RDF_PROPERTY + "[@" + DamlConstants.RDF_ID + "='" + strSameValueAs + "']" + "/" + DamlConstants.RDFS_DOMAIN;
                XmlNode domainNode = root.SelectSingleNode(strXPath, m_mgr);

                // Add to list of inputs
                if (domainNode != null)
                {
                    RdfProperty data = GetNodeData(domainNode.ParentNode);
                    retVal.AddInput(data);

                    // Get restrictions (if any)
                    enuIOPEType       restrictionType = enuIOPEType.Input;
                    DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                    retVal.AddRestriction(restrictionType, arrRestrict);
                    retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
                }
            }

            // Get outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Output;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get preconditions
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.PRECONDITION + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddPrecondition(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Precondition;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get effects
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.EFFECT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddEffect(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Effect;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get conditional outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CONDITIONAL_OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddConditionalOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.ConditionalOutput;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get co-conditions
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CO_CONDITION + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddCoCondition(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.CoCondition;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get co-outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CO_OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddCoOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.CoOutput;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get parameters
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.PARAMETER + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddParameter(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Parameter;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // If we are dealing with a complex process we must go get
            // the substeps - need to get process:<type> data
            if (processType == enuProcessType.CompositeProcess)
            {
                retVal.SubTaskType = GetProcessSubTaskType(retVal.Name);
                retVal.AddSubProcess(GetSubProcesses(retVal.Name));
            }
            return(retVal);
        }