package net.anxuiz.protobuf.packet.base;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import net.anxuiz.protobuf.packet.HandlerException;
import net.anxuiz.protobuf.packet.MessageHandler;

import com.google.common.base.Preconditions;
import com.google.protobuf.Message;

public class MethodMessageExecutor implements MessageHandler {
    private final Object parent;
    private final Method method;

    public MethodMessageExecutor(final Object parent, final Method method) {
        Preconditions.checkNotNull(parent, "parent");
        Preconditions.checkNotNull(method, "method");

        this.parent = parent;
        this.method = method;
    }

    public void handle(Message msg) throws HandlerException {
        try {
            this.method.invoke(this.parent, msg);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            throw new HandlerException(e.getCause());
        }
    }
}

@@ -121,16 +121,84 @@
 ethod;%0A%0A
+import javax.annotation.Nonnull;%0Aimport javax.annotation.Nullable;%0A%0A
 import n
@@ -451,24 +451,34 @@
 ivate final 
+@Nullable 
 Object paren
@@ -494,24 +494,33 @@
 ivate final 
+@Nonnull 
 Method metho
@@ -556,21 +556,25 @@
 xecutor(
-final
+@Nullable
  Object 
@@ -581,20 +581,23 @@
 parent, 
-fina
+@Nonnul
 l Method
@@ -646,25 +646,56 @@
 ull(
+method, %22method%22);%0A%0A        this.
 parent
-, %22
+ = 
 parent
-%22)
 ;%0A  
@@ -704,77 +704,99 @@
     
-Preconditions.checkNotNull(
+this.
 method
-, %22
+ = 
 method
-%22);%0A%0A        this.parent = 
+;%0A    %7D%0A%0A    public @Nullable Object getParent() %7B%0A        return this.
 pare
@@ -803,34 +803,80 @@
 nt;%0A    
+%7D%0A%0A
     
-this.method = 
+public @Nonnull Method getMethod() %7B%0A        return this.
 method;%0A
@@ -905,16 +905,25 @@
  handle(
+@Nonnull 
 Message 
@@ -953,16 +953,69 @@
 ption %7B%0A
+        Preconditions.checkNotNull(msg, %22message%22);%0A%0A
         

Add some handy accessors and annotations to MethodMessageExecutor.