KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > server > container > ServerProducerInterceptor


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.server.container;
8
9 import org.jboss.aop.advice.Interceptor;
10 import org.jboss.aop.joinpoint.Invocation;
11 import org.jboss.aop.joinpoint.MethodInvocation;
12 import org.jboss.jms.message.JBossMessage;
13 import org.jboss.jms.server.DeliveryEndpoint;
14 import org.jboss.jms.server.DeliveryEndpointFactory;
15 import org.jboss.jms.server.MessageReference;
16
17 /**
18  * The server implementation of the producer
19  *
20  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
21  * @version $Revision: 1.4 $
22  */

23 public class ServerProducerInterceptor
24    implements Interceptor
25 {
26    // Constants -----------------------------------------------------
27

28    // Attributes ----------------------------------------------------
29

30    // Static --------------------------------------------------------
31

32    public static ServerProducerInterceptor singleton = new ServerProducerInterceptor();
33
34    // Constructors --------------------------------------------------
35

36    // Public --------------------------------------------------------
37

38    // Interceptor implementation ------------------------------------
39

40    public String JavaDoc getName()
41    {
42       return "ServerProducerInterceptor";
43    }
44
45    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
46    {
47       MethodInvocation mi = (MethodInvocation) invocation;
48       String JavaDoc methodName = mi.getMethod().getName();
49       if (methodName.equals("send"))
50       {
51          
52          JBossMessage message = (JBossMessage) mi.getArguments()[0];
53          JBossMessage clone = (JBossMessage) message.clone();
54          DeliveryEndpointFactory factory = (DeliveryEndpointFactory) mi.getMetaData("JMS", "DeliveryEndpointFactory");
55          MessageReference reference = factory.getMessageReference(clone);
56          DeliveryEndpoint endpoint = factory.getDeliveryEndpoint(reference);
57          endpoint.deliver(reference);
58          return null;
59       }
60       else if (methodName.equals("closing") || methodName.equals("close"))
61          return null;
62       throw new UnsupportedOperationException JavaDoc(mi.getMethod().toString());
63    }
64
65    // Protected ------------------------------------------------------
66

67    // Package Private ------------------------------------------------
68

69    // Private --------------------------------------------------------
70

71    // Inner Classes --------------------------------------------------
72

73 }
74
Popular Tags