As mentioned above, one instance of the Repository class exists for the entire SOM Interface Repository. This object does not, itself, reside in the Interface Repository (hence it does not exhibit any of the behavior defined by the Contained class). It is, however, a Container, and it holds all ConstantDefs, TypeDefs, ExceptionDefs, InterfaceDefs, and ModuleDefs that are global in scope (that is, not contained inside of any other Containers).
When any method provided by the Repository class is used to locate other objects in the Interface Repository, those objects are automatically instantiated and activated. Consequently, when the program is finished using an object from the Interface Repository, the client code should release the object using the somFree method.
All objects contained in the Interface Repository have both a "name" and a "Repository ID" associated with them. The name is not guaranteed to be unique, but it does uniquely identify an object within the context of the object that contains it. The Repository ID of each object is guaranteed to uniquely identify that object, regardless of its context.
For example, two TypeDef objects may have the same name, provided they occur in separate name scopes (ModuleDefs or InterfaceDefs). In this case, asking the Interface Repository to locate the TypeDef object based on its name would result in both TypeDef objects being returned. On the other hand, if the name is looked up from a particular ModuleDef or InterfaceDef object, only the TypeDef object within the scope of that ModuleDef or InterfaceDef would be returned. By contrast, once the Repository ID of an object is known, that object can always be directly obtained from the Repository object via its Repository ID.
C or C++ programmers can obtain an instance of the Repository class using the RepositoryNew macro. Programmers using other languages (and C/C++ programmers without static linkage to the Repository class) should invoke the method somGetInterfaceRepository on the SOMClassMgrObject . For example,
For C or C++ (static linkage):
#include <repostry.h> Repository repo; repo = RepositoryNew();
From other languages (and for dynamic linkage in C/C++):
After obtaining a pointer to the Repository object, use the methods it inherits from Container or its own lookup_id method to instantiate objects in the Interface Repository. As an example, the contents method shown in the C fragment below activates every object with global scope in the Interface Repository and returns a sequence containing a pointer to every global object:
#include <containd.h> /* Behavior common to allIR objects */ Environment *ev; int i; sequence(Contained) everyGlobalObject; ev = SOM_CreateLocalEnvironment(); /* Get an environment to use */ printf ("Every global object in the Interface Repository:\n"); everyGlobalObject = Container_contents (repo, ev, "all", TRUE); for (i=0; i < everyGlobalObject._length; i++) { Contained aContained; aContained = (Contained) everyGlobalObject._buffer[i]; printf ("Name: %s, Id: %s\n", Contained__get_name (aContained, ev), Contained__get_id (aContained, ev)); SOMObject_somFree (aContained); }
Taking this example one step further, here is a complete program that accesses every object in the entire Interface Repository. It, too, uses the contents method, but this time recursively calls the contents method until every object in every container has been found:
#include <stdio.h> #include <containd.h> #include <repostry.h> void showContainer (Container c, int *next); main () { int count = 0; Repository repo; repo = RepositoryNew (); printf ("Every object in the Interface Repository:\n\n"); showContainer ((Container) repo, &count); SOMObject_somFree (repo); printf ("%d objects found\n", count); exit (0); } void showContainer (Container c, int *next) { Environment *ev; int i; sequence(Contained) everyObject; ev = SOM_CreateLocalEnvironment (); /* Get an environment */ everyObject = Container_contents (c, ev, "all", TRUE); for (i=0; i<everyObject._length; i++) { Contained aContained; (*next)++; aContained = (Contained) everyObject._buffer[i]; printf ("%6d. Type: %-12s id: %s\n", *next, SOMObject_somGetClassName (aContained), Contained__get_id (aContained, ev)); if (SOMObject_somIsA (aContained, _Container)) showContainer ((Container) aContained, next); SOMObject_somFree (aContained); } }
Once an object has been retrieved, the methods and attributes appropriate for that particular object can then be used to access the information contained in the object. The methods supported by each class of object in the Interface Repository, as well as the classes themselves, are documented in the SOMobjects Developer Toolkit: Programmers Reference Manual.