View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2013-2015 ForgeRock AS.
15   */
16  
17  package org.forgerock.json.resource;
18  
19  import org.forgerock.services.context.Context;
20  import org.forgerock.util.promise.Promise;
21  
22  /**
23   * An abstract base class from which request handlersmay be easily implemented.
24   * The default implementation of each method is to return a
25   * {@link NotSupportedException}.
26   */
27  public abstract class AbstractRequestHandler implements RequestHandler {
28      /**
29       * Creates a new abstract request handler.
30       */
31      protected AbstractRequestHandler() {
32          // Nothing to do.
33      }
34  
35      /**
36       * {@inheritDoc}
37       * <p>
38       * The default implementation is to return a {@link NotSupportedException}.
39       */
40      @Override
41      public Promise<ActionResponse, ResourceException> handleAction(final Context context,
42              final ActionRequest request) {
43          return new NotSupportedException().asPromise();
44      }
45  
46      /**
47       * {@inheritDoc}
48       * <p>
49       * The default implementation is to return a {@link NotSupportedException}.
50       */
51      @Override
52      public Promise<ResourceResponse, ResourceException> handleCreate(final Context context,
53              final CreateRequest request) {
54          return new NotSupportedException().asPromise();
55      }
56  
57      /**
58       * {@inheritDoc}
59       * <p>
60       * The default implementation is to return a {@link NotSupportedException}.
61       */
62      @Override
63      public Promise<ResourceResponse, ResourceException> handleDelete(final Context context,
64              final DeleteRequest request) {
65          return new NotSupportedException().asPromise();
66      }
67  
68      /**
69       * {@inheritDoc}
70       * <p>
71       * The default implementation is to return a {@link NotSupportedException}.
72       */
73      @Override
74      public Promise<ResourceResponse, ResourceException> handlePatch(final Context context,
75              final PatchRequest request) {
76          return new NotSupportedException().asPromise();
77      }
78  
79      /**
80       * {@inheritDoc}
81       * <p>
82       * The default implementation is to return a {@link NotSupportedException}.
83       */
84      @Override
85      public Promise<QueryResponse, ResourceException> handleQuery(final Context context,
86              final QueryRequest request, final QueryResourceHandler handler) {
87          return new NotSupportedException().asPromise();
88      }
89  
90      /**
91       * {@inheritDoc}
92       * <p>
93       * The default implementation is to return a {@link NotSupportedException}.
94       */
95      @Override
96      public Promise<ResourceResponse, ResourceException> handleRead(final Context context,
97              final ReadRequest request) {
98          return new NotSupportedException().asPromise();
99      }
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 }