Service

Description

A service provides attributes, commands and events that can be used from within any script.

Each service is identified by a unique service identifier. A service identifier is a prefixed identifier starting with se_ as prefix. For more information about prefixed identifiers see the section called “Prefixed identifier”.

Unlike objects, services don't need to be created. They are available all the time, and they are accessed through their identifier.

Any number of services can exist, but services should be organized in such a way that one service contains only features belonging to a logical group of features (e.g. a specific domain). For example, a math service contains mathematical constants and formulas, whereas a net service contains attributes and commands related to networking.

Like a factory, a service can also contain private attributes and commands which can only be accessed from scripts inside the service.

Syntax

Table 5.3. Service

ProductionSyntaxLinks
service

"service" ( "id" ":" ) ? service_id
   RSE_java_code ?
   attribute_list ?
   attribute_list_check ?
   command_list ?
   event_list ?
   RSE_test_script ?
"end" "service" ?

the section called “Service”

Example

Example 5.10. XML utilities service

The following code shows a service that provides attributes and a command to create simple XML tags.

service XML_utilities

   attribute_list type:string
      attribute tag_start_open default: "<" end
      attribute tag_end_open   default: tag_start_open & "/" end
      attribute tag_close      default: ">" end
   end attribute_list
   
   command create_XML_tag
      in tag type:string end
      in data type:string end

      out result type:string end

      script
         o_result = a_tag_start_open & i_tag & a_tag_close & &
         	i_data & &
         	a_tag_end_open & tag & a_tag_close
      end
   end

end service

See Example 5.9, “Factory supplier using a service” for an example of how to use the above service.


[Note]Note
A service in Obix is similar to a class with only static members in Java or C#.

See also