Source code: com/sample/addressbook/view/contact/ContactNavigationView.java
1 /*
2 * ContactNavigationView.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 javax.servlet.*;
13 import javax.servlet.http.*;
14
15 import com.aendvari.common.model.*;
16
17 import com.aendvari.tethys.context.*;
18 import com.aendvari.tethys.context.message.*;
19
20 import com.aendvari.tethys.tag.message.*;
21
22 import com.aendvari.cerberus.component.descriptor.ComponentDescriptor;
23
24 import com.aendvari.cerberus.component.assembly.AssembledComponent;
25 import com.aendvari.cerberus.component.assembly.AssemblyContext;
26
27 import com.aendvari.hermes.broker.*;
28 import com.aendvari.hermes.broker.http.*;
29
30 import com.sample.addressbook.Names;
31 import com.sample.addressbook.view.util.*;
32
33
34 /**
35 * <p>Prepares the messages for navigational purposes.</p>
36 *
37 * @author Scott Milne
38 *
39 */
40
41 public class ContactNavigationView implements AssembledComponent
42 {
43 protected ComponentDescriptor descriptor;
44 protected String model;
45
46
47 /* Constructors. */
48
49
50 /**
51 * Constructs a <code>ContactNavigationView</code> instance.
52 *
53 */
54
55 public ContactNavigationView()
56 {
57 }
58
59 /**
60 * Creates the component based on the provided descriptor.
61 *
62 * The {@link AssemblyContext} object is transient and should not be retained
63 * by the component.
64 *
65 * The {@link ComponentDescriptor} may be retained by the component.
66 *
67 * @param context The {@link AssemblyContext} for this component.
68 * @param descriptor The {@link ComponentDescriptor} for this component.
69 *
70 */
71
72 public void createComponent(AssemblyContext context, ComponentDescriptor descriptor)
73 {
74 MessageBrokerConnection connection = context.getMessageBroker().createConnection();
75
76 // subscribe to the topic associated with the "display" message
77 connection.subscribe(descriptor.getMessage("display").getTopic(), new NavigationListener());
78
79 // store descriptor
80 this.descriptor = descriptor;
81
82 // retrieve information
83 model = descriptor.getAttribute("model").getValue();
84 }
85
86 class NavigationListener implements MessageListener
87 {
88 public void onMessage(Message message)
89 {
90 // retrieve web objects
91 HttpServletRequest request = HttpMessageBrokerContext.getRequest(message.getContext());
92 HttpServletResponse response = HttpMessageBrokerContext.getResponse(message.getContext());
93 HttpSession session = HttpMessageBrokerContext.getSession(message.getContext());
94
95 // get the message tag data for the page
96 MessageTagData messageTagData = MessageTagData.getData(request);
97
98 // get the "close" message and create a mapping for it
99 String closeMessage = descriptor.getMessage("close").getTopic();
100 MessageMapping closeMessageMapping = new MessageMapping("close", closeMessage);
101 messageTagData.getMessageMappingMap().addContext(closeMessageMapping);
102
103 // get the "previous" message and create a mapping for it
104 String previous = descriptor.getMessage("previous").getTopic();
105 MessageMapping previousMapping = new MessageMapping("previous", previous);
106 messageTagData.getMessageMappingMap().addContext(previousMapping);
107
108 // get the "basic" message and create a mapping for it
109 String basic = descriptor.getMessage("basic").getTopic();
110 MessageMapping basicMapping = new MessageMapping("basic", basic);
111 messageTagData.getMessageMappingMap().addContext(basicMapping);
112
113 // get the "address" message and create a mapping for it
114 String address = descriptor.getMessage("address").getTopic();
115 MessageMapping addressMapping = new MessageMapping("address", address);
116 messageTagData.getMessageMappingMap().addContext(addressMapping);
117
118 // get the "associates" message and create a mapping for it
119 String associates = descriptor.getMessage("associates").getTopic();
120 MessageMapping associatesMapping = new MessageMapping("associates", associates);
121 messageTagData.getMessageMappingMap().addContext(associatesMapping);
122
123 // get the "copyform" message and create a mapping for it
124 String copyform = descriptor.getMessage("copyform").getTopic();
125 MessageMapping copyformMapping = new MessageMapping("navigation_copyform", copyform);
126 messageTagData.getMessageMappingMap().addContext(copyformMapping);
127 }
128 }
129 }
130