by
dcooper@jade.co.nz >> Tue, 19 Feb 2002 3:10:49 GMT
Hi Carl,
Yes, this is possible (a facility called global instance visibility was added in JADE 5.0), but not in a particularly type-safe manner right now (you have to use indirect methods to access features of classes not visible in the schema branch of your process). It's also subject to a few restrictions.
The JadeScript below when run from Schema1 will get the first instance of a Schema2 Company class, write its name and also write the oid of the Joe Bloggs customer from the Company's dictionary of customers:
vars
scm : Schema;
cls : Class;
mkd : MemberKeyDictionary;
obj : Object;
begin
scm := rootSchema.getSchema("Schema2");
cls := scm.getClass("Company");
obj := cls.firstInstance;
write obj.getPropertyValue("name").String;
mkd := obj.getPropertyValue("allCustomers").MemberKeyDictionary;
write mkd["Joe Bloggs"];
end;
Prior to JADE 5, the above method would have got 1003 and/or 1046 exceptions.
As you can see, you can only work with common superschema types (I've assumed both Schema1 and Schema2 are directly below RootSchema as in your example) and you need to use indirect methods to get at things (eg: getPropertyValue, sendMsg, etc) which aren't type-safe at compile time, but they will certainly produce some nice exceptions at runtime if you get things wrong
There aren't any restrictions on accessing properties, but the only methods a Schema1 process can invoke on an instance of a Schema2 class are *root class* methods (a root class is the top-most definition of a class). This means that subschema copy methods cannot be invoked (remember that any methods on Object, Application, Global, etc in your schemas are always subschema copy methods as the top-most definition of such classes is in the RootSchema), nor can primitive methods be invoked (again, primitive methods defined in user schemas are always on subschema copy types). If you are invoking methods across schemas remember that any code compiled in Schema2 that accesses app, global or currentSession will have been compiled against the Schema2 classes, but when executed from a Schema1 process, the app, global and currentSession objects are instances of the Schema1 classes, so properties/methods may not be available at runtime (this is a common gotcha when people start doing this kind of thing).
Work is underway on features for JADE 6 to make these "peer schemas" and cross-schema reuse/visibility easy and type-safe.
Dean.