public override void ReadProcessData(XmlElement xmlElement, CreationContext creationContext) { base.ReadProcessData(xmlElement, creationContext); // get the process definition for that name String subProcessDefinitionName = xmlElement.GetProperty("process"); creationContext.Check(((Object) subProcessDefinitionName != null), "process is missing in the process state : " + subProcessDefinitionName); DbSession dbSession = creationContext.DbSession; dbSession.SaveOrUpdate(this._processDefinition); try { this._subProcess = (ProcessDefinitionImpl) dbSession.FindOne(queryFindProcessDefinitionByName, subProcessDefinitionName, DbType.STRING); } catch (SystemException e) { creationContext.AddError("process '" + subProcessDefinitionName + "' was not deployed while it is referenced in a process-state. Exception: " + e.Message); } // parse the processInvokerDelegation creationContext.DelegatingObject = this; this._processInvokerDelegation = new DelegationImpl(); XmlElement invocationElement = xmlElement.GetChildElement("process-invocation"); creationContext.Check((invocationElement != null), "process-invocation is missing in the process-state : " + xmlElement); this._processInvokerDelegation.ReadProcessData(invocationElement, creationContext); creationContext.DelegatingObject = null; // parse the actorExpression this._actorExpression = xmlElement.GetProperty("actor-expression"); creationContext.Check(((Object) _actorExpression != null), "actor-expression is missing in the process-state : " + xmlElement); }
public virtual void ReadWebData(XmlElement xmlElement, CreationContext creationContext) { XmlElement coordinatesXmlElement = xmlElement.GetChildElement("image-coordinates"); if (coordinatesXmlElement != null) { try { _x1 = Int32.Parse(coordinatesXmlElement.GetProperty("x1")); _y1 = Int32.Parse(coordinatesXmlElement.GetProperty("y1")); _x2 = Int32.Parse(coordinatesXmlElement.GetProperty("x2")); _y2 = Int32.Parse(coordinatesXmlElement.GetProperty("y2")); creationContext.Check((((Object) _x1 != null) && ((Object) _y1 != null) && ((Object) _x2 != null) && ((Object) _y2 != null)), "at least one of the image-coordinates (x1,y1,x2,y2) is missing : " + xmlElement); } catch (FormatException e) { creationContext.AddError("at least one of the image-coordinates is not parsable : " + xmlElement + " exception:" + e.Message); } } DbSession dbSession = creationContext.DbSession; creationContext.State = this; creationContext.Index = 0; IEnumerator iter = xmlElement.GetChildElements("field").GetEnumerator(); while (iter.MoveNext()) { XmlElement fieldElement = (XmlElement) iter.Current; String attributeName = fieldElement.GetProperty("attribute"); FieldImpl field = null; Object[] values = new Object[] {_id, attributeName}; IType[] types = new IType[] {DbType.LONG, DbType.STRING}; IList fields = dbSession.Find(queryFindFieldByActivityStateAndAttributeName, values, types); if (fields.Count == 1) { field = (FieldImpl) fields[0]; } else { values = new Object[] {_processBlock.Id, attributeName}; types = new IType[] {DbType.LONG, DbType.STRING}; AttributeImpl attribute = (AttributeImpl) dbSession.FindOne(queryFindAttibuteByName, values, types); field = new FieldImpl(); field.Access = FieldAccess.READ_WRITE; field.State = this; field.Attribute = attribute; this._fields.Add(field); } field.ReadWebData(fieldElement, creationContext); creationContext.IncrementIndex(); } }
private XmlElement GetXmlElementForEntry(String entryName, IDictionary entries, CreationContext creationContext) { XmlElement xmlElement = null; byte[] processDefinitionXml = (byte[]) entries[entryName]; if (processDefinitionXml == null) { creationContext.AddError("entry '" + entryName + "' found not found in the process archive"); throw new SystemException("entry '" + entryName + "' found not found in the process archive"); } Stream processDefinitionInputStream = new MemoryStream(processDefinitionXml); XmlParser xmlParser = new XmlParser(processDefinitionInputStream); xmlElement = xmlParser.Parse(); return xmlElement; }
public void DeployProcessArchive(Stream processArchiveStream, DbSession dbSession) { log.Debug("reading process archive..."); try { IDictionary entries = null; // construct an empty process definition ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl(); try { entries = ReadEntries(processArchiveStream); } catch (IOException e) { throw new NpdlException("couldn't deploy process archive, the processArchiveBytes do not seem to be a valid jar-file : " + e.Message, e); } // Then save the process definition // This is done so hibernate will assign an id to this object. dbSession.Save(processDefinition); CreationContext creationContext = new CreationContext(processDefinition, entries, dbSession); try { // parse the processdefinition.xml XmlElement xmlElement = GetXmlElementForEntry("processdefinition.xml", entries, creationContext); // build the object model from the xml creationContext.PushScope("in processdefinition.xml"); processDefinition.ReadProcessData(xmlElement, creationContext); creationContext.PopScope(); // resolve all forward references creationContext.ResolveReferences(); processDefinition.Validate(creationContext); if (creationContext.HasErrors()) { throw new NpdlException(creationContext.Errors); } // read the optional web-interface information if (entries.Contains("web/webinterface.xml")) { log.Debug("processing webinterface.xml..."); xmlElement = GetXmlElementForEntry("web/webinterface.xml", entries, creationContext); creationContext.PushScope("in webinterface.xml"); processDefinition.ReadWebData(xmlElement, creationContext); creationContext.PopScope(); } else { log.Debug("no web/webinterface.xml was supplied"); } } catch (SystemException e) { log.Error("xml parsing error :", e); creationContext.AddError(e.GetType().FullName + " : " + e.Message); creationContext.AddError("couldn't continue to parse the process archive"); throw new NpdlException(creationContext.Errors); } // flush the changes to the database dbSession.SaveOrUpdate(processDefinition); dbSession.Flush(); } catch (DbException e) { throw new NpdlException("couldn't deploy process archive due to a database exception : " + e.Message, e); } }
public void ReadWebData(XmlElement xmlElement, CreationContext creationContext) { // first read the image XmlElement imageElement = xmlElement.GetChildElement("image"); creationContext.Check((imageElement != null), "element image is missing"); // reading the image-file String imageFileName = imageElement.GetProperty("name"); creationContext.Check(((Object) imageFileName != null), "image name is missing"); this._image = (byte[]) creationContext.Entries[imageFileName]; if (this._image == null) { creationContext.AddError("couldn't find image file '" + imageFileName + "' in the process archive. (make sure the specified path is relative to the archive-root)"); } this._imageMimeType = imageElement.GetProperty("mime-type"); creationContext.Check(((Object) _imageMimeType != null), "image mime-type is missing"); try { _imageHeight = Int32.Parse(imageElement.GetProperty("height")); creationContext.Check(((Object) _imageHeight != null), "image height is missing"); _imageWidth = Int32.Parse(imageElement.GetProperty("width")); creationContext.Check(((Object) _imageWidth != null), "image width is missing"); } catch (FormatException e) { creationContext.AddError("image height or width contains unparsable numbers : height=\"" + imageElement.GetProperty("height") + "\" width=\"" + imageElement.GetProperty("width") + "\". Exception: " + e.Message); } DbSession dbSession = creationContext.DbSession; // then the activity-states IEnumerator iter = xmlElement.GetChildElements("activity-state").GetEnumerator(); while (iter.MoveNext()) { XmlElement activityStateElement = (XmlElement) iter.Current; String activityStateName = activityStateElement.GetProperty("name"); creationContext.Check(((Object) activityStateName != null), "property name in activity state is missing"); Object[] values = new Object[] {activityStateName, _id}; IType[] types = new IType[] {DbType.STRING, DbType.LONG}; StateImpl state = null; try { state = (StateImpl) dbSession.FindOne(queryFindState, values, types); } catch (DbException e) { creationContext.AddError("activity-state '" + activityStateName + "' was referenced from the webinterface.xml but not defined in the processdefinition.xml. Exception:" + e.Message); } state.ReadWebData(activityStateElement, creationContext); } }