Section G.6. Naming Scopes


G.6. Naming Scopes

Each IDL file that you create defines a namespace or naming scope for identifiers that you declare within that file. This namespace is further subdivided into nested scopes whenever you declare a new module, interface, structure, union, or exception in your IDL file. You can think of the naming scope within an IDL file as a sort of naming directory. By default, you start at the root of the directory, and each time you open a declaration of one of these items, you start a new subdirectory of the naming directory, named after the identifier you use for the item.

You can specify scopes using the :: delimiter, which is analogous to the . delimiters in Java class names or the / or \ delimiters in file directories. The root scope for the IDL file is represented as :: by itself, and nested scopes are specified by adding their names, such as ::utils::math::MatrixOps. The names in a scope name can refer to any identifiers that might exist in each scope. In this example case, utils and math might refer to modules (the math module is declared within the utils module), and MatrixOps might refer to an interface declared within the math module. The intermediate elements of a scoped name must refer to one of the IDL elements that define their own scopes (listed previously), but the final element of a scoped name can refer to any item with its own identifier, including constants, data members on interfaces, and so forth.

Within any particular scope in the naming scope of an IDL file (including the root scope), all identifiers within that scope must be unique. Separate nested scopes off of one parent scope can have identical identifiers declared within them and can share identifiers with their parent scope as well, but two identifiers at the same level within a scope can't be the same. So you can legally declare the following in an IDL file:

 // IDL module utils {     interface math {         const float PI = 3.1416;     };     interface baking {         const string PI = "apple";     }; }; 

The two definitions of PI (::utils::math::PI and ::utils::baking::PI) don't conflict, since each has a distinct absolute scoped name within the IDL file. You can't, however, declare a constant named math within the utils module, since its fully scoped name is also ::utils::math, and conflicts with the name of the math interface.

Scoped names that begin with :: are absolute names and are relative to the root file scope of the IDL file. Names that don't start with :: are relative to the local scope in which they appear. So in our previous example, we could add two new constants to our math interface that use scoped names to reference our versions of PI:

 // IDL module utils {      interface math {           const float PI = 3.1416;           const float PIsquared = PI * PI;           const string PIOfTheDay = ::utils::baking::PI;      };      interface baking {           const string PI = "apple";      }; }; 

The reference to PI in the definition of the PIsquared constant is relative to the ::utils::math scope, so it refers to the float constant. The reference to PI in the PIOfTheDay definition is absolute and references the string definition of PI in the baking interface.



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net