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 org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.uddi.api_v3.BindingTemplate;
22  import org.uddi.api_v3.BusinessEntity;
23  import org.uddi.api_v3.BusinessService;
24  /**
25   * Is used to exchange UDDI data between UDDI nodes; for example when Subscriptions are uses.
26   * 
27   * @author kstam
28   *
29   */
30  public class XRegistration {
31  
32  	private Log log = LogFactory.getLog(this.getClass());
33  	private UDDIClerk toClerk;
34  	private UDDIClerk fromClerk;
35  	private String entityKey;
36      
37  	public XRegistration() {}
38  	
39  	public XRegistration(String entityKey, UDDIClerk fromClerk,
40  			UDDIClerk toClerk) {
41  		super();
42  		this.fromClerk = fromClerk;
43  		this.toClerk = toClerk;
44  		this.entityKey = entityKey;
45  	}
46  	
47  	public UDDIClerk getToClerk() {
48  		return toClerk;
49  	}
50  	public void setToClerk(UDDIClerk toClerk) {
51  		this.toClerk = toClerk;
52  	}
53  	public UDDIClerk getFromClerk() {
54  		return fromClerk;
55  	}
56  	public void setFromClerk(UDDIClerk fromClerk) {
57  		this.fromClerk = fromClerk;
58  	}
59  	public String getEntityKey() {
60  		return entityKey;
61  	}
62  	public void setEntityKey(String entityKey) {
63  		this.entityKey = entityKey;
64  	}
65  	
66  	/**
67  	 * Copies the BusinessInformation from one UDDI to another UDDI. Note that no services are being
68  	 * copied over by this service. Use xRegisterService to copy over services.
69  	 */
70  	public void xRegisterBusiness() {
71  		BusinessEntity businessEntity;
72  		try {
73  			businessEntity = fromClerk.getBusinessDetail(entityKey,fromClerk.getUDDINode().getApiNode());
74  			log.info("xregister business " + businessEntity.getName().get(0).getValue() + " + from "
75  					+ fromClerk.getName() + " to " + toClerk.getName() + ".");
76  			//not bringing over the services. They need to be explicitly copied using xRegisterService.
77  			businessEntity.setBusinessServices(null);
78  			toClerk.register(businessEntity,toClerk.getUDDINode().getApiNode());
79  		} catch (Exception e) {
80  			log.error("Could not " + toString() + ". " + e.getMessage() + " " + e.getCause(),e);
81  		}
82  	}
83  	
84  	/**
85  	 * Copies the BusinessInformation from one UDDI to another UDDI.
86  	 */
87  	public void xRegisterBusinessAndServices() {
88  		BusinessEntity businessEntity;
89  		try {
90  			businessEntity = fromClerk.getBusinessDetail(entityKey,fromClerk.getUDDINode().getApiNode());
91  			log.info("xregister business " + businessEntity.getName().get(0).getValue() + " + from "
92  					+ fromClerk.getName() + " to " + toClerk.getName() + " including all services owned by this business.");
93  			toClerk.register(businessEntity,toClerk.getUDDINode().getApiNode());
94  		} catch (Exception e) {
95  			log.error("Could not " + toString() + ". " + e.getMessage() + " " + e.getCause(),e);
96  		}
97  	}
98  	/**
99  	 * Copies the Service from one UDDI to another UDDI.
100 	 */
101 	public void xRegisterService() {
102 		BusinessService businessService;
103 		try {
104 			businessService = fromClerk.getServiceDetail(entityKey,fromClerk.getUDDINode().getApiNode());
105 			log.info("xregister service " + businessService.getName().get(0).getValue() + " + from "
106 					+ fromClerk.getName() + " to " + toClerk.getName());
107 			businessService.setBindingTemplates(null);
108 			toClerk.register(businessService,toClerk.getUDDINode().getApiNode());
109 		} catch (Exception e) {
110 			log.error("Could not " + toString() + ". " + e.getMessage() + " " + e.getCause(),e);
111 		}
112 	}
113 	/**
114 	 * Copies the Service from one UDDI to another UDDI along with all the bindingTemplates.
115 	 */
116 	public void xRegisterServiceAndBindings() {
117 		BusinessService businessService;
118 		try {
119 			businessService = fromClerk.getServiceDetail(entityKey,fromClerk.getUDDINode().getApiNode());
120 			log.info("xregister service " + businessService.getName().get(0).getValue() + " + from "
121 					+ fromClerk.getName() + " to " + toClerk.getName());
122 			toClerk.register(businessService,toClerk.getUDDINode().getApiNode());
123 		} catch (Exception e) {
124 			log.error("Could not " + toString() + ". " + e.getMessage() + " " + e.getCause(),e);
125 		}
126 	}
127 	/**
128 	 * Copies the TemplateBinding from one UDDI to another UDDI.
129 	 */
130 	public void xRegisterServiceBinding() {
131 		try {
132 			BindingTemplate bindingTemplate = fromClerk.getServiceBindingDetail(entityKey,fromClerk.getUDDINode().getApiNode());
133 			log.info("xregister binding " + bindingTemplate.getBindingKey()+ " + from "
134 					+ fromClerk.getName() + " to " + toClerk.getName());
135 			toClerk.register(bindingTemplate,toClerk.getUDDINode().getApiNode());
136 		} catch (Exception e) {
137 			log.error("Could not " + toString() + ". " + e.getMessage() + " " + e.getCause(),e);
138 		}
139 	}
140 	
141 	public String toString() {
142 		return " xregister entityKey: " + entityKey + " + from " + fromClerk.getName() + " to " + toClerk.getName(); 
143 	}
144 	
145 	
146 }