You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by cu...@apache.org on 2002/06/21 17:43:53 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/lib Extensions.java

curcuru     2002/06/21 08:43:53

  Modified:    java/src/org/apache/xalan/lib Extensions.java
  Log:
  Update checkEnvironment to attempt to call org.apache.env.Which first
  by using reflection; Which provides better output data than
  EnvironmentCheck.  If reflection doesn't work, then we
  fallback to EnvironmentCheck as before.
  
  Revision  Changes    Path
  1.18      +60 -2     xml-xalan/java/src/org/apache/xalan/lib/Extensions.java
  
  Index: Extensions.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/Extensions.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Extensions.java	22 Mar 2002 18:54:57 -0000	1.17
  +++ Extensions.java	21 Jun 2002 15:43:53 -0000	1.18
  @@ -419,7 +419,11 @@
      * <p>Simply calls the {@link org.apache.xalan.xslt.EnvironmentCheck}
      * utility to grab info about the Java environment and CLASSPATH, 
      * etc., and then returns the resulting Node.  Stylesheets can 
  -   * then maniuplate this data or simply xsl:copy-of the Node.</p>
  +   * then maniuplate this data or simply xsl:copy-of the Node.  Note 
  +   * that we first attempt to load the more advanced 
  +   * org.apache.env.Which utility by reflection; only if that fails 
  +   * to we still use the internal version.  Which is available from 
  +   * <a href="http://xml.apache.org/commons/">http://xml.apache.org/commons/</a>.</p>
      *
      * <p>We throw a WrappedRuntimeException in the unlikely case 
      * that reading information from the environment throws us an 
  @@ -447,9 +451,17 @@
       Node resultNode = null;
       try
       {
  -      resultNode = factoryDocument.createElement("checkEnvironmentExtension");
  +      // First use reflection to try to load Which, which is a 
  +      //  better version of EnvironmentCheck
  +      resultNode = checkEnvironmentUsingWhich(myContext, factoryDocument);
  +
  +      if (null != resultNode)
  +        return resultNode;
  +
  +      // If reflection failed, fallback to our internal EnvironmentCheck
         EnvironmentCheck envChecker = new EnvironmentCheck();
         Hashtable h = envChecker.getEnvironmentHash();
  +      resultNode = factoryDocument.createElement("checkEnvironmentExtension");
         envChecker.appendEnvironmentReport(resultNode, factoryDocument, h);
         envChecker = null;
       }
  @@ -461,4 +473,50 @@
       return resultNode;
     }
   
  +  /**
  +   * Private worker method to attempt to use org.apache.env.Which.
  +   *
  +   * @param myContext an <code>ExpressionContext</code> passed in by the
  +   *                  extension mechanism.  This must be an XPathContext.
  +   * @param factoryDocument providing createElement services, etc.
  +   * @return a Node with environment info; null if any error
  +   */
  +  private static Node checkEnvironmentUsingWhich(ExpressionContext myContext, 
  +        Document factoryDocument)
  +  {
  +    final String WHICH_CLASSNAME = "org.apache.env.Which";
  +    final String WHICH_METHODNAME = "which";
  +    final Class WHICH_METHOD_ARGS[] = { java.util.Hashtable.class,
  +                                        java.lang.String.class,
  +                                        java.lang.String.class };
  +    try
  +    {
  +      // Use reflection to try to find xml-commons utility 'Which'
  +      // Classloader note: if anyone really cares, we could try to 
  +      //    use the context classloader instead
  +      Class clazz = Class.forName(WHICH_CLASSNAME);
  +      if (null == clazz)
  +        return null;
  +
  +      // Fully qualify names since this is the only method they're used in
  +      java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
  +      Hashtable report = new Hashtable();
  +
  +      // Call the method with our Hashtable, common options, and ignore return value
  +      Object[] methodArgs = { report, "XmlCommons;Xalan;Xerces;Crimson;Ant", "" };
  +      Object returnValue = method.invoke(null, methodArgs);
  +
  +      // Create a parent to hold the report and append hash to it
  +      Node resultNode = factoryDocument.createElement("checkEnvironmentExtension");
  +      org.apache.xml.utils.Hashtree2Node.appendHashToNode(report, "whichReport", 
  +            resultNode, factoryDocument);
  +
  +      return resultNode;
  +    }
  +    catch (Throwable t)
  +    {
  +      // Simply return null; no need to report error
  +      return null;
  +    }
  +  }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org