001: /*
002: * Copyright 2004-2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.portletcontainercommon.descriptor;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Iterator;
018: import java.util.LinkedHashMap;
019: import java.util.logging.Logger;
020:
021: import org.jdom.Element;
022: import org.jdom.Namespace;
023: import com.sun.portal.log.common.PortalLogger;
024:
025: /**
026: * The Portlets Descriptor is the entry point of accessing portlet
027: * descriptors.
028: * <P>
029: * The PortletsDescriptor loads all the portlet descriptors into memory,
030: * it delegates the loading of each portlet descriptor to the
031: * <code>PortletDescriptor</code> classe.
032: * <P>
033: * The PortletsDescriptor class provides member methods to get to all
034: * portlet descriptors, the portlet names, as well as to a specified portlet
035: * description. The following get**() methods are available:
036: * <UL>
037: * <LI><code>getPortletDescriptors()</code>
038: * <LI><code>getPortletNames()</code>
039: * <LI><code>getPortletDescriptor()</code>
040: *</UL>
041: *
042: */
043: public class PortletsDescriptor {
044:
045: // Portlets Descriptor Element Name
046: public static final String PORTLET = "portlet";
047:
048: // Global variables
049: private List _portletDescriptors = new ArrayList();
050: private List _portletNames = new ArrayList();
051: private DeploymentExtensionDescriptor _depExtDescriptor;
052:
053: // Create a logger for this class
054: private static Logger debugLogger = PortalLogger
055: .getLogger(PortletsDescriptor.class);
056:
057: public PortletsDescriptor(Logger logger,
058: DeploymentExtensionDescriptor depExtDescriptor) {
059: _depExtDescriptor = depExtDescriptor;
060: }
061:
062: /**
063: * Loads the portlets descriptor into memory.
064: * <P>
065: * This class only loads the top level elements, it delegates the load
066: * action into portlet descriptor class.
067: * <P>
068: * @param The root Element of the deployment descriptor document
069: */
070: public void load(Element element, Namespace namespace)
071: throws DeploymentDescriptorException {
072: List portletElements = element.getChildren(PORTLET, namespace);
073: if (portletElements.isEmpty()) {
074: debugLogger.warning("PSPL_PCCCSPPCCD0010");
075: }
076:
077: Iterator iterator = portletElements.iterator();
078: while (iterator.hasNext()) {
079: Element portletElement = (Element) iterator.next();
080: PortletDescriptor portletDescriptor = new PortletDescriptor(
081: debugLogger, _depExtDescriptor);
082: portletDescriptor.load(portletElement, namespace);
083: _portletDescriptors.add(portletDescriptor);
084: _portletNames.add(portletDescriptor.getPortletName());
085: }
086: }
087:
088: /**
089: * Returns the portlet names.
090: * <P>
091: * @return A List of portlet names
092: */
093: public List getPortletNames() {
094: return _portletNames;
095: }
096:
097: public LinkedHashMap getGeneratedEvents() {
098: if (_depExtDescriptor == null) {
099: return new LinkedHashMap();
100: } else {
101: return _depExtDescriptor.getGeneratedEvents();
102: }
103: }
104:
105: public LinkedHashMap getConsumeEvents() {
106: if (_depExtDescriptor == null) {
107: return new LinkedHashMap();
108: } else {
109: return _depExtDescriptor.getConsumeEvents();
110: }
111: }
112:
113: /**
114: * Returns the portlet descriptors.
115: * <P>
116: * @return A List of <code>PortletDescriptor</code>s
117: */
118: public List getPortletDescriptors() {
119: return _portletDescriptors;
120: }
121:
122: /**
123: * Returns the specified portlet descriptor.
124: * <P>
125: * @param portletName The portlet name
126: * @return A <code>PortletDescriptor</code>. The returned value could be
127: * null if the specified portlet descriptor is not found.
128: */
129: public PortletDescriptor getPortletDescriptor(String portletName) {
130: PortletDescriptor portlet = null;
131: boolean stop = false;
132: Iterator iterator = _portletDescriptors.iterator();
133: while (iterator.hasNext() && !stop) {
134: PortletDescriptor portletDescriptor = (PortletDescriptor) iterator
135: .next();
136: if (portletDescriptor.getPortletName().equals(portletName)) {
137: portlet = portletDescriptor;
138: stop = true;
139: }
140: }
141:
142: return portlet;
143: }
144:
145: /**
146: * The toString method.
147: * <P>
148: * @return the <code>String</code> representation of the portlets
149: * descriptor.
150: */
151: public String toString() {
152: StringBuffer sb = new StringBuffer("PortletsDescriptor [");
153:
154: Iterator iterator = _portletDescriptors.iterator();
155: while (iterator.hasNext()) {
156: PortletDescriptor portletDescriptor = (PortletDescriptor) iterator
157: .next();
158: sb.append(portletDescriptor.toString());
159: sb.append("\n");
160: }
161: sb.append("]");
162: sb.append("\n");
163: return sb.toString();
164: }
165: }
|