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 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.v3.client.config;
1819import java.net.URI;
20import java.net.URISyntaxException;
21import java.net.URL;
22import java.util.Properties;
2324import javax.xml.namespace.QName;
2526publicclassUDDIKeyConvention27 {
2829//Default Values30publicstaticfinal String DEFAULT_BUSINESS_KEY_FORMAT = "uddi:${keyDomain}:business_${businessName}";
31publicstaticfinal String DEFAULT_SERVICE_KEY_FORMAT = "uddi:${keyDomain}:service_${serviceName}";
32publicstaticfinal String DEFAULT_SUBSCRIPTION_KEY_FORMAT = "uddi:${keyDomain}:service_cache_${serverName}";
33publicstaticfinal String DEFAULT_BINDING_KEY_FORMAT = "uddi:${keyDomain}:binding_${serverName}_${serviceName}_${portName}_${serverPort}";
3435/**36 * Constructs the serviceKey based on the bindingKeyFormat specified in the properties. When no37 * businessKeyFormat is specific the default format of uddi:${keyDomain}:${businessName} is used. The businessName38 * property needs to be set properties.39 * 40 * @param properties41 * @return the businessKey42 */43publicstatic String getBusinessKey(Properties properties) {
44 String businessKey = properties.getProperty(Property.BUSINESS_KEY);
45if (businessKey==null) {
46 String keyFormat = properties.getProperty(Property.BUSINESS_KEY_FORMAT, DEFAULT_BUSINESS_KEY_FORMAT);
47 businessKey = TokenResolver.replaceTokens(keyFormat, properties).toLowerCase();
48 }
49return businessKey;
50 }
5152publicstatic String getSubscriptionKey(Properties properties) {
53 String keyFormat = properties.getProperty(Property.SUBSCRIPTION_KEY_FORMAT, DEFAULT_SUBSCRIPTION_KEY_FORMAT);
54 String subscriptionKey = TokenResolver.replaceTokens(keyFormat, properties).toLowerCase();
55return subscriptionKey;
56 }
57/**58 * Constructs the serviceKey based on the serviceKeyFormat specified in the properties. When no59 * serviceKeyFormat is specific the default format of uddi:${keyDomain}:${serviceName} is used.60 * 61 * @param properties62 * @param serviceName63 * @return the serviceKey64 */65publicstatic String getServiceKey(Properties properties, String serviceName) {
66 Properties tempProperties = new Properties();
67if (properties!=null) tempProperties.putAll(properties);
68 tempProperties.put("serviceName", serviceName);
69//Constructing the serviceKey70 String keyFormat = tempProperties.getProperty(Property.SERVICE_KEY_FORMAT, DEFAULT_SERVICE_KEY_FORMAT);
71 String serviceKey = TokenResolver.replaceTokens(keyFormat, tempProperties).toLowerCase();
72return serviceKey;
73 }
7475publicstatic String getBindingKey(Properties properties, QName serviceName, String portName, URL bindingUrl) {
7677 String bindingKey = null;
78try {
79 URI bindingURI = bindingUrl.toURI();
80 bindingKey = getBindingKey(properties, serviceName, portName, bindingURI);
81 } catch (URISyntaxException e) {
8283 }
84return bindingKey;
8586 }
87/**88 * Constructs the bindingKey based on the bindingKeyFormat specified in the properties. When no89 * bindingKeyFormat is specific the default format of uddi:${keyDomain}:${nodeName}-${serviceName}-{portName} is used.90 * 91 * @param properties92 * @param serviceName93 * @param portName94 * @param bindingUrl95 * @return the bindingKey96 */97publicstatic String getBindingKey(Properties properties, QName serviceName, String portName, URI bindingUrl) {
98 Properties tempProperties = new Properties();
99if (properties!=null) tempProperties.putAll(properties);
100 tempProperties.put("serviceName", serviceName.getLocalPart());
101 tempProperties.put("portName", portName);
102int port = bindingUrl.getPort();
103if (port==-1) {
104if ("http".equals(bindingUrl.getScheme())) {
105 port = 80;
106 } elseif ("https".equals(bindingUrl.getScheme())) {
107 port = 443;
108 }
109 }
110 tempProperties.put("serverPort", String.valueOf(port));
111//Constructing the binding Key112 String keyFormat = tempProperties.getProperty(Property.BINDING_KEY_FORMAT, DEFAULT_BINDING_KEY_FORMAT);
113 String bindingKey = TokenResolver.replaceTokens(keyFormat, tempProperties).toLowerCase();
114return bindingKey;
115 }
116 }