KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > util > DependencyChecker


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.util;
13
14 import javax.servlet.jsp.JspTagException JavaDoc;
15
16 import org.displaytag.Messages;
17
18
19 /**
20  * An user-friendly dependency checker. This will check the presence of libraries needed by displaytag, throwing an
21  * Exception with an informative message if the library is missing or the version is not compatible.
22  * @author Fabrizio Giustina
23  * @version $Revision: 956 $ ($Author: fgiust $)
24  */

25 public final class DependencyChecker
26 {
27
28     /**
29      * Has the commons-lang dependency been checked?
30      */

31     private static boolean commonsLangChecked;
32
33     /**
34      * Don't instantiate.
35      */

36     private DependencyChecker()
37     {
38         // unused
39
}
40
41     /**
42      * Displaytag requires commons-lang 2.x or better; it is not compatible with earlier versions.
43      * @throws JspTagException if the wrong library, or no library at all, is found.
44      */

45     public static void check() throws JspTagException JavaDoc
46     {
47         if (commonsLangChecked)
48         {
49             return;
50         }
51         try
52         {
53             // Do they have commons lang ?
54
Class JavaDoc stringUtils = Class.forName("org.apache.commons.lang.StringUtils"); //$NON-NLS-1$
55
try
56             {
57                 // this method is new in commons-lang 2.1
58
stringUtils.getMethod("splitPreserveAllTokens", new Class JavaDoc[]{String JavaDoc.class}); //$NON-NLS-1$
59
}
60             catch (NoSuchMethodException JavaDoc ee)
61             {
62                 throw new JspTagException JavaDoc(Messages.getString("DependencyChecker.lib.incompatible", //$NON-NLS-1$
63
new Object JavaDoc[]{"commons-lang", "2.1", "http://jakarta.apache.org/commons/lang"} //$NON-NLS-1$ //$NON-NLS-1$
64
));
65             }
66         }
67         catch (ClassNotFoundException JavaDoc e)
68         {
69             throw new JspTagException JavaDoc(Messages.getString("DependencyChecker.lib.missing", //$NON-NLS-1$
70
new Object JavaDoc[]{"commons-lang", "2.1", "http://jakarta.apache.org/commons/lang"} //$NON-NLS-1$ //$NON-NLS-1$
71
));
72         }
73         commonsLangChecked = true;
74     }
75
76 }
Popular Tags