001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.tools.checks;
007:
008: /**
009: * Checks that JAXP is present in the JVM. This allows us to give a
010: * useful error back to the deployer if we find JAXP missing. Instead of getting many
011: * class not found errors the deployer will see a message instructing how to fix
012: * the problem.
013: *
014: * JaxpCheck fulfills two purposes. First, it is an executable class which will
015: * make an educated guess at whether the JAXP jars are present (by checking for
016: * a particular class found only in the JAXP distribution) and if it guesses we're
017: * missing those jars will report this error to System.err and return a nonzero
018: * return code. A nonzero return value from a main method stop an Ant build
019: * when the class was run with stopOnFailure declared to true, as it is by default
020: * in our build.xml.
021: *
022: * Second, JaxpCheck implements the ICheck interface and so can be used via the
023: * CheckRunner API in this package. This allows us to run this check as part of the
024: * context initialization sanity checking. An instance of this check is configured in
025: *
026: *
027: * @version $Revision: 35837 $ $Date: 2005-05-20 12:01:34 -0700 (Fri, 20 May 2005) $
028: * @since uPortal 2.5
029: */
030: public class JaxpCheck implements ICheck {
031:
032: /**
033: * The name of a class found only in the JAXP distribution.
034: */
035: private static final String A_JAXP_CLASS = "javax.xml.xpath.XPathConstants";
036:
037: /**
038: * ICheck implementation to which we delegate as the way we
039: * implement ICheck.
040: */
041: private ICheck checkDelegate;
042:
043: public static void main(String[] args) {
044: try {
045: Class c = JaxpCheck.class.getClassLoader().loadClass(
046: A_JAXP_CLASS);
047: } catch (ClassNotFoundException e) {
048: System.err.println(e);
049: System.err
050: .println("The missing class is provided as part of JAXP.\n"
051: + "Check that you have the JAXP jars installed in your JDK.\n"
052: + "For more information see lib/jaxp/README.txt.");
053: System.exit(1);
054: }
055: System.exit(0);
056: }
057:
058: public JaxpCheck() {
059: super ();
060:
061: /*
062: * We implement the ICheck interface by delegation to an instance of
063: * ClassPresenceCheck, which we configure here.
064: */
065:
066: ClassPresenceCheck check = new ClassPresenceCheck(A_JAXP_CLASS);
067: check
068: .setDescription("Check for the presence of the class "
069: + A_JAXP_CLASS
070: + ", which will only be present when JAXP 1.3 or better is installed.");
071:
072: CheckResult failureResult = CheckResult
073: .createFailure(
074: "The class "
075: + A_JAXP_CLASS
076: + " was not present. This class is part of the JAXP 1.3 distribution.",
077: "Install the JAXP 1.3 jars into your JDK and into your servlet container as described in /lib/jaxp/README.txt");
078: check.setFailureResult(failureResult);
079:
080: CheckResult successResult = CheckResult
081: .createSuccess("The class "
082: + A_JAXP_CLASS
083: + " was present. "
084: + "This class is part of the JAXP 1.3 distribution and its presence "
085: + "suggests that JAXP 1.3 is properly installed.");
086: check.setSuccessResult(successResult);
087:
088: this .checkDelegate = check;
089:
090: }
091:
092: public CheckResult doCheck() {
093: // we implement this interface method by delegation
094: return this .checkDelegate.doCheck();
095: }
096:
097: public String getDescription() {
098: // we implement this interface method by delegation
099: return this.checkDelegate.getDescription();
100: }
101:
102: }
|