Skip to content

Commit

Permalink
example showing the conversion of the OCCI text format to OCCI JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dizz committed Jul 14, 2011
1 parent 3314764 commit 3776957
Show file tree
Hide file tree
Showing 2 changed files with 555 additions and 0 deletions.
89 changes: 89 additions & 0 deletions occi-antlr-json/example/occijson.java
@@ -0,0 +1,89 @@
import be.edmonds.occi.occi_http_textParser;


public class occijson {

/**
This will output this (unformatted) JSON
[
{
"category": [
{
"term": "ie",
"scheme": "http://",
"class": "mixin",
"title": "null",
"rel": "null",
"location": "null",
"attributes": [
null
],
"actions": [
null
]
},
{
"term": "compute",
"scheme": "http://",
"class": "kind",
"title": "null",
"rel": "null",
"location": "null",
"attributes": [
null
],
"actions": [
null
]
},
{
"term": "large",
"scheme": "http://",
"class": "mixin",
"title": "null",
"rel": "null",
"location": "null",
"attributes": [
null
],
"actions": [
null
]
},
{
"term": "ubuntu",
"scheme": "http://",
"class": "mixin",
"title": "null",
"rel": "null",
"location": "null",
"attributes": [
null
],
"actions": [
null
]
}
],
"attributes": {
"my.attr": "val",
"my.other": 123
}
}
]
*/
public static void main(String[] args) {

//Note that the grammar does not correct support certain values
String convertMe = "Category: ie; scheme=\"http://\"; class=\"mixin\", compute; scheme=\"http://\"; class=\"kind\", large; scheme=\"http://\"; class=\"mixin\", ubuntu; scheme=\"http://\"; class=\"mixin\"" +
"X-OCCI-Attribute: my.attr=\"val\", my.other=123";

try {
occi_http_textParser p = occi_http_textParser.getParser(convertMe);
System.out.println(p.occi_request());

} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 3776957

Please sign in to comment.