Getting started with omixed
Server and Schematographer Installation
- Download, build and deploy the omixed server (see installation instructions).
- Download and install the schematographer. (requires the Adobe AIR runtime).
Create a schema
- Open the schematographer
- Drag and drop an item type palette item from the palette onto empty model. A new item type panel should appear on the model.
- Double click on the newly created panel.
- A property panel should appear, use it to edit the name of the item type; let's call it "Person".
- From the palette, drag a new String palette item onto the the newly created Person item type, double click on it to open its property panel and call this new String "Email".
- Drag and drop another item type onto the model; let's call this one "Message".
- From the palette, drag a new Text palette item onto the the newly created Message item type, call this new Text "Contents".
- Double click on the Message item type again to open its property panel and check the checkbox "check if root"; this will be the root item type.
- From the palette, drag a new Link palette onto the Message item type, double click on it to activate its property box, use the combo box to point this to the Person, call this Link "To".
- Save this file as Messages.xml.
-
You can open this file using a text editor: it should look like this (the x and y attributes will of course be different):
<OmixedDatabaseSchema>
<ItemTypeList>
<ItemType name="Person" x="491" y="131">
<Attribute name="Email" type="String"/>
</ItemType>
<ItemType name="Message" x="334" y="391">
<Attribute name="Contents" type="Text"/>
<Link name="To" arity="one" to="Person"/>
</ItemType>
</ItemTypeList>
<RootItemTypeList>
<ItemType name="Message"/>
</RootItemTypeList>
</OmixedDatabaseSchema>
Create a resource with the schema
Please note that you must have SSL properly configured on your tomcat installation for this to work. The server installation faq has more details.
- Open a terminal and cd into the omixed server folder that you used to build and deploy from.
- Type:
java -jar AdminConsole.jar
- Enter your connection details to connect.
- In the AdminConsole, type :
resource-create messages
resource-set-schema messages file:///home/buggy/schema/Messages.xml
user-create bobber user builder
policy-add-on-resource allow connect bobber messages
(obviously changing the path to wherever you saved the Messages.xml file!)
Interact with the resource using client libraries
Please note these clients do not even have to be on the same machine as the server. For convenience, these instructions assume that they are. Please change "localhost" to match your server's domain name if you are trying this from another machine.
Java Example
- Make a folder called omixed-test.
- Using bazaar download the latest version of the java_library inside the omixed-test folder.
- Build the library by typing "ant" inside the java_library folder
- in the omixed-test folder create a new file called NewMessage.java :
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.omixed.omixedclient.*;
class NewMessage
{
public static void main(String [ ] args) throws OmixedClientException, ParserConfigurationException
{
OmixedClient client = new OmixedClient("localhost", "8080"); // create a client object
client.connect("messages", "bobber", "builder"); // connect to the resource
OmixedItem person = new OmixedItem(client, "Person", "Jack", "public"); // make an empty local person object
person.setAttribute("Email", "Jack@omixed.org"); // set its email value
client.create(person); // create the person object on the resource
OmixedItem message = new OmixedItem(client, "Message", "email1", "public"); // make an empty local message object
message.setAttribute("Contents", "Hello Omixed World"); // set its contents value
message.setLink("To", person.getItemID()); // link it to the person
client.create(message); // create the message object on the resource
NodeList itemElements = client.getItems( message.getItemID() ).getChildNodes(); // for through all the message items
for (int i=0; i < itemElements.getLength() ; i++){
Node itemNode = itemElements.item(i);
Element itemElement = (Element) itemNode;
String itemID = itemElement.getAttribute("itemID");
OmixedItem messageOnServer = new OmixedItem( client, itemID, itemElement );
System.out.println(messageOnServer.getAttribute("Contents")); // print the Contents of the message
}
client.delete(message.getItemID()); // delete the message item
client.delete(person.getItemID()); // delete the person item
client.disconnect(); // disconnect
}
}
- build with
javac -cp java_library/OmixedJavaClient_jdk6.jar NewMessage.java
- run with (if you're using windows, please replace the ":" with ";")
java -classpath .:java_library/OmixedJavaClient_jdk6.jar:java_library/lib/* NewMessage
-
should result in : Hello Omixed World
Ruby Example
- Make a folder called omixed-test-ruby.
- Make a new file called NewMessage.rb :
require ('ruby_library/omixed.rb')
include Omixed
client = OmixedClient.new("localhost")
client.connect("messages", "bobber", "builder");
person = OmixedItem.new()
person.setupNewItem(client, "Person", "Jack", "public");
person.setAttribute("Email", "Jack@omixed.org");
client.createItem(person);
message = OmixedItem.new()
message.setupNewItem(client, "Message", "email1", "public");
message.setAttribute("Contents", "Hello Omixed World");
message.setLink("To", person.itemID);
client.createItem(message);
itemElements = client.getItemsWithoutLinks( message.itemID );
itemElements.each_element do |el|
messageFromServer = OmixedItem.new()
messageFromServer.setupXML(client, el.attributes["itemID"], el)
puts messageFromServer.getAttribute("Contents")
end
client.delete(message.itemID);
client.delete(person.itemID);
client.disconnect();
- pull the ruby library by doing:
bzr get http://www.omixed.org/downloads/files/bazaar/ruby_library
- and run by doing:
ruby NewMessage.rb
-
should result in : Hello Omixed World