View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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   */
41  public abstract class AnnotatedEndpointMetadata<T extends Annotation, C extends EndpointConfig> implements EndpointMetadata
42  {
43      /**
44       * Callable for &#064;{@link OnOpen} annotation.
45       */
46      public OnOpenCallable onOpen;
47  
48      /**
49       * Callable for &#064;{@link OnClose} annotation
50       */
51      public OnCloseCallable onClose;
52  
53      /**
54       * Callable for &#064;{@link OnError} annotation
55       */
56      public OnErrorCallable onError;
57  
58      /**
59       * Callable for &#064;{@link OnMessage} annotation dealing with Text Message Format
60       */
61      public OnMessageTextCallable onText;
62  
63      /**
64       * Callable for &#064;{@link OnMessage} annotation dealing with Text Streaming Message Format
65       */
66      public OnMessageTextStreamCallable onTextStream;
67  
68      /**
69       * Callable for &#064;{@link OnMessage} annotation dealing with Binary Message Format
70       */
71      public OnMessageBinaryCallable onBinary;
72  
73      /**
74       * Callable for &#064;{@link OnMessage} annotation dealing with Binary Streaming Message Format
75       */
76      public OnMessageBinaryStreamCallable onBinaryStream;
77  
78      /**
79       * Callable for &#064;{@link OnMessage} annotation dealing with Pong Message Format
80       */
81      public OnMessagePongCallable onPong;
82  
83      private final Class<?> endpointClass;
84      private DecoderMetadataSet decoders;
85      private EncoderMetadataSet encoders;
86  
87      protected AnnotatedEndpointMetadata(Class<?> endpointClass)
88      {
89          this.endpointClass = endpointClass;
90          this.decoders = new DecoderMetadataSet();
91          this.encoders = new EncoderMetadataSet();
92      }
93  
94      public void customizeParamsOnClose(LinkedList<IJsrParamId> params)
95      {
96          /* do nothing */
97      }
98  
99      public void customizeParamsOnError(LinkedList<IJsrParamId> params)
100     {
101         /* do nothing */
102     }
103 
104     public void customizeParamsOnMessage(LinkedList<IJsrParamId> params)
105     {
106         for (DecoderMetadata metadata : decoders)
107         {
108             params.add(new JsrParamIdDecoder(metadata));
109         }
110     }
111 
112     public void customizeParamsOnOpen(LinkedList<IJsrParamId> params)
113     {
114         /* do nothing */
115     }
116 
117     public abstract T getAnnotation();
118 
119     public abstract C getConfig();
120 
121     @Override
122     public DecoderMetadataSet getDecoders()
123     {
124         return decoders;
125     }
126 
127     @Override
128     public EncoderMetadataSet getEncoders()
129     {
130         return encoders;
131     }
132 
133     @Override
134     public Class<?> getEndpointClass()
135     {
136         return endpointClass;
137     }
138 }