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

Quick Search    Search Deep

Source code: com/sample/addressbook/view/contact/ContactSearchView.java


1   /*
2    * ContactSearchView.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.addressbook.view.contact;
11  
12  import java.util.Iterator;
13  import java.util.Collection;
14  
15  import javax.servlet.*;
16  import javax.servlet.http.*;
17  
18  import com.aendvari.griffin.util.XmlUtil;
19  
20  import com.aendvari.common.util.*;
21  import com.aendvari.common.model.*;
22  import com.aendvari.common.notices.*;
23  
24  import com.aendvari.tethys.context.*;
25  import com.aendvari.tethys.context.model.*;
26  import com.aendvari.tethys.context.message.*;
27  
28  import com.aendvari.tethys.tag.message.*;
29  import com.aendvari.tethys.tag.context.*;
30  import com.aendvari.tethys.tag.model.*;
31  
32  import com.aendvari.satyr.servlet.*;
33  
34  import com.aendvari.cerberus.component.descriptor.ComponentDescriptor;
35  
36  import com.aendvari.cerberus.component.assembly.AssembledComponent;
37  import com.aendvari.cerberus.component.assembly.AssemblyContext;
38  
39  import com.aendvari.hermes.broker.*;
40  import com.aendvari.hermes.broker.http.*;
41  
42  import com.sample.addressbook.Names;
43  import com.sample.addressbook.view.util.*;
44  
45  
46  /**
47   * <p>Displays a search form or result page.</p>
48   *
49   * @author  Scott Milne
50   *
51   */
52  
53  public class ContactSearchView implements AssembledComponent
54  {
55    protected ComponentDescriptor descriptor;
56    protected String model;
57  
58  
59    /* Constructors. */
60  
61  
62    /**
63     * Constructs a <code>ContactSearchView</code> instance.
64     *
65     */
66  
67    public ContactSearchView()
68    {
69    }
70  
71    /**
72     * Creates the component based on the provided descriptor.
73     *
74     * The {@link AssemblyContext} object is transient and should not be retained
75     * by the component.
76     *
77     * The {@link ComponentDescriptor} may be retained by the component.
78     *
79     * @param    context            The {@link AssemblyContext} for this component.
80     * @param    descriptor          The {@link ComponentDescriptor} for this component.
81     *
82     */
83  
84    public void createComponent(AssemblyContext context, ComponentDescriptor descriptor)
85    {
86      MessageBrokerConnection connection = context.getMessageBroker().createConnection();
87  
88      // subscribe to the topic associated with the "display" message
89      connection.subscribe(descriptor.getMessage("display").getTopic(), new DisplayListener());
90  
91      // store descriptor
92      this.descriptor = descriptor;
93  
94      // retrieve information
95      model = descriptor.getAttribute("model").getValue();
96    }
97  
98    class DisplayListener implements MessageListener
99    {
100     public void onMessage(Message message)
101     {
102       // retrieve web objects
103       HttpServletRequest request = HttpMessageBrokerContext.getRequest(message.getContext());
104       HttpServletResponse response = HttpMessageBrokerContext.getResponse(message.getContext());
105       HttpSession session = HttpMessageBrokerContext.getSession(message.getContext());
106 
107       // obtain model tree
108       ModelTree modelTree = ServletModelUtil.getModelTree(session);
109 
110       // get the message tag data for the page
111       MessageTagData messageTagData = MessageTagData.getData(request);
112 
113       // get the model tag data
114       ModelTagData modelTagData = ModelTagData.getData(request);
115 
116       // check for error messages
117       ContactViewUtil.checkForErrorMessages(descriptor, message, request);
118 
119       // get the  node
120       ModelNode modelNode = modelTree.getNode(modelTree.getRootNode(), model);
121 
122       // define a context for the search form model location
123       ModelContext tagContext = new ModelContext("searchform", modelNode);
124       modelTagData.getModelContextMap().setContext(tagContext);
125 
126       // get the submit message and create a mapping for it
127       String submit = descriptor.getMessage("submit").getTopic();
128       MessageMapping submitMapping = new MessageMapping("submit", submit);
129       messageTagData.getMessageMappingMap().addContext(submitMapping);
130 
131       // get the currentsearchform message and create a mapping for it
132       String currentsearchform = descriptor.getMessage("currentsearchform").getTopic();
133       MessageMapping currentsearchformMapping = new MessageMapping("currentsearchform", currentsearchform);
134       messageTagData.getMessageMappingMap().addContext(currentsearchformMapping);
135 
136       String newsearchform = descriptor.getMessage("newsearchform").getTopic();
137       MessageMapping newsearchformMapping = new MessageMapping("newsearchform", newsearchform);
138       messageTagData.getMessageMappingMap().addContext(newsearchformMapping);
139 
140       // get the "includeResource" topic
141       String includeResource = descriptor.getAttribute("includeResource").getValue();
142 
143       // set the attribute for what page should be loaded
144       request.setAttribute(Names.Constants.IncludeResource, includeResource);
145     }
146   }
147 }
148