This project has retired. For details please refer to its Attic page.
NotifierFactory xref
View Javadoc
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 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   */
17  package org.apache.juddi.subscription.notify;
18  
19  import java.lang.reflect.InvocationTargetException;
20  import java.net.URISyntaxException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.juddi.ClassUtil;
25  import org.apache.juddi.model.BindingTemplate;
26  import org.apache.juddi.model.TmodelInstanceInfo;
27  /**
28   * The factory figures out which Notifier class to instantiate.
29   * 
30   * @author kstam
31   *
32   */
33  public class NotifierFactory {
34  	
35  	Log log = LogFactory.getLog(this.getClass());
36  	public static final String UDDI_TRANSPORT_KEY = "uddi:uddi.org:transport:";
37  	
38  	public Notifier getNotifier(BindingTemplate bindingTemplate) 
39  		throws URISyntaxException, IllegalArgumentException, SecurityException, 
40  		InstantiationException, IllegalAccessException, InvocationTargetException, 
41  		NoSuchMethodException, ClassNotFoundException 
42  	{
43  	    String notifierClassName = null;
44  		for (TmodelInstanceInfo tModelInstanceInfo : bindingTemplate.getTmodelInstanceInfos()) {
45  			if (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";
50  				break;
51  			}
52  		}
53  		if (notifierClassName == null) {
54  			//JUDDI-496 TODO make sure the tModel is loaded
55  			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 specified
58  			notifierClassName =   "org.apache.juddi.subscription.notify.HTTPNotifier";
59  		}
60  		if (log.isDebugEnabled()) log.debug("Going find and instantiate notifier class: " + notifierClassName);
61  		
62  		@SuppressWarnings("unchecked")
63  		Class<Notifier> notifierClass = (Class<Notifier>) ClassUtil.forName(notifierClassName,this.getClass());
64  		Notifier notifier = notifierClass.getConstructor(BindingTemplate.class).newInstance(bindingTemplate);
65  	    return notifier;
66  	}
67  	
68  }