View Javadoc

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