This project has retired. For details please refer to its Attic page.
UDDIClient xref
View Javadoc
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 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.v3.client.config;
18  
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  import java.util.Properties;
24  import java.util.Set;
25  import org.apache.commons.configuration.ConfigurationException;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.juddi.api_v3.Node;
29  import org.apache.juddi.v3.annotations.AnnotationProcessor;
30  import org.apache.juddi.v3.client.ClassUtil;
31  import org.apache.juddi.v3.client.Release;
32  import org.apache.juddi.v3.client.UDDIConstants;
33  import org.apache.juddi.v3.client.embed.EmbeddedRegistry;
34  import org.apache.juddi.v3.client.mapping.ServiceLocator;
35  import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
36  import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener;
37  import org.apache.juddi.v3.client.transport.InVMTransport;
38  import org.apache.juddi.v3.client.transport.Transport;
39  import org.uddi.api_v3.BindingTemplate;
40  import org.uddi.api_v3.BusinessService;
41  import org.uddi.api_v3.CategoryBag;
42  import org.uddi.api_v3.KeyedReference;
43  import org.uddi.api_v3.TModelInstanceDetails;
44  import org.uddi.api_v3.TModelInstanceInfo;
45  
46  /**
47   * <p>
48   * The UDDIClient is the main entry point for using the jUDDI client. The
49   * UDDICLient provides a simple way to get interact with a UDDI registry using
50   * the UDDI v3 API.</p>
51   *
52   * <h3>Note:</h3>
53   * <p>
54   * It is also possible to use the Java API for XML Registries (JAXR). Apache
55   * Scout is an implementation of this API that can be configured to -behind the
56   * scenes- use the jUDDI Client code to access either UDDIv2 or UDDIv3 registry.
57   * The advantage of using JAXR is that your code can be configured to interact
58   * with any XML Registry (such as UDDI or ebXML). The downside is that JAXR has
59   * not evolved beyond the 1.0 release and is tightly coupled to the ebXML data
60   * structures, which being mapped to the UDDI data structures. For more
61   * information on JAXR see the Apache Scout project, which is a sub project of
62   * Apache jUDDI. If programmatic acess to a UDDIv3 registry is what you want, we
63   * recommend using the UDDIv3 API with the UDDIClient.</p>
64   *
65   * <p>
66   * The UDDIClient uses a XML formatted configuration file, which by default is
67   * loaded from the classpath from location META-INF/uddi.xml.</p>
68   *
69   * @author kstam
70   *
71   */
72  public class UDDIClient {
73  
74          private static Log log = LogFactory.getLog(UDDIClient.class);
75          private ClientConfig clientConfig = null;
76          private String CONFIG_FILE = "META-INF/uddi.xml";
77          private Properties properties = null;
78          private static Map<String, ServiceLocator> serviceLocators = new HashMap<String, ServiceLocator>();
79  
80          
81          public static void  clearServiceLocatorCaches(){
82                  serviceLocators.clear();
83          }
84          /**
85           * Default constructor, loads from the default config, META-INF/uddi.xml
86           *
87           * @throws ConfigurationException
88           */
89          public UDDIClient() throws ConfigurationException {
90                  super();
91                  log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
92                  clientConfig = new ClientConfig(CONFIG_FILE, properties);
93                  UDDIClientContainer.addClient(this);
94          }
95  
96          /**
97           * Manages the clerks. Initiates reading the client configuration from
98           * the uddi.xml.
99           *
100          * @throws ConfigurationException
101          */
102         public UDDIClient(String configurationFile) throws ConfigurationException {
103                 super();
104                 log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
105                 clientConfig = new ClientConfig(configurationFile);
106                 UDDIClientContainer.addClient(this);
107         }
108 
109         /**
110          * Manages the clerks. Initiates reading the client configuration from
111          * the uddi.xml.
112          *
113          * @param configurationFile
114          * @param properties
115          * @throws ConfigurationException
116          */
117         public UDDIClient(String configurationFile, Properties properties) throws ConfigurationException {
118                 super();
119                 log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
120                 clientConfig = new ClientConfig(configurationFile, properties);
121                 UDDIClientContainer.addClient(this);
122         }
123 
124         /**
125          * Uses the client config, and looks for a clerk called "default"
126          *
127          * @return returns getServiceLocator(null);
128          * @throws ConfigurationException
129          */
130         public synchronized ServiceLocator getServiceLocator() throws ConfigurationException {
131                 return getServiceLocator(null);
132         }
133 
134         /**
135          * @param clerkName - if null defaults to "default"
136          * @return a serviceLocator object
137          * @throws ConfigurationException
138          */
139         public synchronized ServiceLocator getServiceLocator(String clerkName) throws ConfigurationException {
140                 UDDIClerk clerk = getClerk(clerkName);
141                 if (clerk==null){
142                     throw new ConfigurationException("could not locate the UDDI Clerk '" + clerkName +"'.");
143                 }
144                 if (!serviceLocators.containsKey(clerk.getName())) {
145                         ServiceLocator serviceLocator = new ServiceLocator(clerk, new URLLocalizerDefaultImpl(), properties);
146                         serviceLocators.put(clerk.getName(), serviceLocator);
147                 }
148                 return serviceLocators.get(clerk.getName());
149         }
150 
151         /**
152          * Stops the clerks. If transport is InVM, all database resources are
153          * released. If anything was auto registered, it will be removed prior
154          * to shutdown
155          *
156          * @throws ConfigurationException
157          */
158         public void stop() throws ConfigurationException {
159                 log.info("Stopping UDDI Client " + clientConfig.getClientName());
160                 releaseResources();
161                 //fix for when someone runs UDDIClient.stop more than once
162                 if (UDDIClientContainer.contains(getName())) {
163                         UDDIClientContainer.removeClerkManager(getName());
164                 }
165 
166                 //If running in embedded mode
167                 if (InVMTransport.class.getCanonicalName().equals(getClientConfig().getHomeNode().getProxyTransport())) {
168                         log.info("Shutting down embedded Server");
169                         stopEmbeddedServer();
170                 }
171                 log.info("UDDI Clerks shutdown completed for manager " + clientConfig.getClientName());
172         }
173 
174         private void releaseResources() {
175                 if (this.clientConfig.isRegisterOnStartup()) {
176                         unRegisterWSDLs();
177                         unRegisterBindingsOfAnnotatedServices(true);
178                 }
179         }
180 
181         /**
182          * Initializes the UDDI Clerk. If transport is set to InVM, this will
183          * initialize all database connections, other it will trigger all
184          * background registration threads
185          *
186          * @throws ConfigurationException
187          */
188         public void start() throws ConfigurationException {
189 
190                 if (UDDIClientContainer.addClient(this)) {
191                         //If running in embedded mode
192                         if (InVMTransport.class.getCanonicalName().equals(getClientConfig().getHomeNode().getProxyTransport())) {
193                                 log.info("Starting embedded Server");
194                                 startEmbeddedServer();
195                         }
196                         if (this.clientConfig.isRegisterOnStartup()) {
197                                 Runnable runnable = new BackGroundRegistration(this);
198                                 Thread thread = new Thread(runnable);
199                                 thread.setName("juddi background registration");
200                                 thread.setDaemon(true);
201                                 thread.start();
202                         }
203                 }
204         }
205 
206         protected void startEmbeddedServer() throws ConfigurationException {
207 
208                 try {
209                         String embeddedServerClass = getClientConfig().getHomeNode().getProperties().getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry");
210                         Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass());
211                         EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance();
212                         embeddedRegistry.start();
213                 } catch (Exception e) {
214                         throw new ConfigurationException(e.getMessage(), e);
215                 }
216         }
217 
218         protected void stopEmbeddedServer() throws ConfigurationException {
219 
220                 try {
221                         String embeddedServerClass = getClientConfig().getHomeNode().getProperties().getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry");
222                         Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass());
223                         EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance();
224                         embeddedRegistry.stop();
225                 } catch (Exception e) {
226                         throw new ConfigurationException(e.getMessage(), e);
227                 }
228         }
229 
230         /**
231          * calls stop and start again
232          *
233          * @throws ConfigurationException
234          */
235         public void restart() throws ConfigurationException {
236                 stop();
237                 start();
238         }
239 
240         /**
241          * Saves the clerk and node info from the uddi.xml to the home jUDDI
242          * registry. This info is needed if you want to JUDDI Server to do
243          * XRegistration/"replication".
244          */
245         public void saveClerkAndNodeInfo() {
246 
247                 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
248 
249                 if (uddiClerks.size() > 0) {
250 
251                         //obtaining a clerk that can write to the home registry
252                         UDDIClerk homeClerk = null;
253                         for (UDDIClerk clerk : uddiClerks.values()) {
254                                 if (clerk.getUDDINode().isHomeJUDDI()) {
255                                         homeClerk = clerk;
256                                 }
257                         }
258                         //registering nodes and clerks
259                         if (homeClerk != null) {
260                                 int numberOfHomeJUDDIs = 0;
261                                 for (UDDINode uddiNode : clientConfig.getUDDINodes().values()) {
262                                         if (uddiNode.isHomeJUDDI()) {
263                                                 numberOfHomeJUDDIs++;
264                                         }
265                                         homeClerk.saveNode(uddiNode.getApiNode());
266                                 }
267                                 if (numberOfHomeJUDDIs == 1) {
268                                         for (UDDIClerk clerk : clientConfig.getUDDIClerks().values()) {
269                                                 homeClerk.saveClerk(clerk);
270                                         }
271                                 } else {
272                                         log.error("The client config needs to have one homeJUDDI node and found " + numberOfHomeJUDDIs);
273                                 }
274                         } else {
275                                 log.debug("No home clerk found.");
276                         }
277                 }
278         }
279 
280         /**
281          * X-Register services listed in the uddi.xml
282          */
283         public void xRegister() {
284                 log.debug("Starting cross registration...");
285                 //XRegistration of listed businesses
286                 Set<XRegistration> xBusinessRegistrations = clientConfig.getXBusinessRegistrations();
287                 for (XRegistration xRegistration : xBusinessRegistrations) {
288                         xRegistration.xRegisterBusiness();
289                 }
290                 //XRegistration of listed serviceBindings
291                 Set<XRegistration> xServiceBindingRegistrations = clientConfig.getXServiceBindingRegistrations();
292                 for (XRegistration xRegistration : xServiceBindingRegistrations) {
293                         xRegistration.xRegisterServiceBinding();
294                 }
295                 log.debug("Cross registration completed");
296         }
297 
298         /**
299          * Registers services to UDDI using a clerk, and the uddi.xml
300          * configuration.
301          */
302         public void registerAnnotatedServices() {
303                 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
304                 if (uddiClerks.size() > 0) {
305                         AnnotationProcessor ap = new AnnotationProcessor();
306                         for (UDDIClerk uddiClerk : uddiClerks.values()) {
307                                 Collection<BusinessService> services = ap.readServiceAnnotations(
308                                         uddiClerk.getClassWithAnnotations(), uddiClerk.getUDDINode().getProperties());
309                                 for (BusinessService businessService : services) {
310                                         log.info("Node=" + uddiClerk.getUDDINode().getApiNode().getName());
311                                         uddiClerk.register(businessService, uddiClerk.getUDDINode().getApiNode());
312                                 }
313                         }
314                 }
315         }
316 
317         /**
318          * Removes the service and all of its bindingTemplates of the annotated
319          * classes.
320          *
321          */
322         public void unRegisterAnnotatedServices() {
323                 Map<String, UDDIClerk> clerks = clientConfig.getUDDIClerks();
324                 if (clerks.size() > 0) {
325                         AnnotationProcessor ap = new AnnotationProcessor();
326                         for (UDDIClerk clerk : clerks.values()) {
327                                 Collection<BusinessService> services = ap.readServiceAnnotations(
328                                         clerk.getClassWithAnnotations(), clerk.getUDDINode().getProperties());
329                                 for (BusinessService businessService : services) {
330                                         clerk.unRegisterService(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
331                                 }
332                         }
333                 }
334         }
335 
336         /**
337          * Removes the bindings of the services in the annotated classes.
338          * Multiple nodes may register the same service using different
339          * BindingTempates. If the last BindingTemplate is removed the service
340          * can be removed as well.
341          *
342          * @param removeServiceWithNoBindingTemplates - if set to true it will
343          * remove the service if there are no other BindingTemplates.
344          */
345         public void unRegisterBindingsOfAnnotatedServices(boolean removeServiceWithNoBindingTemplates) {
346 
347                 Map<String, UDDIClerk> clerks = clientConfig.getUDDIClerks();
348                 if (clerks.size() > 0) {
349                         AnnotationProcessor ap = new AnnotationProcessor();
350                         for (UDDIClerk clerk : clerks.values()) {
351                                 Collection<BusinessService> services = ap.readServiceAnnotations(
352                                         clerk.getClassWithAnnotations(), clerk.getUDDINode().getProperties());
353                                 for (BusinessService businessService : services) {
354                                         if (businessService.getBindingTemplates() != null) {
355                                                 List<BindingTemplate> bindingTemplates = businessService.getBindingTemplates().getBindingTemplate();
356                                                 for (BindingTemplate bindingTemplate : bindingTemplates) {
357                                                         clerk.unRegisterBinding(bindingTemplate.getBindingKey(), clerk.getUDDINode().getApiNode());
358                                                 }
359                                         }
360                                         if (removeServiceWithNoBindingTemplates) {
361                                                 try {
362                                                         BusinessService existingService = clerk.getServiceDetail(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
363                                                         if (existingService.getBindingTemplates() == null || existingService.getBindingTemplates().getBindingTemplate().size() == 0) {
364                                                                 clerk.unRegisterService(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
365                                                         }
366                                                 } catch (Exception e) {
367                                                         log.error(e.getMessage(), e);
368                                                 }
369                                         }
370                                 }
371                         }
372                 }
373 
374         }
375 
376         /**
377          * Returns a live instance of the raw configuration file
378          *
379          * @return the client config loaded from file
380          */
381         public ClientConfig getClientConfig() {
382                 return clientConfig;
383         }
384 
385         /**
386          * returns getClientConfig().getClientName()
387          *
388          * @return getClientConfig().getClientName()
389          */
390         public String getName() {
391                 return clientConfig.getClientName();
392         }
393 
394         /**
395          * maps to config file client[@callbackUrl] Not currently used
396          *
397          * @return client[@callbackUrl]
398          * @deprecated use SubscriptionCallbackListener
399          * @see SubscriptionCallbackListener
400          */
401         @Deprecated 
402         public String getClientCallbackUrl() {
403                 return clientConfig.getClientCallbackUrl();
404         }
405 
406         /**
407          * Returns the transport defined for the node with the given name
408          * "default". deprecated, use the getTransport(String nodeName) instead.
409          * Returns the "default" jUDDI nodes Transport.
410          * @deprecated use the getTransport(String nodeName) instead. Returns
411          * the "default" jUDDI nodes Transport. Note: this will always return a
412          * new instance of Transport
413          * @return a transport object
414          * @throws ConfigurationException
415          */
416         public Transport getTransport() throws ConfigurationException {
417                 return getTransport("default");
418         }
419 
420         /**
421          * Returns the transport defined for the node with the given nodeName.
422          * Note: this will always return a new instance of Transport
423          *
424          * @param nodeName
425          * @return a transport object
426          * @throws ConfigurationException
427          */
428         public Transport getTransport(String nodeName) throws ConfigurationException {
429                 try {
430                         String clazz = clientConfig.getUDDINode(nodeName).getProxyTransport();
431                         String managerName = clientConfig.getClientName();
432                         Class<?> transportClass = ClassUtil.forName(clazz, UDDIClient.class);
433                         if (transportClass != null) {
434                                 Transport transport = (Transport) transportClass.getConstructor(String.class, String.class).newInstance(managerName, nodeName);
435                                 return transport;
436                         } else {
437                                 throw new ConfigurationException("ProxyTransport was not defined in the " + clientConfig.getConfigurationFile());
438                         }
439                 } catch (Exception e) {
440                         throw new ConfigurationException(e.getMessage(), e);
441                 }
442         }
443         
444        /**
445          * Gets the UDDI Clerk, the entry point into many functions of the juddi
446          * client
447          *
448          * @param clerkName - This references the uddi/client/clerk@name of the
449          * juddi client config file. it stores credentials if necessary and
450          * associates it with a particular UDDI node (server/cluster) If not
451          * specified, the value of "default" will be used.
452          * @return A clerk instance if the clerk is defined in the config file
453          * or NULL if not found
454          */
455         public UDDIClerk getClerk(String clerkName) {
456                 if (clerkName == null || clerkName.length() == 0) {
457                         return getClientConfig().getUDDIClerks().get("default");
458                 }
459                 return getClientConfig().getUDDIClerks().get(clerkName);
460         }
461 
462         /**
463          * Registers services to UDDI using a clerk, and the uddi.xml
464          * configuration.
465          *
466          */
467         public void registerWSDLs() {
468                 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
469                 if (uddiClerks.size() > 0) {
470                         for (UDDIClerk uddiClerk : uddiClerks.values()) {
471                                 uddiClerk.registerWsdls();
472                         }
473                 }
474         }
475 
476         /**
477          * unregisters all config defined wsdls
478          */
479         public void unRegisterWSDLs() {
480                 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
481                 if (uddiClerks.size() > 0) {
482                         for (UDDIClerk uddiClerk : uddiClerks.values()) {
483                                 uddiClerk.unRegisterWsdls();
484                         }
485                 }
486         }
487 
488         /**
489          * adds the typical SOAP tmodel references, but only if they aren't
490          * already present
491          *
492          * @param bt
493          * @return a modified instance of the source binding template
494          */
495         public static BindingTemplate addSOAPtModels(BindingTemplate bt) {
496                 if (bt.getCategoryBag() == null) {
497                         bt.setCategoryBag(new CategoryBag());
498                 }
499                 boolean found = false;
500                 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
501                         if (bt.getCategoryBag().getKeyedReference().get(i).getTModelKey() != null
502                                 && bt.getCategoryBag().getKeyedReference().get(i).getTModelKey().equalsIgnoreCase("uddi:uddi.org:categorization:types")) {
503                                 if (bt.getCategoryBag().getKeyedReference().get(i).getKeyName() != null
504                                         && bt.getCategoryBag().getKeyedReference().get(i).getKeyName().equalsIgnoreCase("uddi-org:types:wsdl")) {
505                                         found = true;
506                                 }
507                         }
508                 }
509                 if (!found) {
510                         bt.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "uddi-org:types:wsdl", "wsdlDeployment"));
511                 }
512                 if (bt.getCategoryBag().getKeyedReference().isEmpty() && bt.getCategoryBag().getKeyedReferenceGroup().isEmpty()) {
513                         bt.setCategoryBag(null);
514                 }
515                 if (bt.getTModelInstanceDetails() == null) {
516                         bt.setTModelInstanceDetails(new TModelInstanceDetails());
517                 }
518                 TModelInstanceInfo tModelInstanceInfo;
519                 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SOAP)) {
520                         tModelInstanceInfo = new TModelInstanceInfo();
521                         tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SOAP);
522                         bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
523                 }
524 
525                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("http:")) {
526                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_HTTP)) {
527                                 tModelInstanceInfo = new TModelInstanceInfo();
528                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
529                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
530                         }
531                 }
532                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("jms:")) {
533                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_JMS)) {
534                                 tModelInstanceInfo = new TModelInstanceInfo();
535                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_JMS);
536                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
537                         }
538                 }
539                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("rmi:")) {
540                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_RMI)) {
541                                 tModelInstanceInfo = new TModelInstanceInfo();
542                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_RMI);
543                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
544                         }
545                 }
546                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("udp:")) {
547                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_UDP)) {
548                                 tModelInstanceInfo = new TModelInstanceInfo();
549                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_UDP);
550                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
551                         }
552                 }
553                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("amqp:")) {
554                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_AMQP)) {
555                                 tModelInstanceInfo = new TModelInstanceInfo();
556                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_AMQP);
557                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
558                         }
559                 }
560                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("mailto:")) {
561                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_EMAIL)) {
562                                 tModelInstanceInfo = new TModelInstanceInfo();
563                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_EMAIL);
564                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
565                         }
566                 }
567                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("ftp:")) {
568                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_FTP)) {
569                                 tModelInstanceInfo = new TModelInstanceInfo();
570                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_FTP);
571                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
572                         }
573                 }
574                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("https:")) {
575                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
576                                 tModelInstanceInfo = new TModelInstanceInfo();
577                                 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
578                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
579                         }
580                 }
581                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("ftps:")) {
582                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
583                                 tModelInstanceInfo = new TModelInstanceInfo();
584                                 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
585                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
586                         }
587                 }
588                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("jndi:")) {
589                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_JNDI_RMI)) {
590                                 tModelInstanceInfo = new TModelInstanceInfo();
591                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_JNDI_RMI);
592                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
593                         }
594                 }
595                 return bt;
596         }
597 
598         /**
599          * adds the typical REST tmodel references, but only if they aren't
600          * already present
601          *
602          * @param bt
603          * @return a modified instance of the source binding template
604          */
605         public static BindingTemplate addRESTtModels(BindingTemplate bt) {
606                 if (bt.getTModelInstanceDetails() == null) {
607                         bt.setTModelInstanceDetails(new TModelInstanceDetails());
608                 }
609                 TModelInstanceInfo tModelInstanceInfo;
610                 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_REST)) {
611                         tModelInstanceInfo = new TModelInstanceInfo();
612                         tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_REST);
613                         bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
614                 }
615 
616                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("http:")) {
617                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_HTTP)) {
618                                 tModelInstanceInfo = new TModelInstanceInfo();
619                                 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
620                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
621                         }
622                 }
623                 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("https:")) {
624                         if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
625                                 tModelInstanceInfo = new TModelInstanceInfo();
626                                 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
627                                 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
628                         }
629                 }
630                 return bt;
631         }
632 
633         private static boolean exists(List<TModelInstanceInfo> items, String key) {
634                 for (int i = 0; i < items.size(); i++) {
635                         if (items.get(i).getTModelKey() != null
636                                 && items.get(i).getTModelKey().equalsIgnoreCase(key)) {
637                                 return true;
638                         }
639                 }
640                 return false;
641         }
642 }