1 16 package org.apache.cocoon.portal.wsrp.consumer; 17 18 import java.util.Hashtable ; 19 import java.util.Iterator ; 20 21 import org.apache.avalon.framework.logger.LogEnabled; 22 import org.apache.avalon.framework.logger.Logger; 23 import org.apache.wsrp4j.consumer.PortletKey; 24 import org.apache.wsrp4j.consumer.WSRPPortlet; 25 import org.apache.wsrp4j.consumer.driver.ConsumerPortletContext; 26 import org.apache.wsrp4j.consumer.driver.GenericPortletRegistryImpl; 27 import org.apache.wsrp4j.exception.WSRPException; 28 import org.apache.wsrp4j.util.StateChangedEvent; 29 import org.apache.wsrp4j.util.StateChangedListener; 30 import org.apache.wsrp4j.util.StateChangedService; 31 32 41 public class PortletRegistryImpl 42 extends GenericPortletRegistryImpl 43 implements StateChangedListener, LogEnabled { 44 45 46 protected Logger logger; 47 48 49 private Hashtable contextMap = new Hashtable (); 50 51 54 public void enableLogging(Logger logger) { 55 this.logger = logger; 56 } 57 58 64 public void addPortlet(WSRPPortlet portlet) throws WSRPException { 65 if (portlet != null) { 66 super.addPortlet(portlet); 67 68 ConsumerPortletContext consumerPortletContext = new ConsumerPortletContext(); 70 consumerPortletContext.setPortletContext(portlet.getPortletContext()); 71 consumerPortletContext.setPortletKey(portlet.getPortletKey()); 72 this.contextMap.put(portlet.getPortletKey().toString(), consumerPortletContext); 73 74 if (portlet instanceof StateChangedService) { 76 ((StateChangedService)portlet).addListener(this); 77 } 78 } 79 } 80 81 87 public WSRPPortlet removePortlet(PortletKey portletKey) { 88 WSRPPortlet portlet = null; 89 if (portletKey != null) { 90 portlet = super.removePortlet(portletKey); 91 contextMap.remove(portletKey.toString()); 92 } 93 return portlet; 94 } 95 96 100 public void removeAllPortlets() { 101 Iterator iterator = getAllPortlets(); 102 while (iterator.hasNext()) { 103 WSRPPortlet portlet = (WSRPPortlet)iterator.next(); 104 105 contextMap.remove(portlet.getPortletKey().toString()); 107 } 108 super.removeAllPortlets(); 109 } 110 111 119 public void stateChanged(StateChangedEvent event) { 120 WSRPPortlet portlet = null; 121 try { 122 portlet = (WSRPPortlet)event.getSource(); 123 124 ConsumerPortletContext consumerPortletContext = 126 (ConsumerPortletContext)contextMap.get(portlet.getPortletKey().toString()); 127 128 consumerPortletContext.setPortletContext(portlet.getPortletContext()); 129 consumerPortletContext.setPortletKey(portlet.getPortletKey()); 130 } catch (ClassCastException ce) { 131 logger.error("StateChanged-error in portlet: " + portlet.getPortletKey().getPortletHandle(), ce); 132 } 133 } 134 } 135 | Popular Tags |