+ public static ObjectName createReadOnlyServiceON(final String serviceQName, final String refName) {
+ Map<String, String> onParams = createServiceMap(serviceQName, refName);
+ return createON(ON_DOMAIN, onParams);
+ }
+
+ public static ObjectName createTransactionServiceON(final String transactionName, final String serviceQName,
+ final String refName) {
+ Map<String, String> onParams = createServiceON(transactionName, serviceQName, refName);
+ return createON(ON_DOMAIN, onParams);
+ }
+
+ public static String getServiceQName(final ObjectName objectName) {
+ checkType(objectName, TYPE_SERVICE_REFERENCE);
+ String quoted = objectName.getKeyProperty(SERVICE_QNAME_KEY);
+ return unquoteAndUnescape(objectName, quoted);
+ }
+
+ // 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(final ObjectName objectName, final String quoted) {
+ if (quoted == null) {
+ throw new IllegalArgumentException("Cannot find " + SERVICE_QNAME_KEY + " in " + objectName);
+ }
+ if (!quoted.startsWith("\"") || !quoted.endsWith("\"")) {
+ 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(final String serviceQName) {
+ return "\"" + serviceQName.replace("?", REPLACED_QUOTATION_MARK) + "\"";
+ }
+
+ public static String getReferenceName(final ObjectName objectName) {
+ checkType(objectName, TYPE_SERVICE_REFERENCE);
+ return objectName.getKeyProperty(REF_NAME_KEY);
+ }
+
+ private static Map<String, String> createServiceON(final String transactionName, final String serviceQName,
+ final 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(final String serviceQName, final 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;
+ }
+
+ private static Map<String, String> createModuleMap(final String moduleName, final String instanceName) {