com/scalagent/joram/osgi/client/Activator.java

00001 package com.scalagent.joram.osgi.client;
00002 
00003 import java.io.*;
00004 import java.util.*;
00005 
00006 import org.osgi.framework.*;
00007 
00008 import javax.naming.*;
00009 
00010 import org.objectweb.joram.client.jms.ConnectionFactory;
00011 import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
00012 import org.objectweb.joram.client.jms.local.LocalConnectionFactory;
00013 import org.objectweb.joram.client.jms.Queue;
00014 import org.objectweb.joram.client.jms.Topic;
00015 import org.objectweb.joram.client.jms.admin.User;
00016 import org.objectweb.joram.client.jms.admin.AdminModule;
00017 
00018 public class Activator implements BundleActivator {
00019 
00020   private static BundleContext bcontext;
00021 
00022   public static BundleContext getBundleContext() {
00023     return bcontext;
00024   }
00025 
00031   public void start(BundleContext context) throws Exception {
00032     bcontext = context;
00033 
00034     Properties props = new Properties();
00035     context.registerService(
00036       com.scalagent.joram.osgi.client.service.JoramClient.class.getName(), 
00037       new JoramClientImpl(), props);
00038   }
00039 
00045   public void stop(BundleContext context) {
00046   }
00047 
00048   public static class JoramClientImpl 
00049     implements com.scalagent.joram.osgi.client.service.JoramClient {
00053     public void connect(String host, int port,
00054                         String name, String password,
00055                         int cnxTimer) throws Exception {
00056       AdminModule.connect(host, port, name, password, cnxTimer);
00057     }
00061     public void disconnect() {
00062       AdminModule.disconnect();
00063     }
00064 
00068     public ConnectionFactory
00069         getTcpConnectionFactory(String hostname, int port) throws Exception {
00070       return new TcpConnectionFactory(hostname, port);
00071     }
00072 
00076     public Context getInitialContext() throws Exception {
00077       Properties prop = new Properties();
00078       prop.setProperty("java.naming.factory.initial", "fr.dyade.aaa.jndi2.client.NamingContextFactory");
00079       prop.setProperty("java.naming.factory.host", "localhost");
00080       prop.setProperty("java.naming.factory.port", "16400");
00081       return getInitialContext(prop);
00082     }
00083 
00087     public Context getInitialContext(Hashtable prop) throws Exception {
00088       Thread ct = Thread.currentThread();
00089       ClassLoader cl = ct.getContextClassLoader();
00090       ct.setContextClassLoader(JoramClientImpl.class.getClassLoader());
00091       Context ctx = new InitialContext(prop);
00092       ct.setContextClassLoader(cl);
00093       return ctx;
00094     }
00095 
00099     public boolean executeAdminXML(Reader reader) throws Exception {
00100       return AdminModule.executeAdmin(reader);
00101     }
00102 
00108     public void createUser(String name, String password) throws Exception {
00109       User.create(name, password);
00110     }
00111 
00120     public Queue createQueue(String name) throws Exception {
00121       Queue queue = Queue.create(name);
00122       queue.setFreelyWriteable(true);
00123       queue.setFreelyReadable(true);
00124 
00125       return queue;
00126     }
00127 
00134     public Topic createTopic(String name) throws Exception {
00135       Topic topic = Topic.create(name);
00136       topic.setFreelyWriteable(true);
00137       topic.setFreelyReadable(true);
00138 
00139       return topic;
00140     }
00141 
00145     public List getDestinations() throws Exception {
00146       return AdminModule.getDestinations();
00147     }
00148 
00152     public List getUsers() throws Exception {
00153       return AdminModule.getUsers();
00154     }
00155   }
00156 }

Generated on Tue Sep 16 16:14:23 2008 for joram by  doxygen 1.5.0