org.chromium.sdk/src/org/chromium/sdk/internal/protocolparser/dynamicimpl/JsonInvocationHandler.java
equal
deleted
inserted
replaced
|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.sdk.internal.protocolparser.dynamicimpl; |
|
6 |
|
7 import java.lang.reflect.InvocationHandler; |
|
8 import java.lang.reflect.Method; |
|
9 import java.util.Map; |
|
10 |
|
11 /** |
|
12 * The implementation of {@link InvocationHandler} for JSON types. It dispatches calls to method |
|
13 * handlers from the map. |
|
14 */ |
|
15 class JsonInvocationHandler implements InvocationHandler { |
|
16 private final ObjectData objectData; |
|
17 private final Map<Method, MethodHandler> methodHandlerMap; |
|
18 |
|
19 JsonInvocationHandler(ObjectData objectData, Map<Method, MethodHandler> methodHandlerMap) { |
|
20 this.objectData = objectData; |
|
21 this.methodHandlerMap = methodHandlerMap; |
|
22 } |
|
23 |
|
24 ObjectData getObjectData() { |
|
25 return objectData; |
|
26 } |
|
27 |
|
28 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
|
29 MethodHandler methodHandler = methodHandlerMap.get(method); |
|
30 if (methodHandler == null) { |
|
31 throw new RuntimeException("No method handler for " + method); |
|
32 } |
|
33 return methodHandler.handle(proxy, objectData, args); |
|
34 } |
|
35 } |