1/*2 * Copyright 2001-2008 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 *16 */17package org.apache.juddi.subscription.notify;
1819import java.lang.reflect.InvocationTargetException;
20import java.net.URISyntaxException;
2122import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24import org.apache.juddi.ClassUtil;
25import org.apache.juddi.model.BindingTemplate;
26import org.apache.juddi.model.TmodelInstanceInfo;
27/**28 * The factory figures out which Notifier class to instantiate.29 * 30 * @author kstam31 *32 */33publicclassNotifierFactory {
3435 Log log = LogFactory.getLog(this.getClass());
36publicstaticfinal String UDDI_TRANSPORT_KEY = "uddi:uddi.org:transport:";
3738publicNotifier getNotifier(BindingTemplate bindingTemplate)
39throws URISyntaxException, IllegalArgumentException, SecurityException,
40 InstantiationException, IllegalAccessException, InvocationTargetException,
41 NoSuchMethodException, ClassNotFoundException
42 {
43 String notifierClassName = null;
44for (TmodelInstanceInfo tModelInstanceInfo : bindingTemplate.getTmodelInstanceInfos()) {
45if (tModelInstanceInfo.getTmodelKey().startsWith(UDDI_TRANSPORT_KEY)) {
46 log.debug("Found transport tModelKey " + tModelInstanceInfo.getTmodelKey());
47 String transport = tModelInstanceInfo.getTmodelKey().substring(UDDI_TRANSPORT_KEY.length(),tModelInstanceInfo.getTmodelKey().length());
48 transport = transport.replaceAll("-", "_");
49 notifierClassName = "org.apache.juddi.subscription.notify." + transport.toUpperCase() + "Notifier";
50break;
51 }
52 }
53if (notifierClassName == null) {
54//JUDDI-496 TODO make sure the tModel is loaded55 log.warn("The bindingTemplate " + bindingTemplate.getEntityKey() + " does not contain a tModel to define its type of transport. Defaulting "56 + "to http.");
57//JUDDI-596, attempt http transport, even if a transport isn't specified58 notifierClassName = "org.apache.juddi.subscription.notify.HTTPNotifier";
59 }
60if (log.isDebugEnabled()) log.debug("Going find and instantiate notifier class: " + notifierClassName);
6162 @SuppressWarnings("unchecked")
63 Class<Notifier> notifierClass = (Class<Notifier>) ClassUtil.forName(notifierClassName,this.getClass());
64 Notifier notifier = notifierClass.getConstructor(BindingTemplate.class).newInstance(bindingTemplate);
65return notifier;
66 }
6768 }