Home > Services
Programmatic Access
A Programmatic Access is an advanced features that provides a read only access to EBX.Platform repository data.
The consumer Java/JSP application uses EBX.Platform API but does not need a session as opposed to a Programmatic Service.
Example of Programmatic Services:
- Get parameters for Java application configuration
- ...
Loading / verifying an adaptation instance
Each adaptation instance created with EBX.Manager is persisted in the EBX.Platform repository and has a unique reference. In order to use its Master Data, the Java application has first to find an adaptation by its reference.
In order to know the root adaptation reference, log into EBX.Manager, select a branch and select an adaptation root in the left pane (for example, the "Books" adaptation instance as illustrated below). The reference is displayed at the right of the adaptation label (in brackets).
The Java expression used to load an adaptation instance by using its reference name (here "Books") is:
AdaptationName.forName("Books" ).resolve();
Below is described a complete example we have created for initializing an HTTP session. This program registers the adaptation into the session, in order to use it later.
{
// Finds the adaptation whose reference is passed via HTTP request parameter
String adaptationName = aRequest.getParameter("adaptation");
Adaptation adaptation = AdaptationName.forName(adaptationName).resolve();
// Checks adaptation exists.
if (adaptation == null)
return aRequest.getRequestDispatcher("/pageErrorAdaptationNotFound.jsp");
// Checks adaptation status.
ActivationStatus status = adaptation.checkActivable();
if (!status.isOK())
return aRequest.getRequestDispatcher("/pageErrorActivationNotOK.jsp");
// OK - register adaptation into session context
ServletUtils.registerContextToSession(adaptation, session);
return aRequest.getRequestDispatcher("/page1.jsp");
}
Access to a Master Data from a Java application
EBX.Platform API provides two ways to get Master Data: Java code or JSP TagLib. In order to get a Master Data, you have to specify its path in the adaptation model.
Java code example
To write the path to a Master Data, you can use the Developer
Assistant in
EBX.Manager. Navigate in the root adaptation and use the button
at
the right of the Master Data, then choose the option %PATH.
Copy/Paste the code in your Java code.
String label = adaptation.getString(AspectPath.forName("/domain/rebate/label"));
Date beginDate = adaptation.getDate(AspectPath.forName("/domain/rebate/beginDate"));
if (adaptation.get_boolean(AspectPath.forName( "/domain/product_xv37/isDisplayed")))
/* action */ ;
JSP code example
The Developer Assistant in EBX.Manager
allows you to generate JSP Tag for Master Data access. Click on the button
at
the right of the Master Data and then choose the option <ebx:display
name="%path"/>.
Copy/Paste the code in your JSP code.
<table border ="0" cellpadding ="2" cellspacing ="2" width ="100%">
<tr>
<td><ebx:display name ="/domain/product_xv34/productLabel"/></td>
<td><ebx:display name ="/domain/product_xv34/price"/></td>
</tr>
<tr>
<td><ebx:display name ="/domain/product_xv37/productLabel"/></td>
<td><ebx:display name ="/domain/product_xv37/price"/></td>
</tr>
<tr>
<td><ebx:display name ="/domain/product_xz12/productLabel"/></td>
<td><ebx:display name ="/domain/product_xz12/price"/></td>
</tr>
</table>
<!-- END PRODUCT TABLE -->
Java interfaces generation
EBX.Platform allows you to generate Java types from an adaptation model. This feature guarantees a better reliability and productivity in your development. We strongly recommend to use this feature.
The Java code generation can be done in EBX.Manager (see section Developer Assistant : Button "Generate Java") or with and Ant Script (see section Using Ant).
Accès programmatique
Un Accès programmatique est une fonctionnalité avancée qui permet un accès en lecture seule aux données de EBX.Platform.
L'application Java/JSP consommatrice utilise les API EBX.Platform mais ne nécessite pas de session contrairement à un Service Programmatique.
Exemple d'Accès Programmatique:
- Récupérer des paramètres pour la configuration d'une application Java
- ...
Récupération / Vérification d'une adaptation instance
Chaque adaptation instance créée avec EBX.Manager est persistée dans le référentiel XML et dispose d'une référence unique. L'application utilisatrice doit appeler l'adaptation pour utiliser ses Master Data.
Pour connaître la référence d'une adaptation racine, connectez-vous à EBX.Manager, sélectionnez une branche puis sélectionnez une adaptation racine (par exemple, le modèle " Books" illustré ci-dessous). La référence figure à droite du libellé de l'adaptation (entre parenthèses) :

