Javantura v4 - True RESTful Java Web Services with JSON API and Katharsis - Matija Dujmović
Itemscript, a specification for RESTful JSON integration
-
Upload
itemfoo -
Category
Technology
-
view
894 -
download
1
description
Transcript of Itemscript, a specification for RESTful JSON integration
![Page 1: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/1.jpg)
Itemscript
A declarative languagebased on JSON
![Page 2: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/2.jpg)
Vision
Simple schema
data storeapplication markup
Applications from componentsDe-couple technical details
Lean developmentBusiness agility
![Page 3: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/3.jpg)
Itemscript is Declarative
• Separates design (what) from construction (how)o Simple APIo Lends itself to iterative developmento Technical details are hiddeno Controls are exposedo Swap components without breaking the API
![Page 4: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/4.jpg)
![Page 5: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/5.jpg)
![Page 6: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/6.jpg)
Itemscript Philosophy
Applications are multi-layered• Core is compiled code• Wrapped around that are configuration files• Wrapped around that are user settings • Compiled settings are the hardest to change• Configuration files help,
but only offer limited access• User settings are usually very limited
Applications should expose all useful settings
Core
Configuration
User settings
![Page 7: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/7.jpg)
Itemscript is JSON
• JSON is simple• JSON has widespread support• JSON is an ideal data-interchange language
![Page 8: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/8.jpg)
JSON easily maps to native objects
JSON Objects• Native objects & packages• Nested object graphs• Maps/hashes/dictionaries• Databases• Key-value stores• Cloud databases
JSON Arrays• Lists/arrays/sets• Query results
![Page 9: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/9.jpg)
Extending JSON
• Deal with more data than fits in memoryo Databaseso Queries
• Handle references• Manage local and remote data• Handle identifiers• Support schemas• Manage persistence• Handle events
![Page 10: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/10.jpg)
Semantics
• Itemscript Schema JSON Schema language
• Itemscript JAM
JSON Application Markup
![Page 11: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/11.jpg)
Itemscript schemaDog Type"com.example.petstore.SCHEMA" :{"Dog" : {"ID name" : "","weight" : 0,"REQUIRED owner" : "","breed" : "","isFixed" : true,}}item of type Dog:"com.example.petstore.dogs.Bella" : {"TYPE" : "com.example.petstore.SCHEMA.Dog","name" : "Bella","weight" : 9.2,"owner" : "Vera","breed" : "Cavalier King Charles","isFixed" : true}
http://itemscript.org/ItemscriptSchema.html
![Page 12: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/12.jpg)
Itemscript JAM
{ "widget" : "GWT.Image", "title" : "Itemscript Logo", "width" : "100px", "height" : "100px", "url" : "./itemscript-logo.jpg" }
![Page 13: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/13.jpg)
![Page 14: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/14.jpg)
Business agility
• Lean development using declarationso Developer & user iterate togethero Discover needs as you develop solutions
• Iterate applications as requirements developo Add elements & event handlers as you need themo Trade up as better options arrive
![Page 15: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/15.jpg)
Proof of Concept
• Item Lens (JAM animator)o rich web UI based on Google GWT
• Item Store (Column store)o persistence based on Apache Derby
• Item Hash (Model application)
o item tracker built using Itemscript JAM
![Page 16: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/16.jpg)
![Page 17: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/17.jpg)
Itemscript execution
Itemscript
Item Lens Item Store
SchemaJAM
Item StoreProtocol
SQL
MQ
Cache
XML
![Page 18: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/18.jpg)
Itemscript Applications
“Small pieces loosely joined” a collection of Lego bricks
Compiled objects are managed in libraries, by type
All "wiring-up" is done using JSON declarations
No sharp distinction between application-building, configuration, or user settings
http://www.smallpieces.com
![Page 19: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/19.jpg)
How we built it
• Build objects that can be configured using JSON.• Use semantics that describe the domain
widget, handler, page ticket, priority, status
white • For each object type,
build a factory that trades JSON for an object instance.• For each class of object (e.g. widget),
combine the factories into a foundry.• Factor out common code.
![Page 20: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/20.jpg)
Itemscript System
• Each system has one "root" JSON objecto Acts as shared in-memory database for your application.o Application configurationo Application state
• You can load additional Items - hold as long as needed, natively-garbage-collected.o Load system and initial configurationo Load Item from remote datastoreo Copy part of Item to current application stateo Discard Item
![Page 21: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/21.jpg)
The Item
The smallest unit of transferrable data.• Guaranteed to be transmitted as a whole.• Guaranteed to be fully navigable locally/synchronously.
Consists of a JSON Object, including nested other objects.
Metadata and data live together in the JSON Object. _ prefix denotes metadata.
_CONNECTION key tells you where this Item came from._ID key gives you the GUID key for an Item.
_PARENT_ID key gives you the GUID key for a parent
![Page 22: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/22.jpg)
Item Lens applications
• Application o a set of nested Widgets.o usually includes a PagePanel.
• PagePanel shows the Pages that have been defined.• Each Page is a set of nested Widgets.
• Popups are also a set of nested Widgets.• Dialog boxes• Error boxes
![Page 23: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/23.jpg)
Item Lens bootstrap
• Item Lens starts an application: o loads modules (using GWT module system), o modules register Foundries containing Factories, or register
additional Factories in existing Foundries. e.g. WidgetFoundry
• Item Lens loads and stores the script file.o Reads script file for more definitions - widgets, pages, popupso stores them in the corresponding Foundry.
• Item Lens reads script file to build the application.
![Page 24: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/24.jpg)
Item Store
The Item Store is a key-value store of Items. Any Item can be the root of another key-value store.
o May map to: database-table-row.o Or to: database-table-row-subTable-rowset.
Easily replaced with SQL tables, key/value stores Maps Item Store namespace locations to connect to
remote locations and services.
![Page 25: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/25.jpg)
Item Store
• Item Store RPCo Simple data store
Get Put Remove
o Simple proxy for the service provider Connect services when your application is ready Swap out services without changing applications
![Page 26: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/26.jpg)
Developing Itemscript applications
• Client sideo Wrap widgets and components in Itemscripto Wire up components to build interfaces
• Server sideo Declare Itemscript data types o Assign types to locationso Connect locations to services
![Page 27: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/27.jpg)
Item Hash
• Building the model application o item hash use caseo item hash design processo pulldown list exampleo date picker exampleo event exampleo adding a new fieldo adding a new event handler
![Page 28: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/28.jpg)
Item Hash Page Nesting
![Page 29: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/29.jpg)
New Case Page Nesting
![Page 30: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/30.jpg)
Editing the Form
{ "widget" : "GWT.VerticalPanel", "contents" : [ { "widget" : "GWT.Html", "html" : "<small>Priority</small>" "id" : "Priority" }, { "widget" : "GWT.ListBox", "width" : "200px", "height" : "20px" "data" : "ItemHash.db/priorities" } ] }
![Page 31: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/31.jpg)
Item Lens
"Can I set the date picker to tomorrow?"
![Page 32: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/32.jpg)
Changing the Date Picker
What would the JSON look like?
{ "widget" : "ItemLens.DatePickerTextBox" "width" : "200px", "height" : "25px", "date" : "tomorrow"}
![Page 33: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/33.jpg)
Changing the Date Picker
When the "date" declaration says "tomorrow", what logic do we need to add?
if (params.hasOptionalString("date")) { String dateStr = params.getString("date"); if (dateStr.equalsIgnoreCase("tomorrow")) { Date tomorrow = new Date(new Date().getTime()+DAY_AS_MILLISECONDS); box.setValue(tomorrow); }}
![Page 34: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/34.jpg)
Event Handling
"Let's make the login box pop up."
![Page 35: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/35.jpg)
Event Handling
What would the JSON look like?
{ "widget" : "GWT.Html" "cellHorizontalAlignment" : "right" "html" : "<small><b>login</b></small>" "clickHandlers" : { "clickHandler" : "ItemLens.PopupPanelShowClickHandler", "popup" : "loginPrompt" }}
![Page 36: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/36.jpg)
Event Handling
Implementing a "clickHandler"
Register a factory to create an action.
Animating "popup" : "loginPrompt"
• Read the "loginPrompt" object in "popups" section.• Parse loginPrompt for the parameter needed.• Build a popup widget.
![Page 37: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/37.jpg)
Event Handling"popups": { "loginPrompt" : { "widget" : "GWT.DialogBox", "id" : "Login", "title" : "user login", "showRelativeTo" : "searchbox", "width" : "100px", "cellHorizontalAlignment" : "center", "cellVerticalAlignment" : "bottom", "html" : "<strong>User Login</strong>", "autohide" : false, "contents" : { "widget" : "GWT.VerticalPanel", "cellSpacing" : 5 "contents" : [ ...
![Page 38: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/38.jpg)
Adding Widget Libraries
GChart{ "widget" : "GChart.Chart", "canvas" : true, "chartHeight" : 200, "chartWidth" : 300, "chartTitle" : "<h3>2008 Sales by Pie Flavor<br>(Puny Pies, Inc.) </h3>", "legendVisible" : false, "initialPieSliceOrientation" : 0.425, "curves" : [ { "symbol" : "pieSliceOptimalShading", "modelWidth" : 6, "backgroundColor" : "green", "borderColor" : "white", "height" : 0, "fillSpacing" : 0, "fillThickness" : 3, "hoverText" : "Apple, 65%", "pieSliceSize" : 0.65, "points" : [ { "point" : "5,5", "annotationText" : "Apple", "annotationLocation" : "outsidePieArc" } ...
• Designers learn a few new declarations, not a new API
• Full demo at http://tinyurl.com/gchartdemo
![Page 39: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/39.jpg)
Downloads
• Item Lens AJAX using Google GWT Components from Google Maps, Gchart, GWT Widget library
• Itemscript Core Libraries Convenient JSON library for Java & GWT applications
![Page 40: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/40.jpg)
What's Next?
• Item Store
• Itemscript schema validator
• Declarative security model
• Hosted Service
• Application exchange
![Page 41: Itemscript, a specification for RESTful JSON integration](https://reader033.fdocuments.net/reader033/viewer/2022061222/54bf0bd34a7959c5538b45d9/html5/thumbnails/41.jpg)
Working with Itemscript
Project pageshttp://itemscript.orghttp://code.google.com/p/itemscript/
Twitter updateshttp://twitter.com/itemscript
FAQhttp://code.google.com/p/itemscript/wiki/itemscriptfaq