1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2014 Red Hat, Inc., and individual contributors
4  * as indicated by the @author tags.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */

18
19 package io.undertow.server.handlers.resource;
20
21 import io.undertow.UndertowMessages;
22
23 import java.io.Closeable;
24 import java.io.IOException;
25
26 /**
27  *
28  * Representation of a resource manager. A resource manager knows how to obtain
29  * a resource for a given path.
30  *
31  * @author Stuart Douglas
32  */

33 public interface ResourceManager extends Closeable {
34
35     /**
36      * Returns a resource for the given path.
37      *
38      * It is the responsibility of the called to make sure that the path in Canonicalised.
39      *
40      * @param path The path
41      * @return The resource representing the path, or null if no resource was found.
42      */

43     Resource getResource(final String path) throws IOException;
44
45     /**
46      *
47      * @return <code>true</code> if a resource change listener is supported
48      */

49     boolean isResourceChangeListenerSupported();
50
51     /**
52      * Registers a resource change listener, if the underlying resource manager support it
53      * @param listener The listener to register
54      * @throws IllegalArgumentException If resource change listeners are not supported
55      */

56     void registerResourceChangeListener(final ResourceChangeListener listener);
57
58     /**
59      * Removes a resource change listener
60      * @param listener
61      */

62     void removeResourceChangeListener(final ResourceChangeListener listener);
63
64     ResourceManager EMPTY_RESOURCE_MANAGER = new ResourceManager() {
65         @Override
66         public Resource getResource(final String path){
67             return null;
68         }
69
70         @Override
71         public boolean isResourceChangeListenerSupported() {
72             return false;
73         }
74
75         @Override
76         public void registerResourceChangeListener(ResourceChangeListener listener) {
77             throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
78         }
79
80         @Override
81         public void removeResourceChangeListener(ResourceChangeListener listener) {
82             throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
83         }
84
85         @Override
86         public void close() throws IOException {
87         }
88     };
89 }
90