1 /** 2 * 3 * Copyright 2005 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.system.plugin; 18 19 import java.io.Serializable; 20 import java.net.URL; 21 import java.util.List; 22 import java.util.ArrayList; 23 import java.util.Set; 24 import java.util.HashSet; 25 import org.apache.geronimo.kernel.repository.Artifact; 26 27 /** 28 * Metadata on a list of configurations available in a remote server. 29 * 30 * @version $Rev: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $ 31 */ 32 public class PluginList implements Serializable { 33 private final URL[] repositories; 34 private final PluginMetadata[] plugins; 35 36 public PluginList(URL[] repositories, PluginMetadata[] plugins) { 37 this.repositories = repositories; 38 this.plugins = plugins; 39 } 40 41 public static PluginList createInstallList(PluginList all, Artifact[] selectedConfigIDs) { 42 URL[] repositories = all.repositories; 43 List list = new ArrayList(); 44 Set set = new HashSet(); 45 for (int i = 0; i < selectedConfigIDs.length; i++) { 46 Artifact artifact = selectedConfigIDs[i]; 47 set.add(artifact); 48 } 49 for (int i = 0; i < all.getPlugins().length; i++) { 50 PluginMetadata metadata = all.getPlugins()[i]; 51 if(set.contains(metadata.getModuleId())) { 52 if(metadata.isInstalled() || !metadata.isEligible()) { 53 throw new IllegalArgumentException("Cannot install "+metadata.getModuleId()); 54 } 55 list.add(metadata); 56 } 57 } 58 if(list.size() == 0) { 59 return null; 60 } 61 PluginMetadata[] configurations = (PluginMetadata[]) list.toArray(new PluginMetadata[list.size()]); 62 return new PluginList(repositories, configurations); 63 } 64 65 public static PluginList createInstallList(PluginList all, Artifact selectedConfigID) { 66 URL[] repositories = all.repositories; 67 PluginMetadata target = null; 68 for (int i = 0; i < all.getPlugins().length; i++) { 69 PluginMetadata metadata = all.getPlugins()[i]; 70 if(selectedConfigID.equals(metadata.getModuleId())) { 71 if(metadata.isInstalled() || !metadata.isEligible()) { 72 throw new IllegalArgumentException("Cannot install "+metadata.getModuleId()); 73 } 74 target = metadata; 75 break; 76 } 77 } 78 if(target == null) { 79 return null; 80 } 81 return new PluginList(repositories, new PluginMetadata[]{target}); 82 } 83 84 public URL[] getRepositories() { 85 return repositories; 86 } 87 88 public PluginMetadata[] getPlugins() { 89 return plugins; 90 } 91 }