| Home >> All >> com >> sample >> addressbook >> controller >> [ contact Javadoc ] |
Source code: com/sample/addressbook/controller/contact/ContactNavigationController.java
1 /* 2 * ContactNavigationController.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.controller.contact; 11 12 import java.util.ArrayList; 13 14 import javax.servlet.*; 15 import javax.servlet.http.*; 16 17 import com.aendvari.satyr.servlet.*; 18 import com.aendvari.satyr.servlet.gateway.tethys.*; 19 20 import com.aendvari.griffin.util.XmlUtil; 21 import com.aendvari.griffin.bean.transform.BeanTransformer; 22 23 import com.aendvari.common.model.*; 24 25 import com.aendvari.tethys.context.model.*; 26 27 import com.aendvari.tethys.tag.context.*; 28 import com.aendvari.tethys.tag.model.*; 29 30 import com.aendvari.cerberus.component.descriptor.ComponentDescriptor; 31 32 import com.aendvari.cerberus.component.assembly.AssembledComponent; 33 import com.aendvari.cerberus.component.assembly.AssemblyContext; 34 35 import com.aendvari.hermes.broker.*; 36 import com.aendvari.hermes.broker.http.*; 37 38 import com.sample.addressbook.model.contact.data.Contact; 39 40 import com.sample.addressbook.Names; 41 import com.sample.addressbook.dumbdb.*; 42 43 44 /** 45 * <p>Manages copyform message for navigation calls.</p> 46 * 47 * @author Scott Milne 48 * 49 */ 50 51 public class ContactNavigationController implements AssembledComponent 52 { 53 protected ComponentDescriptor descriptor; 54 protected String model; 55 56 57 /* Constructors. */ 58 59 60 /** 61 * Constructs a <code>ContactNavigationController</code> instance. 62 * 63 */ 64 65 public ContactNavigationController() 66 { 67 } 68 69 /** 70 * Creates the component based on the provided descriptor. 71 * 72 * The {@link AssemblyContext} object is transient and should not be retained 73 * by the component. 74 * 75 * The {@link ComponentDescriptor} may be retained by the component. 76 * 77 * @param context The {@link AssemblyContext} for this component. 78 * @param descriptor The {@link ComponentDescriptor} for this component. 79 * 80 */ 81 82 public void createComponent(AssemblyContext context, ComponentDescriptor descriptor) 83 { 84 MessageBrokerConnection connection = context.getMessageBroker().createConnection(); 85 86 // subscribe to the topic associated with the "copyform" message 87 connection.subscribe(descriptor.getMessage("copyform").getTopic(), new CopyFormListener()); 88 89 // store descriptor 90 this.descriptor = descriptor; 91 92 // retrieve information 93 model = descriptor.getAttribute("model").getValue(); 94 } 95 96 class CopyFormListener implements MessageListener 97 { 98 public void onMessage(Message message) 99 { 100 // retrieve web objects 101 HttpServletRequest request = HttpMessageBrokerContext.getRequest(message.getContext()); 102 HttpServletResponse response = HttpMessageBrokerContext.getResponse(message.getContext()); 103 HttpSession session = HttpMessageBrokerContext.getSession(message.getContext()); 104 105 // get view model 106 ModelTree modelTree = ServletModelUtil.getModelTree(session); 107 108 // get the node that is holding the form data 109 ModelNode messageNode = modelTree.getNode(modelTree.getRootNode(), model); 110 111 // update the DOM with the form data 112 ModelUtil.osmToModel(message.getProperties(), "MainForm", messageNode, false); 113 } 114 } 115 } 116