This project has retired. For details please refer to its Attic page.
JNDIRegistration xref
View Javadoc
1   /*
2    * Copyright 2001-2009 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.rmi;
17  
18  import javax.naming.Context;
19  import javax.naming.InitialContext;
20  import javax.naming.NamingException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  /**
26   * @author Kurt Stam (kstam@apache.org)
27   */
28  public class JNDIRegistration
29  {
30  	public static final String JUDDI = "/juddiv3";
31  	public static final String UDDI_SECURITY_SERVICE    = JUDDI + "/UDDISecurityService";
32  	public static final String UDDI_PUBLICATION_SERVICE = JUDDI + "/UDDIPublicationService";
33  	public static final String UDDI_INQUIRY_SERVICE     = JUDDI + "/UDDIInquiryService";
34  	public static final String UDDI_SUBSCRIPTION_SERVICE = JUDDI + "/UDDISubscriptionService";
35  	public static final String UDDI_SUBSCRIPTION_LISTENER_SERVICE = JUDDI + "/UDDISubscriptionListenerService";
36  	public static final String UDDI_CUSTODY_TRANSFER_SERVICE = JUDDI + "/UDDICustodyTransferService";
37  	public static final String JUDDI_PUBLISHER_SERVICE  = JUDDI + "/JUDDIApiService";
38  	
39  	private UDDISecurityService securityService = null;
40  	private UDDIPublicationService publicationService = null;
41  	private UDDIInquiryService inquiryService = null;
42  	private UDDISubscriptionService subscriptionService = null;
43  	private UDDISubscriptionListenerService subscriptionListenerService = null;
44  	private UDDICustodyTransferService custodyTransferService = null;
45  	private JUDDIApiService publisherService = null;
46  	
47  	private Log log = LogFactory.getLog(this.getClass());
48  	InitialContext context = null;
49  	private static JNDIRegistration registration = null;
50  	
51  	public static JNDIRegistration getInstance() throws NamingException {
52  		if (registration==null) {
53  			registration = new JNDIRegistration();
54  		}
55  		return registration;
56  	}
57  	
58  	private JNDIRegistration() throws NamingException{
59  		super();
60  		context = new InitialContext(); 
61  	}
62  	/**
63  	 * Registers the Publish and Inquiry Services to JNDI and instantiates a
64  	 * instance of each so we can remotely attach to it later.
65  	 */
66  	public void register(int port) {
67  		try {
68  			Context juddiContext = context.createSubcontext(JUDDI);
69  			
70  			securityService = new UDDISecurityService(port);
71  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_SECURITY_SERVICE + ", " + securityService.getClass());
72  			juddiContext.bind(UDDI_SECURITY_SERVICE, securityService);
73  			
74  			publicationService = new UDDIPublicationService(port);
75  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_PUBLICATION_SERVICE + ", " + publicationService.getClass());
76  			juddiContext.bind(UDDI_PUBLICATION_SERVICE, publicationService);
77  			
78  			inquiryService = new UDDIInquiryService(port);
79  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_INQUIRY_SERVICE + ", " + inquiryService.getClass());
80  			juddiContext.bind(UDDI_INQUIRY_SERVICE, inquiryService);
81  			
82  			subscriptionService = new UDDISubscriptionService(port);
83  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_SUBSCRIPTION_SERVICE + ", " + subscriptionService.getClass());
84  			juddiContext.bind(UDDI_SUBSCRIPTION_SERVICE, subscriptionService);
85  			
86  			subscriptionListenerService = new UDDISubscriptionListenerService(port);
87  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_SUBSCRIPTION_LISTENER_SERVICE + ", " + subscriptionListenerService.getClass());
88  			juddiContext.bind(UDDI_SUBSCRIPTION_LISTENER_SERVICE, subscriptionListenerService);
89  			
90  			custodyTransferService = new UDDICustodyTransferService(port);
91  			if (log.isDebugEnabled()) log.debug("Setting " + UDDI_CUSTODY_TRANSFER_SERVICE + ", " + custodyTransferService.getClass());
92  			juddiContext.bind(UDDI_CUSTODY_TRANSFER_SERVICE, custodyTransferService);
93  			
94  			publisherService = new JUDDIApiService(port);
95  			if (log.isDebugEnabled()) log.debug("Setting " + JUDDI_PUBLISHER_SERVICE + ", " + publisherService.getClass());
96  			juddiContext.bind(JUDDI_PUBLISHER_SERVICE, publisherService);
97  			
98  		} catch (Exception e) {
99  			log.error(e.getMessage(),e);
100 		}
101 	}
102 	
103 	public void unregister() {
104 		
105 		try {
106 			context.unbind(UDDI_SECURITY_SERVICE);
107 		} catch (NamingException e) {
108 			log.error(e.getMessage(),e);
109 		}
110 		securityService = null;
111 		try {
112 			context.unbind(UDDI_PUBLICATION_SERVICE);
113 		} catch (NamingException e) {
114 			log.error(e.getMessage(),e);
115 		}
116 		publicationService = null;
117 		try {
118 			context.unbind(UDDI_INQUIRY_SERVICE);
119 		} catch (NamingException e) {
120 			log.error(e.getMessage(),e);
121 		}
122 		inquiryService = null;
123 		try {
124 			context.unbind(UDDI_SUBSCRIPTION_SERVICE);
125 		} catch (NamingException e) {
126 			log.error(e.getMessage(),e);
127 		}
128 		subscriptionService = null;
129 		try {
130 			context.unbind(UDDI_SUBSCRIPTION_LISTENER_SERVICE);
131 		} catch (NamingException e) {
132 			log.error(e.getMessage(),e);
133 		}
134 		subscriptionListenerService = null;
135 		try {
136 			context.unbind(UDDI_CUSTODY_TRANSFER_SERVICE);
137 		} catch (NamingException e) {
138 			log.error(e.getMessage(),e);
139 		}
140 		custodyTransferService = null;
141 		try {
142 			context.unbind(JUDDI_PUBLISHER_SERVICE);
143 		} catch (NamingException e) {
144 			log.error(e.getMessage(),e);
145 		}
146 		publisherService = null;
147 		try {
148 			context.unbind(JUDDI);
149 		} catch (NamingException e) {
150 			log.error(e.getMessage(),e);
151 		}
152 		
153 	}
154 }