Embedded Java source code

java instruction

Description

The java instruction is used to embed Java source code within Obix source code.

For more information about embedded Java, please refer to Chapter 10, Embedded Java source code.

Syntax

Table 8.31. java syntax

ProductionSyntaxLinks
java_instruction

"java"
   // any Java source code
"end java"

the section called “java instruction”

Examples

Example 8.26. java example

service instruction_examples

   command embedded_java_example
      script
      
         var string hello_from_java = "Hello from Java"
         var string hello_from_obix
         
         java
            // access variable defined in Obix code
            System.out.println(v_hello_from_java.a_value_get().java_value());
            
            // use Obix service
            li_obix.li_system.li_user_interface.se_console.co_message_command(v_hello_from_java);
            
            // assign value to variable defined in Obix code
            v_hello_from_obix = new fa_string("Hello from Obix");
         end java
         
         // display value defined in Java code
         se_console.co_message ( v_hello_from_obix )

      end script
   end command
     
end service

The above code displays the following on the system console:

Hello from Java
Hello from Java
Hello from Obix