source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/SubscriptionDteEjb/src/java/gov/hhs/fha/nhinc/subscription/dte/SubscriptionReferenceHelper.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.9 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package gov.hhs.fha.nhinc.subscription.dte;
6
7import gov.hhs.fha.nhinc.common.subscription.ReferenceParameterType;
8import gov.hhs.fha.nhinc.common.subscription.ReferenceParametersType;
9import gov.hhs.fha.nhinc.common.subscription.SubscriptionItemType;
10import gov.hhs.fha.nhinc.common.subscription.SubscriptionReferenceType;
11import gov.hhs.fha.nhinc.common.subscriptiondte.TransformNhinSubscribeResponseToSubscriptionReferenceResponseType;
12import gov.hhs.fha.nhinc.subscription.*;
13import javax.xml.parsers.DocumentBuilderFactory;
14import javax.xml.parsers.ParserConfigurationException;
15import javax.xml.ws.wsaddressing.*;
16import org.oasis_open.docs.wsn.b_2.*;
17import org.w3c.dom.*;
18
19/**
20 *
21 * @author rayj
22 */
23public class SubscriptionReferenceHelper {
24
25 private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(SubscriptionReferenceHelper.class);
26
27 public static TransformNhinSubscribeResponseToSubscriptionReferenceResponseType transformNhinSubscribeResponseToSubscriptionReference(SubscribeResponse subscribeResponse) {
28 TransformNhinSubscribeResponseToSubscriptionReferenceResponseType response = new TransformNhinSubscribeResponseToSubscriptionReferenceResponseType();
29 W3CEndpointReference nhinSubscriptionReference = subscribeResponse.getSubscriptionReference();
30 SubscriptionReferenceType internalSubscriptionReference = transformNhinSubscriptionReferenceToInternalSubscriptionReference(nhinSubscriptionReference);
31
32 response.setSubscriptionReference(internalSubscriptionReference);
33 return response;
34 }
35
36 public static SubscriptionReferenceType transformNhinSubscriptionReferenceToInternalSubscriptionReference(W3CEndpointReference nhinSubscriptionReference) {
37 SubscriptionReferenceType internalSubscriptionReference = new SubscriptionReferenceType();
38
39 Document document = XmlHelper.transformEndpointReferenceToDocument(nhinSubscriptionReference);
40 internalSubscriptionReference.setSubscriptionManagerEndpointAddress(getAddress(document));
41
42 internalSubscriptionReference.setReferenceParameters(new ReferenceParametersType());
43 NodeList referenceParameterNodes = XmlHelper.getSingleNodeChildren(document, "ReferenceParameters");
44 if (referenceParameterNodes != null) {
45 for (int i = 0; i < referenceParameterNodes.getLength(); i++) {
46 Node nhinReferenceParamterNode = referenceParameterNodes.item(i);
47 ReferenceParameterType internalReferenceParameter = new ReferenceParameterType();
48
49 internalReferenceParameter.setValue(XmlHelper.getNodeValue(nhinReferenceParamterNode));
50 internalReferenceParameter.setNamespace(nhinReferenceParamterNode.getNamespaceURI());
51 internalReferenceParameter.setElementName(nhinReferenceParamterNode.getLocalName());
52 internalSubscriptionReference.getReferenceParameters().getReferenceParameter().add(internalReferenceParameter);
53 }
54 }
55
56 return internalSubscriptionReference;
57 }
58
59 public static W3CEndpointReference createNhinSubscriptionReference(SubscriptionItemType subscriptionItem) {
60 return createNhinSubscriptionReference(subscriptionItem.getSubscriptionReference());
61 }
62
63 public static W3CEndpointReference createNhinSubscriptionReference(SubscriptionReferenceType internalSubscriptionRef) {
64 log.info("begin createNhinSubscriptionReference");
65 W3CEndpointReference subRef;
66
67 W3CEndpointReferenceBuilder resultBuilder = new W3CEndpointReferenceBuilder();
68 log.info("internalSubscriptionRef.getSubscriptionManagerEndpointAddress()=" + internalSubscriptionRef.getSubscriptionManagerEndpointAddress());
69 resultBuilder.address(internalSubscriptionRef.getSubscriptionManagerEndpointAddress());
70
71 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
72 Document doc = null;
73 try {
74 doc = docBuilderFactory.newDocumentBuilder().newDocument();
75 } catch (ParserConfigurationException ex) {
76 throw new RuntimeException(ex);
77 }
78
79 doc.setXmlStandalone(true);
80
81 ReferenceParametersType referenceParamters = internalSubscriptionRef.getReferenceParameters();
82 if (referenceParamters != null) {
83 for (ReferenceParameterType referenceParamter : referenceParamters.getReferenceParameter()) {
84 log.info("handling reference parameter " + referenceParamter.getNamespace() + ";" + referenceParamter.getElementName() + ";" + referenceParamter.getValue());
85 Element subscriptionElem = doc.createElementNS(referenceParamter.getNamespace(), referenceParamter.getElementName());
86 subscriptionElem.setTextContent(referenceParamter.getValue());
87 resultBuilder.referenceParameter(subscriptionElem);
88 }
89 } else {
90 log.info("referenceParamters==null");
91 }
92
93 log.info("building.. resultBuilder.build()");
94 subRef = resultBuilder.build();
95 log.info("end createNhinSubscriptionReference");
96 return subRef;
97 }
98
99 public static String getAddress(W3CEndpointReference subscriptionReference) {
100 Document document = XmlHelper.transformEndpointReferenceToDocument(subscriptionReference);
101 return getAddress(document);
102 }
103
104 public static String getAddress(Document document) {
105 return XmlHelper.getNodeValue(document, "Address");
106 }
107
108 public static NodeList getReferenceParameters(W3CEndpointReference subscriptionReference) {
109 Document document = XmlHelper.transformEndpointReferenceToDocument(subscriptionReference);
110 return getReferenceParameters(document);
111 }
112
113 public static NodeList getReferenceParameters(Document document) {
114 return XmlHelper.getSingleNodeChildren(document, "ReferenceParameters");
115 }
116
117 public static String getReferenceParameterValue(W3CEndpointReference subscriptionReference, String parameterName) {
118 Document document = XmlHelper.transformEndpointReferenceToDocument(subscriptionReference);
119 return getReferenceParameterValue(document, parameterName);
120 }
121
122 public static String getReferenceParameterValue(Document document, String parameterName) {
123 String parameterValue = null;
124 NodeList referenceParameterNodes = getReferenceParameters(document);
125 if (referenceParameterNodes != null) {
126 for (int i = 0; i < referenceParameterNodes.getLength(); i++) {
127 Node nhinReferenceParamterNode = referenceParameterNodes.item(i);
128 String elementName = nhinReferenceParamterNode.getLocalName();
129 if ((elementName != null) && (elementName.contentEquals(parameterName))) {
130 parameterValue = XmlHelper.getNodeValue(nhinReferenceParamterNode);
131 }
132 }
133 }
134 return parameterValue;
135 }
136}
Note: See TracBrowser for help on using the repository browser.