com.ibm.mashups.iwidget.widget
Interface IWidgetDefinition

All Superinterfaces:
EventProvider, PropertiesProvider

public IWidgetDefinition
extends EventProvider, PropertiesProvider

Interface defines functions to access all the data object in widget definition. PropertiesProvider is not implemented.


Method Summary
 String[] getSupportedModes()
           This method returns an array of supported modes such as "view" and "edit".
 object toSpecObject()
           This method returns a JSON based spec compliant object that represents all the data that's defined in widget xml.
 
Methods inherited from interface com.ibm.mashups.iwidget.widget.EventProvider
getWidgetPublishedEvents, getWidgetHandledEvents, getPublicEvent
 
Methods inherited from interface com.ibm.mashups.iwidget.widget.PropertiesProvider
getIDescriptorItems, getAttributes
 

Method Detail

getSupportedModes

String[] getSupportedModes()
This method returns an array of supported modes such as "view" and "edit".

Returns:
array of supported modes this iWidget supports.

toSpecObject

object toSpecObject()
This method returns a JSON based spec compliant object that represents all the data that's defined in widget xml.

Rule to follow:
1. Element -- "iw:iwidget" is considered to be root Element and a root object is created from here.

2. Any attribute of this element will be a field in the root object. '_' will be added as prefix to field names.
":" within any namespaced attribute will be replaced with "_". <iw:iwidget id="map" xml:base="/root/test/" allowInstanceContent="false"......>
{ _id:"map",_xml_base:"/root/test/",_allowInstanceContent:"false"......}

3. All repreatable elements, element name (append with "s") is used as a field name and an object is created to contain all the repeatable elements.Within that object, value of "id" attribute is used as field name for an individual element if id attribute is available.
{
     resources: {
          "myId": { _id:"myId",_src:"my.js"},
          "myOtherId": { _id:"myOtherId",_src:"my2.js"}
     }
}

4. For "iw:content" elements, "contents" is used as the key in the parent object and an object is created to contain all the content elements.
For each "content" element, "mode" attribute is used as the key and CDATA section is saved as the value.
{
   contents: {
       "view": {
         "_mode": "view",
         "value": "mycontent"
       }
    }
}

5. For "iw:alt" elements,"alts" is used as the key in parent object and an object is created to contain all the alt elements.
For each "alt" element, "lang" attribute is used as the key and all the attributes are saved per attributes convention.
eventDescname: {
     _id:"eventDescnname",
     _payloadType:"payloadType",
     alts: {
          "en": { _lang:'en',_description:"description",_descriptionURI:"descriptionURI"},
          "zh": { _lang:'zh',_description:"description",_descriptionURI:"descriptionURI"}
     }
}

An example of simple iWidget and the return result.
<iw:iwidget id="stock" xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget" iScope="stock" allowInstanceContent="true" supportedModes="view edit " mode="view" lang="en">
    <iw:itemSet id="attributes" private="true" onItemSetChanged="changeItemSet">
      <iw:item id="broker" readOnly="false" value="Etrade" />
      <iw:item id="company" value="IBM" />
   </iw:itemSet>
    <iw:event id="sendStockData" eventDescName="sendStockDataDesc" published="true" onNewWire="sendData" />
    <iw:eventDescription id="sendStockDataDesc" payloadType="stockData" title="Send stock data" lang="en" >
     <iw:alt title="Send stock data" lang="en" />
   </iw:eventDescription>
   <iw:resource src="stock.js" id="stock" />
   <iw:content mode="view"> <![CDATA[ mycontent ]]> </iw:content>
   </iw:iwidget>

Example of returnin json object.
{ _id:"map",_allowInstanceContent:"true",_iScope:"stock",_supportedModes:"view edit",_mode:"view",_lang:"en",
    itemSets: {
      "attributes": { _id:"attributes", _private:"true",_onItemSetChanged:"changedItemSet",
       items: {
          "broker": { _id:"broker",_readOnly:"false", _value:"Etrade"},
          "company": { _id:"company",_value;"IBM"}
       }
       }
   },
   events: {
      "sendStockData": { _id:"sendStockData", _eventDescName:"sendStockDataDesc", _published:"true",_onNewWire:"sendData"}
   },
   eventDescriptions: {
      "sendStockDataDesc": { _id:"sendStockDataDesc", _payloadType:"stockData",_title:"Send stock data",_lang:"en",
          alts: {
              "en": { _lang:"en",_title:"Send stock data"}
          }
      }
    },
    resources: {
      "stock": { _id:"stock", _src:"stock.js"}
   },
   contents: {
       "view": {
         "_mode": "view",
         "value": "mycontent"
       }
    }
}

Returns:
a JSON based, spec compliant object that represents all the data that's defined in widget.xml


Copyright IBM Corp. 2010 All Rights Reserved.