KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > joram > osgi > test > Activator


1 package com.scalagent.joram.osgi.test;
2
3 import java.io.*;
4 import java.util.Properties JavaDoc;
5
6 import org.osgi.framework.*;
7
8 import javax.jms.*;
9 import javax.naming.*;
10
11 import com.scalagent.joram.osgi.client.service.JoramClient;
12
13 public class Activator implements BundleActivator {
14
15   private static BundleContext bcontext;
16
17   public static BundleContext getBundleContext() {
18     return bcontext;
19   }
20
21   ServiceReference ref = null;
22   JoramClient jclient = null;
23
24   /**
25    * Implements BundleActivator.start().
26    *
27    * @param context the framework context for the bundle.
28    */

29   public void start(BundleContext context) throws Exception JavaDoc {
30     bcontext = context;
31
32     ref = context.getServiceReference(JoramClient.class.getName());
33     jclient = (JoramClient) context.getService(ref);
34
35     Context ictx = jclient.getInitialContext();
36     System.err.println("" + ictx.getClass());
37
38     // Admin phase
39
ClassLoader JavaDoc cl = getClass().getClassLoader();
40 // Thread ct = Thread.currentThread();
41
// ClassLoader cl = ct.getContextClassLoader();
42
InputStream is = cl.getResourceAsStream("joramAdmin.xml");
43     jclient.executeAdminXML(new InputStreamReader(is));
44
45     Reference refQ = (Reference) ictx.lookup("queue");
46
47     System.err.println("" + refQ.getClass());
48     System.err.println("" + refQ.getFactoryClassName());
49     System.err.println(refQ.toString());
50
51 // Thread ct = Thread.currentThread();
52
// ClassLoader cl = ct.getContextClassLoader();
53
// ct.setContextClassLoader(ictx.getClass().getClassLoader());
54
// Queue queue = (Queue) ictx.lookup("queue");
55
// Topic topic = (Topic) ictx.lookup("topic");
56
// ct.setContextClassLoader(cl);
57
// ictx.close();
58

59     ConnectionFactory cf = jclient.getTcpConnectionFactory("localhost", 16010);
60     Connection cnx = cf.createConnection();
61     Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
62 // Queue queue = sess.createQueue("#0.0.1026");
63
Queue queue = sess.createQueue((String JavaDoc) refQ.get("dest.name").getContent());
64
65     TextMessage msg = sess.createTextMessage();
66     MessageProducer producer = sess.createProducer(queue);
67     msg.setText("Hello world");
68     producer.send(msg);
69     sess.close();
70     cnx.close();
71   }
72
73   /**
74    * Implements BundleActivator.stop().
75    *
76    * @param context the framework context for the bundle.
77    */

78   public void stop(BundleContext context) {
79     context.ungetService(ref);
80   }
81 }
82
Popular Tags