001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.layout.renderer.impl;
018:
019: import java.util.Iterator;
020:
021: import org.apache.avalon.framework.activity.Disposable;
022: import org.apache.avalon.framework.configuration.Configurable;
023: import org.apache.avalon.framework.configuration.Configuration;
024: import org.apache.avalon.framework.configuration.ConfigurationException;
025: import org.apache.avalon.framework.context.Context;
026: import org.apache.avalon.framework.context.ContextException;
027: import org.apache.avalon.framework.context.Contextualizable;
028: import org.apache.avalon.framework.logger.AbstractLogEnabled;
029: import org.apache.avalon.framework.service.ServiceException;
030: import org.apache.avalon.framework.service.ServiceManager;
031: import org.apache.avalon.framework.service.ServiceSelector;
032: import org.apache.avalon.framework.service.Serviceable;
033: import org.apache.avalon.framework.thread.ThreadSafe;
034: import org.apache.cocoon.components.ContextHelper;
035: import org.apache.cocoon.portal.PortalService;
036: import org.apache.cocoon.portal.layout.Layout;
037: import org.apache.cocoon.portal.layout.renderer.Renderer;
038: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect;
039: import org.apache.cocoon.portal.layout.renderer.aspect.impl.DefaultRendererContext;
040: import org.apache.cocoon.portal.layout.renderer.aspect.impl.RendererAspectChain;
041: import org.xml.sax.ContentHandler;
042: import org.xml.sax.SAXException;
043:
044: /**
045: * Container for chain of aspect renderers. All aspect renderers are applied in order
046: * of appearance.
047: *
048: * <h2>Configuration</h2>
049: * <table><tbody>
050: * <tr><th>aspects</th><td>List of aspect renderers to apply. See
051: * {@link org.apache.cocoon.portal.layout.renderer.aspect.impl.RendererAspectChain}</td>
052: * <td></td><td>Configuration</td><td><code>EmptyConfiguration</code></td></tr>
053: * </tbody></table>
054: *
055: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
056: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
057: *
058: * @version CVS $Id: AspectRenderer.java 433543 2006-08-22 06:22:54Z crossley $
059: */
060: public class AspectRenderer extends AbstractLogEnabled implements
061: Renderer, Serviceable, Configurable, Disposable, ThreadSafe,
062: Contextualizable {
063:
064: protected ServiceManager manager;
065:
066: protected RendererAspectChain chain;
067:
068: protected ServiceSelector aspectSelector;
069:
070: protected Context context;
071:
072: /* (non-Javadoc)
073: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
074: */
075: public void service(ServiceManager manager) throws ServiceException {
076: this .manager = manager;
077: this .aspectSelector = (ServiceSelector) this .manager
078: .lookup(RendererAspect.ROLE + "Selector");
079: }
080:
081: /**
082: * Stream out raw layout
083: */
084: public void toSAX(Layout layout, PortalService service,
085: ContentHandler handler) throws SAXException {
086: Boolean isRenderable = service.isRenderable();
087: DefaultRendererContext renderContext = new DefaultRendererContext(
088: this .chain, layout, service);
089: renderContext.setObjectModel(ContextHelper
090: .getObjectModel(this .context));
091: renderContext.invokeNext(layout, service, handler);
092: service.setRenderable(isRenderable);
093: }
094:
095: /* (non-Javadoc)
096: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
097: */
098: public void configure(Configuration conf)
099: throws ConfigurationException {
100: this .chain = new RendererAspectChain();
101: this .chain.configure(this .aspectSelector, conf
102: .getChild("aspects"));
103: }
104:
105: /* (non-Javadoc)
106: * @see org.apache.avalon.framework.activity.Disposable#dispose()
107: */
108: public void dispose() {
109: if (this .manager != null) {
110: if (this .chain != null) {
111: this .chain.dispose(this .aspectSelector);
112: }
113: this .manager.release(this .aspectSelector);
114: this .aspectSelector = null;
115: this .manager = null;
116: }
117: }
118:
119: /**
120: * Return the aspects required for this renderer
121: */
122: public Iterator getAspectDescriptions() {
123: return this .chain.getAspectDescriptionIterator();
124: }
125:
126: /* (non-Javadoc)
127: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
128: */
129: public void contextualize(Context context) throws ContextException {
130: this.context = context;
131: }
132:
133: }
|