Imagine a web application which two types of users can log into. Administrators, and normal users. When administrators log in, they are presented with the AdminMainMenu. When normal users log in, they are presented with the UserMainMenu. For the purposes of this example we'll keep this fairly concise and forget about what sorts of things might be on the UserMainMenu. On the AdminMainMenu there might be a number of options. Since users have to log into this web application, there certainly must be a way the admin can add users. So lets Imagine there's an Enrollment link off the AdminMainMenu. Off the Enrollment screen you could imagine an AddUser screen, a DeleteUser screen and a ModifyUser screen. There's probably other links off the AdminMainMenu other then Enrollment too, lets say a screen to send messages to other logged in users, a SendMessage screen. If you take the sample web application I've described (which admittedly doesn't do much) and tried to describe it using a graphical tree, here's what it might look like:
You'll notice that I've given each node on the tree a name. The lingo we use to describe the name we give to each node is UID; an acronym that stands for Unique Identifier. As you can imagine, there is no limitation to attaching a different "AddUser" node under UserMainMenu. If we did that, it would be awfully confusing to know which one we were talking about if just called it the "AddUser" node. That's why there a second way of addressing each node called the FQUID. An acronym that stands for Fully Qualified Unique Identifier. The FQUID of the AddUser node as drawn above is AdminMainMenu.AddUser. A period delimits between the parent node names. Some people might find it ironic that you must "fully qualify" a unique identifier for it to be truly unique. The theory is the UID is only unique at it's local level, as you cannot have two AddUser nodes attached to the same parent.
Each node on the tree now represents a functional piece of this web application. In the tree above, all of the nodes are PageHandlers. The PageHandler interface simply means it is capable of rendering itself. A PageBroker is a special kind of PageHandler which can also have zero or more children attached to it. In the above case the Root, AdminMainMenu and UserMainMenu nodes are PageBrokers. Adduser, DeleteUser, ModifyUser and SendMessage can be implemented as PageHandlers or PageBrokers with no children. All nodes are PageHandlers, and this includes the root. Customarily the RootPageBroker is the login page.The tree is created when the RootPageBroker is instantiated by system initalization functions. The RootPageBroker will in turn register AdminMainMenu and UserMainMenu. The AdminMainMenu will in turn register each of it's children, AddUser, DeleteUser and ModifyUser. Here's what might appear in the RootPageBroker to register the two nodes AdminMainMenu and UserMainMenu:
public
class RootPageBroker extends PageBroker {In this example we are calling the registerPageHandler method of the RootPageBroker. The first argument is the name of the node being registered. This is the UID value, and not the FQUID value. The second parameter is the PageHandler (or PageBroker) object being registered. The parameters for instantiating a PageBroker or PageHandler are not strictly defined by the java interface. However, the superclass constructor for the PageBroker is strictly defined; so it would be wise to create the constructors of your PageBrokers and PageHandlers in the same fashion to avoid confusion. In the PageBroker constructor used here, the first parameter is a pointer to the ManagerTracker. The second parameter is the FQUID of the node, so the node will know it's own name. In this case the FQUID is the same as the UID. As you will see in other nodes, that's not always the case. The third parameter is a pointer to the current node, this allows the Child to have a pointer to it's parent. Lets look at the AdminMainMenu constructor:
public
class AdminMainMenu extends PageBroker {In this case we can see the three children of the AdminMainMenu being added. The only significant difference is you can see when the Brokers are being instantiated the FQUID value is being added to the UID value. Also the period delimitor is added to seperate the FQUID value from the UID value.
public class SamplePageBroker extends PageBroker {
public HTTPResponse render(TransactionTracker TT, HTTPRequest req, WebSession thisSession) throws ApolloException {
//Perform some actions
return MT.getPM().handleRequest(TT, "AdminMainMenu.AddUser", req, thisSession);
}
As you can see control is passed off to the node AdminMainMenu.AddUser. That node is now responsible for rendering a response to the user's browser. As you can see, you're passing in a request object and a session object. You may need to modify these prior to passing them.
Passing control via a Parent Page Broker
Examples from the demo site:
StatusBarBroker