L'expression Java qui permet de récupérer l'adaptation de nom "gettingStarted" est la suivante :
AdaptationName.forName("gettingStarted" ).resolve();
Voici un exemple complet, effectué dans un cadre d'initialisation d'une session HTTP, qui enregistre l'adaptation au sein de la session afin d'utiliser les balises EBX.Platform (voir plus bas) :
{
// Finds the adaptation whose reference is passed via HTTP request parameter
String adaptationName = aRequest.getParameter("adaptation");
Adaptation adaptation = AdaptationName.forName(adaptationName).resolve();
// Checks adaptation exists.
if (adaptation == null)
return aRequest.getRequestDispatcher("/pageErrorAdaptationNotFound.jsp");
// Checks adaptation status.
ActivationStatus status = adaptation.checkActivable();
if (!status.isOK())
return aRequest.getRequestDispatcher("/pageErrorActivationNotOK.jsp");
// OK - register adaptation into session context
ServletUtils.registerContextToSession(adaptation, session);
return aRequest.getRequestDispatcher("/page1.jsp");
}
Accès à une Master Data depuis une application Java
L'API EBX.Platform propose deux modes d'accès aux Master Data : sous la forme de code Java ou d'une balise JSP. L'appel d'une Master Data consiste à écrire son chemin d'accès dans le modèle d'adaptation.
Exemple de code Java
Pour écrire le chemin d'accès à une Master Data, vous pouvez utiliser
l'assistant développeur de EBX.Manager.
Naviguez dans l'adaptation racine du modèle d'adaptation et utilisez le bouton
à droite de la
Master Data, puis choisissez l'option %PATH. Il suffit de copier/coller le code généré
dans le code Java.
String label = adaptation.getString(AspectPath.forName("/domain/rebate/label"));
Date beginDate = adaptation.getDate(AspectPath.forName("/domain/rebate/beginDate"));
if (adaptation.get_boolean(AspectPath.forName( "/domain/product_xv37/isDisplayed")))
/* action */ ;
Exemple de code JSP
L' Assistant Developpeur de EBX.Manager vous permet de
générer automatiquement les balises JSP pour accéder à une Master Data.
Cliquez sur le bouton
à droite de la Master Data puis choisissez l'option <ebx:display name="%path"/>.
Il suffit de copier/coller le code dans votre page JSP.
<table border ="0" cellpadding ="2" cellspacing ="2" width ="100%">
<tr>
<td><ebx:display name ="/domain/product_xv34/productLabel"/></td>
<td><ebx:display name ="/domain/product_xv34/price"/></td>
</tr>
<tr>
<td><ebx:display name ="/domain/product_xv37/productLabel"/></td>
<td><ebx:display name ="/domain/product_xv37/price"/></td>
</tr>
<tr>
<td><ebx:display name ="/domain/product_xz12/productLabel"/></td>
<td><ebx:display name ="/domain/product_xz12/price"/></td>
</tr>
</table>
<!-- END PRODUCT TABLE -->
Génération des interfaces Java
EBX.Platform permet de générer des types Java à partir d'un modèle d'adaptation. Cette fonctionnalité apporte entre autres une meilleure fiabilité des accès et une meilleure productivité du développement. En conséquence, il est fortement recommandé d'utiliser cette fonctionnalité.
La fonction de génération est facilement accessible à partir de l'outil EBX.Manager (voir la section Assistant développeur : Bouton "Générer Java"). On peut aussi la mettre en oeuvre au moyen d'un script Ant (voir la section Utilisation de Ant).
Home > Services