1 16 package org.apache.cocoon.portal.layout.renderer.aspect.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.ParameterException; 25 import org.apache.avalon.framework.parameters.Parameters; 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.avalon.framework.service.ServiceSelector; 28 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect; 29 30 49 public final class RendererAspectChain { 50 51 protected List aspects = new ArrayList (3); 52 53 protected List configs = new ArrayList (3); 54 55 protected List aspectDescriptions = new ArrayList (2); 56 57 private boolean isRequired = false; 58 59 public void configure(ServiceSelector selector, Configuration conf) 60 throws ConfigurationException { 61 if ( conf != null ) { 62 Configuration[] aspects = conf.getChildren("aspect"); 63 if ( aspects != null ) { 64 for(int i=0; i < aspects.length; i++) { 65 final Configuration current = aspects[i]; 66 final String role = current.getAttribute("type"); 67 try { 68 RendererAspect rAspect = (RendererAspect) selector.select(role); 69 this.aspects.add(rAspect); 70 if (rAspect.isRequired()) { 71 isRequired = true; 72 } 73 Parameters aspectConfiguration = Parameters.fromConfiguration(current); 74 Object compiledConf = rAspect.prepareConfiguration(aspectConfiguration); 75 this.configs.add(compiledConf); 76 77 Iterator descriptionIterator = rAspect.getAspectDescriptions(compiledConf); 78 if ( descriptionIterator != null ) { 79 while ( descriptionIterator.hasNext() ) { 80 this.aspectDescriptions.add( descriptionIterator.next() ); 81 } 82 } 83 } catch (ParameterException pe) { 84 throw new ConfigurationException("Unable to configure renderer aspect " + role, pe); 85 } catch (ServiceException se) { 86 throw new ConfigurationException("Unable to lookup aspect " + role, se); 87 } 88 } 89 } 90 } else { 91 throw new ConfigurationException("No aspects configured"); 92 } 93 } 94 95 public Iterator getIterator() { 96 return this.aspects.iterator(); 97 } 98 99 public Iterator getConfigIterator() { 100 return this.configs.iterator(); 101 } 102 103 public Iterator getAspectDescriptionIterator() { 104 return this.aspectDescriptions.iterator(); 105 } 106 107 public void dispose(ServiceSelector selector) { 108 Iterator i = this.aspects.iterator(); 109 while (i.hasNext()) { 110 selector.release(i.next()); 111 } 112 this.aspects.clear(); 113 } 114 115 public boolean isRequired() { 116 return this.isRequired; 117 } 118 } 119 | Popular Tags |