+ public static ObjectName createReadOnlyServiceON(String serviceQName, String refName) {
+ Map<String, String> onParams = createServiceMap(serviceQName, refName);
+ return createON(ON_DOMAIN, onParams);
+ }
+
+ public static ObjectName createTransactionServiceON(String transactionName, String serviceQName, String refName) {
+ Map<String, String> onParams = createServiceON(transactionName, serviceQName, refName);
+ return createON(ON_DOMAIN, onParams);
+ }
+
+ public static String getServiceQName(ObjectName objectName) {
+ checkType(objectName, TYPE_SERVICE_REFERENCE);
+ String quoted = objectName.getKeyProperty(SERVICE_QNAME_KEY);
+ String result = unquoteAndUnescape(objectName, quoted);
+ return result;
+ }
+
+ // ObjectName supports quotation and ignores tokens like =, but fails to ignore ? sign.
+ // It must be replaced with another character that hopefully does not collide
+ // with actual value.
+ private static String unquoteAndUnescape(ObjectName objectName, String quoted) {
+ if (quoted == null) {
+ throw new IllegalArgumentException("Cannot find " + SERVICE_QNAME_KEY + " in " + objectName);
+ }
+ if (quoted.startsWith("\"") == false || quoted.endsWith("\"") == false) {
+ throw new IllegalArgumentException("Quotes not found in " + objectName);
+ }
+ String substring = quoted.substring(1);
+ substring = substring.substring(0, substring.length() - 1);
+ substring = substring.replace(REPLACED_QUOTATION_MARK, "?");
+ return substring;
+ }
+
+ private static String quoteAndEscapeValue(String serviceQName) {
+ return "\"" + serviceQName.replace("?", REPLACED_QUOTATION_MARK) + "\"";
+ }
+
+ public static String getReferenceName(ObjectName objectName) {
+ checkType(objectName, TYPE_SERVICE_REFERENCE);
+ return objectName.getKeyProperty(REF_NAME_KEY);
+ }
+
+ private static Map<String, String> createServiceON(String transactionName, String serviceQName,
+ String refName) {
+ Map<String, String> result = new HashMap<>(createServiceMap(serviceQName, refName));
+ result.put(TRANSACTION_NAME_KEY, transactionName);
+ return result;
+ }
+
+ private static Map<String, String> createServiceMap(String serviceQName,
+ String refName) {
+ Map<String, String> onParams = new HashMap<>();
+ onParams.put(TYPE_KEY, TYPE_SERVICE_REFERENCE);
+ onParams.put(SERVICE_QNAME_KEY, quoteAndEscapeValue(serviceQName));
+ onParams.put(REF_NAME_KEY, refName);
+ return onParams;
+ }
+
+