1 | package gov.hhs.fha.nhinc.connectmgr;
|
---|
2 |
|
---|
3 | import org.apache.commons.logging.Log;
|
---|
4 | import org.apache.commons.logging.LogFactory;
|
---|
5 |
|
---|
6 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
7 |
|
---|
8 | import gov.hhs.fha.nhinc.connectmgr.data.CMEprInfo;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * This class has utilities for constructing the information needed for an endpoint reference
|
---|
12 | * object. It retrieves the information based on a uniform service name from the
|
---|
13 | * connectionsEPR.properties file.
|
---|
14 | *
|
---|
15 | * @author Les Westberg
|
---|
16 | */
|
---|
17 | public class CMEprUtil
|
---|
18 | {
|
---|
19 | private static Log log = LogFactory.getLog(CMEprUtil.class);
|
---|
20 | private static final String EPR_PROPERTY_FILE_NAME = "connectionEPR";
|
---|
21 | private static final String EPR_NAMESPACE_URI = "NamespaceURI";
|
---|
22 | private static final String EPR_PORT_NAME = "PortName";
|
---|
23 | private static final String EPR_SERVICE_NAME = "ServiceName";
|
---|
24 | private static final String EPR_NAMESPACE_PREFIX = "NamespacePrefix";
|
---|
25 |
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * This method returns specific EPR data about a service. The information is
|
---|
29 | * in the connectionEPR.properties file.
|
---|
30 | *
|
---|
31 | * @param sServiceName The Uniform Service name - this is used as a key to the properties in
|
---|
32 | * the property file that are specific to this service.
|
---|
33 | * @param sEPRKey The specific key that is being wanted.
|
---|
34 | * @return The value of that key for that service.
|
---|
35 | * @throws ConnectionManagerException
|
---|
36 | */
|
---|
37 | public static String getServiceSpecificEPRInfo(String sServiceName, String sEPRKey)
|
---|
38 | throws ConnectionManagerException
|
---|
39 | {
|
---|
40 | String sKey = sServiceName + "." + sEPRKey;
|
---|
41 | String sValue = "";
|
---|
42 | try
|
---|
43 | {
|
---|
44 | sValue = PropertyAccessor.getProperty(EPR_PROPERTY_FILE_NAME, sKey);
|
---|
45 | }
|
---|
46 | catch (Exception e)
|
---|
47 | {
|
---|
48 | String sErrorMessage = "Failed to retrieve property: '" + sKey + "' from " +
|
---|
49 | EPR_PROPERTY_FILE_NAME + ".properties file. Exception: " +
|
---|
50 | e.getMessage();
|
---|
51 | log.error(sErrorMessage, e);
|
---|
52 | throw new ConnectionManagerException(sErrorMessage, e);
|
---|
53 | }
|
---|
54 | if (sValue == null)
|
---|
55 | {
|
---|
56 | sValue = "";
|
---|
57 | }
|
---|
58 |
|
---|
59 | return sValue;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * This method creates an endpoint for the given service name and URL.
|
---|
64 | *
|
---|
65 | * @param sUniformServiceName The service name for the service.
|
---|
66 | * @return The Endpoint reference to be returned.
|
---|
67 | * @throws ConnectionManagerException
|
---|
68 | */
|
---|
69 | public static CMEprInfo createEPR(String sUniformServiceName)
|
---|
70 | throws ConnectionManagerException
|
---|
71 | {
|
---|
72 | if ((sUniformServiceName == null) || (sUniformServiceName.length() <= 0))
|
---|
73 | {
|
---|
74 | return null;
|
---|
75 | }
|
---|
76 |
|
---|
77 | CMEprInfo oEpr = new CMEprInfo();
|
---|
78 |
|
---|
79 | oEpr.setUniformServiceName(sUniformServiceName);
|
---|
80 | oEpr.setNamespacePrefix(getServiceSpecificEPRInfo(sUniformServiceName, EPR_NAMESPACE_PREFIX));
|
---|
81 | oEpr.setNamespaceURI(getServiceSpecificEPRInfo(sUniformServiceName, EPR_NAMESPACE_URI));
|
---|
82 | oEpr.setPortName(getServiceSpecificEPRInfo(sUniformServiceName, EPR_PORT_NAME));
|
---|
83 | oEpr.setServiceName(getServiceSpecificEPRInfo(sUniformServiceName, EPR_SERVICE_NAME));
|
---|
84 |
|
---|
85 | return oEpr;
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|