1/*2 * Copyright 2001-2010 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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16package org.apache.juddi.v3.client.config;
1718import java.util.HashMap;
19import java.util.Iterator;
20import java.util.Map;
2122import org.apache.commons.configuration.ConfigurationException;
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
2526/**27 * Internal jUDDI class to handle multiple clients on the same classloader.28 * 29 * @author kstam30 *31 */32publicclassUDDIClientContainer {
3334privatestatic Log log = LogFactory.getLog(UDDIClientContainer.class);
35privatestatic Map<String,UDDIClient> clients = new HashMap<String, UDDIClient>();
3637publicstaticUDDIClient getUDDIClient(String clientName)
38throws ConfigurationException {
3940if (clientName!=null) {
41if (clients.containsKey(clientName)) {
42return (clients.get(clientName));
43 } else {
44 StringBuilder sb = new StringBuilder();
45 Iterator<String> iterator = clients.keySet().iterator();
46while (iterator.hasNext()){
47 sb.append(iterator.next());
48if (iterator.hasNext())
49 sb.append(",");
50 }
51thrownew ConfigurationException("No client by name " + clientName + " was found. " +
52" Please check your client uddi.xml files, and make sure this client was started. Available clients: " + sb.toString());
53 }
54 } elsethrownew IllegalArgumentException("clientName is a required argument");
55 }
5657/**58 * adds the named client, but only if it isn't registered already59 * @param manager60 * @return true if successful61 */62publicstaticboolean addClient(UDDIClient manager) {
63if (!clients.containsKey(manager.getClientConfig().getClientName())) {
64 clients.put(manager.getClientConfig().getClientName(), manager);
65returntrue;
66 } else {
67return false;
68 }
69 }
7071publicstaticvoid removeClerkManager(String clientName)
72throws ConfigurationException {
73if (clients.containsKey(clientName)) {
74 clients.remove(clientName);
75 } elseif (clients.size()==1 && clientName==null) {
76 String name = clients.keySet().iterator().next();
77 log.info("Removing " + name + " from UDDIClient.");
78 clients.remove(name);
79 } else {
80thrownew ConfigurationException("Could not remove UDDIClient for name " + clientName);
81 }
82 }
8384/**85 * return true if the client exists in the current client collection86 * @param name87 * @return true/false88 */89publicstaticboolean contains(String name) {
90return (clients.containsKey(name)) ;
91 }
9293publicstaticvoid removeAll() {
94 clients.clear();
95 }
9697 }