1 16 package org.apache.cocoon.portal.impl; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.parameters.Parameters; 25 import org.apache.avalon.framework.service.ServiceException; 26 import org.apache.avalon.framework.service.ServiceSelector; 27 import org.apache.cocoon.portal.PortalManagerAspect; 28 import org.apache.cocoon.portal.coplet.adapter.CopletAdapter; 29 30 35 public final class PortalManagerAspectChain { 36 37 protected List aspects = new ArrayList (3); 38 39 protected List configs = new ArrayList (3); 40 41 public void configure(ServiceSelector aspectSelector, 42 ServiceSelector adapterSelector, 43 Configuration conf, 44 PortalManagerAspect endAspect, 45 Parameters endAspectParameters) 46 throws ConfigurationException { 47 if ( conf != null ) { 48 Configuration[] aspects = conf.getChildren("aspect"); 49 for(int i=0; i < aspects.length; i++) { 50 final Configuration current = aspects[i]; 51 final String role = current.getAttribute("type", null); 52 PortalManagerAspect pAspect; 53 if ( role != null ) { 54 if ( aspectSelector == null ) { 55 throw new ConfigurationException("No selector for aspects defined."); 56 } 57 try { 58 pAspect = (PortalManagerAspect) aspectSelector.select(role); 59 } catch (ServiceException se) { 60 throw new ConfigurationException("Unable to lookup aspect " + role, current, se); 61 } 62 } else { 63 final String adapterName = current.getAttribute("adapter", null); 64 if ( adapterName == null ) { 65 throw new ConfigurationException("Aspect configuration requires either a type or an adapter attribute.", current); 66 } 67 try { 68 pAspect = (PortalManagerAspect)adapterSelector.select(adapterName); 69 } catch (ServiceException se) { 70 throw new ConfigurationException("Unable to lookup coplet adapter " + adapterName, current, se); 71 } 72 } 73 this.aspects.add(pAspect); 74 Parameters aspectConfiguration = Parameters.fromConfiguration(current); 75 this.configs.add(aspectConfiguration); 76 } 77 } 78 this.aspects.add(endAspect); 79 this.configs.add(endAspectParameters); 80 } 81 82 public Iterator getIterator() { 83 return this.aspects.iterator(); 84 } 85 86 public Iterator getConfigIterator() { 87 return this.configs.iterator(); 88 } 89 90 public void dispose(ServiceSelector aspectSelector, ServiceSelector adapterSelector) { 91 Iterator i = this.aspects.iterator(); 92 while (i.hasNext()) { 93 final Object component = i.next(); 94 if ( component instanceof CopletAdapter ) { 95 adapterSelector.release(component); 96 } else { 97 aspectSelector.release(i.next()); 98 } 99 } 100 this.aspects.clear(); 101 this.configs.clear(); 102 } 103 104 110 public void addAsFirst(PortalManagerAspect firstAspect, Parameters firstAspectParameters) { 111 this.aspects.add(0, firstAspect); 112 this.configs.add(0, firstAspectParameters); 113 } 114 } 115 | Popular Tags |