ingo@100: /* ingo@100: * Copyright (c) 2010 by Intevation GmbH ingo@100: * ingo@100: * This program is free software under the LGPL (>=v2.1) ingo@100: * Read the file LGPL.txt coming with the software for details ingo@100: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@100: */ ingo@100: sascha@19: package de.intevation.artifactdatabase.rest; sascha@19: sascha@19: import de.intevation.artifacts.ArtifactDatabase; sascha@19: sascha@20: import java.util.concurrent.ConcurrentMap; sascha@20: sascha@19: import org.restlet.Application; ingo@79: import org.restlet.Context; sascha@19: import org.restlet.Restlet; sascha@19: sascha@19: import org.restlet.routing.Router; sascha@19: sascha@19: /** sascha@88: * This is the core REST application that binds the serveral resources sascha@88: * used to manage the artifact database to the HTTP server provided sascha@88: * by the Restlet framework. sascha@19: * sascha@77: * @author Sascha L. Teichmann sascha@19: */ sascha@19: public class RestApp sascha@19: extends Application sascha@19: { sascha@88: /** sascha@88: * The central artifact database instance to work with. sascha@88: */ sascha@19: protected ArtifactDatabase database; sascha@19: sascha@88: /** sascha@88: * Default constructor sascha@88: */ sascha@19: public RestApp() { sascha@19: } sascha@19: sascha@264: public RestApp(Context context, ArtifactDatabase database) { sascha@264: super(context); sascha@264: this.database = database; sascha@264: } sascha@264: sascha@88: /** sascha@88: * Constructor to create REST appliction bound to a specific sascha@88: * artifact database. sascha@88: * sascha@88: * @param database The artifact database to be used. sascha@88: */ sascha@19: public RestApp(ArtifactDatabase database) { sascha@19: this.database = database; sascha@19: } sascha@19: sascha@88: /** sascha@88: * Overwrites the createRoot() method of Application to sascha@88: * build the resource tree to form the exposed server URLs. sascha@88: * sascha@88: * @return The root of the URL tree exposed by the HTTP server. sascha@88: */ sascha@88: @Override sascha@19: public Restlet createRoot() { sascha@19: sascha@20: Context context = getContext(); sascha@19: sascha@20: ConcurrentMap map = context.getAttributes(); sascha@20: map.put("database", database); sascha@20: sascha@20: Router router = new Router(context); sascha@20: sascha@72: router.attach(ServicesResource.PATH, ServicesResource.class); sascha@73: router.attach(ServiceResource.PATH, ServiceResource.class); sascha@29: router.attach(FactoriesResource.PATH, FactoriesResource.class); sascha@29: router.attach(CreateResource.PATH, CreateResource.class); sascha@29: router.attach(ArtifactResource.PATH, ArtifactResource.class); sascha@29: router.attach(ArtifactOutResource.PATH, ArtifactOutResource.class); ingo@79: router.attach(ExportResource.PATH, ExportResource.class); ingo@80: router.attach(ImportResource.PATH, ImportResource.class); ingo@131: router.attach(CreateUserResource.PATH, CreateUserResource.class); ingo@136: router.attach(ListUsersResource.PATH, ListUsersResource.class); ingo@137: router.attach(UserResource.PATH, UserResource.class); ingo@140: router.attach( ingo@140: CreateCollectionResource.PATH, CreateCollectionResource.class); ingo@141: router.attach( ingo@141: ListCollectionsResource.PATH, ListCollectionsResource.class); ingo@142: router.attach( ingo@142: CollectionResource.PATH, CollectionResource.class); ingo@143: router.attach( ingo@143: CollectionOutResource.PATH, CollectionOutResource.class); sascha@19: sascha@19: return router; sascha@19: } sascha@19: } ingo@79: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :