View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.jsr356.annotations;
20  
21  import java.lang.annotation.Annotation;
22  import java.util.LinkedList;
23  
24  import javax.websocket.EndpointConfig;
25  import javax.websocket.OnClose;
26  import javax.websocket.OnError;
27  import javax.websocket.OnMessage;
28  import javax.websocket.OnOpen;
29  
30  import org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata;
31  import org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadataSet;
32  import org.eclipse.jetty.websocket.jsr356.metadata.EncoderMetadataSet;
33  import org.eclipse.jetty.websocket.jsr356.metadata.EndpointMetadata;
34  
35  /**
36   * Static reference to a specific annotated classes metadata.
37   * 
38   * @param <T>
39   *            the annotation this metadata is based off of
40   * @param <C>
41   *            the endpoint configuration this is based off of
42   */
43  public abstract class AnnotatedEndpointMetadata<T extends Annotation, C extends EndpointConfig> implements EndpointMetadata
44  {
45      /**
46       * Callable for &#064;{@link OnOpen} annotation.
47       */
48      public OnOpenCallable onOpen;
49  
50      /**
51       * Callable for &#064;{@link OnClose} annotation
52       */
53      public OnCloseCallable onClose;
54  
55      /**
56       * Callable for &#064;{@link OnError} annotation
57       */
58      public OnErrorCallable onError;
59  
60      /**
61       * Callable for &#064;{@link OnMessage} annotation dealing with Text Message Format
62       */
63      public OnMessageTextCallable onText;
64  
65      /**
66       * Callable for &#064;{@link OnMessage} annotation dealing with Text Streaming Message Format
67       */
68      public OnMessageTextStreamCallable onTextStream;
69  
70      /**
71       * Callable for &#064;{@link OnMessage} annotation dealing with Binary Message Format
72       */
73      public OnMessageBinaryCallable onBinary;
74  
75      /**
76       * Callable for &#064;{@link OnMessage} annotation dealing with Binary Streaming Message Format
77       */
78      public OnMessageBinaryStreamCallable onBinaryStream;
79  
80      /**
81       * Callable for &#064;{@link OnMessage} annotation dealing with Pong Message Format
82       */
83      public OnMessagePongCallable onPong;
84  
85      private final Class<?> endpointClass;
86      private DecoderMetadataSet decoders;
87      private EncoderMetadataSet encoders;
88  
89      protected AnnotatedEndpointMetadata(Class<?> endpointClass)
90      {
91          this.endpointClass = endpointClass;
92          this.decoders = new DecoderMetadataSet();
93          this.encoders = new EncoderMetadataSet();
94      }
95  
96      public void customizeParamsOnClose(LinkedList<IJsrParamId> params)
97      {
98          /* do nothing */
99      }
100 
101     public void customizeParamsOnError(LinkedList<IJsrParamId> params)
102     {
103         /* do nothing */
104     }
105 
106     public void customizeParamsOnMessage(LinkedList<IJsrParamId> params)
107     {
108         for (DecoderMetadata metadata : decoders)
109         {
110             params.add(new JsrParamIdDecoder(metadata));
111         }
112     }
113 
114     public void customizeParamsOnOpen(LinkedList<IJsrParamId> params)
115     {
116         /* do nothing */
117     }
118 
119     public abstract T getAnnotation();
120 
121     public abstract C getConfig();
122 
123     @Override
124     public DecoderMetadataSet getDecoders()
125     {
126         return decoders;
127     }
128 
129     @Override
130     public EncoderMetadataSet getEncoders()
131     {
132         return encoders;
133     }
134 
135     @Override
136     public Class<?> getEndpointClass()
137     {
138         return endpointClass;
139     }
140 }