DefaultDispatcher.java

  1. /***************************************************************************
  2.    Copyright 2008 Emily Estes

  3.    Licensed under the Apache License, Version 2.0 (the "License");
  4.    you may not use this file except in compliance with the License.
  5.    You may obtain a copy of the License at

  6.        http://www.apache.org/licenses/LICENSE-2.0

  7.    Unless required by applicable law or agreed to in writing, software
  8.    distributed under the License is distributed on an "AS IS" BASIS,
  9.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10.    See the License for the specific language governing permissions and
  11.    limitations under the License.
  12. ***************************************************************************/
  13. package net.metanotion.web.concrete;


  14. import net.metanotion.util.Dispatcher;
  15. import net.metanotion.util.Message;

  16. import net.metanotion.web.Default;
  17. import net.metanotion.web.RequestObject;

  18. /** Since the Default service is a really simple interface, this dispatcher implements it by just grabbing the
  19. URL from the RequestObject to call Default's single method(<code>Default.get(String url)</code>) with the
  20. URL.
  21. */
  22. public final class DefaultDispatcher implements Dispatcher<Default,RequestObject> {
  23.     /** This is the Message class this dispatcher returns. It just holds the message and call's Default with the URL
  24.     when invoked. */
  25.     private static final class DefaultMessage implements Message<Default> {
  26.         /** The URL for the message. */
  27.         private final String url;
  28.         /** Create a new Message.
  29.             @param url The URL to pass to Default.get(...) when invoked.
  30.         */
  31.         public DefaultMessage(String url) { this.url = url; }
  32.         @Override public Object call(Default o) { return o.get(this.url); }
  33.         @Override public Class<Default> receiverType() { return Default.class; }
  34.     }

  35.     @Override public Message<Default> dispatch(RequestObject data) { return new DefaultMessage(data.getResource()); }
  36. }