Technical Paper
Neuron Data's OOScript (Object-Oriented Script) is a powerful language in aiding professional developers quickly build business-critical applications. OOScript is easy to learn, yet powerful in integrating graphical user interface objects, data sources, business rules and external objects into distributed application functionality. The OOScript language combines the speed of 3GLs with the visual programming style and productivity of today's 4GLs. The OOScript language is consistent across the Neuron Data ELEMENTS ENVIRONMENT suite of products. It is event-based, compiled as needed at run time for fast execution, and provides extensibility and immediate portability for applications.
The OOScript language is used to define the dynamics of the application through the use of statements, classes, custom verbs, interoperable objects and events (defined below). A script is a collection of statements that control the actions that take place when an event occurs. Scripts can be called from a GUI Widget like a window or button, a program module, a data access object, an applet embedded in HTML or can be an independent script that can be created and invoked dynamically. The Script specifies the behavior of an object during the application processing session. A script provides two functions: control of objects like GUI widgets, data sources and external objects, and control of application logic.
OOScript includes a compiler and a script engine for interactive development and testing, access to pre-packaged classes for fast development, events, the language constructs (if-then-else, while loop, procedures, break, etc.), a script editor with class browser for point and click development, and a C/C++ API for executing script from 3GL languages.
OOScript Language Highlights
Event-Based
The script language is event-driven. It provides high productivity and flexibility
to developers by incorporating default script behavior, and supporting customization
to meet specific application needs. Default script behavior for objects at the class
level is automatically executed if a script is not attached to the object. Default
scripts can be accessed from custom scripts, minimizing the code required to execute
an action.
Interoperable
The OOScript language is designed to be both interoperable with many object types
as well as with 3GL programming languages. Neuron Data objects as well as external
objects can be access using OOScript's simple, yet powerful dot notation syntax.
OOScript allows for external objects, like OLE objects, to be accessed transparently
by the application developer. OOScript can also be mixed with C or C++ code.
Portability
The script language provides complete portability for scripts across all hardware,
GUI, object model and data sources supported by Neuron Data. Since the scripts are
implemented via the Elements Architecture open API, they are insulated from the
complexities of the native windowing system and machine dependent features,
guaranteeing application portability across databases, window managers and Object
Model standards.
Extensibility
The script language provides extensibility in four ways:
Compiled for Fast Execution
Scripts can be attached to any GUI, rules or data access object. They are saved along
with the rest of your application's resources as a text string, and are compiled into
a p-code on an as-needed basic. This allows for fast and efficient execution of
applications.
Easy to learn
OOScript is a simple 4GL style of language but with powerful object-oriented
capabilities. Based upon the simple language statements of Visual BASIC and C it
provides an easy to learn language that Visual BASIC and C programmers will find
familiar. The script language provides this capability without the compiling and
linking cycle required by conventional programming languages like C & C++.
Pre-programmed functionality is provided through simple declarative statements and
an extensive class library. This allows for easy-to-write and easy-to-maintain code.
Object-Aware
Even though OOScript is based upon common programming languages. It has powerful
object-oriented capabilities. Using a simple dot-notion syntax. An object's
attributes and methods can be referenced by name. In this way, the power of objects
can be utilized to build powerful business-critical applications.
OOScript Features
Class Libraries
Neuron Data provides access to an extensive set of pre-defined classes. Instanced
objects can be accessed via the script language using the INTEROPERABLE OBJECTS
ELEMENT (IOE). IOE is an architecture that gives access to all internal Neuron Data
classes and objects as well as external object servers via standard object models like
OLE.
There are five Neuron Data class libraries provided:
The Data Access and Intelligent Rules objects are available as stand-alone servers that can be accessed from non-Neuron Data clients via IOE. For example, an OLE-enabled application such as an Excel Spreadsheet can access the DAE or Rules Server without recompilation or linking. IOE is explained in more detail in the INTEROPERABLE OBJECTS ELEMENT datasheet.
External Objects
The OOScript language can also provide access to external objects via the
INTEROPERABLE OBJECTS ELEMENT (IOE). External objects are accessed via drivers
to a specific object model like OLE or in the future, CORBA-based servers.
Now, external objects, such as Excel spreadsheet objects, ReportWriter objects, or
any other OLE-automation-enabled server, through OLE for the Microsoft Windows 3.1x,
Windows NT and the Windows 95 platforms using the same OOScript syntax. The initial
release of IOE will supports OLE. In the future, additional drivers supporting CORBA
standards will be added.
Custom Verbs
Verbs are custom routines, that are extensions to OOScript and written in a
programming language such as C or C++. Any script statement can invoke a verb.
A verb can be any action related to the application. The extensibility of the script
language allows developers to create portable custom verbs to meet specific
application requirements. Custom verbs can be registered with the script engine
so that the script language can call the verbs to produce actions specific to the
application.
Events
A system event like a button push results in the execution of a script. An event
may get generated as a result of any of the following actions:
Examples of events:
Event Name HIT | When Sent After the end user clicks the mouse selection button with the mouse cursor positioned over a push, radio, or check button. |
Event Name OPENED | When Sent After the system opens the window |
In the examples above, the event HIT was generated as a result of an end-user interaction with the user interface, and the event OPENED was generated by the application.
Event answers in OOScript are coded in two ways. As an event handler, attached to the object that receives the event, like a window, GUI widget or Data Access object or as an event callback. A callback is an OOScript procedure attached to a specific Object in answer to a specific event.
Event Handlers
Event answers in OOScript can be defined as an event handler. A script can consists of a series of event handlers, where each handler is responsible for handling a particular event. Event handlers are coded in script that is attached to the widget. The syntax of the event handler is as follows:
on event XXX statement 1 ; statement 2 ....... statement n ; end eventwhere XXX is the name of the event, and statements 1, 2 and n may be any type of OOScript statement (Except an "on event" statement).
Event Callbacks
An event callback is an OOScript procedure attached to a specific object for a particular event. A callback is assigned to the object as an OOScript statement. This allows for sharing of callbacks between objects. Also, because the event processing procedures can be maintained and stored independently of the objects better modular code can be written.
The following example assigned the procedure ExitOnHit to the button ExitButton in module MyMod:
MyWindow.ExitButton.HitProc = "MyMod::ExitOnHit";In this case, the event HIT, invokes the procedure ExitOnHit().
Custom Events
Neuron Data's ELEMENTS ENVIRONMENT includes a comprehensive set of default events for GUI, Data Access and Rules objects and at the application level. A developer also has the flexibility of creating portable custom events to meet specific application needs.
Creating and Editing OOScript
OOScript is created using the visual script editor. OOScript application code can be organized in a number of different ways. Primarily, OOScript can be attached to a widget or coded in modules. Script can also be organized as downloadable applets or created and executed dynamically as bare scripts. Script associated with widgets are normally implemented as event handler. Module script usually consist of procedure definitions, global variable and server initializations but can also consist of callback that define the procedures executed in response to specific events. Applets contain script procedures that are associated with an HTML directive and downloaded via the Neuron Data WEB ELEMENT to a client machine at runtime. Bare scripts are independent scripts that can be stored in files or as string resources within an application. Bare scripts can be created and compiled dynamically at runtime and can be executed through an API.
The Script Editor is a visual editor that lets you build and edit scripts for different objects within the ELEMENTS ENVIRONMENT. It can be invoked on any Neuron Data object within the ELEMENTS ENVIRONMENT at any time. The Script Editor displays a browser that lets you select external servers, classes, modules or script procedures that can be inserted into your application script. The script editor browser can also browse external objects via INTEROPERABLE OBJECTS ELEMENT. Further, the Script Editor allows you to copy and paste using standard keyboard commands, making it easy to reuse a script for another object or to make a copy and modify it.
OOScript Language
Statements
OOScript is a series of statements that represent the application logic. Statements
can be nested in conditional or loop statements. There are a number of basic
concepts in the script language:
Variables are place holders for the actual data or object references. They can also be reused within different event handlers of the same or different objects, procedures or modules, depending upon their scope. Two levels of scoping are provided for variables:
Data Types
The script language supports the familiar data types such as integer, float, double, pointer and string. In addition, all objects, accessed via INTEROPERABLE OBJECTS ELEMENT are referenced with the data type 'object'. The Variant datatype is supported which defines the datatype of a non-declared variable or unknown datatype.
Arrays
The OOScript language supports arrays. Arrays can be dynamic (no pre-defined boundaries) or static (pre-declared). Arrays can be single or multi-dimensional and support all of Neuron Data's basic data types. Boundaries can be pre-defined using any integer representation, omitted (thus dynamic) and queried (through built-in operators). Associative arrays are also supported.
Procedures and Functions
Procedures and functions are supported in the OOScript language. As with the other features of OOScript, they are portable across platforms. Procedures can be called in any block of OOScript code. Parameters are passed as in (these cannot be modified by the procedure), out parameters (will be modified by the procedure) or in-out parameters. Parameters can be of any of the script basic types or arrays. Procedures are declared local in scope to script module but can be accessed outside the scope of a module explicitly. Procedures support recursion.
This example show the definition of a procedure:
// calculate a factorial integer proc Factorial (integer i) if (i == 1) return 1; return i * Factorial (i - 1); end procDynamic OOScript
Script can be executed from a C or C++ program. These scripts, called bare scripts, are not attached to a widget or module are be just a list of statements to be executed. There is a C & C++ API to compile and execute these scripts.
Script Notation
The notation used in the OOScript language allows you to write simple declarative statements to access from object, to subobject, to property or method. The notation takes the form <object>.{Property | SubObject | Method}. For example, an Order Window has an entry field called Name. To assign a string to that field:
OrderWindow.Name.String = "Smith";To access an object method, in this case, to terminate a window:
OrderWindow.Terminate();
Examples of OOScript
In the OOScript language, access to any object is done through an INTEROPERABLE OBJECTS ELEMENT server (GUI, Data Access, Rules, Core services, Web, or external). You will need to first "connect" to the server by creating an instance of it getting back its reference which you will reuse across all of your application.
// To access an Intelligent Rules server: // Define an Object object myRulesSvr; myRulesSvr = getserver( "ND.Nx"); // get a rules server instance reference myRulesSvr.KBs.Load ("satfault.tkb"); // load knowledge base using the load methodThis example shows how to access GUI objects in a window:
// To access a GUI server // Global variables declaration global integer start; object myGuiSvr; object Win; // Script variables declaration integer count = 0; // Event handler for the event INITIALIZE on event INITIALIZE if (start == 0) return; myGuiSvr = getserver ("ND.Gui"); Win = myGuiSvr.Windows.Load("app1","win1"); Win.Init(); Win.BgColor = myGuiSvr.Color.Blue; Win.Show(); start = 1; end event // Event handler for a button hit event on event HIT count += 1; SELF.String =string(count); end event
Copyright 1996 Neuron Data, Inc. The ELEMENTS ENVIRONMENT, DATA ACCESS ELEMENT,
DISTRIBUTED MESSAGING ELEMENT, INTELLIGENT RULES ELEMENT, INTEROPERABLE OBJECTS
ELEMENT, OPEN INTERFACE ELEMENT, WEB ELEMENT, Open Editor and OOScript are
trademarks of Neuron Data. Other product names are trademarks and/or trade names
of their respective manufacturers.
|