KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > jms > ServerPeerJMSDestinationFactory


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.ejb3.jms;
23
24 import javax.jms.Destination JavaDoc;
25 import javax.jms.Queue JavaDoc;
26 import javax.jms.Topic JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.ejb3.KernelAbstraction;
30 import org.jboss.ejb3.KernelAbstractionFactory;
31 import org.jboss.logging.Logger;
32
33 /**
34  * Use ServerPeer for creation of destinations.
35  *
36  * JBoss AS 5.0
37  *
38  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
39  * @version $Revision: $
40  */

41 public class ServerPeerJMSDestinationFactory extends JMSDestinationFactory
42 {
43    private static final Logger log = Logger.getLogger(ServerPeerJMSDestinationFactory.class);
44    
45    // Do not instantiate outside package
46
ServerPeerJMSDestinationFactory()
47    {
48       
49    }
50    
51    public void createDestination(Class JavaDoc<? extends Destination JavaDoc> type, String JavaDoc jndiSuffix) throws Exception JavaDoc
52    {
53       String JavaDoc methodName;
54       String JavaDoc destinationContext;
55       if (type == Topic JavaDoc.class)
56       {
57          destinationContext = "topic";
58          methodName = "createTopic";
59       }
60       else if (type == Queue JavaDoc.class)
61       {
62          destinationContext = "queue";
63          methodName = "createQueue";
64       }
65       else
66       {
67          // type was not a Topic or Queue, bad user
68
throw new IllegalArgumentException JavaDoc
69                  ("Expected javax.jms.Queue or javax.jms.Topic: " + type);
70       }
71       
72       String JavaDoc name = jndiSuffix;
73       String JavaDoc jndiName = destinationContext + "/" + jndiSuffix;
74       
75       ObjectName JavaDoc serverPeerName = new ObjectName JavaDoc("jboss.messaging:service=ServerPeer");
76       
77       KernelAbstraction kernel = KernelAbstractionFactory.getInstance();
78       // invoke the server to create the destination
79
Object JavaDoc result = kernel.invoke(serverPeerName,
80               methodName,
81               new Object JavaDoc[]{name, jndiName},
82               new String JavaDoc[]{"java.lang.String", "java.lang.String"});
83       
84       log.debug("result = " + result);
85    }
86 }
87
Popular Tags