Tags:
create new tag
, view all tags
-- PedroRio - 21 Dec 2010

XEO Object Model Behavior- XEO Library

Custom Behavior in XEO Object Models can be achieved through various way :

  • Object Events
  • Object Methods
  • Attribute Events
  • Attribute Properties

To define custom behavior there are two methods: BOL and the Java API. BOL is an acronym for Business Object Language which is essentially a small expression language specific to the XEO platform to aid in creating custom behavior. Everything that can be done using BOL can be done using Java (BOL expressions are ultimately converted to Java as the whole Object Model is also converted to Java).

In this chapter we'll create the custom behavior required for the Object Models in the XEO Library and introduce briefly the XEO Java API (and BOL).

XEO Java API (Basic Introduction)

Each XEO Object Model is ultimatelly converted to a Java class to support operations (database tables are also created to persist data) and abstract from the relational data model. The classes created from Object Models extend from a java class included in the framework, the boObject class , which has a set of base methods to deal with attributes and other Model properties.

A user can login to a XEO Application via the login form or using the Java API to create a session within the XEO application. With access to a boSession, the Java API can be used to create new instances of Object Models, load existing instances, change attribute values in an existing instance as well as save the changed values. One can also query object instances and iterate through the results as well as checking the Object Model definitions to perform operations based on that information.

In order to load an instance object, to create a new instance or to make a query XEO needs a "context". A context is an instance of the EboContext class which can be created anytime (given there's access to a boSession) and the operations to load an object, create an object and query objects all require a parameter which is the context. The EboContext keeps in memory the loaded objects (and changes to their attribute values) and acts as cache and has a connection to the database (as such they should be managed with care). It's possible to create two different contexts and load the same object instance into both of them, in this scenario changes made each instance are not visible from another context and if both objects are changed and then saved , the last save will crush the first one. The hierarchy of these classes is depicted in figure OB.1.

boSession and <span class=EboContext hierarchy" src="http://wiki.itds.pt/pub/WebITDS/XeoPrimerObjectBehavior/JavaAPIboSession.png" title="boSession and EboContext hierarchy" height="720" />

Figure OB.1 - boSession and EboContext hierarchy

In most situations, there's no need to explictly create instances of EboContext, because an EboContext is always created in each request ( FIXME: Vericar se isto é correcto) and that context can be used inside your custom code. Each boObject instance has access to an EboContext instance (the context in which its loaded) so even if a method receives as parameter a boObject, you still have access to the EboContext.

Most Important APIs for defining custom behavior in the XEO Library

boObject - Represents an instance of an Object Model

Method Name Description Arguments Return type
update Saves the object instance - void
getAttribute Retrieves the handler for an attribute (non-collection) (String) attributeName AttributeHandler
exists Checks whether the instance is saved in the database - boolean
getBridge Retrieves the handler for a collection attribute (String) collectionName BridgeHandler

AttributeHandler - Represents a handler to deal with an attribute (non-collection) of an Object Model

Method Name Description Arguments Return Type
getName Returns the name of the attribute (as defined in the Object Model) - String
getValueString Retrieves the value of the attribute as a String* - String
getValueLong Retrieves the value of the attribute as a Long* - Long
getValueDate Retrieves the value of the attribute as a Data* - java.util.Date
getValueiFile Retrieves the value of the attribute as a binary data Wrapper (iFile)* - netgest.io.iFile
getValueBoolean Retrieves the value of the attribute as a Boolean* - Boolean
setValueString Sets the value of the attribute with a String* (String) newVal void
setValueLong Sets the value of the attribute with a Long* (Long) newVal void
setValueDate Sets the value of the attribute with a Date* (Date) newVal void
setValueiFile Sets the value of the attribute with a IFile* (iFile) newVal void
setValueBoolean Sets the value of the attribute with a Boolean* (Boolean) newVal void

* - If an attribute is of a given type (String, Number) and you try to retrieve/set the value of the attribute of a different type it will throw an exception.

bridgeHandler - Represents a handler to deal with a collection attribute of an Object Model (similar to an java.util.Iterator)

Method Name Description Arguments Return Type
getName Returns the name of the collection attribute - String
beforeFirst Resets the handler to the first position of the collection - Boolean
next Advances the handler to next position of the collection - Boolean
getObject Retrieves the object in the current position of the handler - boObject
add Add a new object to the end of the collection (Long) BOUI void
remove Removes the current    
Topic attachments
I Attachment Action Size Date Who Comment
PNGpng JavaAPIboSession.png manage 31.7 K 2010-12-23 - 11:38 PedroRio boSession e EboContext
Edit | Attach | Print version | History: r24 | r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r6 - 2010-12-23 - PedroRio
 

No permission to view TWiki.WebTopBar

This site is powered by the TWiki collaboration platform Powered by Perl

No permission to view TWiki.WebBottomBar