One of the more elegant aspects of EGL is its
use of resource bindings, each of which is a value that describes
how to access a service or database. In most cases, you maintain bindings
in an EGL deployment descriptor, which is external to your logic.
The deployment descriptor provides the access details when you are
developing or deploying your application.
This use of the deployment descriptor is safe and flexible. You
can change the details stored there and redeploy the code without
changing the logic and without spending the time to regenerate output.
The typical process
The binding mechanism
is the same for service and database access. The typical process is
to write a resource binding in an EGL deployment descriptor and to
relate a variable to the stored resource binding in either of two
ways:
- By invoking the SysLib.getResource function; or
- By writing a Resource annotation.
Here is an example use of the function, which can be
invoked only inside an EGL function:
myService MyInterfaceType?;
myService = SysLib.getResource("binding:myBinding");
Here
is the equivalent annotation, which you can specify anywhere that
you can declare a variable:
myService MyInterfaceType?{@Resource{uri="binding:myBinding"}};
// another declaration
myService02 MyOtherInterfaceType?{@Resource};
The
uri annotation field is optional and refers by default to a resource
binding that has the same name as the variable. For example, in the
preceding annotation, the missing value for the uri field is
"binding:myService02".
Whether you specify the function or annotation:
Bindings in your code
A resource binding
includes a series of fields that are characteristic of a particular
type of binding. For example, a REST service binding has fields that
are different from those in an SQL database binding. The existence
of binding types means that you can go beyond the typical process
described earlier:
- You might define a variable that is of the appropriate binding
type. You can assign field values to that variable and use the variable
for resource access. In this case, the resource binding is solely
in your code.
- In relation to service bindings, you can initialize the variable
with values from the EGL deployment descriptor and then update the
fields in your code.
For further information
The next topics
give further details: