The CycleStrategy represents a strategy that is used to augment the deserialization and serialization process such that cycles in an object graph can be supported. This adds additional attributes to the serialized XML elements so that during the deserialization process an objects cycles can be created. Without the use of a strategy such as this, cycles could cause an infinite loop during the serialization process while traversing the graph. <root id="1"> <object id="2"> <object id="3" name="name">Example</item> <object reference="2"/> </object> </root> In the above serialized XML there is a circular reference, where the XML element with id "2" contains a reference to itself. In most data binding frameworks this will cause an infinite loop, or in some cases will just fail to represent the references well. With this strategy you can ensure that cycles in complex object graphs will be maintained and can be serialized safely.
Inheritance: Strategy
    //public List<Pet> GetPets() {
    //   return list;
    //}
 public void TestCycle() {
    Registry registry = new Registry();
    CycleStrategy inner = new CycleStrategy();
    RegistryStrategy strategy = new RegistryStrategy(registry, inner);
    Persister persister = new Persister(strategy);
    PetBucket bucket = new PetBucket();
    StringWriter writer = new StringWriter();
    registry.bind(Cat.class, CatConverter.class);
 /// <summary>
 /// </summary>
 /// <param name="args">
 /// the command line arguments
 /// </param>
 public void TestEmptyMapEntry() {
     Strategy resolver = new CycleStrategy("id", "ref");
     Serializer s = new Persister(resolver);
     StringWriter w = new StringWriter();
     SimpleBug1 bug1 = new SimpleBug1();
     AssertEquals(bug1.test1.data.get("key1"), "value1");
     AssertEquals(bug1.test1.data.get("key2"), "value1");
     AssertEquals(bug1.test1.data.get("key3"), "");
     AssertEquals(bug1.test1.data.get(""), "");
     s.write(bug1, w);
     System.err.println(w.toString());
     SimpleBug1 bug2 = s.read(SimpleBug1.class, w.toString());
Beispiel #3
0
        /// <summary>
        /// </summary>
        /// <param name="args">
        /// the command line arguments
        /// </param>
        public void TestEmptyMapEntry()
        {
            Strategy     resolver = new CycleStrategy("id", "ref");
            Serializer   s        = new Persister(resolver);
            StringWriter w        = new StringWriter();
            SimpleBug1   bug1     = new SimpleBug1();

            AssertEquals(bug1.test1.data.get("key1"), "value1");
            AssertEquals(bug1.test1.data.get("key2"), "value1");
            AssertEquals(bug1.test1.data.get("key3"), "");
            AssertEquals(bug1.test1.data.get(""), "");
            s.write(bug1, w);
            System.err.println(w.toString());
            SimpleBug1 bug2 = s.read(SimpleBug1.class, w.toString());
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void okButton_Click(object sender, EventArgs e)
 {
     if (this.Task.Strategy is CycleStrategy)
     {
         TimeSpan ts = dtpTaskCycle.Value.TimeOfDay;
         if (!CycleStrategy.CheckCycleTimeSpan(ts))
         {
             NUnit.UiKit.UserMessage.DisplayFailure("无效的数值");
             return;
         }
         CycleStrategy cycStrategy = (CycleStrategy)this.Task.Strategy;
         //if ( CycleStrategy.MinCycle
         cycStrategy.Cycle = ts;
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 private void Fill()
 {
     this.txtStation.Text     = this.Task.Device.Station.Name;
     this.txtDevice.Text      = this.Task.Device.Text;
     this.txtTask.Text        = this.Task.Opera.Text;
     this.txtLastExecute.Text = this.Task.LastExecute.ToString();
     if (this.Task.Strategy is CycleStrategy)
     {
         this.lblCycle.Visible     = true;
         this.dtpTaskCycle.Visible = true;
         CycleStrategy cycStrategy = this.Task.Strategy as CycleStrategy;
         this.dtpTaskCycle.Value = DateTimePicker.MinimumDateTime + cycStrategy.Cycle;
     }
     else
     {
         this.lblCycle.Visible     = false;
         this.dtpTaskCycle.Visible = false;
     }
 }
    //public List<Entry> GetEntries() {
    //   return list;
    //}
 public void TestCycle() {
    CycleStrategy inner = new CycleStrategy();
    AnnotationStrategy strategy = new AnnotationStrategy(inner);
    Persister persister = new Persister(strategy);
    EntryListExample list = new EntryListExample();
    StringWriter writer = new StringWriter();
    Entry a = new Entry("A", "a");
    Entry b = new Entry("B", "b");
    Entry c = new Entry("C", "c");
    Entry primary = new Entry("PRIMARY", "primary");
    list.Primary = primary;
    list.AddEntry(a);
    list.AddEntry(b);
    list.AddEntry(c);
    list.AddEntry(b);
    list.AddEntry(c);
    persister.write(list, writer);
    persister.write(list, System.out);
    String text = writer.toString();
    EntryListExample copy = persister.read(EntryListExample.class, text);
Beispiel #7
0
    //public Class GetType() {
    //   return type;
    //}
 public void TestArray() {
    Dictionary map = new HashMap();
    StringReader reader = new StringReader(ARRAY);
    CycleStrategy strategy = new CycleStrategy();
    InputNode event = NodeBuilder.read(reader);