Hello World (using Beanshell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/wb/ (C) Ken Webb Mon Feb 13 2012 17:25:48 GMT-0500 (EST)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Hello World (using Beanshell) | |
Description: This is a Chameleon Beanshell version of the original Xholon "Hello World" tutorial. | |
Url: http://www.primordion.com/Xholon/doc/tutorial.html | |
InternalName: HelloWorld | |
YoutubeId: | |
Keywords: Hello World, Xholon, tutorial, Beanshell | |
My Notes | |
-------- | |
In this version of the Xholon "Hello World" tutorial: | |
The infrastructure is provided by Xholon Chameleon. | |
The Hello and World script objects are interpreted using Beanshell. | |
The code is written as Java. | |
**To run this app, select the basic Chameleon launcher.** | |
OR (under development) | |
---- | |
This app can be run in the Bestiary, although it's more complex because the Bestiary: | |
- is a Java applet, and is therefore subject to a stronger security policy which forbids use of a Java bytecode compiler | |
- does not use the default Xholon GUI | |
Follow these steps: | |
- Load the Xholon Bestiary page at:: | |
http://www.primordion.com/Xholon/pulpcore/Bestiary/index.html | |
- Press "Start app" | |
- Navigate to a Cat node by pasting the following into the console textarea, and then pressing the Submit button:: | |
xpath ../descendant-or-self::*[@name='cat_2'] | |
- Paste the contents of "Step 4" below, into the console, and press Submit. | |
- Navigate to the HelloWorldSystem node by pasting the following into the console textarea, and then pressing the Submit button:: | |
xpath *[4]/* | |
- Paste the contents of the Hello script into the console, and press Submit. | |
- Paste the contents of the World script into the console, and press Submit. | |
- Watch the Java Console for "Hello World!". | |
]]></Notes> | |
<script implName="lang:python:inline:"><![CDATA[ | |
print "Hello World!" | |
]]></script> | |
<script implName="lang:javascript:inline:"><![CDATA[ | |
print("Hello World!\n"); | |
]]></script> | |
<_-.XholonClass/> | |
<xholonClassDetails/> | |
<PhysicalSystem> | |
<HelloWorldSystem> | |
<!-- Hello and World should be inserted as children of this node --> | |
</HelloWorldSystem> | |
</PhysicalSystem> | |
<Hellobehavior implName="lang:python:inline:"><![CDATA[]]></Hellobehavior> | |
<Worldbehavior implName="lang:javascript:inline:"><![CDATA[]]></Worldbehavior> | |
<Blockbehavior implName="lang:bsh:inline:"><![CDATA[]]></Blockbehavior> | |
<Hello implName="org.primordion.script.Behavior_beanshell"><![CDATA[ | |
// Hello should be inserted as a child of HelloWorldSystem | |
import org.primordion.xholon.base.IMessage; | |
import org.primordion.xholon.base.IXholon; | |
behavior() { | |
// references to other Xholon instance; index into the port array | |
public static final int P_PARTNER = 0; | |
// Signals, Events | |
public static final int SIGNAL_ONE = 100; // no data | |
public int state = 0; | |
public String roleName = null; | |
public IXholon[] port = null; | |
public void postConfigure() { | |
if (port == null) { | |
port = new IXholon[1]; | |
} | |
} | |
public void act() { | |
if (port[P_PARTNER] == null) { | |
port[P_PARTNER] = contextNodeKey.getNextSibling(); | |
} | |
else if (state == 0) { | |
System.out.print("Hello "); | |
port[P_PARTNER].sendMessage(SIGNAL_ONE, null, contextNodeKey); | |
state = 1; | |
} | |
} | |
public void processReceivedMessage(IMessage msg) { | |
int event = msg.getSignal(); | |
switch (state) { | |
case 1: // Ready | |
switch(event) { | |
case SIGNAL_ONE: | |
System.out.print("Hello "); | |
port[P_PARTNER].sendMessage(SIGNAL_ONE, null, contextNodeKey); | |
break; | |
default: | |
break; | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
public String toString() { | |
String outStr = contextNodeKey.getName(); | |
if ((port != null) && (port.length > 0)) { | |
outStr = " ["; | |
for (int i = 0; i < port.length; i ) { | |
if (port[i] != null) { | |
outStr = " port:" port[i].getName(); | |
} | |
} | |
outStr = "]"; | |
} | |
outStr = " state=" state; | |
return outStr; | |
} | |
return this; | |
} | |
behaviorObject = behavior(); | |
]]></Hello> | |
<World implName="org.primordion.script.Behavior_beanshell"><![CDATA[ | |
// World should be inserted as a child of HelloWorldSystem | |
import org.primordion.xholon.base.IMessage; | |
import org.primordion.xholon.base.IXholon; | |
behavior() { | |
// references to other Xholon instance; index into the port array | |
public static final int P_PARTNER = 0; | |
// Signals, Events | |
public static final int SIGNAL_ONE = 100; // no data | |
public int state = 0; | |
public String roleName = null; | |
public IXholon[] port = null; | |
public void postConfigure() { | |
if (port == null) { | |
port = new IXholon[1]; | |
} | |
if (port[P_PARTNER] == null) { | |
port[P_PARTNER] = contextNodeKey.getFirstSibling(); | |
} | |
} | |
public void act(){} | |
public void processReceivedMessage(IMessage msg) { | |
int event = msg.getSignal(); | |
switch (state) { | |
case 0: // Ready | |
switch(event) { | |
case SIGNAL_ONE: | |
System.out.println("World !"); | |
port[P_PARTNER].sendMessage(SIGNAL_ONE, null, contextNodeKey); | |
break; | |
default: | |
break; | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
public String toString() { | |
String outStr = contextNodeKey.getName(); | |
if ((port != null) && (port.length > 0)) { | |
outStr = " ["; | |
for (int i = 0; i < port.length; i ) { | |
if (port[i] != null) { | |
outStr = " port:" port[i].getName(); | |
} | |
} | |
outStr = "]"; | |
} | |
outStr = " state=" state; | |
return outStr; | |
} | |
return this; | |
} | |
behaviorObject = behavior(); | |
]]></World> | |
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg xml, | |
<svg width="261" height="101" xmlns="http://www.w3.org/2000/svg"> | |
<g> | |
<title>Layer 1</title> | |
<g transform="matrix(2, 0, 0, 2, -19.5, -19.5)" id="toplevelgroup"> | |
<g id="g5"> | |
<desc>helloWorldSystem_0 state=0</desc> | |
<rect fill="#efffdf" stroke="#a121f1" stroke-width="0.5px" height="50" width="130" y="10" x="10" id="HelloWorldSystem"/> | |
<text fill="#000000" font-family="Verdana" id="text10" font-size="8px" y="20" x="15">HelloWorldSystem</text> | |
</g> | |
<g id="g12"> | |
<desc>hello_1 [ port:world_2] state=1</desc> | |
<rect fill="#ffffff" stroke="#a121f1" stroke-width="0.5px" height="20" width="40" y="30" x="20" id="HelloWorldSystem/Hello"/> | |
<text fill="#000000" font-family="Verdana" id="text17" font-size="8px" y="40" x="25">Hello</text> | |
<!--port[0]:world_2--> | |
<rect fill="#0000ff" stroke="#e0e0f8" stroke-width="0.5px" height="6" width="6" ry="2.5" y="44" x="57" id="hello_1.port[0]"/> | |
<polygon fill="#e0e0f8" stroke="#0000ff" stroke-width="0.5px" points="63,40 63,34 57,37" id="hello_1.conjport[0]"/> | |
</g> | |
<g id="g21"> | |
<desc>world_2 [ port:hello_1] state=0</desc> | |
<rect fill="#ffffff" stroke="#a121f1" stroke-width="0.5px" height="20" width="40" y="30" x="80" id="HelloWorldSystem/World"/> | |
<text fill="#000000" font-family="Verdana" id="text26" font-size="8px" y="40" x="85">World</text> | |
<!--port[0]:hello_1--> | |
<rect fill="#0000ff" stroke="#e0e0f8" stroke-width="0.5px" height="6" width="6" ry="2.5" y="34" x="77" id="world_2.port[0]"/> | |
<polygon fill="#e0e0f8" stroke="#0000ff" stroke-width="0.5px" points="77,44 77,50 83,47" id="world_2.conjport[0]"/> | |
</g> | |
<path stroke="#000000" stroke-width="0.5px" id="path30" d="m63,47l14,0"/> | |
<path stroke="#000000" stroke-width="0.5px" id="path32" d="m77,37l-14,0"/> | |
</g> | |
</g> | |
</svg> | |
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient> | |
</XholonWorkbook> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment