1 16 package org.apache.cocoon.portal.pluto.factory; 17 18 import java.util.ArrayList ; 19 import java.util.Collections ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.avalon.framework.activity.Disposable; 24 import org.apache.avalon.framework.container.ContainerUtil; 25 import org.apache.avalon.framework.context.Context; 26 import org.apache.avalon.framework.context.ContextException; 27 import org.apache.avalon.framework.context.Contextualizable; 28 import org.apache.avalon.framework.service.ServiceException; 29 import org.apache.avalon.framework.service.ServiceManager; 30 import org.apache.avalon.framework.service.Serviceable; 31 import org.apache.avalon.framework.thread.ThreadSafe; 32 import org.apache.cocoon.portal.pluto.om.PortletDefinitionImpl; 33 import org.apache.pluto.factory.PortletInvokerFactory; 34 import org.apache.pluto.invoker.PortletInvoker; 35 import org.apache.pluto.invoker.impl.PortletInvokerImpl; 36 import org.apache.pluto.om.portlet.PortletDefinition; 37 38 45 public class PortletInvokerFactoryImpl 46 extends AbstractFactory 47 implements PortletInvokerFactory, Serviceable, Contextualizable, ThreadSafe, Disposable { 48 49 50 protected Context context; 51 52 53 protected ServiceManager manager; 54 55 56 protected List localPortlets = Collections.synchronizedList(new ArrayList ()); 57 58 61 public void contextualize(Context context) throws ContextException { 62 this.context = context; 63 } 64 65 68 public void service(ServiceManager manager) throws ServiceException { 69 this.manager = manager; 70 } 71 72 75 public void dispose() { 76 final Iterator i = this.localPortlets.iterator(); 77 while (i.hasNext()) { 78 LocalPortletInvokerImpl current = (LocalPortletInvokerImpl)i.next(); 79 current.destroy(); 80 } 81 this.localPortlets.clear(); 82 this.manager = null; 83 this.context = null; 84 } 85 86 89 public PortletInvoker getPortletInvoker(PortletDefinition portletDefinition) { 90 boolean local = false; 92 PortletInvoker invoker; 93 if ( portletDefinition instanceof PortletDefinitionImpl ) { 94 local = ((PortletDefinitionImpl)portletDefinition).isLocalPortlet(); 95 } 96 if (local) { 97 invoker = ((PortletDefinitionImpl)portletDefinition).getLocalPortletInvoker(); 98 if ( invoker == null ) { 99 invoker = new LocalPortletInvokerImpl(portletDefinition, this.servletConfig); 100 this.localPortlets.add(invoker); 101 ((PortletDefinitionImpl)portletDefinition).setLocalPortletInvoker(invoker); 102 try { 103 ContainerUtil.enableLogging(invoker, this.getLogger()); 104 ContainerUtil.contextualize(invoker, this.context); 105 ContainerUtil.service(invoker, this.manager); 106 ContainerUtil.initialize(invoker); 107 } catch (Exception ignore) { 108 this.getLogger().warn("Unable to initialize local portlet invoker.", ignore); 109 } 110 } 111 } else { 112 invoker = new PortletInvokerImpl(portletDefinition, this.servletConfig); 113 } 114 115 return invoker; 116 } 117 118 121 public void releasePortletInvoker(PortletInvoker invoker) { 122 } 124 125 } 126 | Popular Tags |