source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincLib/src/gov/hhs/fha/nhinc/connectmgr/data/CMUDDIConnectionInfoXML.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 6.6 KB
Line 
1package gov.hhs.fha.nhinc.connectmgr.data;
2
3import com.thoughtworks.xstream.XStream;
4import gov.hhs.fha.nhinc.connectmgr.ConnectionManagerException;
5
6/**
7 * This class is used to serialize/deserialize an XML document to/from a UDDIConnectionInfo object.
8 * This class uses XStream to do this.
9 *
10 * @author Les Westberg.
11 */
12public class CMUDDIConnectionInfoXML
13{
14 /**
15 * This method serializes an CMUDDIConnectionInfo object to an
16 * XML string.
17 *
18 * @param oCMUDDIConnectionInfo The object to be serialized.
19 * @return The XML string representation of the object.
20 */
21 public static String serialize(CMUDDIConnectionInfo oCMUDDIConnectionInfo)
22 throws ConnectionManagerException
23 {
24 String sXML = "";
25
26 try
27 {
28 XStream oXStream = new XStream();
29 oXStream.alias("UDDIConnectionInfo", CMUDDIConnectionInfo.class);
30 oXStream.addImplicitCollection(CMBusinessEntities.class, "businessEntityList", "businessEntity", CMBusinessEntity.class);
31 oXStream.useAttributeFor(CMBusinessEntity.class, "businessKey");
32 oXStream.addImplicitCollection(CMDiscoveryURLs.class, "discoveryURLList", "discoveryURL", String.class);
33 oXStream.addImplicitCollection(CMBusinessNames.class, "businessNameList", "businessName", String.class);
34 oXStream.addImplicitCollection(CMBusinessDescriptions.class, "businessDescriptionList", "businessDescription", String.class);
35 oXStream.addImplicitCollection(CMContacts.class, "contactList", "contact", CMContact.class);
36 oXStream.addImplicitCollection(CMContactDescriptions.class, "descriptionList", "description", String.class);
37 oXStream.addImplicitCollection(CMPersonNames.class, "personNameList", "personName", String.class);
38 oXStream.addImplicitCollection(CMPhones.class, "phoneList", "phone", String.class);
39 oXStream.addImplicitCollection(CMEmails.class, "emailList", "email", String.class);
40 oXStream.addImplicitCollection(CMAddresses.class, "addressList", "address", CMAddress.class);
41 oXStream.addImplicitCollection(CMAddress.class, "addressLineList", "addressLine", String.class);
42 oXStream.addImplicitCollection(CMStates.class, "stateList", "state", String.class);
43 oXStream.addImplicitCollection(CMBusinessServices.class, "businessServiceList", "businessService", CMBusinessService.class);
44 oXStream.useAttributeFor(CMBusinessService.class, "serviceKey");
45 oXStream.addImplicitCollection(CMBindingNames.class, "nameList", "name", String.class);
46 oXStream.addImplicitCollection(CMBindingDescriptions.class, "descriptionList", "description", String.class);
47 oXStream.addImplicitCollection(CMBindingTemplates.class, "bindingTemplateList", "bindingTemplate", CMBindingTemplate.class);
48 oXStream.useAttributeFor(CMBindingTemplate.class, "bindingKey");
49
50 oXStream.processAnnotations(CMUDDIConnectionInfo.class);
51 sXML = oXStream.toXML(oCMUDDIConnectionInfo);
52 }
53 catch (Exception e)
54 {
55 String sErrorMessage = "Failed to serialize the CMUDDIConnectionInfo object to XML. Error: " + e.getMessage();
56 throw new ConnectionManagerException(sErrorMessage, e);
57 }
58
59 return sXML;
60 }
61
62 /**
63 * This method takes an XML representation of CMUDDIConnectionInfo and
64 * produces an instance of the object.
65 *
66 * @param sXML The serialized representation of the CMUDDIConnectionInfo object.
67 * @return The object instance of the XML.
68 */
69 public static CMUDDIConnectionInfo deserialize(String sXML)
70 throws ConnectionManagerException
71 {
72 CMUDDIConnectionInfo oCMUDDIConnectionInfo = null;
73
74 try
75 {
76 oCMUDDIConnectionInfo = new CMUDDIConnectionInfo();
77
78 XStream oXStream = new XStream();
79 oXStream.alias("UDDIConnectionInfo", CMUDDIConnectionInfo.class);
80 oXStream.addImplicitCollection(CMBusinessEntities.class, "businessEntityList", "businessEntity", CMBusinessEntity.class);
81 oXStream.useAttributeFor(CMBusinessEntity.class, "businessKey");
82 oXStream.addImplicitCollection(CMDiscoveryURLs.class, "discoveryURLList", "discoveryURL", String.class);
83 oXStream.addImplicitCollection(CMBusinessNames.class, "businessNameList", "businessName", String.class);
84 oXStream.addImplicitCollection(CMBusinessDescriptions.class, "businessDescriptionList", "businessDescription", String.class);
85 oXStream.addImplicitCollection(CMContacts.class, "contactList", "contact", CMContact.class);
86 oXStream.addImplicitCollection(CMContactDescriptions.class, "descriptionList", "description", String.class);
87 oXStream.addImplicitCollection(CMPersonNames.class, "personNameList", "personName", String.class);
88 oXStream.addImplicitCollection(CMPhones.class, "phoneList", "phone", String.class);
89 oXStream.addImplicitCollection(CMEmails.class, "emailList", "email", String.class);
90 oXStream.addImplicitCollection(CMAddresses.class, "addressList", "address", CMAddress.class);
91 oXStream.addImplicitCollection(CMAddress.class, "addressLineList", "addressLine", String.class);
92 oXStream.addImplicitCollection(CMStates.class, "stateList", "state", String.class);
93 oXStream.addImplicitCollection(CMBusinessServices.class, "businessServiceList", "businessService", CMBusinessService.class);
94 oXStream.useAttributeFor(CMBusinessService.class, "serviceKey");
95 oXStream.addImplicitCollection(CMBindingNames.class, "nameList", "name", String.class);
96 oXStream.addImplicitCollection(CMBindingDescriptions.class, "descriptionList", "description", String.class);
97 oXStream.addImplicitCollection(CMBindingTemplates.class, "bindingTemplateList", "bindingTemplate", CMBindingTemplate.class);
98 oXStream.useAttributeFor(CMBindingTemplate.class, "bindingKey");
99
100 oXStream.processAnnotations(CMInternalConnectionInfos.class);
101 Object oObject = oXStream.fromXML(sXML);
102 if (oObject instanceof CMUDDIConnectionInfo)
103 {
104 oCMUDDIConnectionInfo = (CMUDDIConnectionInfo) oObject;
105 }
106 }
107 catch (Exception e)
108 {
109 String sErrorMessage = "Failed to deserialize the XML to a CMUDDIConnectionInfo object. Error: " + e.getMessage();
110 throw new ConnectionManagerException(sErrorMessage, e);
111 }
112
113
114 return oCMUDDIConnectionInfo;
115 }
116
117}
Note: See TracBrowser for help on using the repository browser.