KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.geronimo.kernel.repository.Artifact;
24 import org.apache.geronimo.system.configuration.GBeanOverride;
25
26 /**
27  * Various metadata on a configuration that's used when listing, importing,
28  * and exporting configurations.
29  *
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class PluginMetadata implements Serializable JavaDoc, Comparable JavaDoc {
33     private final String JavaDoc name;
34     private final Artifact moduleId;
35     private final String JavaDoc category;
36     private final String JavaDoc description;
37     private final String JavaDoc pluginURL;
38     private final String JavaDoc author;
39     private License[] licenses = new License[0];
40     private final Hash hash;
41     private String JavaDoc[] geronimoVersions = new String JavaDoc[0];
42     private String JavaDoc[] jvmVersions = new String JavaDoc[0];
43     private Prerequisite[] prerequisites = new Prerequisite[0];
44     private String JavaDoc[] dependencies = new String JavaDoc[0];
45     private String JavaDoc[] forceStart = new String JavaDoc[0];
46     private String JavaDoc[] obsoletes = new String JavaDoc[0];
47     private URL JavaDoc[] repositories = new URL JavaDoc[0];
48     private CopyFile[] filesToCopy = new CopyFile[0];
49     private GBeanOverride[] configXmls = new GBeanOverride[0];
50
51     private final boolean installed;
52     private final boolean eligible;
53
54     public PluginMetadata(String JavaDoc name, Artifact moduleId, String JavaDoc category, String JavaDoc description, String JavaDoc pluginURL, String JavaDoc author, Hash hash, boolean installed, boolean eligible) {
55         this.name = name;
56         this.moduleId = moduleId;
57         this.category = category;
58         this.description = description;
59         this.pluginURL = pluginURL;
60         this.author = author;
61         this.hash = hash;
62         this.installed = installed;
63         this.eligible = eligible;
64     }
65
66     public void setDependencies(String JavaDoc[] dependencies) {
67         this.dependencies = dependencies;
68     }
69
70     public void setObsoletes(String JavaDoc[] obsoletes) {
71         this.obsoletes = obsoletes;
72     }
73
74     public void setForceStart(String JavaDoc[] forceStart) {
75         this.forceStart = forceStart;
76     }
77
78     /**
79      * Gets the Config ID for this configuration, which is a globally unique
80      * identifier.
81      */

82     public Artifact getModuleId() {
83         return moduleId;
84     }
85
86     /**
87      * Gets a human-readable name for this configuration.
88      */

89     public String JavaDoc getName() {
90         return name;
91     }
92
93     /**
94      * Gets a description of this configuration and why it is interesting
95      */

96     public String JavaDoc getDescription() {
97         return description;
98     }
99
100     /**
101      * Gets a description of this module in HTML format (with paragraph
102      * markers).
103      */

104     public String JavaDoc getHTMLDescription() {
105         String JavaDoc[] paras = splitParas(description);
106         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
107         for (int i = 0; i < paras.length; i++) {
108             String JavaDoc para = paras[i];
109             buf.append("<p>").append(para).append("</p>\n");
110         }
111         return buf.toString();
112     }
113
114     /**
115      * Gets a category name for this configuration. In a list, configurations
116      * in the same category will be listed together. There are no specific
117      * allowed values, though each repository may have standards for that.
118      */

119     public String JavaDoc getCategory() {
120         return category;
121     }
122
123     public boolean isInstalled() {
124         return installed;
125     }
126
127     public String JavaDoc getVersion() {
128         return moduleId.getVersion() == null ? "unknown version" : moduleId.getVersion().toString();
129     }
130
131     /**
132      * Gets the JAR or configuration dependencies for this configuration, Each
133      * String in the result is an Artifact (or Config ID) in String form.
134      * Generally speaking, the dependency names may be partial artifact names
135      * (but not, for example, if this whole thing is a plugin list).
136      */

137     public String JavaDoc[] getDependencies() {
138         return dependencies;
139     }
140
141     /**
142      * Gets the configurations obsoleted by this configuration. Each
143      * String in the result is an Artifact (or Config ID) in String form.
144      */

145     public String JavaDoc[] getObsoletes() {
146         return obsoletes;
147     }
148
149     /**
150      * Gets the configurations that should definitely be started when the
151      * install process completes.
152      */

153     public String JavaDoc[] getForceStart() {
154         return forceStart;
155     }
156
157     public String JavaDoc[] getGeronimoVersions() {
158         return geronimoVersions;
159     }
160
161     public String JavaDoc getAuthor() {
162         return author;
163     }
164
165     public Hash getHash() {
166         return hash;
167     }
168
169     public String JavaDoc getPluginURL() {
170         return pluginURL;
171     }
172
173     public URL JavaDoc[] getRepositories() {
174         return repositories;
175     }
176
177     public void setGeronimoVersions(String JavaDoc[] geronimoVersions) {
178         this.geronimoVersions = geronimoVersions;
179     }
180
181     public License[] getLicenses() {
182         return licenses;
183     }
184
185     public void setLicenses(License[] licenses) {
186         this.licenses = licenses;
187     }
188
189     public String JavaDoc[] getJvmVersions() {
190         return jvmVersions;
191     }
192
193     public void setJvmVersions(String JavaDoc[] jdkVersions) {
194         this.jvmVersions = jdkVersions;
195     }
196
197     public Prerequisite[] getPrerequisites() {
198         return prerequisites;
199     }
200
201     public void setRepositories(URL JavaDoc[] repositories) {
202         this.repositories = repositories;
203     }
204
205     public void setPrerequisites(Prerequisite[] prerequisites) {
206         this.prerequisites = prerequisites;
207     }
208
209     public boolean isEligible() {
210         return eligible;
211     }
212
213     /**
214      * Gets a list of files to copy from the plugin CAR into the server installation.
215      */

