
EGL predefines the Serializable external type, which you can reference if you are defining an external type that is based on a Java class that itself implements the java.io.Serializable interface. If the external type that you are defining does not extend the EGL Serializable external type, any EGL variables that are based on that external type are marked as transient in the generated Java code. Transient variables are not preserved when a Java object is serialized by a runtime platform such as an application server. For example, serialization might occur when the server creates a backup copy of the object in response to a shut down.
The function can return a primitive-type value, an array, or no value at all. The function cannot return a record.
Function nextElement() { JavaName = "next" };
Variable declarations can also include the following properties:
UpperLimit INT { @JavaProperty{} };
A field is read only if getMethod is specified but setMethod is not, and a field is write-only if setMethod is defined but getMethod is not. An error occurs if you try to set the value of a read-only field or to get the value of a write-only field.
For example, consider the java.beans package, which a Java developer uses to code a kind of Java class typically known as a Java bean or, more simply, a bean. Among its capabilities, a bean can invoke a method of a Java object in response to a runtime event. The rest of this description assumes that the runtime event is a change of a property value in the bean. .
The Java developer registers that type of event by invoking the addPropertyChangeListener method of the bean and by passing a PropertyChangeListener object. In general terms, the PropertyChangeListener object is an event listener.
After a property value changes, the bean calls the event listener. Specifically, the bean calls the propertyChange method of the PropertyChangeListener object and passes a PropertyChangeEvent object that gives details about the change.
A further detail is that the event listener is based on a Java interface, and the propertyChange method is specific to a business application. The EGL developer's use of the @eventListener property means that the EGL-generated propertyChange method invokes logic that is derived from a developer-coded EGL function.
In the current example, the value of addMethod is “addPropertyChangeListener”.
In the current example, the value of listenerType is “java.beans.PropertyChangeListener”.
In the current example, the value of method is “propertyChange”.
ExternalType MyBean type JavaObject
onPropertyChange PropertyChangeDelegate
{ @eventListener{ addMethod = "addPropertyChangeListener",
listenerType = "java.beans.PropertyChangeListener",
method = "propertyChange" } };
end
The onPropertyChange field is not in the bean, but is present so that the listener pattern is available in your EGL code, where you assign that EGL function that will be invoked when an event occurs.
Delegate PropertyChangeDelegate( evt PropertyChangeEvent in )
end
ExternalType PropertyChangeEvent type JavaObject { packageName = "java.beans" }
function getPropertyName() returns ( string );
// You might make available other methods of java.beans.PropertyChangeEvent.
end
program MyEGLProgram
function main()
mb MyBean{ onPropertyChange = propChange };
end
function propChange( evt PropertyChangeEvent in )
writeStdout( "Property " :: evt.getPropertyName() :: " has changed." );
end
end
The program creates a variable of type MyBean, assigns a function to the onPropertyChange field of that type, and defines the function itself. When a property value changes in the bean, the function is invoked and uses getPropertyName, which is the one method that was made available from the PropertyChangeEvent object.
Always assign the @eventListener property to a variable that is based on a Delegate part. The characteristics of the Delegate part must conform to an event-handling method such as propertyChange, which is in a specific Java event listener such as PropertyChangeListener.
When you reference Java field and method names in the code, remember that they are case sensitive, even though the equivalent EGL names are not.