Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.plugins; 16 : 17 : import com.google.gerrit.extensions.registration.DynamicMap; 18 : import com.google.gerrit.extensions.restapi.IdString; 19 : import com.google.gerrit.extensions.restapi.ResourceNotFoundException; 20 : import com.google.gerrit.extensions.restapi.RestCollection; 21 : import com.google.gerrit.extensions.restapi.RestView; 22 : import com.google.gerrit.extensions.restapi.TopLevelResource; 23 : import com.google.inject.Inject; 24 : import com.google.inject.Provider; 25 : import com.google.inject.Singleton; 26 : 27 : @Singleton 28 : public class PluginsCollection implements RestCollection<TopLevelResource, PluginResource> { 29 : 30 : private final DynamicMap<RestView<PluginResource>> views; 31 : private final PluginLoader loader; 32 : private final Provider<ListPlugins> list; 33 : 34 : @Inject 35 : public PluginsCollection( 36 149 : DynamicMap<RestView<PluginResource>> views, PluginLoader loader, Provider<ListPlugins> list) { 37 149 : this.views = views; 38 149 : this.loader = loader; 39 149 : this.list = list; 40 149 : } 41 : 42 : @Override 43 : public RestView<TopLevelResource> list() throws ResourceNotFoundException { 44 1 : return list.get(); 45 : } 46 : 47 : @Override 48 : public PluginResource parse(TopLevelResource parent, IdString id) 49 : throws ResourceNotFoundException { 50 1 : return parse(id.get()); 51 : } 52 : 53 : public PluginResource parse(String id) throws ResourceNotFoundException { 54 3 : Plugin p = loader.get(id); 55 3 : if (p == null) { 56 2 : throw new ResourceNotFoundException(id); 57 : } 58 3 : return new PluginResource(p); 59 : } 60 : 61 : @Override 62 : public DynamicMap<RestView<PluginResource>> views() { 63 1 : return views; 64 : } 65 : }