Difference between revisions of "Function Library DSL"

From OS.bee documentation
Jump to: navigation, search
(group)
(blip group)
Line 194: Line 194:
 
package <package name>  {
 
package <package name>  {
 
}
 
}
 +
</syntaxhighlight>
 +
 +
 +
► '''Example''':
 +
<syntaxhighlight lang="java">
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 07:58, 23 October 2017

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

Syntax:

package <package name>  {
}


Example:

converter

Syntax:

package <package name>  {
}


statemachine

Syntax:

package <package name>  {
}


rating

Syntax:

package <package name>  {
}

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