1 package com.scalagent.joram.osgi.client; 2 3 import java.io.*; 4 import java.util.*; 5 6 import org.osgi.framework.*; 7 8 import javax.naming.*; 9 10 import org.objectweb.joram.client.jms.ConnectionFactory; 11 import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory; 12 import org.objectweb.joram.client.jms.local.LocalConnectionFactory; 13 import org.objectweb.joram.client.jms.Queue; 14 import org.objectweb.joram.client.jms.Topic; 15 import org.objectweb.joram.client.jms.admin.User; 16 import org.objectweb.joram.client.jms.admin.AdminModule; 17 18 public class Activator implements BundleActivator { 19 20 private static BundleContext bcontext; 21 22 public static BundleContext getBundleContext() { 23 return bcontext; 24 } 25 26 31 public void start(BundleContext context) throws Exception { 32 bcontext = context; 33 34 Properties props = new Properties(); 35 context.registerService( 36 com.scalagent.joram.osgi.client.service.JoramClient.class.getName(), 37 new JoramClientImpl(), props); 38 } 39 40 45 public void stop(BundleContext context) { 46 } 47 48 public static class JoramClientImpl 49 implements com.scalagent.joram.osgi.client.service.JoramClient { 50 53 public void connect(String host, int port, 54 String name, String password, 55 int cnxTimer) throws Exception { 56 AdminModule.connect(host, port, name, password, cnxTimer); 57 } 58 61 public void disconnect() { 62 AdminModule.disconnect(); 63 } 64 65 68 public ConnectionFactory 69 getTcpConnectionFactory(String hostname, int port) throws Exception { 70 return new TcpConnectionFactory(hostname, port); 71 } 72 73 76 public Context getInitialContext() throws Exception { 77 Properties prop = new Properties(); 78 prop.setProperty("java.naming.factory.initial", "fr.dyade.aaa.jndi2.client.NamingContextFactory"); 79 prop.setProperty("java.naming.factory.host", "localhost"); 80 prop.setProperty("java.naming.factory.port", "16400"); 81 return getInitialContext(prop); 82 } 83 84 87 public Context getInitialContext(Hashtable prop) throws Exception { 88 Thread ct = Thread.currentThread(); 89 ClassLoader cl = ct.getContextClassLoader(); 90 ct.setContextClassLoader(JoramClientImpl.class.getClassLoader()); 91 Context ctx = new InitialContext(prop); 92 ct.setContextClassLoader(cl); 93 return ctx; 94 } 95 96 99 public boolean executeAdminXML(Reader reader) throws Exception { 100 return AdminModule.executeAdmin(reader); 101 } 102 103 108 public void createUser(String name, String password) throws Exception { 109 User.create(name, password); 110 } 111 112 120 public Queue createQueue(String name) throws Exception { 121 Queue queue = Queue.create(name); 122 queue.setFreelyWriteable(true); 123 queue.setFreelyReadable(true); 124 125 return queue; 126 } 127 128 134 public Topic createTopic(String name) throws Exception { 135 Topic topic = Topic.create(name); 136 topic.setFreelyWriteable(true); 137 topic.setFreelyReadable(true); 138 139 return topic; 140 } 141 142 145 public List getDestinations() throws Exception { 146 return AdminModule.getDestinations(); 147 } 148 149 152 public List getUsers() throws Exception { 153 return AdminModule.getUsers(); 154 } 155 } 156 } 157 | Popular Tags |