Difference between revisions of "Function Library DSL"
(→blip group) |
(→converter) |
||
Line 233: | Line 233: | ||
=====converter===== | =====converter===== | ||
+ | |||
+ | Keyword '''converter''' is used to define the converter for different units, e.g. cm -> m, g -> kg…. | ||
► '''Syntax''': | ► '''Syntax''': | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
− | + | converter <converter name> { | |
+ | model-datatype <DataType1> | ||
+ | presentation-datatype <DataType2> | ||
+ | to-model {<block expression1>} | ||
+ | to-presentation {<block expression2>} | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | * Data type for model and data type for presentation must be defined. | ||
+ | * The converter function defined in the block expression. The function for model should be defined after keyword '''to-model''' in the {} ; and the function for presentation should be defined after keyword '''to-presentation''' in the {}. | ||
► '''Example''': | ► '''Example''': | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
+ | converter UomoKMMetricConverter { | ||
+ | model-datatype Double presentation-datatype BaseAmount | ||
+ | to-model { | ||
+ | var localUnitFormat = LocalUnitFormatImpl.getInstance( presentationLocale ); | ||
+ | var baseUnit = localUnitFormat.format( MetricLengthUnit.KM ) var suffix =( presentationParams.get( 1 ) as String ) if( suffix == null ) { | ||
+ | uffix = baseUnit | ||
+ | } | ||
+ | if( localUnitFormat.format( MetricLengthUnit.M ).equals( suffix ) ) | ||
+ | { | ||
+ | var amount = MetricLengthUnit.amount( presentationValue, MetricLengthUnit.M ) return amount.to( MetricLengthUnit.KM ).value.doubleValue | ||
+ | } | ||
+ | else if( localUnitFormat.format( MetricLengthUnit.CM ).equals( suffix ) ) { | ||
+ | var amount = MetricLengthUnit.amount( presentationValue, MetricLengthUnit.CM ) return amount.to( MetricLengthUnit.KM ).value.doubleValue | ||
+ | } | ||
+ | else { | ||
+ | return presentationValue | ||
+ | } | ||
+ | } | ||
+ | to-presentation { | ||
+ | var amount = MetricLengthUnit.amount( modelValue, MetricLengthUnit.KM ) if( modelValue < 1d && modelValue > 0.001d ) { | ||
+ | amount = amount.to( MetricLengthUnit.M ) | ||
+ | } | ||
+ | else if( modelValue < 0.001d ) { | ||
+ | amount = amount.to( MetricLengthUnit.CM ) | ||
+ | } | ||
+ | return amount as BaseAmount | ||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 08:03, 23 October 2017
Contents
Introduction
Function Library model defines the java functions for Os.bee. It could be used in other models. For example, in entity Person, the function getImagePickerMap from group ComboBox is used here.
Function Library DSL
The FunctionLibraryDSL defines the java functions for Os.bee and the functions will be used in other Os.bee models..
The main semantic elements of the FunctionLibraryDSL are:
- package - The root element that contains all the other elements. A model can contain multiple packages.
- import declarations - Used to import external models or other Java classes.
- group - define the function group, including function, test and rate.
- blip-group - define the function group for blip, including function, test and rate.
- converter - define the function for converter.
- statemachine - define the function for statemachine.
- rating - define the rating, all value of the rating will be saved as enum.
Syntax
package definition
► Syntax:
package <package name> {
group <group name> {. . .}
|blip-group <blipGroup name> {. . .}
|converter <converter name> {. . .}
|statemachine <statemachine name> {. . .}
|rating <rating name> {. . .}
. . .
}
► Example:
package net.osbee.sample.foodmart.functionlibraries {
group Lengths {. . .}
. . .
blip-group ProductMaintenance {. . .}
. . .
converter UomoGRAMMetricConverter {. . .}
. . .
statemachine CashRegister {. . .}
. . .
rating CountRating {. . .}
. . .
}
- For every group, blip-group, converter, statemachine or rating, a new .java files will be generated, <group/blip-group/converter/statmachine/rating name>.java. This .java files is generated in folder ./src-gen/<package name>/.
important definition
There are 3 important definitions of FunctionLibraryDSL which will be used in more than one place; they are FunctionLibraryFunction, FunctionLibraryTest and FunctionLibraryRate.
FunctionLibraryFunction
FunctionLibraryfunction defines the function for functionlibrary.
► Syntax:
function <function name> ([<JvmType1> <parameter1> [, <JvmType2> <parameter2>]. . .]) returns <JvmType3>
{<block expression>}
- One or more function parameter can be defined in () follow the function name. The parameter must be defined with its data type.
- The data type of return value can be defined after keyword returns.
- Inside {}, the function expression will be defined.
► Example:
function getTaskId(Context context) returns Long {
return Library.getTaskId(context);
}
FunctionLibraryTest
FunctionLibraryTest defines the test function for function library.
► Syntax:
test <test name> ([<JvmType1> <parameter1> [, <JvmType2> <parameter2>]. . . ] )
{<block expression>}
- One or more test parameter can be defined in () follow the test name. The parameter must be defined with its data type.
- The return value of test function is only true or false.
- Inside {}, the test function expression will be defined.
► Example:
test isNearZero( double value ) {
return Math.abs( value ) < Float.MIN_VALUE
}
test noProductsSelected( Object kcontext ) {
return rateCountOfProductsSelected( kcontext ).equals( CountRating.NONE )
}
FunctionLibraryRate
FunctionLibraryRate define the rate function for function library.
► Syntax:
rate <rate name> ([<JvmType1 > <parameter1 > [, <JvmType2> <parameter2>]. . . ])returns [Rating name]
{<block expression>}
- One or more rate parameter can be defined in () follow the rate name. The parameter must be defined with its data type.
- The return value of rate function can only be one of the redefined rating values.
- Inside {}, the rate function expression will be defined.
► Example:
rating CountRating {
NONE
ONE
MANY
}
. . .
rate rateCountOfProductsSelected( Object kcontext ) returns CountRating {
switch( countOfProductsSelected( kcontext ) ) {
case 0 : return CountRating.NONE case 1 : return CountRating.ONE
}
return CountRating.MANY
}
group
Keyword group is used to define the normal function group.
► Syntax:
group <group name> {
FunctionLibraryFunction
| FunctionLibraryTest
| FunctionLibraryRate
. . .
}
- One or more FunctionLibraryFunction or FunctionLibraryTest or FunctionLibraryRate can be defined in the group.
► Example:
group TaskToolbar {
function getTaskId(Context context) returns Long {
return Library.getTaskId(context);
}
function claimCanExecute(Context context) returns boolean {
var userName = Library.getUserName(context);
if( "Administrator".equals( userName ) ) {
return false
}
return Library.isTask(context, Status.Created);
}
function startCanExecute(Context context) returns boolean {
var userName = Library.getUserName(context);
if( "Administrator".equals( userName ) ) {
return false
}
return Library.isTask(context, Status.Ready);
}
function resumeCanExecute(Context context) returns boolean {
var userName = Library.getUserName(context);
if( "Administrator".equals( userName ) ) {
return false
}
var suspended = Library.isTask(context, Status.Suspended);
var progress = Library.isTask(context, Status.InProgress);
return( suspended || progress )
}
}
blip group
Keyword blip-group is used to define the blip function group.
► Syntax:
blip-group <blipGroup name> {
FunctionLibraryFunction
| FunctionLibraryTest
| FunctionLibraryRate
. . .
}
- One or more FunctionLibraryFunction or FunctionLibraryTest or FunctionLibraryRate can be defined in the blip group.
► Example:
blip-group MultipleEndEventsEverythinNeedsToBeDone {
function NecessaryTask1_Enter( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 1 - enter" ) )
}
function NecessaryTask1_Exit( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 1 - EXIT" ) )
}
function NecessaryTask2_Enter( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 2 - enter" ) )
}
function NecessaryTask2_Exit( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 2 - EXIT" ) )
}
function NecessaryTask3_Enter( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 3 - enter" ) )
}
function NecessaryTask3_Exit( Object kcontext ) returns void {
System.err.println( appendProcessProtocol( kcontext, "Necessary Task 3 - EXIT" ) )
}
}
converter
Keyword converter is used to define the converter for different units, e.g. cm -> m, g -> kg….
► Syntax:
converter <converter name> {
model-datatype <DataType1>
presentation-datatype <DataType2>
to-model {<block expression1>}
to-presentation {<block expression2>}
}
- Data type for model and data type for presentation must be defined.
- The converter function defined in the block expression. The function for model should be defined after keyword to-model in the {} ; and the function for presentation should be defined after keyword to-presentation in the {}.
► Example:
converter UomoKMMetricConverter {
model-datatype Double presentation-datatype BaseAmount
to-model {
var localUnitFormat = LocalUnitFormatImpl.getInstance( presentationLocale );
var baseUnit = localUnitFormat.format( MetricLengthUnit.KM ) var suffix =( presentationParams.get( 1 ) as String ) if( suffix == null ) {
uffix = baseUnit
}
if( localUnitFormat.format( MetricLengthUnit.M ).equals( suffix ) )
{
var amount = MetricLengthUnit.amount( presentationValue, MetricLengthUnit.M ) return amount.to( MetricLengthUnit.KM ).value.doubleValue
}
else if( localUnitFormat.format( MetricLengthUnit.CM ).equals( suffix ) ) {
var amount = MetricLengthUnit.amount( presentationValue, MetricLengthUnit.CM ) return amount.to( MetricLengthUnit.KM ).value.doubleValue
}
else {
return presentationValue
}
}
to-presentation {
var amount = MetricLengthUnit.amount( modelValue, MetricLengthUnit.KM ) if( modelValue < 1d && modelValue > 0.001d ) {
amount = amount.to( MetricLengthUnit.M )
}
else if( modelValue < 0.001d ) {
amount = amount.to( MetricLengthUnit.CM )
}
return amount as BaseAmount
}
}
statemachine
► Syntax:
package <package name> {
}
► Example:
rating
► Syntax:
package <package name> {
}
► Example:
Copyright Notice
All rights are reserved by Compex Systemhaus GmbH. In particular, duplications, translations, microfilming, saving and processing in electronic systems are protected by copyright. Use of this manual is only authorized with the permission of Compex Systemhaus GmbH. Infringements of the law shall be punished in accordance with civil and penal laws. We have taken utmost care in putting together texts and images. Nevertheless, the possibility of errors cannot be completely ruled out. The Figures and information in this manual are only given as approximations unless expressly indicated as binding. Amendments to the manual due to amendments to the standard software remain reserved. Please note that the latest amendments to the manual can be accessed through our helpdesk at any time. The contractually agreed regulations of the licensing and maintenance of the standard software shall apply with regard to liability for any errors in the documentation. Guarantees, particularly guarantees of quality or durability can only be assumed for the manual insofar as its quality or durability are expressly stipulated as guaranteed. If you would like to make a suggestion, the Compex Team would be very pleased to hear from you.
(c) 2016-2024 Compex Systemhaus GmbH