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.core.impl.api.node;
023:
024: import org.jboss.portal.api.PortalRuntimeContext;
025: import org.jboss.portal.api.node.PortalNode;
026: import org.jboss.portal.api.node.event.PortalNodeEvent;
027: import org.jboss.portal.api.node.event.PortalNodeEventContext;
028: import org.jboss.portal.api.node.event.PortalNodeEventListener;
029: import org.jboss.portal.core.event.PortalEventListenerRegistry;
030:
031: /**
032: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
033: * @version $Revision: 8786 $
034: */
035: public class PortalNodeEventContextImpl implements
036: PortalNodeEventContext {
037:
038: /** . */
039: PortalEventListenerRegistry registry;
040:
041: /** . */
042: private PortalNodeEvent event;
043:
044: /** . */
045: private PortalNodeImpl node;
046:
047: /** . */
048: private PortalRuntimeContext prc;
049:
050: public PortalNodeEventContextImpl(
051: PortalEventListenerRegistry registry, PortalNodeImpl node,
052: PortalNodeEvent event, PortalRuntimeContext prc) {
053: this .registry = registry;
054: this .node = node;
055: this .event = event;
056: this .prc = prc;
057: }
058:
059: public PortalRuntimeContext getPortalRuntimeContext() {
060: return prc;
061: }
062:
063: public PortalNodeEvent dispatch() {
064: PortalNodeEventListener listener = null;
065: String listenerId = node.object.getListener();
066: if (listenerId != null && listenerId.length() > 0) {
067: Object tmp = registry.getListener(listenerId);
068: if (tmp != null && tmp instanceof PortalNodeEventListener) {
069: listener = (PortalNodeEventListener) tmp;
070: }
071: }
072:
073: // Dispatch to the listener
074: PortalNodeEvent nextEvent = null;
075: if (listener != null) {
076: PortalNodeImpl current = node;
077: try {
078: node = (PortalNodeImpl) node.getParent();
079: nextEvent = listener.onEvent(this , event);
080: } finally {
081: node = current;
082: }
083: } else {
084: if (node.getParent() != null) {
085: PortalNodeImpl current = node;
086: try {
087: node = (PortalNodeImpl) node.getParent();
088: nextEvent = dispatch();
089: } finally {
090: node = current;
091: }
092: }
093: }
094:
095: //
096: return nextEvent;
097: }
098:
099: public PortalNode getNode() {
100: return node;
101: }
102: }
|