Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.Communication.Data/ProtocolState.cs @ 2139

Last change on this file since 2139 was 591, checked in by abeham, 16 years ago

Put the GPL license in the files from the communication framework and simulation optimization project

File size: 6.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Constraints;
29
30namespace HeuristicLab.Communication.Data {
31  public class ProtocolState : ItemBase {
32    private StringData name;
33    public StringData Name {
34      get { return name; }
35      set {
36        name.Changed -= new EventHandler(Name_Changed);
37        name = value;
38        name.Changed += new EventHandler(Name_Changed);
39        OnChanged();
40      }
41    }
42    private BoolData acceptingState;
43    public BoolData AcceptingState {
44      get { return acceptingState; }
45      set {
46        acceptingState = value;
47        OnChanged();
48      }
49    }
50    private ConstrainedItemList sendingData;
51    public ConstrainedItemList SendingData {
52      get { return sendingData; }
53      set {
54        sendingData = value;
55        OnChanged();
56      }
57    }
58    private ConstrainedItemList receivingData;
59    public ConstrainedItemList ReceivingData {
60      get { return receivingData; }
61      set {
62        receivingData = value;
63        OnChanged();
64      }
65    }
66    private ItemList<StateTransition> stateTransitions;
67    public ItemList<StateTransition> StateTransitions {
68      get { return stateTransitions; }
69      set {
70        stateTransitions = value;
71        OnChanged();
72      }
73    }
74    private Protocol protocol;
75    public Protocol Protocol {
76      get { return protocol; }
77      set {
78        protocol = value;
79        OnChanged();
80      }
81    }
82
83    public ProtocolState() {
84      name = new StringData("Unnamed state");
85      name.Changed += new EventHandler(Name_Changed);
86      acceptingState = new BoolData(true);
87      sendingData = new ConstrainedItemList();
88      sendingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
89      receivingData = new ConstrainedItemList();
90      receivingData.AddConstraint(new ItemTypeConstraint(typeof(Variable)));
91      stateTransitions = null;
92      protocol = null;
93    }
94
95    public void Dispose() {
96      name.Changed -= new EventHandler(Name_Changed);
97    }
98
99    public override IView CreateView() {
100      return new ProtocolStateView(this);
101    }
102
103    public override object Clone(IDictionary<Guid, object> clonedObjects) {
104      ProtocolState clone = new ProtocolState();
105      clonedObjects.Add(Guid, clone);
106      clone.name = (StringData)Auxiliary.Clone(Name, clonedObjects);
107      clone.acceptingState = (BoolData)Auxiliary.Clone(AcceptingState, clonedObjects);
108      clone.sendingData = (ConstrainedItemList)Auxiliary.Clone(SendingData, clonedObjects);
109      clone.receivingData = (ConstrainedItemList)Auxiliary.Clone(ReceivingData, clonedObjects);
110      if (StateTransitions != null)
111        clone.stateTransitions = (ItemList<StateTransition>)Auxiliary.Clone(StateTransitions, clonedObjects);
112      else clone.StateTransitions = null;
113      clone.protocol = Protocol;
114      return clone;
115    }
116
117    #region persistence
118    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
119      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
120      XmlNode protocolNode = PersistenceManager.Persist("ParentProtocol", Protocol, document, persistedObjects);
121      node.AppendChild(protocolNode);
122      XmlNode nameNode = PersistenceManager.Persist("Name", Name, document, persistedObjects);
123      node.AppendChild(nameNode);
124      XmlNode acceptingNode = PersistenceManager.Persist("AcceptingState", AcceptingState, document, persistedObjects);
125      node.AppendChild(acceptingNode);
126      XmlNode requestNode = PersistenceManager.Persist("Request", SendingData, document, persistedObjects);
127      node.AppendChild(requestNode);
128      XmlNode responseNode = PersistenceManager.Persist("Response", ReceivingData, document, persistedObjects);
129      node.AppendChild(responseNode);
130      if (StateTransitions != null) {
131        XmlNode transitionsNode = PersistenceManager.Persist("StateTransitions", StateTransitions, document, persistedObjects);
132        node.AppendChild(transitionsNode);
133      }
134      return node;
135    }
136
137    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
138      base.Populate(node, restoredObjects);
139      protocol = (Protocol)PersistenceManager.Restore(node.SelectSingleNode("ParentProtocol"), restoredObjects);
140      name = (StringData)PersistenceManager.Restore(node.SelectSingleNode("Name"), restoredObjects);
141      acceptingState = (BoolData)PersistenceManager.Restore(node.SelectSingleNode("AcceptingState"), restoredObjects);
142      sendingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Request"), restoredObjects);
143      receivingData = (ConstrainedItemList)PersistenceManager.Restore(node.SelectSingleNode("Response"), restoredObjects);
144      XmlNode transitions = node.SelectSingleNode("StateTransitions");
145      if (transitions != null)
146        stateTransitions = (ItemList<StateTransition>)PersistenceManager.Restore(transitions, restoredObjects);
147      else
148        stateTransitions = null;
149    }
150    #endregion persistence
151
152    private void Name_Changed(object sender, EventArgs e) {
153      OnChanged();
154    }
155
156    public override string ToString() {
157      return Name.ToString();
158    }
159  }
160}
Note: See TracBrowser for help on using the repository browser.