1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.common.events.annotated;
20
21 import java.io.InputStream;
22 import java.io.Reader;
23 import java.lang.reflect.Method;
24
25 import org.eclipse.jetty.websocket.api.Session;
26
27
28
29
30 public class OptionalSessionCallableMethod extends CallableMethod
31 {
32 private final boolean wantsSession;
33 private final boolean streaming;
34
35 public OptionalSessionCallableMethod(Class<?> pojo, Method method)
36 {
37 super(pojo,method);
38
39 boolean foundConnection = false;
40 boolean foundStreaming = false;
41
42 if (paramTypes != null)
43 {
44 for (Class<?> paramType : paramTypes)
45 {
46 if (Session.class.isAssignableFrom(paramType))
47 {
48 foundConnection = true;
49 }
50 if (Reader.class.isAssignableFrom(paramType) || InputStream.class.isAssignableFrom(paramType))
51 {
52 foundStreaming = true;
53 }
54 }
55 }
56
57 this.wantsSession = foundConnection;
58 this.streaming = foundStreaming;
59 }
60
61 public void call(Object obj, Session connection, Object... args)
62 {
63 if (wantsSession)
64 {
65 Object fullArgs[] = new Object[args.length + 1];
66 fullArgs[0] = connection;
67 System.arraycopy(args,0,fullArgs,1,args.length);
68 call(obj,fullArgs);
69 }
70 else
71 {
72 call(obj,args);
73 }
74 }
75
76 public boolean isSessionAware()
77 {
78 return wantsSession;
79 }
80
81 public boolean isStreaming()
82 {
83 return streaming;
84 }
85
86 @Override
87 public String toString()
88 {
89 return String.format("%s[%s]",this.getClass().getSimpleName(),method.toGenericString());
90 }
91 }