コード例 #1
0
 /* Procedure Adds a subprocess to a (composite) DamlProcess
  *
  * Inputs: data - DamlProcess details of the process
  *
  * Exceptions: throws InvalidOperationException if the process is not being
  *			   added to a Composite DamlProcess. ONLY Composite DAMLProcesses
  *			   support subprocesses.
  */
 public void AddSubProcess(DamlProcess data)
 {
     if (ProcessType == enuProcessType.CompositeProcess)
     {
         m_arrSubProcesses.Add(data);
     }
     else
     {
         throw new InvalidOperationException("Only Composite Processes can have SubProcesses");
     }
 }
        public void AddDamlProcess(DamlProcess process)
        {
            if (process == null)
            {
                throw new ArgumentNullException("process", "DamlProcess parameter cannot be null");
            }

            if (process.Name == null || process.Name.Length == 0)
            {
                throw new ArgumentException("DamlProcess name must be set", "process");
            }

            if (!this.m_processMap.ContainsKey(process.Name))
            {
                this.m_processMap.Add(process.Name, process);
            }
        }
コード例 #3
0
        /* Function returns all the sub processes of a named process
         *
         * Inputs: strProcessName - named process
         *
         * Return values: an array of its sub processes
         */
        private DamlProcess[] GetSubProcesses(string strProcessName)
        {
            ArrayList lstSubProcesses = new ArrayList();

            try
            {
                XmlNode root       = m_doc.DocumentElement;
                string  strBaseUri = GetNamespaceBaseUri(DamlConstants.PROCESS_NS);

                string  strXPath       = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + strProcessName + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.DAML_COMPOSITE_PROCESS + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_SUBCLASSOF;
                XmlNode SubClassOfNode = root.SelectSingleNode(strXPath, m_mgr);

                if (SubClassOfNode == null)
                {
                    return((DamlProcess[])lstSubProcesses.ToArray(typeof(DamlProcess)));
                }

                // Use fuzzy paths from here -> "//" operator looking for any matching
                // child node - more expensive but intermediate nodes are not
                // interesting/contain no info we can use

                strXPath = ".//" + DamlConstants.DAML_LIST_OF_INSTANCES_OF + "/" + DamlConstants.DAML_CLASS;
                XmlNodeList lstInstances = SubClassOfNode.SelectNodes(strXPath, m_mgr);

                foreach (XmlNode node in lstInstances)
                {
                    string strProcess = node.Attributes[DamlConstants.RDF_ABOUT].Value;
                    strProcess = strProcess.Trim(new Char[] { '#' });
                    enuProcessType processType = GetProcessType(strProcess);
                    DamlProcess    process     = GetProcessData(strProcess, processType);
                    lstSubProcesses.Add(process);
                }
            }
            catch (Exception /*e*/)
            {
            }
            return((DamlProcess[])lstSubProcesses.ToArray(typeof(DamlProcess)));
        }
コード例 #4
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);
        }
        public string ToXml()
        {
            // Get a document template
            XmlDocument doc = DamlContainer.BuildDamlDocumentTemplate(true);

            // Get the document element (document root)
            XmlNode root = doc.DocumentElement;

            // DamlProcessWriter may have to control the datatypes
            // being written out by each DamlProcess, multiple processes in
            // a proces model may share data types, we only need one
            // data type definition

            IDictionaryEnumerator it = this.m_processMap.GetEnumerator();

            while (it.MoveNext())
            {
                DamlProcess proc = (DamlProcess)it.Value;

                XmlDocument processDoc = new XmlDocument();
                // DO NOT add type defintions to xml document we create
                // the ProcessModel should keep track of all the data types
                // in each process to ensure each type definition gets written
                // only once since multiple process in a process model may share
                // data types an as such could cause duplicate definitions
                // to be written out in the process model xml document
                processDoc.LoadXml(proc.ToXml(false));

                XmlNode processDocRoot = processDoc.DocumentElement;

                XmlNodeList lstChildren = processDocRoot.ChildNodes;

                foreach (XmlNode child in lstChildren)
                {
                    // Add every child to our document root except the ontology imports
                    // since we already have these from the DamlDocumentTemplate
                    if (child.Name != DamlConstants.DAML_ONTOLOGY)
                    {
                        XmlNode temp = doc.ImportNode(child, true);
                        root.AppendChild(temp);
                    }
                }

                // Get the data types we have not seen as yet
                DamlTypeDefinition[] arrDefinitions = proc.TypeDefinitions;
                for (int i = 0; i < arrDefinitions.Length; i++)
                {
                    if (!this.m_dataTypeDefinitionMap.ContainsKey(arrDefinitions[i].Name))
                    {
                        this.m_dataTypeDefinitionMap.Add(arrDefinitions[i].Name, arrDefinitions[i]);
                    }
                }
            }

            // Write data type map last
            IDictionaryEnumerator typeIt = this.m_dataTypeDefinitionMap.GetEnumerator();

            while (typeIt.MoveNext())
            {
                DamlTypeDefinition definition = (DamlTypeDefinition)typeIt.Value;
                XmlDocument        typeDoc    = new XmlDocument();
                // Load the xml of the type definition
                typeDoc.LoadXml(definition.ToXml());
                // Get the document element
                XmlNode typeDocRoot = typeDoc.DocumentElement;
                // Import the first child of the root into the damlProcess xml document
                // being created
                XmlNode temp = doc.ImportNode(typeDocRoot.FirstChild, true);
                // Append that node to our current document root
                root.AppendChild(temp);
            }

            return(doc.OuterXml);
        }