View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2002 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.ebxml.registry.util; 11 12 import java.lang.reflect.InvocationTargetException; 13 import java.lang.reflect.Method; 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.apache.xalan.Version; 18 19 /*** 20 * Provides utility methods to verify the version of xalan. 21 * 22 * @author Fabian Ritzmann 23 */ 24 public class XalanVersion { 25 26 private static Log log = LogFactory.getLog("com.sun.ebxml.registry.util.XalanVersion"); 27 28 /*** 29 * Throw an exception if the installed version of Xalan is not recent 30 * enough. 31 * @throws XalanVersionException Thrown if Xalan version could not be 32 * determined or Xalan version is not at least 2.2D14. 33 */ 34 public static void verifyVersion() throws XalanVersionException { 35 36 int majorVersion = getMajorVersion().intValue(); 37 if (majorVersion < 2) { 38 // This case should never occur because Xalan 1 does not have a Version class: 39 throw new XalanVersionException("Found Xalan version 1. We need at least Xalan version 2.2D14!"); 40 } 41 42 int releaseVersion = getReleaseVersion().intValue(); 43 if ((majorVersion == 2) && (releaseVersion < 2)) { 44 throw new XalanVersionException("Found Xalan version " 45 + majorVersion + "." + releaseVersion 46 + ". We need at least Xalan version 2.2D14!"); 47 } 48 49 if ((majorVersion == 2) && (releaseVersion == 2)) { 50 int developmentVersion = getDevelopmentVersion().intValue(); 51 if (developmentVersion < 14) { 52 String endorsedDirs = System.getProperty("java.endorsed.dirs"); 53 throw new XalanVersionException("Found Xalan version " 54 + majorVersion + "." + releaseVersion 55 + "D" + developmentVersion 56 + ". We need at least Xalan version 2.2D14! Please install an updated version of Xalan in one of your endorsed directories: " 57 + endorsedDirs); 58 } 59 } 60 } 61 62 63 /*** 64 * Invokes getMajorVersionNum on xalan.Version. 65 * @see org.apache.xalan.Version#getMajorVersionNum 66 * @return The result of xalan.Version.getMajorVersionNum 67 * @throws XalanVersionException Thrown if xalan.Version could not be 68 * found or method could not be executed. 69 */ 70 public static Integer getMajorVersion() throws XalanVersionException { 71 return invokeVersionMethod("getMajorVersionNum"); 72 } 73 74 /*** 75 * Invokes getReleaseVersionNum on xalan.Version. 76 * @see org.apache.xalan.Version#getReleaseVersionNum 77 * @return The result of xalan.Version.getReleaseVersionNum 78 * @throws XalanVersionException Thrown if xalan.Version could not be 79 * found or method could not be executed. 80 */ 81 public static Integer getReleaseVersion() throws XalanVersionException { 82 return invokeVersionMethod("getReleaseVersionNum"); 83 } 84 85 /*** 86 * Invokes getDevelopmentVersionNum on xalan.Version. 87 * @see org.apache.xalan.Version#getDevelopmentVersionNum 88 * @return The result of xalan.Version.getDevelopmentVersionNum 89 * @throws XalanVersionException Thrown if xalan.Version could not be 90 * found or method could not be executed. 91 */ 92 public static Integer getDevelopmentVersion() throws XalanVersionException { 93 return invokeVersionMethod("getDevelopmentVersionNum"); 94 } 95 96 /*** 97 * Invoke method on org.apache.xalan.Version. 98 * @param name Name of the method to be invoked 99 * @return Return value wrapped in Integer 100 * @throws XalanVersionException Thrown if xalan.Version could not be 101 * found or method could not be executed. 102 */ 103 private static Integer invokeVersionMethod(String name) throws XalanVersionException { 104 try { 105 Class version = Class.forName("org.apache.xalan.Version"); 106 Method getMajorVersion = version.getMethod(name, null); 107 Version versionObject = (Version) version.newInstance(); 108 Object majorVersion = getMajorVersion.invoke(versionObject, null); 109 return (Integer) majorVersion; 110 } catch (ClassCastException e) { 111 log.warn("Cast to incompatible type when accessing xalan Version", e); 112 throw new XalanVersionException("Cast to incompatible type when accessing xalan Version", e); 113 } catch (ClassNotFoundException e) { 114 log.warn("Could not find xalan Version class.", e); 115 throw new XalanVersionException("Could not find xalan Version class.", e); 116 } catch (NoSuchMethodException e) { 117 log.warn("Could not find xalan Version " + name + " method", e); 118 throw new XalanVersionException("Could not find xalan Version " + name + " method", e); 119 } catch (NullPointerException e) { 120 log.warn("Passed null object where instance was required", e); 121 throw new XalanVersionException("Passed null object where instance was required", e); 122 } catch (SecurityException e) { 123 log.warn("Not allowed to access xalan Version methods", e); 124 throw new XalanVersionException("Not allowed to access xalan Version methods", e); 125 } catch (IllegalAccessException e) { 126 log.warn("Could not access xalan Version methods", e); 127 throw new XalanVersionException("Could not access xalan Version constructor", e); 128 } catch (InstantiationException e) { 129 log.warn("Could not instantiate xalan Version object", e); 130 throw new XalanVersionException("Could not instantiate xalan Version object", e); 131 } catch (IllegalArgumentException e) { 132 log.warn("Passed illegal argument to Xalan Version method", e); 133 throw new XalanVersionException("Passed illegal argument to Xalan Version method", e); 134 } catch (InvocationTargetException e) { 135 log.warn("Xalan Version method threw an exception", e); 136 throw new XalanVersionException("Xalan Version method threw an exception", e); 137 } 138 } 139 140 }

This page was automatically generated by Maven