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.server.impl.invocation;
023:
024: import org.jboss.portal.common.invocation.Interceptor;
025: import org.jboss.portal.common.invocation.InterceptorStack;
026: import org.jboss.portal.common.invocation.InterceptorStackFactory;
027: import org.jboss.portal.jems.as.system.AbstractJBossService;
028:
029: import javax.management.ObjectName;
030: import java.util.ArrayList;
031: import java.util.Collections;
032: import java.util.List;
033:
034: /**
035: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
036: * @version $Revision: 8784 $
037: */
038: public class JBossInterceptorStackFactory extends AbstractJBossService
039: implements InterceptorStackFactory {
040:
041: /** . */
042: protected List interceptorNames;
043:
044: /** . */
045: protected List dynamicInterceptorNames;
046:
047: /** . */
048: protected InterceptorStack stack;
049:
050: public JBossInterceptorStackFactory() {
051: interceptorNames = null;
052: dynamicInterceptorNames = new ArrayList();
053: stack = JBossInterceptorStack.EMPTY_STACK;
054: }
055:
056: public List getInterceptorNames() {
057: return interceptorNames;
058: }
059:
060: public void setInterceptorNames(List interceptorNames) {
061: this .interceptorNames = interceptorNames;
062: }
063:
064: public List getDynamicInterceptorNames() {
065: return Collections.unmodifiableList(dynamicInterceptorNames);
066: }
067:
068: public InterceptorStack getInterceptorStack() {
069: return stack;
070: }
071:
072: /**
073: * Add's the supplied name to the list of interceptor names.
074: *
075: * @param name the intercptor's ObjectName.
076: * @throws Exception
077: */
078: public void addInterceptor(ObjectName name) throws Exception {
079: dynamicInterceptorNames.add(name);
080: }
081:
082: /**
083: * Remove's the supplied name from the list of interceptor names.
084: *
085: * @param name the intercptor's ObjectName.
086: * @throws Exception
087: */
088: public void removeInterceptor(ObjectName name) throws Exception {
089: interceptorNames.remove(name);
090: }
091:
092: public void startService() throws Exception {
093: rebuild();
094: }
095:
096: /** Rebuild the interceptor stack. */
097: public void rebuild() throws Exception {
098: List names = new ArrayList();
099:
100: //
101: if (interceptorNames != null) {
102: names.addAll(interceptorNames);
103: }
104:
105: //
106: names.addAll(dynamicInterceptorNames);
107:
108: //
109: log.debug("Building interceptor stack " + getName());
110: Interceptor[] interceptors = new Interceptor[names.size()];
111: for (int i = 0; i < names.size(); i++) {
112: ObjectName name = (ObjectName) names.get(i);
113: log.debug("Adding interceptor " + name + " to the stack");
114: interceptors[i] = (Interceptor) server.getAttribute(name,
115: "ManagedResource");
116: }
117:
118: //
119: stack = new JBossInterceptorStack(interceptors);
120: }
121:
122: public void stopService() {
123: this.stack = JBossInterceptorStack.EMPTY_STACK;
124: }
125: }
|