4.4. import site: Import Site

A site declaration makes an Orc site that is present in the environment available for use by the program.

Orc sites provide operations such as arithmetic functions, platform facilities, or Web services for Orc programs to invoke. The Orc standard prelude, which is implicitly included in Orc programs by the compiler, contains declarations for all items in the Orc standard library. Sites beyond those in the standard library are made available by a site declaration. A site declaration names a variable to bind to the site and specifies a location from with the site is obtained (site resolution). In the present Orc implementation, this location is specified as a fully qualified name of a class that can be loaded from the JVM classpath.

4.4.1. Syntax

[26]DeclareSite::= import site Variable = ClassName  

4.4.2. Site Resolution

A site is resolved as follows: The site class loader is requested to load the class of the fully qualified name specified in the site declaration. The resolver verifies that the loaded class is a subtype of orc.values.site.Site. If so, that class is bound to the variable name in the site declaration. If it is not, the resolver attempts to load the Scala companion module for this class. If this exists and is a subtype of orc.values.site.Site, it is bound to the variable name in the site declaration. If it is not found, or is not the expected type, site resolution fails.

The site class loader referred to above is the usual JVM stack of delegating class loaders. In the Orc implementation, the stack is initially the first non-null of: 1) the current thread's context class loader, 2) the class loader of the site resolver class, or 3) the JVM system class loader. This loader has a URL class loader stacked on it if a site classpath is configured. Thus, if a site classpath is configured, is is searched first. If no class is found on the site classpath, or the site classpath is not configured, then the normal classpath is searched.

4.4.3. Type

The type of a site is determined entirely by the site itself. It may be representable in Orc, for example as a function type, or it may be an entirely opaque type. The type of a site behaves very much like a site itself during typechecking; it is invoked with argument types and responds with a return type.

The Orc typechecker cannot independently verify that a site's stated type is correct. If the site misrepresents its type, this may result in a runtime type error.

4.4.4. Examples

Declaring a user-supplied site
 - Assume a JVM class file named com.example.MySite is
 - availalble on the classpath, and that it implements
 - the orc.values.site.Site trait.

import site MySite = "com.example.MySite"


4.4.5. Related Links

Related Reference Topics

Related Tutorial Sections