DefaultDispatcher.java
- /***************************************************************************
- Copyright 2008 Emily Estes
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ***************************************************************************/
- package net.metanotion.web.concrete;
- import net.metanotion.util.Dispatcher;
- import net.metanotion.util.Message;
- import net.metanotion.web.Default;
- import net.metanotion.web.RequestObject;
- /** Since the Default service is a really simple interface, this dispatcher implements it by just grabbing the
- URL from the RequestObject to call Default's single method(<code>Default.get(String url)</code>) with the
- URL.
- */
- public final class DefaultDispatcher implements Dispatcher<Default,RequestObject> {
- /** This is the Message class this dispatcher returns. It just holds the message and call's Default with the URL
- when invoked. */
- private static final class DefaultMessage implements Message<Default> {
- /** The URL for the message. */
- private final String url;
- /** Create a new Message.
- @param url The URL to pass to Default.get(...) when invoked.
- */
- public DefaultMessage(String url) { this.url = url; }
- @Override public Object call(Default o) { return o.get(this.url); }
- @Override public Class<Default> receiverType() { return Default.class; }
- }
- @Override public Message<Default> dispatch(RequestObject data) { return new DefaultMessage(data.getResource()); }
- }