001package org.consensusj.jsonrpc.introspection; 002 003import java.lang.reflect.Method; 004import java.util.Map; 005 006/** 007 * Implementation of {@link JsonRpcServiceWrapper} that takes a delegate 008 * object in the constructor. 009 * <p> 010 * Use this class when 011 */ 012public class DelegatingJsonRpcService extends AbstractJsonRpcService { 013 private final Object service; 014 015 /** 016 * Use this constructor for simplicity and if you don't need GraalVM support 017 * @param serviceObject the service object to wrap. 018 */ 019 public DelegatingJsonRpcService(Object serviceObject) { 020 this(JsonRpcServiceWrapper.reflect(serviceObject.getClass()), serviceObject); 021 } 022 023 /** 024 * Use this constructor for GraalVM compatibility and make sure your {@code methods} {@link Map} 025 * was statically initialized. 026 * 027 * @param serviceObject The service object to wrap 028 * @param methods A map that maps method-name strings to {@link Method} objects. 029 */ 030 public DelegatingJsonRpcService(Map<String, Method> methods, Object serviceObject) { 031 super(methods); 032 this.service = serviceObject; 033 } 034 035 @Override 036 public Object getServiceObject() { 037 return service; 038 } 039 040 @Override 041 public Method getMethod(String methodName) { 042 return methods.get(methodName); 043 } 044}