KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > plugin > PluginList


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.HashSet JavaDoc;
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: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class PluginList implements Serializable JavaDoc {
33     private final URL JavaDoc[] repositories;
34     private final PluginMetadata[] plugins;
35
36     public PluginList(URL JavaDoc[] repositories, PluginMetadata[] plugins) {
37         this.repositories = repositories;
38         this.plugins = plugins;
39     }
40
41     public static PluginList createInstallList(PluginList all, Artifact[] selectedConfigIDs) {
42         URL JavaDoc[] repositories = all.repositories;
43         List JavaDoc list = new ArrayList JavaDoc();
44         Set JavaDoc set = new HashSet JavaDoc();
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 JavaDoc("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 JavaDoc[] 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 JavaDoc("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 JavaDoc[] getRepositories() {
85         return repositories;
86     }
87
88     public PluginMetadata[] getPlugins() {
89         return plugins;
90     }
91 }
92
Popular Tags