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.common.extensions.identity;
20  
21  import org.eclipse.jetty.util.QuotedStringTokenizer;
22  import org.eclipse.jetty.util.annotation.ManagedObject;
23  import org.eclipse.jetty.websocket.api.WebSocketException;
24  import org.eclipse.jetty.websocket.api.WriteCallback;
25  import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
26  import org.eclipse.jetty.websocket.api.extensions.Frame;
27  import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
28  
29  @ManagedObject("Identity Extension")
30  public class IdentityExtension extends AbstractExtension
31  {
32      private String id;
33  
34      public String getParam(String key)
35      {
36          return getConfig().getParameter(key,"?");
37      }
38  
39      @Override
40      public void incomingError(WebSocketException e)
41      {
42          // pass through
43          nextIncomingError(e);
44      }
45  
46      @Override
47      public void incomingFrame(Frame frame)
48      {
49          // pass through
50          nextIncomingFrame(frame);
51      }
52  
53      @Override
54      public void outgoingFrame(Frame frame, WriteCallback callback)
55      {
56          // pass through
57          nextOutgoingFrame(frame,callback);
58      }
59  
60      @Override
61      public void setConfig(ExtensionConfig config)
62      {
63          super.setConfig(config);
64          StringBuilder s = new StringBuilder();
65          s.append(config.getName());
66          s.append("@").append(Integer.toHexString(hashCode()));
67          s.append("[");
68          boolean delim = false;
69          for (String param : config.getParameterKeys())
70          {
71              if (delim)
72              {
73                  s.append(';');
74              }
75              s.append(param).append('=').append(QuotedStringTokenizer.quoteIfNeeded(config.getParameter(param,""),";="));
76              delim = true;
77          }
78          s.append("]");
79          id = s.toString();
80      }
81  
82      @Override
83      public String toString()
84      {
85          return id;
86      }
87  }