| Home >> All >> com >> sample >> addressbook >> view >> [ contact Javadoc ] |
Source code: com/sample/addressbook/view/contact/ContactEditView.java
1 /* 2 * ContactEditView.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.common.util.*; 19 import com.aendvari.common.model.*; 20 import com.aendvari.common.notices.*; 21 22 import com.aendvari.tethys.context.*; 23 import com.aendvari.tethys.context.message.*; 24 25 import com.aendvari.tethys.tag.message.*; 26 27 import com.aendvari.cerberus.component.descriptor.ComponentDescriptor; 28 29 import com.aendvari.cerberus.component.assembly.AssembledComponent; 30 import com.aendvari.cerberus.component.assembly.AssemblyContext; 31 32 import com.aendvari.hermes.broker.*; 33 import com.aendvari.hermes.broker.http.*; 34 35 import com.sample.addressbook.Names; 36 import com.sample.addressbook.view.util.*; 37 38 39 /** 40 * <p>Displays the modify/create contact form.</p> 41 * 42 * @author Scott Milne 43 * 44 */ 45 46 public class ContactEditView implements AssembledComponent 47 { 48 protected ComponentDescriptor descriptor; 49 protected String model; 50 51 52 /* Constructors. */ 53 54 55 /** 56 * Constructs a <code>ContactEditView</code> instance. 57 * 58 */ 59 60 public ContactEditView() 61 { 62 } 63 64 /** 65 * Creates the component based on the provided descriptor. 66 * 67 * The {@link AssemblyContext} object is transient and should not be retained 68 * by the component. 69 * 70 * The {@link ComponentDescriptor} may be retained by the component. 71 * 72 * @param context The {@link AssemblyContext} for this component. 73 * @param descriptor The {@link ComponentDescriptor} for this component. 74 * 75 */ 76 77 public void createComponent(AssemblyContext context, ComponentDescriptor descriptor) 78 { 79 MessageBrokerConnection connection = context.getMessageBroker().createConnection(); 80 81 // subscribe to the topic associated with the "display" message 82 connection.subscribe(descriptor.getMessage("display").getTopic(), new ContactListener()); 83 84 // store descriptor 85 this.descriptor = descriptor; 86 87 // retrieve information 88 model = descriptor.getAttribute("model").getValue(); 89 } 90 91 class ContactListener implements MessageListener 92 { 93 public void onMessage(Message message) 94 { 95 // retrieve web objects 96 HttpServletRequest request = HttpMessageBrokerContext.getRequest(message.getContext()); 97 HttpServletResponse response = HttpMessageBrokerContext.getResponse(message.getContext()); 98 HttpSession session = HttpMessageBrokerContext.getSession(message.getContext()); 99 100 // get the message tag data for the page 101 MessageTagData messageTagData = MessageTagData.getData(request); 102 103 // check for error messages 104 ContactViewUtil.checkForErrorMessages(descriptor, message, request); 105 106 // create the "contact" context 107 ContactViewUtil.createContactContext(request, model); 108 109 // get the "includeResource" topic 110 String includeResource = descriptor.getAttribute("includeResource").getValue(); 111 112 // set the attribute for what page should be loaded 113 request.setAttribute(Names.Constants.IncludeResource, includeResource); 114 115 // get the edit message and create a mapping for it 116 String editMessage = descriptor.getMessage("edit").getTopic(); 117 MessageMapping mapping = new MessageMapping("edit", editMessage); 118 messageTagData.getMessageMappingMap().addContext(mapping); 119 } 120 } 121 } 122