/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ package com.facebook.react.bridge; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; /** * Class stores configuration of javascript modules that can be used across the bridge */ public class JavaScriptModulesConfig { private final List mModules; public JavaScriptModulesConfig(List modules) { mModules = modules; } public List getModuleDefinitions() { return mModules; } public void writeModuleDescriptions(JsonWriter writer) throws IOException { writer.beginObject(); for (JavaScriptModuleRegistration registration : mModules) { writer.name(registration.getName()).beginObject(); appendJSModuleToJSONObject(writer, registration); writer.endObject(); } writer.endObject(); } private void appendJSModuleToJSONObject( JsonWriter writer, JavaScriptModuleRegistration registration) throws IOException { writer.name("moduleID").value(registration.getName()); writer.name("methods").beginObject(); for (Method method : registration.getMethods()) { writer.name(method.getName()).beginObject(); writer.name("methodID").value(method.getName()); writer.endObject(); } writer.endObject(); if (registration.getModuleInterface().isAnnotationPresent(SupportsWebWorkers.class)) { writer.name("supportsWebWorkers").value(true); } } public static class Builder { private List mModules = new ArrayList(); public Builder add(Class moduleInterfaceClass) { mModules.add(new JavaScriptModuleRegistration(moduleInterfaceClass)); return this; } public JavaScriptModulesConfig build() { return new JavaScriptModulesConfig(mModules); } } }