1 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 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 } 92 | Popular Tags |