001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.jms.client.container;
023:
024: import org.jboss.aop.advice.Interceptor;
025: import org.jboss.aop.joinpoint.Invocation;
026: import org.jboss.aop.joinpoint.MethodInvocation;
027: import org.jboss.jms.client.BrowserDelegate;
028: import org.jboss.jms.client.ConsumerDelegate;
029: import org.jboss.jms.client.ProducerDelegate;
030: import org.jboss.jms.client.SessionDelegate;
031: import org.jboss.jms.container.Container;
032: import org.jboss.jms.message.standard.MessageFactoryInterceptor;
033:
034: /**
035: * An interceptor for creating delegates
036: *
037: * @author <a href="mailto:adrian@jboss.org>Adrian Brock</a>
038: * @version $Revision: 57195 $
039: */
040: public class FactoryInterceptor implements Interceptor {
041: // Constants -----------------------------------------------------
042:
043: // Attributes ----------------------------------------------------
044:
045: // Static --------------------------------------------------------
046:
047: public static final FactoryInterceptor singleton = new FactoryInterceptor();
048:
049: // Constructors --------------------------------------------------
050:
051: // Public --------------------------------------------------------
052:
053: // Interceptor implementation -----------------------------------
054:
055: public String getName() {
056: return "FactoryInterceptor";
057: }
058:
059: public Object invoke(Invocation invocation) throws Throwable {
060: Object result = invocation.invokeNext();
061: String methodName = ((MethodInvocation) invocation).getMethod()
062: .getName();
063: if (methodName.equals("createSession"))
064: return createSession(invocation, (SessionDelegate) result);
065: else if (methodName.equals("createBrowser"))
066: return createBrowser(invocation, (BrowserDelegate) result);
067: else if (methodName.equals("createConsumer"))
068: return createConsumer(invocation, (ConsumerDelegate) result);
069: else if (methodName.equals("createProducer"))
070: return createProducer(invocation, (ProducerDelegate) result);
071: else
072: return result;
073: }
074:
075: // Protected ------------------------------------------------------
076:
077: protected SessionDelegate createSession(Invocation invocation,
078: SessionDelegate server) throws Throwable {
079: Interceptor[] interceptors = new Interceptor[] {
080: MessageFactoryInterceptor.singleton,
081: FactoryInterceptor.singleton };
082: Container connection = Container.getContainer(invocation);
083: return ClientContainerFactory.getSessionContainer(connection,
084: server, interceptors, null);
085: }
086:
087: protected BrowserDelegate createBrowser(Invocation invocation,
088: BrowserDelegate server) throws Throwable {
089: Interceptor[] interceptors = new Interceptor[0];
090: Container session = Container.getContainer(invocation);
091: return ClientContainerFactory.getBrowserContainer(session,
092: server, interceptors, null);
093: }
094:
095: protected ConsumerDelegate createConsumer(Invocation invocation,
096: ConsumerDelegate server) throws Throwable {
097: Interceptor[] interceptors = new Interceptor[0];
098: Container session = Container.getContainer(invocation);
099: return ClientContainerFactory.getConsumerContainer(session,
100: server, interceptors, null);
101: }
102:
103: protected ProducerDelegate createProducer(Invocation invocation,
104: ProducerDelegate server) throws Throwable {
105: Interceptor[] interceptors = new Interceptor[0];
106: Container session = Container.getContainer(invocation);
107: return ClientContainerFactory.getProducerContainer(session,
108: server, interceptors, null);
109: }
110:
111: // Package Private ------------------------------------------------
112:
113: // Private --------------------------------------------------------
114:
115: // Inner Classes --------------------------------------------------
116:
117: }
|