KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > layout > renderer > aspect > impl > RendererAspectChain


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.layout.renderer.aspect.impl;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
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 /**
31  * This chain holds all configured renderer aspects for one renderer.
32  *
33  * <h2>Configuration</h2>
34  * <table><tbody>
35  * <tr><th>aspect</th>
36  * <td>Multiple aspect renderer configurations. Required attribute
37  * <code>type</code>. Nested configuration must contain parameters
38  * for aspect rederer.
39  * </td>
40  * <td>req</td><td>Configuration</td><td><code>null</code></td>
41  * </tr>
42  * </tbody></table>
43  *
44  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
45  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
46  *
47  * @version CVS $Id: RendererAspectChain.java 330865 2005-11-04 18:54:05Z rgoers $
48  */

49 public final class RendererAspectChain {
50     
51     protected List JavaDoc aspects = new ArrayList JavaDoc(3);
52     
53     protected List JavaDoc configs = new ArrayList JavaDoc(3);
54     
55     protected List JavaDoc aspectDescriptions = new ArrayList JavaDoc(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 JavaDoc 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 JavaDoc compiledConf = rAspect.prepareConfiguration(aspectConfiguration);
75                         this.configs.add(compiledConf);
76                         
77                         Iterator JavaDoc 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 JavaDoc getIterator() {
96         return this.aspects.iterator();
97     }
98     
99     public Iterator JavaDoc getConfigIterator() {
100         return this.configs.iterator();
101     }
102     
103     public Iterator JavaDoc getAspectDescriptionIterator() {
104         return this.aspectDescriptions.iterator();
105     }
106     
107     public void dispose(ServiceSelector selector) {
108         Iterator JavaDoc 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