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