001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2013-2015 ForgeRock AS.
015 */
016
017package org.forgerock.json.resource;
018
019import org.forgerock.services.context.Context;
020import org.forgerock.util.promise.Promise;
021
022/**
023 * An abstract base class from which request handlersmay be easily implemented.
024 * The default implementation of each method is to return a
025 * {@link NotSupportedException}.
026 */
027public abstract class AbstractRequestHandler implements RequestHandler {
028    /**
029     * Creates a new abstract request handler.
030     */
031    protected AbstractRequestHandler() {
032        // Nothing to do.
033    }
034
035    /**
036     * {@inheritDoc}
037     * <p>
038     * The default implementation is to return a {@link NotSupportedException}.
039     */
040    @Override
041    public Promise<ActionResponse, ResourceException> handleAction(final Context context,
042            final ActionRequest request) {
043        return new NotSupportedException().asPromise();
044    }
045
046    /**
047     * {@inheritDoc}
048     * <p>
049     * The default implementation is to return a {@link NotSupportedException}.
050     */
051    @Override
052    public Promise<ResourceResponse, ResourceException> handleCreate(final Context context,
053            final CreateRequest request) {
054        return new NotSupportedException().asPromise();
055    }
056
057    /**
058     * {@inheritDoc}
059     * <p>
060     * The default implementation is to return a {@link NotSupportedException}.
061     */
062    @Override
063    public Promise<ResourceResponse, ResourceException> handleDelete(final Context context,
064            final DeleteRequest request) {
065        return new NotSupportedException().asPromise();
066    }
067
068    /**
069     * {@inheritDoc}
070     * <p>
071     * The default implementation is to return a {@link NotSupportedException}.
072     */
073    @Override
074    public Promise<ResourceResponse, ResourceException> handlePatch(final Context context,
075            final PatchRequest request) {
076        return new NotSupportedException().asPromise();
077    }
078
079    /**
080     * {@inheritDoc}
081     * <p>
082     * The default implementation is to return a {@link NotSupportedException}.
083     */
084    @Override
085    public Promise<QueryResponse, ResourceException> handleQuery(final Context context,
086            final QueryRequest request, final QueryResourceHandler handler) {
087        return new NotSupportedException().asPromise();
088    }
089
090    /**
091     * {@inheritDoc}
092     * <p>
093     * The default implementation is to return a {@link NotSupportedException}.
094     */
095    @Override
096    public Promise<ResourceResponse, ResourceException> handleRead(final Context context,
097            final ReadRequest request) {
098        return new NotSupportedException().asPromise();
099    }
100
101    /**
102     * {@inheritDoc}
103     * <p>
104     * The default implementation is to return a {@link NotSupportedException}.
105     */
106    @Override
107    public Promise<ResourceResponse, ResourceException> handleUpdate(final Context context,
108            final UpdateRequest request) {
109        return new NotSupportedException().asPromise();
110    }
111}