KickJava   Java API By Example, From Geeks To Geeks.

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


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.impl;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.avalon.framework.activity.Disposable;
21 import org.apache.avalon.framework.configuration.Configurable;
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.context.Context;
25 import org.apache.avalon.framework.context.ContextException;
26 import org.apache.avalon.framework.context.Contextualizable;
27 import org.apache.avalon.framework.logger.AbstractLogEnabled;
28 import org.apache.avalon.framework.service.ServiceException;
29 import org.apache.avalon.framework.service.ServiceManager;
30 import org.apache.avalon.framework.service.ServiceSelector;
31 import org.apache.avalon.framework.service.Serviceable;
32 import org.apache.avalon.framework.thread.ThreadSafe;
33 import org.apache.cocoon.components.ContextHelper;
34 import org.apache.cocoon.portal.PortalService;
35 import org.apache.cocoon.portal.layout.Layout;
36 import org.apache.cocoon.portal.layout.renderer.Renderer;
37 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect;
38 import org.apache.cocoon.portal.layout.renderer.aspect.impl.DefaultRendererContext;
39 import org.apache.cocoon.portal.layout.renderer.aspect.impl.RendererAspectChain;
40 import org.xml.sax.ContentHandler JavaDoc;
41 import org.xml.sax.SAXException JavaDoc;
42
43 /**
44  * Container for chain of aspect renderers. All aspect renderers are applied in order
45  * of appearance.
46  *
47  * <h2>Configuration</h2>
48  * <table><tbody>
49  * <tr><th>aspects</th><td>List of aspect renderers to apply. See
50  * {@link org.apache.cocoon.portal.layout.renderer.aspect.impl.RendererAspectChain}</td>
51  * <td></td><td>Configuration</td><td><code>EmptyConfiguration</code></td></tr>
52  * </tbody></table>
53  *
54  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
55  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
56  *
57  * @version CVS $Id: AspectRenderer.java 331660 2005-11-08 01:22:30Z rgoers $
58  */

59 public class AspectRenderer
60     extends AbstractLogEnabled
61     implements Renderer, Serviceable, Configurable, Disposable, ThreadSafe, Contextualizable {
62
63     protected ServiceManager manager;
64
65     protected RendererAspectChain chain;
66     
67     protected ServiceSelector aspectSelector;
68     
69     protected Context context;
70     
71     /* (non-Javadoc)
72      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
73      */

74     public void service(ServiceManager manager) throws ServiceException {
75         this.manager = manager;
76         this.aspectSelector = (ServiceSelector) this.manager.lookup( RendererAspect.ROLE+"Selector");
77     }
78
79     /**
80      * Stream out raw layout
81      */

82     public void toSAX(Layout layout, PortalService service, ContentHandler JavaDoc handler) throws SAXException JavaDoc {
83         Boolean JavaDoc isRenderable = service.isRenderable();
84         DefaultRendererContext renderContext = new DefaultRendererContext(this.chain, layout, service);
85         renderContext.setObjectModel(ContextHelper.getObjectModel(this.context));
86         renderContext.invokeNext(layout, service, handler);
87         service.setRenderable(isRenderable);
88     }
89
90     /* (non-Javadoc)
91      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
92      */

93     public void configure(Configuration conf) throws ConfigurationException {
94         this.chain = new RendererAspectChain();
95         this.chain.configure(this.aspectSelector, conf.getChild("aspects"));
96     }
97
98     /* (non-Javadoc)
99      * @see org.apache.avalon.framework.activity.Disposable#dispose()
100      */

101     public void dispose() {
102         if (this.manager != null) {
103             if ( this.chain != null) {
104                 this.chain.dispose( this.aspectSelector );
105             }
106             this.manager.release( this.aspectSelector );
107             this.aspectSelector = null;
108             this.manager = null;
109         }
110     }
111
112     /**
113      * Return the aspects required for this renderer
114      */

115     public Iterator JavaDoc getAspectDescriptions() {
116         return this.chain.getAspectDescriptionIterator();
117     }
118
119     /* (non-Javadoc)
120      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
121      */

122     public void contextualize(Context context) throws ContextException {
123         this.context = context;
124     }
125
126 }
127
Popular Tags