MSC Trial 1

Ken Webb 2010-04-10T13:48:31Z

In this Malleable Software Challenge (MSC) trial, I will run an unmodified Xholon application, and will then inject additional nodes into the running app. The root of the new subtree, an instance of the Plus class, will sum the values in all of its children which will all be instances of the Number class. The new subtree does not interact with any of the nodes in the original application. It just piggy-backs on the run-time framework. It's a bit like a neutral virus.

Plus

package org.primordion.user.app.msc;

import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;

public class Plus extends Xholon {
  
  public void act() {
    println("--> sum=" + sum());
    super.act();
  }
  
  protected int sum() {
    int sum = 0;
    IXholon node = getFirstChild();
    while (node != null) {
      sum += node.getVal_int();
      node = node.getNextSibling();
    }
    return sum;
  }
  
  public String toString() {
    return Integer.toString(sum());
  }
  
}

Number

package org.primordion.user.app.msc;

import org.primordion.xholon.base.Xholon;

public class Number extends Xholon {
  
  int val = 0;

  public int getVal_int() {
    return val;
  }

  public void setVal(int val) {
    this.val = val;
  }
  
  public String toString() {
    return Integer.toString(val);
  }
  
}

Simple subtree

<Plus implName="org.primordion.user.app.msc.Plus">
  <Number implName="org.primordion.user.app.msc.Number">17</Number>
  <Number implName="org.primordion.user.app.msc.Number">25</Number>
</Plus>

Complete all-in-one subtree

<Plus implName="lang:bsh:inline:"><![CDATA[
import org.primordion.xholon.base.IXholon;
import org.primordion.xholon.base.Xholon;
class Plus extends Xholon {
  public void act() {
    println("--> sum=" + sum());
    super.act();
  }
  protected int sum() {
    int sum = 0;
    IXholon node = getFirstChild();
    while (node != null) {
      sum += node.getVal_int();
      node = node.getNextSibling();
    }
    return sum;
  }
  public String toString() {
    return Integer.toString(sum());
  }
}
new Plus();
]]>

<Number implName="lang:bsh:inline:"><![CDATA[
import org.primordion.xholon.base.Xholon;
class Number extends Xholon {
  public Number(int val) {
    this.val = val;
  }
  int val = 0;
  public int getVal_int() {
    return val;
  }
  public void setVal(int val) {
    this.val = val;
  }
  public String toString() {
    return Integer.toString(val);
  }
}
new Number(17);
]]>
</Number>

<Number implName="lang:bsh:inline:"><![CDATA[
import org.primordion.xholon.base.Xholon;
class Number extends Xholon {
  public Number(int val) {
    this.val = val;
  }
  int val = 0;
  public int getVal_int() {
    return val;
  }
  public void setVal(int val) {
    this.val = val;
  }
  public String toString() {
    return Integer.toString(val);
  }
}
new Number(25);
]]>
</Number>

</Plus>

return to main page