001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme;
023:
024: import org.jboss.portal.common.util.MediaType;
025: import org.jboss.portal.theme.impl.render.dynamic.DynaDecorationRenderer;
026: import org.jboss.portal.theme.impl.render.dynamic.DynaPortletRenderer;
027: import org.jboss.portal.theme.impl.render.dynamic.DynaRegionRenderer;
028: import org.jboss.portal.theme.impl.render.dynamic.DynaWindowRenderer;
029: import org.jboss.portal.theme.metadata.RendererSetMetaData;
030: import org.jboss.portal.theme.render.ObjectRenderer;
031: import org.jboss.portal.theme.render.renderer.DecorationRenderer;
032: import org.jboss.portal.theme.render.renderer.PortletRenderer;
033: import org.jboss.portal.theme.render.renderer.RegionRenderer;
034: import org.jboss.portal.theme.render.renderer.WindowRenderer;
035:
036: /**
037: * The portal render set is a set of renderer implementations for the markup container of a page. <p>A render set
038: * consists of 4 iterface implementations with some meta data describing the web application the render set is coming
039: * from, and the content type it is capable of handling.</p>
040: *
041: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>.
042: * @version <tt>$Revision: 8784 $</tt>
043: */
044: public final class PortalRenderSet {
045:
046: private final RegionRenderer regionRenderer;
047: private final WindowRenderer windowRenderer;
048: private final PortletRenderer portletRenderer;
049: private final DecorationRenderer decorationRenderer;
050: private final MediaType contentType;
051: private final String appID;
052: private final String name;
053: private final ServerRegistrationID registrationId;
054: private final boolean ajaxEnabled;
055:
056: /**
057: * construct a render set
058: *
059: * @param renderSetName the name of the render set as defined in the portal-renderSet.xml descriptor, or null if it
060: * was defined as part of a layout descriptor.
061: * @param runtimeContext the runtime environment (data describing the portal web application in wich the render set
062: * was defined)
063: * @param rendererSetMD meta data about an individual set of 4 renderer implementation together with their supported
064: * content type
065: * @throws IllegalAccessException
066: * @throws InstantiationException
067: * @throws ClassNotFoundException
068: */
069: public PortalRenderSet(String renderSetName,
070: RuntimeContext runtimeContext,
071: RendererSetMetaData rendererSetMD)
072: throws IllegalAccessException, InstantiationException,
073: ClassNotFoundException {
074: // there CAN be render sets without a name !
075:
076: if (runtimeContext == null) {
077: throw new IllegalArgumentException("no valid container");
078: }
079: if (rendererSetMD == null) {
080: throw new IllegalArgumentException("no valid set");
081: }
082: this .name = renderSetName;
083: this .appID = runtimeContext.getAppId();
084: this .registrationId = ServerRegistrationID.createID(
085: ServerRegistrationID.TYPE_RENDERSET, new String[] {
086: appID, name });
087: this .contentType = rendererSetMD.getContentType();
088: this .ajaxEnabled = rendererSetMD.isAjaxEnabled();
089:
090: if (ajaxEnabled) // wrap the current renderer with the ajax delegator one.
091: {
092: this .regionRenderer = new DynaRegionRenderer(
093: (RegionRenderer) loadRenderer(runtimeContext
094: .getClassLoader(), rendererSetMD
095: .getRegionRenderer()));
096: this .windowRenderer = new DynaWindowRenderer(
097: (WindowRenderer) loadRenderer(runtimeContext
098: .getClassLoader(), rendererSetMD
099: .getWindowRenderer()));
100: this .portletRenderer = new DynaPortletRenderer(
101: (PortletRenderer) loadRenderer(runtimeContext
102: .getClassLoader(), rendererSetMD
103: .getPortletRenderer()));
104: this .decorationRenderer = new DynaDecorationRenderer(
105: (DecorationRenderer) loadRenderer(runtimeContext
106: .getClassLoader(), rendererSetMD
107: .getDecorationRenderer()));
108: } else {
109: this .regionRenderer = (RegionRenderer) loadRenderer(
110: runtimeContext.getClassLoader(), rendererSetMD
111: .getRegionRenderer());
112: this .windowRenderer = (WindowRenderer) loadRenderer(
113: runtimeContext.getClassLoader(), rendererSetMD
114: .getWindowRenderer());
115: this .portletRenderer = (PortletRenderer) loadRenderer(
116: runtimeContext.getClassLoader(), rendererSetMD
117: .getPortletRenderer());
118: this .decorationRenderer = (DecorationRenderer) loadRenderer(
119: runtimeContext.getClassLoader(), rendererSetMD
120: .getDecorationRenderer());
121: }
122: }
123:
124: public ServerRegistrationID getRegistrationId() {
125: return registrationId;
126: }
127:
128: /** @see PortalRenderSet#getMediaType */
129: public MediaType getMediaType() {
130: return contentType;
131: }
132:
133: /**
134: * Get the name of the application (the WAR) that contains this render set.
135: *
136: * @return the name of the application (the WAR) that contains this render set
137: */
138: public String getAppId() {
139: return appID;
140: }
141:
142: /**
143: * Get the name of this render set.
144: *
145: * @return the name of this render set
146: */
147: public String getName() {
148: return name;
149: }
150:
151: /** @see PortalRenderSet#getRegionRenderer */
152: public RegionRenderer getRegionRenderer() {
153: return regionRenderer;
154: }
155:
156: /** @see PortalRenderSet#getWindowRenderer */
157: public WindowRenderer getWindowRenderer() {
158: return windowRenderer;
159: }
160:
161: /** @see PortalRenderSet#getPortletRenderer */
162: public PortletRenderer getPortletRenderer() {
163: return portletRenderer;
164: }
165:
166: /** @see PortalRenderSet#getDecorationRenderer */
167: public DecorationRenderer getDecorationRenderer() {
168: return decorationRenderer;
169: }
170:
171: public boolean isAjaxEnabled() {
172: return ajaxEnabled;
173: }
174:
175: /** @see java.lang.Object#toString */
176: public String toString() {
177: return "PortalRenderSet: " + getAppId() + "."
178: + (getName() == null ? "<from layout>" : getName())
179: + ": " + getMediaType() + " [" + getRegionRenderer()
180: + "][" + getWindowRenderer() + "]["
181: + getDecorationRenderer() + "][" + getPortletRenderer()
182: + "]";
183: }
184:
185: private ObjectRenderer loadRenderer(ClassLoader loader,
186: String className) throws ClassNotFoundException,
187: IllegalAccessException, InstantiationException {
188: return (ObjectRenderer) loader.loadClass(className)
189: .newInstance();
190: }
191: }
|