216     public CopyFile[] getFilesToCopy() {
217         return filesToCopy;
218     }
219
220     public void setFilesToCopy(CopyFile[] filesToCopy) {
221         this.filesToCopy = filesToCopy;
222     }
223
224     /**
225      * Gets a list of settings to populate in config.xml
226      */

227     public GBeanOverride[] getConfigXmls() {
228         return configXmls;
229     }
230
231     public void setConfigXmls(GBeanOverride[] configXmls) {
232         this.configXmls = configXmls;
233     }
234
235     public int compareTo(Object JavaDoc o) {
236         PluginMetadata other = (PluginMetadata) o;
237         int test = category.compareTo(other.category);
238         if(test != 0) return test;
239         test = name.compareTo(other.name);
240
241         return test;
242     }
243
244     public static class License implements Serializable JavaDoc {
245         private final String JavaDoc name;
246         private final boolean osiApproved;
247
248         public License(String JavaDoc name, boolean osiApproved) {
249             this.name = name;
250             this.osiApproved = osiApproved;
251         }
252
253         public String JavaDoc getName() {
254             return name;
255         }
256
257         public boolean isOsiApproved() {
258             return osiApproved;
259         }
260     }
261
262     public static class Hash implements Serializable JavaDoc {
263         private final String JavaDoc type; // MD5 or SHA-1
264
private final String JavaDoc value;
265
266         public Hash(String JavaDoc type, String JavaDoc value) {
267             this.type = type;
268             this.value = value;
269         }
270
271         public String JavaDoc getType() {
272             return type;
273         }
274
275         public String JavaDoc getValue() {
276             return value;
277         }
278     }
279
280     public static class CopyFile implements Serializable JavaDoc {
281         private final boolean relativeToVar; // if not, relative to the Geronimo install directory
282
private final String JavaDoc sourceFile;
283         private final String JavaDoc destDir;
284
285         public CopyFile(boolean relativeToVar, String JavaDoc sourceFile, String JavaDoc destDir) {
286             this.relativeToVar = relativeToVar;
287             this.sourceFile = sourceFile;
288             this.destDir = destDir;
289         }
290
291         public boolean isRelativeToVar() {
292             return relativeToVar;
293         }
294
295         public String JavaDoc getSourceFile() {
296             return sourceFile;
297         }
298
299         public String JavaDoc getDestDir() {
300             return destDir;
301         }
302     }
303
304     public static class Prerequisite implements Serializable JavaDoc {
305         private final Artifact moduleId;
306         private final String JavaDoc resourceType;
307         private final String JavaDoc description;
308         private final boolean present;
309
310         public Prerequisite(Artifact moduleId, boolean present) {
311             this.moduleId = moduleId;
312             this.present = present;
313             resourceType = null;
314             description = null;
315         }
316
317         public Prerequisite(Artifact moduleId, boolean present, String JavaDoc resourceType, String JavaDoc description) {
318             this.moduleId = moduleId;
319             this.present = present;
320             this.resourceType = resourceType;
321             this.description = description;
322         }
323
324         public Artifact getModuleId() {
325             return moduleId;
326         }
327
328         public String JavaDoc getResourceType() {
329             return resourceType;
330         }
331
332         public String JavaDoc getDescription() {
333             return description;
334         }
335
336         public boolean isPresent() {
337             return present;
338         }
339
340         public String JavaDoc getModuleIdWithStars() {
341             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
342             if(moduleId.getGroupId() == null) {
343                 buf.append("*");
344             } else {
345                 buf.append(moduleId.getGroupId());
346             }
347             buf.append("/");
348             if(moduleId.getArtifactId() == null) {
349                 buf.append("*");
350             } else {
351                 buf.append(moduleId.getArtifactId());
352             }
353             buf.append("/");
354             if(moduleId.getVersion() == null) {
355                 buf.append("*");
356             } else {
357                 buf.append(moduleId.getVersion());
358             }
359             buf.append("/");
360             if(moduleId.getType() == null) {
361                 buf.append("*");
362             } else {
363                 buf.append(moduleId.getType());
364             }
365             return buf.toString();
366         }
367     }
368
369     private static String JavaDoc[] splitParas(String JavaDoc desc) {
370         int start = 0, last=0;
371         List JavaDoc list = new ArrayList JavaDoc();
372         boolean inSpace = false, multiple = false;
373         for(int i=0; i<desc.length(); i++) {
374             char c = desc.charAt(i);
375             if(inSpace) {
376                 if(Character.isWhitespace(c)) {
377                     if(c == '\r' || c == '\n') {
378                         multiple = true;
379                         for(int j=i+1; j<desc.length(); j++) {
380                             char d = desc.charAt(j);
381                             if(d != c && (d == '\r' || d == '\n')) {
382                                 i = j;
383                             } else {
384                                 break;
385                             }
386                         }
387                     }
388                 } else {
389                     if(multiple) {
390                         list.add(desc.substring(last, start).trim());
391                         last = i;
392                     }
393                     inSpace = false;
394                 }
395             } else {
396                 if(c == '\r' || c == '\n') {
397                     inSpace = true;
398                     multiple = false;
399                     start = i;
400                     for(int j=i+1; j<desc.length(); j++) {
401                         char d = desc.charAt(j);
402                         if(d != c && (d == '\r' || d == '\n')) {
403                             i = j;
404                         } else {
405                             break;
406                         }
407                     }
408                 }
409             }
410         }
411         if(last < desc.length()) {
412             list.add(desc.substring(last).trim());
413         }
414         return (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
415     }
416 }
417
Popular Tags