Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sample/tutorial/login/view/main/MainView.java


1   /*
2    * MainView.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.sample.tutorial.login.view.main;
11  
12  import javax.servlet.*;
13  import javax.servlet.http.*;
14  
15  import com.aendvari.cerberus.component.assembly.*;
16  import com.aendvari.cerberus.component.descriptor.*;
17  
18  import com.aendvari.common.model.*;
19  
20  import com.aendvari.hermes.broker.*;
21  import com.aendvari.hermes.broker.http.*;
22  
23  import com.aendvari.satyr.servlet.*;
24  
25  import com.aendvari.tethys.tag.*;
26  import com.aendvari.tethys.tag.model.ModelTagData;
27  
28  /**
29   * Main view.
30   *
31   * @author  Trevor Milne
32   *
33   */
34  
35  public class MainView implements AssembledComponent
36  {
37    protected ComponentDescriptor descriptor;
38    protected String model;
39  
40    /**
41     * Creates the component based on the provided descriptor.
42     *
43     * @param    context            The {@link AssemblyContext} for this component.
44     * @param    descriptor          The {@link ComponentDescriptor} for this component.
45     *
46     */
47  
48    public void createComponent(AssemblyContext context, ComponentDescriptor descriptor)
49    {
50      // create a connection to the message broker
51      MessageBrokerConnection connection = context.getMessageBroker().createConnection();
52  
53      // subscribe to the topic associated with the "show" message
54      connection.subscribe(descriptor.getMessage("show").getTopic(), new ShowListener());
55  
56      // store descriptor
57      this.descriptor = descriptor;
58  
59      // retrieve model information
60      model = descriptor.getAttribute("model").getValue();
61    }
62  
63    protected class ShowListener implements MessageListener
64    {
65      /**
66       * Receives a message from the {@link MessageBroker}.
67       *
68       * @param    message            The {@link Message} received.
69       *
70       */
71  
72      public void onMessage(Message message)
73      {
74        // retrieve web objects
75        HttpServletRequest request = HttpMessageBrokerContext.getRequest(message.getContext());
76        HttpServletResponse response = HttpMessageBrokerContext.getResponse(message.getContext());
77        HttpSession session = HttpMessageBrokerContext.getSession(message.getContext());
78  
79        // obtain model tree
80        ModelTree modelTree = ServletModelUtil.getModelTree(session);
81  
82        // create tag model using the model tree
83  
84        // create the model tag data using the root node as the base
85        ModelTagData modelTagData = new ModelTagData(
86          modelTree.getNode(modelTree.getRootNode(), model));
87  
88        ModelTagData.setData(request, modelTagData);
89  
90        // include the jsp for the view
91        try
92        {
93          request.getRequestDispatcher("/main.jsp").include(request, response);
94        }
95        catch (Exception exception)
96        {
97          exception.printStackTrace(System.err);
98        }
99      }
100   }
101 }
102