Created
February 13, 2012 22:21
Hello World (using Groovy)
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:21:38 GMT-0500 (EST)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Hello World (using Groovy) | |
Description: This is a Chameleon Groovy 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, Groovy | |
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 compiled using the Groovy compiler. They are Java objects, and not just scripted behaviors. | |
The code is written as Java. Groovy is a dynamic object-oriented programming language that's a superset of Java. | |
**To run this app, select the Chameleon groovy launcher.** | |
OR | |
---- | |
Alternatively, this app can be run using the Beanshell Java interpreter. | |
The Java code for the Hello and World objects is compatible with both Groovy and Beanshell. | |
To do this: | |
1. Change Hello implName="lang:groovy:inline:" to Hello implName="lang:bsh:inline:" | |
2. Select the plain Chameleon launcher (Chameleon_0.jnlp). | |
]]></Notes> | |
<script implName="lang:python:inline:"><![CDATA[ | |
print "Hello World!" | |
]]></script> | |
<script implName="lang:javascript:inline:"><![CDATA[ | |
print("Hello World!\n"); | |
]]></script> | |
<_-.XholonClass> | |
<!-- domain objects --> | |
<PhysicalSystem/> | |
<HelloWorldSystem/> | |
</_-.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="lang:groovy:inline:"><![CDATA[ | |
// Hello should be inserted as a child of HelloWorldSystem | |
import org.primordion.xholon.base.IMessage; | |
import org.primordion.xholon.base.XholonWithPorts; | |
public class Hello extends XholonWithPorts { | |
// 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 void act() | |
{ | |
if (port[0] == null) { | |
port[0] = getXPath().evaluate("ancestor::HelloWorldSystem/World", this); | |
} | |
if (state == 0) { | |
System.out.print("Hello "); | |
port[P_PARTNER].sendMessage(SIGNAL_ONE, null, this); | |
state = 1; | |
} | |
super.act(); | |
} | |
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, this); | |
break; | |
default: | |
break; | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
public String toString() { | |
String outStr = 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; | |
} | |
} | |
// the following object will be returned from this script | |
new Hello() | |
]]></Hello> | |
<World implName="lang:groovy:inline:"><![CDATA[ | |
// World should be inserted as a child of HelloWorldSystem | |
import org.primordion.xholon.base.IMessage; | |
import org.primordion.xholon.base.XholonWithPorts; | |
public class World extends XholonWithPorts { | |
// 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 void act() | |
{ | |
if (port[0] == null) { | |
port[0] = getXPath().evaluate("ancestor::HelloWorldSystem/Hello", this); | |
} | |
super.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, this); | |
break; | |
default: | |
break; | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
public String toString() { | |
String outStr = 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; | |
} | |
} | |
// the following object will be returned from this script | |
new World() | |
]]></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