Java tutorial
/** * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at * http://mozilla.org/MPL/2.0/. * * This Source Code Form is also subject to the terms of the Health-Related Additional * Disclaimer of Warranty and Limitation of Liability available at * http://www.carewebframework.org/licensing/disclaimer. */ package org.carewebframework.smart; import java.util.Map; import org.carewebframework.api.spring.SpringUtil; import org.springframework.util.Assert; /** * Static utility class. */ public class SmartUtil { private static final String SMART_CONTEXT_PREFIX = "smart.context."; /** * Returns the SMART context implementation corresponding to the specified scope. * * @param contextScope The name of the SMART context scope. * @return The context implementation. */ public static ISmartContext getContext(String contextScope) { ISmartContext context = SpringUtil.getBean(SMART_CONTEXT_PREFIX + contextScope, ISmartContext.class); Assert.notNull(context, "Unknown SMART context type: " + contextScope); return context; } /** * Executes a SMART API. * * @param apiPath The path to be used to locate the SMART API implementation. * @param params Any parameters to be supplied to the API. * @param response Map to receive response values from the API. */ public static void executeAPI(String apiPath, Map<String, String> params, Map<String, Object> response) { SmartAPIRegistry.executeSmartAPI(apiPath, params, response); } /** * Attaches a subscriber to a SMART context scope. * * @param contextScope The name of the SMART context scope. * @param subscriber A SMART context subscriber. */ public static void subscribe(String contextScope, ISmartContextSubscriber subscriber) { getContext(contextScope).subscribe(subscriber); } /** * Detaches a subscriber from a SMART context scope. * * @param contextScope The name of the SMART context scope. * @param subscriber A SMART context subscriber. */ public static void unsubscribe(String contextScope, ISmartContextSubscriber subscriber) { getContext(contextScope).unsubscribe(subscriber); } /** * Enforce static class. */ private SmartUtil() { }; }