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.api.impl;
1819import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogFactory;
21import org.apache.juddi.api_v3.Clerk;
22import org.apache.juddi.v3.client.config.UDDIClerk;
23import org.apache.juddi.v3.client.config.XRegistration;
24import org.uddi.api_v3.BindingDetail;
25import org.uddi.api_v3.BindingTemplate;
26import org.uddi.api_v3.BusinessDetail;
27import org.uddi.api_v3.BusinessEntity;
28import org.uddi.api_v3.BusinessInfo;
29import org.uddi.api_v3.BusinessService;
30import org.uddi.api_v3.ServiceDetail;
31import org.uddi.api_v3.ServiceInfo;
32import org.uddi.sub_v3.SubscriptionResultsList;
3334/**35 * Used to factor out inquiry functionality as it is used in more than one spot.36 * 37 * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>38 */39publicclassXRegisterHelper {
4041privatestatic Log log = LogFactory.getLog(XRegisterHelper.class);
4243publicstaticvoid handle(Clerk fromClerk, Clerk toClerk, SubscriptionResultsList list) {
4445 UDDIClerk uddiToClerk = new UDDIClerk(toClerk);
46 UDDIClerk uddiFromClerk = new UDDIClerk(fromClerk);
47//SERVICE LIST48if (list.getServiceList()!=null) {
49 log.info("Subscription result for ServiceList with subscription key=" + list.getSubscription().getSubscriptionKey());
50for (ServiceInfo serviceInfo : list.getServiceList().getServiceInfos().getServiceInfo() ) {
5152 BusinessEntity existingBusinessEntity = null;
53try {
54if (existingBusinessEntity==null) {
55 existingBusinessEntity = uddiToClerk.findBusiness(serviceInfo.getBusinessKey(), toClerk.getNode());
56 }
57if (existingBusinessEntity!=null) {
58 log.debug("Found business with key " + existingBusinessEntity.getBusinessKey() + ". No need to add it again");
59 } else {
60 log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName()
61 + ", going to add it in.");
62new XRegistration(serviceInfo.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
63 }
64new XRegistration(serviceInfo.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceAndBindings();
65 } catch (Exception e) {
66 log.error(e.getMessage(),e);
67 }
68 }
69 }
70//SERVICE DETAIL71if (list.getServiceDetail()!=null) {
72 log.info("Subscription result for ServiceDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
73 ServiceDetail serviceDetail = list.getServiceDetail();
74if (serviceDetail.isTruncated()) {
75 log.info("The serviceDetail is truncated, the maxEntries must have been hit. The number of services is " + serviceDetail.getBusinessService().size());
76 }
77for (BusinessService service : serviceDetail.getBusinessService()) {
78 BusinessEntity existingBusinessEntity = null;
79try {
80if (existingBusinessEntity==null) {
81 existingBusinessEntity = uddiToClerk.findBusiness(service.getBusinessKey(), toClerk.getNode());
82 }
83if (existingBusinessEntity!=null) {
84 log.debug("Found business with key " + existingBusinessEntity.getBusinessKey() + ". No need to add it again");
85 } else {
86 log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName()
87 + ", going to add it in.");
88new XRegistration(service.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
89 }
90new XRegistration(service.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceAndBindings();
91 } catch (Exception e) {
92 log.error(e.getMessage(),e);
93 }
94 }
95 }
9697//BUSINESS LIST98if (list.getBusinessList()!=null) {
99 log.info("Subscription result for BusinessList with subscription key=" + list.getSubscription().getSubscriptionKey());
100for (BusinessInfo businessInfo : list.getBusinessList().getBusinessInfos().getBusinessInfo()) {
101new XRegistration(businessInfo.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusinessAndServices();
102 }
103 }
104105//BUSINESS DETAIL106if (list.getBusinessDetail()!=null) {
107 log.info("Subscription result for BusinessDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
108 BusinessDetail businessDetail = list.getBusinessDetail();
109if (businessDetail.isTruncated()) {
110 log.info("The businessDetail is truncated, the maxEntries must have been hit. The number of businesses is " + businessDetail.getBusinessEntity().size());
111 }
112for (BusinessEntity businessEntity : businessDetail.getBusinessEntity()) {
113new XRegistration(businessEntity.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusinessAndServices();
114 }
115 }
116117//KEY BAG, NOT IMPLEMENTED118if (list.getKeyBag()!=null) {
119 log.info("Returning results when a 'brief' format is selected, please do not use 'brief' results when using the XRegistration functionality");
120 }
121122//BINDING DETAIL123if (list.getBindingDetail()!=null) {
124 log.info("Subscription result for BindingDetail with subscription key=" + list.getSubscription().getSubscriptionKey());
125 BindingDetail bindingDetail = list.getBindingDetail();
126if (bindingDetail.isTruncated()) {
127 log.info("The bindingDetail is truncated, the maxEntries must have been hit. The number of bindings is " + bindingDetail.getBindingTemplate().size());
128 }
129for (BindingTemplate bindingTemplate : bindingDetail.getBindingTemplate()) {
130try {
131//check if the service exist132 BusinessService existingToService = uddiToClerk.findService(bindingTemplate.getServiceKey(), toClerk.getNode());
133if (existingToService!=null) {
134 log.debug("Found service with key " + existingToService.getServiceKey() + ". No need to add it again");
135 } else {
136 BusinessService fromService = uddiFromClerk.findService(bindingTemplate.getServiceKey(), fromClerk.getNode());
137//check if the business exist138 BusinessEntity existingBusinessEntity = uddiToClerk.findBusiness(fromService.getBusinessKey(), toClerk.getNode());
139if (existingBusinessEntity!=null) {
140 log.debug("Found business with key " + existingBusinessEntity.getBusinessKey() + ". No need to add it again");
141 } else {
142 log.info("Business was not found in the destination UDDI " + toClerk.getNode().getName()
143 + ", going to add it in.");
144new XRegistration(fromService.getBusinessKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterBusiness();
145 }
146 log.info("Service was not found in the destination UDDI " + toClerk.getNode().getName()
147 + ", going to add it in.");
148new XRegistration(fromService.getServiceKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterService();
149 }
150//now the service exists in the toNode and we can add this binding151new XRegistration(bindingTemplate.getBindingKey(), new UDDIClerk(fromClerk), new UDDIClerk(toClerk)).xRegisterServiceBinding();
152 } catch (Exception e) {
153 log.error(e.getMessage(),e);
154 }
155 }
156 }
157158//RELATED BUSINESSES159if (list.getRelatedBusinessesList()!=null) {
160 log.info("Subscription result for RelatedBusinesses with subscription key=" + list.getSubscription().getSubscriptionKey());
161 log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
162 }
163164//ASSERTION STATUS REPORT165if (list.getAssertionStatusReport()!=null) {
166 log.info("Subscription result for AssertionStatusReport with subscription key=" + list.getSubscription().getSubscriptionKey());
167 log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
168 }
169170//TMODELS171if (list.getTModelList()!=null ){
172 log.info("Subscription result for tModelList with subscription key=" + list.getSubscription().getSubscriptionKey());
173 log.info("The jUDDI Listener is not doing anything with this subscription at this moment");
174 }
175 }
176177 }