--
PedroRio - 22 Dec 2010
XEO Java API
The XEO Java API allows direct interaction with a XEO Application (instances of XEO Models and XEO Model definitions). It can be used in the following situations:
- Custom Behavior definition (for XEO Model Events, Methods, Attribute Events and Attribute Logic (requirement, validation, etc...).
- To create Schedules and Threads that perform background operations on instances of XEO Models.
- Custom development around a XEO Application (ex. Java Server Pages, Servlets, Java Server Faces)
- Creating XEO Modules
- Applications sharing the same J2EE server as the XEO application who want to access information in XEO Model instances.
Basic Concepts
A XEO application is all about creating instances of XEO Models, setting values for their attributes, processing lists of XEO Model instances, handling events generated for those instances and executing methods.
Recall from the Object Behavior chapter the basics for the
Java API.
A XEO application has an entry point which is an instance of the
boApplication class. The
boApplication instance provides access to most features of the XEO Java API. When implementing custom behavior for XEO Models, you (probably) won't need the
boApplication instance as you'll have access to instances of XEO classes that'll allow you to implement your logic.
boApplication
The
boApplication class represents the point of entry in a XEO Application and has methods to reach most of the manager classes to deal with
boObjects,
boObjectLists, Lists of Values and XEO Model definition handlers. The list of relevant methods to retrieve the classes mentioned is the following:
Method Signature |
Description |
Return Type |
Note |
getDefaultApplication() |
Retrieves the default application instance |
boApplication |
(static) |
getObjectManager() |
Retrieves an instance of the boManagerBean to load/create object instances |
boManagerBean |
|
getSecurityObjectManager() |
Retrieves an instance of the boManagerBean to load/create object instances which respects permissions declared |
boManagerBean |
|
getObjectListManager() |
Retrieve an instance of ObjectListManager to create boObject lists |
ObjectListManager |
|
getLovManager() |
Retrieve the Lov Manager to load lov instances |
LovManager |
|
getModelDefinition(String name) |
Retrieve the Model definition handler for a specific model |
boDefHandler |
|
getInterfaceDefinition(String name) |
Retrieve the Interface definition handler for a specific model |
boDefInterface |
|
createContext(boSession session) |
Create an EboContext from a session |
EboContext |
|
When creating custom Java code to define behavior for a given XEO Mode, as seen in the
Object Behavior chapter, most of the times you'll be given access to a
boObject instance and/or an
attributeHandler instance.
Whenever a user successfully logs into a XEO Application, a
boSession instance is created to represent the user session within the application and it's in that
boSession instance that several information regarding the user is stored. Transactional control can also be done at the context level, so to read more about these classes go to
boSession and EboContext API Page
boManagerLocal & boObject
The
boObject represents an instance of a particular XEO Model and is the most important class in XEO's Java API as it allows access to an instance's attributes and its definition.
To know more about the
boObject class, read the
boObject API page.
The boManagerLocal interface represents the manager of
boObject instances, which allows to create and load those instances, read more in the
boManagerLocal API page.
The
ObjectListManager class allows to create instances of the
boObjectList class which represents a lists of
boObject (as the name implies).
boObjectList instances are created by issuing
BOQL queries against the datasource (typically a DBMS) and its results are paginated (default value: 50 results per page).
boObjectList instances are much like (paged) iterators, to know more about the API check the
ObjectListManager API page and the
boObjectList API page.
Interactions with XEO Model attributes can be done using the
AttributeHandler (all but collection attributes) and
BridgeHandler (collection attributes) classes. These classes allow to retrieve and set the value(s) of the attribute as well as reaching the attribute definition. Read more about
AttributeHandler and
BridgeHandler.
boDefHandler
The
bodefHandler class is a programmatic way to have access to a XEO Model definition.
Read more about boDefHandler.
Relations between XEO Java Classes
To help understand the relation between the most important Java classes of the XEO API and how to have access them, see the two following figures (separated due to their size)
Figure JA.1 - Relations between
Figure JA.2 - Relations between Java class
_
Sample Workflow Code - Creating an instance, set attribute values and save the instance
The XEO Java API can be used arbitrarily to fit your needs, but to illustrate a situation where one needs to create an instance of XEO Model A, set the value of two attributes (
att1 and
att2) and save the instance, see the following code:
try{
//Get the application instance
boApplication app = boApplication.getDefaultApplication();
//Login a user
boSession session = app.boLogin("SYSUSER", "ABC");
//Create a context
EboContext ctx = app.createContext(session);
//Retrieve the Object Manager
boManagerBean objectManager = (boManagerBean) app.getObjectManager();
//Create a new instance object for Class "A"
boObject obj = objectManager.createObject(ctx, "A");
//Retrieve attributes and set their value
obj.getAttribute("att1").setValueString("my Value");
obj.getAttribute("att2").setValueBoolean(true);
//In the end, update the object
obj.update();
//Close all resources
ctx.close();
session.closeSession();
}
catch (boLoginException e) {
//Log login error
} catch (boRuntimeException e) {
//Write to log, or something
}
_