Defining a top-level object type is a special case of defining a singleton type, with two differences: First, a top-level object type does
not require a
getConcept method, because its concept is self-evident (it is always
TeaConcept.TOP_LEVEL). Second,
TopLevelTeaObject extends the
WithMembers interface, so you must implement the
getMemebers method.
Procedure
-
Define a class that models the managed object type. Your class must implement the interface
TopLevelTeaObject.
For example, when modeling a car, the top-level is the car itself.
public class Car implements TopLevelTeaObject {
public String getName() {
// Return the name of the car instance;
return "Car";
}
public String getDescription() {
// Return the description of the car instance;
return "Car";
}
public String getKey() {
// Return the key that corresponds to the car instance;
return "Car";
}
// These methods give the top-level object functionality
// that would otherwise be in the provider.
public String getTypeName() {
// Return the name of the car object type.
return "Car";
}
public String getTypeDescription() {
// Return the description of the car object type.
return "Car";
}
public Collection<BaseTeaObject> getMembers() {
// Return the main parts of the car.
}
}
-
Register the unique instance of the class.
CarAgentServer server = ...
Car myCar = new Car;
server.registerInstance(myCar);
// Register other instances.
...
server.start();
Notice that instead of registering the provider, we register the unique instance of the car class.
Copyright © Cloud Software Group, Inc. All Rights Reserved.