Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.ui.web; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.Map; |
| 6 | |
| 7 | import org.restlet.Client; |
| 8 | import org.restlet.Context; |
| 9 | import org.restlet.Restlet; |
| 10 | import org.restlet.data.Protocol; |
| 11 | import org.restlet.resource.Directory; |
| 12 | import org.restlet.routing.Router; |
| 13 | |
| 14 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 15 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 16 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 17 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 18 | import net.floodlightcontroller.restserver.IRestApiService; |
| 19 | import net.floodlightcontroller.restserver.RestletRoutable; |
| 20 | |
| 21 | public class StaticWebRoutable implements RestletRoutable, IFloodlightModule { |
| 22 | |
| 23 | private IRestApiService restApi; |
| 24 | |
| 25 | @Override |
| 26 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 27 | Collection<Class<? extends IFloodlightService>> l = |
| 28 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 29 | l.add(IRestApiService.class); |
| 30 | return l; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 40 | getServiceImpls() { |
| 41 | return null; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void init(FloodlightModuleContext context) |
| 46 | throws FloodlightModuleException { |
| 47 | restApi = context.getServiceImpl(IRestApiService.class); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void startUp(FloodlightModuleContext context) { |
| 52 | // Add our REST API |
| 53 | restApi.addRestletRoutable(this); |
| 54 | |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Restlet getRestlet(Context context) { |
| 59 | Router router = new Router(context); |
| 60 | router.attach("", new Directory(context, "clap://classloader/web/")); |
| 61 | context.setClientDispatcher(new Client(context, Protocol.CLAP)); |
| 62 | return router; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String basePath() { |
| 67 | return "/ui/"; |
| 68 | } |
| 69 | |
| 70 | } |