#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Constraints;
namespace HeuristicLab.Communication.Data {
public class ProtocolState : ItemBase {
private StringData name;
public StringData Name {
get { return name; }
set {
name.Changed -= new EventHandler(Name_Changed);
name = value;
name.Changed += new EventHandler(Name_Changed);
OnChanged();
}
}
private BoolData acceptingState;
public BoolData AcceptingState {
get { return acceptingState; }
set {
acceptingState = value;
OnChanged();
}
}
private ConstrainedItemList sendingData;
public ConstrainedItemList SendingData {
get { return sendingData; }
set {
sendingData = value;
OnChanged();
}
}
private ConstrainedItemList receivingData;
public ConstrainedItemList ReceivingData {
get { return receivingData; }
set {
receivingData = value;
OnChanged();
}
}
private ItemList stateTransitions;
public ItemList StateTransitions {
get { return stateTransitions; }
set {
stateTransitions = value;
OnChanged();
}
}
private Protocol protocol;
public Protocol Protocol {
get { return protocol; }
set {
protocol = value;
OnChanged();
}
}
public ProtocolState() {
name = new StringData("Unnamed state");
name.Changed += new EventHandler(Name_Changed);
acceptingState = new BoolData(true);
sendingData = new ConstrainedItemList();
sendingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
receivingData = new ConstrainedItemList();
receivingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
stateTransitions = null;
protocol = null;
}
public void Dispose() {
name.Changed -= new EventHandler(Name_Changed);
}
public override IView CreateView() {
return new ProtocolStateView(this);
}
public override object Clone(IDictionary clonedObjects) {
ProtocolState clone = new ProtocolState();
clonedObjects.Add(Guid, clone);
clone.name = (StringData)Auxiliary.Clone(Name, clonedObjects);
clone.acceptingState = (BoolData)Auxiliary.Clone(AcceptingState, clonedObjects);
clone.sendingData = (ConstrainedItemList)Auxiliary.Clone(SendingData, clonedObjects);
clone.receivingData = (ConstrainedItemList)Auxiliary.Clone(ReceivingData, clonedObjects);
if (StateTransitions != null)
clone.stateTransitions = (ItemList)Auxiliary.Clone(StateTransitions, clonedObjects);
else clone.StateTransitions = null;
clone.Protocol = (Protocol)Auxiliary.Clone(Protocol, clonedObjects);
return clone;
}
#region persistence
public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary persistedObjects) {
XmlNode node = base.GetXmlNode(name, document, persistedObjects);
XmlNode protocolNode = PersistenceManager.Persist("ParentProtocol", Protocol, document, persistedObjects);
node.AppendChild(protocolNode);
XmlNode nameNode = PersistenceManager.Persist("Name", Name, document, persistedObjects);
node.AppendChild(nameNode);
XmlNode acceptingNode = PersistenceManager.Persist("AcceptingState", AcceptingState, document, persistedObjects);
node.AppendChild(acceptingNode);
XmlNode requestNode = PersistenceManager.Persist("Request", SendingData, document, persistedObjects);
node.AppendChild(requestNode);
XmlNode responseNode = PersistenceManager.Persist("Response", ReceivingData, document, persistedObjects);
node.AppendChild(responseNode);
if (StateTransitions != null) {
XmlNode transitionsNode = PersistenceManager.Persist("StateTransitions", StateTransitions, document, persistedObjects);
node.AppendChild(transitionsNode);
}
return node;
}
public override void Populate(XmlNode node, IDictionary restoredObjects) {
base.Populate(node, restoredObjects);
protocol = (Protocol)PersistenceManager.Restore(node.SelectSingleNode("ParentProtocol"), restoredObjects);
name = (StringData)PersistenceManager.Restore(node.SelectSingleNode("Name"), restoredObjects);
acceptingState = (BoolData)PersistenceManager.Restore(node.SelectSingleNode("AcceptingState"), restoredObjects);
sendingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Request"), restoredObjects);
receivingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Response"), restoredObjects);
XmlNode transitions = node.SelectSingleNode("StateTransitions");
if (transitions != null)
stateTransitions = (ItemList)PersistenceManager.Restore(transitions, restoredObjects);
else
stateTransitions = null;
}
#endregion persistence
private void Name_Changed(object sender, EventArgs e) {
OnChanged();
}
public override string ToString() {
return Name.ToString();
}
}
}