1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.registry.rmi;
17
18 import java.util.Properties;
19
20 import javax.naming.InitialContext;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.juddi.registry.RegistryEngine;
25 import org.apache.juddi.util.Config;
26
27 /***
28 * @author Kurt Stam (kurt.stam@redhat.com)
29 */
30 public class JNDIRegistration
31 {
32 /*** Instance of the InqueryService, so we have a running instance we
33 * can remotely attach to it later. */
34 public static Inquiry mInquery=null;
35 /*** Instance of the PublishService, so we have a running instance we
36 * can remotely attach to it later. */
37 public static Publish mPublish=null;
38 /*** Name of the inquiry service in JNDI */
39 public static String INQUIRY_SERVICE="/InquiryService";
40 /*** Name of the publish service in JNDI */
41 public static String PUBLISH_SERVICE="/PublishService";
42 /*** Logger */
43 private static Log log = LogFactory.getLog(JNDIRegistration.class);
44 /***
45 * Registers the Publish and Inquiry Services to JNDI and instantiates a
46 * instance of each so we can remotely attach to it later.
47 */
48 public static void register()
49 {
50 try {
51
52 String factoryInitial = System.getProperty(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL);
53 String providerURL = System.getProperty(RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL);
54 String factoryURLPkgs = System.getProperty(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS);
55
56 if (factoryInitial==null) {
57 factoryInitial = Config.getStringProperty(
58 RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL,
59 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_INITIAL);
60 } else {
61 log.debug("FactoryInitial was obtained from a System Parameter");
62 }
63 if (providerURL==null) {
64 providerURL = Config.getStringProperty(
65 RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL,
66 RegistryEngine.DEFAULT_JAVA_NAMING_PROVIDER_URL);
67 } else {
68 log.debug("ProviderUrl was obtained from a System Parameter");
69 }
70
71 if (factoryURLPkgs==null) {
72 factoryURLPkgs = Config.getStringProperty(
73 RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS,
74 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_URL_PKGS);
75 } else {
76 log.debug("FactoryURLPkgs was obtained from a System Parameter");
77 }
78
79 Properties env = new Properties();
80 env.setProperty(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL, factoryInitial);
81 env.setProperty(RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL, providerURL);
82 env.setProperty(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS, factoryURLPkgs);
83 if (log.isDebugEnabled()) {
84 log.debug("Creating Initial Context using: \n"
85 + RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL + "=" + factoryInitial + "\n"
86 + RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL + "=" + providerURL + "\n"
87 + RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS + "=" + factoryURLPkgs + "\n");
88 }
89 InitialContext context = new InitialContext(env);
90 Inquiry inquiry = new InquiryService();
91 if (log.isDebugEnabled()) {
92 log.debug("Setting " + INQUIRY_SERVICE + ", " + inquiry.getClass().getName());
93 }
94 mInquery = inquiry;
95 context.rebind(INQUIRY_SERVICE, inquiry);
96 Publish publish = new PublishService();
97 if (log.isDebugEnabled()) {
98 log.debug("Setting " + PUBLISH_SERVICE + ", " + publish.getClass().getName());
99 }
100 mPublish = publish;
101 context.rebind(PUBLISH_SERVICE, publish);
102 } catch (Exception e) {
103 e.printStackTrace();
104 }
105 }
106 }