Java Code Examples for com.sun.org.apache.xalan.internal.utils.ObjectFactory#findProviderClass()

The following examples show how to use com.sun.org.apache.xalan.internal.utils.ObjectFactory#findProviderClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnvironmentCheck.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report version info from DOM interfaces.
 *
 * @param h Map to put information in
 */
protected boolean checkDOML3(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  final String DOM_CLASS = "org.w3c.dom.Document";
  final String DOM_LEVEL3_METHOD = "getDoctype";  // no parameter

  try
  {
    Class clazz = ObjectFactory.findProviderClass(DOM_CLASS, true);

    Method method = clazz.getMethod(DOM_LEVEL3_METHOD, (Class<?>[])null);

    // If we succeeded, we have loaded interfaces from a
    //  level 3 DOM somewhere
    h.put(VERSION + "DOM", "3.0");
    return true;
  }
  catch (Exception e)
  {
    return false;
  }
}
 
Example 2
Source File: EnvironmentCheck.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report product version information from Ant.
 *
 * @param h Map to put information in
 */
protected void checkAntVersion(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  try
  {
    final String ANT_VERSION_CLASS = "org.apache.tools.ant.Main";
    final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
    final Class noArgs[] = new Class[0];

    Class clazz = ObjectFactory.findProviderClass(ANT_VERSION_CLASS, true);

    Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
    Object returnValue = method.invoke(null, new Object[0]);

    h.put(VERSION + "ant", (String)returnValue);
  }
  catch (Exception e)
  {
    h.put(VERSION + "ant", CLASS_NOTPRESENT);
  }
}
 
Example 3
Source File: EnvironmentCheck.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report version information about JAXP interfaces.
 *
 * Currently distinguishes between JAXP 1.0.1 and JAXP 1.1,
 * and not found; only tests the interfaces, and does not
 * check for reference implementation versions.
 *
 * @param h Map to put information in
 */
protected void checkJAXPVersion(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  Class clazz = null;

  try
  {
    final String JAXP1_CLASS = "javax.xml.stream.XMLStreamConstants";

    clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, true);

    // If we succeeded, we have JAXP 1.4 available
    h.put(VERSION + "JAXP", "1.4");
  }
  catch (Exception e)
  {
      h.put(ERROR + VERSION + "JAXP", "1.3");
      h.put(ERROR, ERROR_FOUND);
    }
    }
 
Example 4
Source File: ObjectType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Used to represent a Java Class type such is required to support
 * non-static java functions.
 * @param javaClassName name of the class such as 'com.foo.Processor'
 */
protected ObjectType(String javaClassName) {
    _javaClassName = javaClassName;

    try {
      _clazz = ObjectFactory.findProviderClass(javaClassName, true);
    }
    catch (ClassNotFoundException e) {
      _clazz = null;
    }
}
 
Example 5
Source File: ObjectPool.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor ObjectPool
 *
 * @param className Fully qualified name of the type of objects for this pool.
 */
public ObjectPool(String className)
{
  try
  {
    objectType = ObjectFactory.findProviderClass(className, true);
  }
  catch(ClassNotFoundException cnfe)
  {
    throw new WrappedRuntimeException(cnfe);
  }
  freeStack = new ArrayList<>();
}
 
Example 6
Source File: Extensions.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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'
    Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
    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");
    com.sun.org.apache.xml.internal.utils.Hashtree2Node.appendHashToNode(report, "whichReport",
          resultNode, factoryDocument);

    return resultNode;
  }
  catch (Throwable t)
  {
    // Simply return null; no need to report error
    return null;
  }
}
 
Example 7
Source File: ObjectType.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Used to represent a Java Class type such is required to support
 * non-static java functions.
 * @param javaClassName name of the class such as 'com.foo.Processor'
 */
protected ObjectType(String javaClassName) {
    _javaClassName = javaClassName;

    try {
      _clazz = ObjectFactory.findProviderClass(javaClassName, true);
    }
    catch (ClassNotFoundException e) {
      _clazz = null;
    }
}
 
Example 8
Source File: ObjectType.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Used to represent a Java Class type such is required to support
 * non-static java functions.
 * @param javaClassName name of the class such as 'com.foo.Processor'
 */
protected ObjectType(String javaClassName) {
    _javaClassName = javaClassName;

    try {
      _clazz = ObjectFactory.findProviderClass(javaClassName, true);
    }
    catch (ClassNotFoundException e) {
      _clazz = null;
    }
}
 
Example 9
Source File: ObjectPool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor ObjectPool
 *
 * @param className Fully qualified name of the type of objects for this pool.
 */
public ObjectPool(String className)
{
  try
  {
    objectType = ObjectFactory.findProviderClass(className, true);
  }
  catch(ClassNotFoundException cnfe)
  {
    throw new WrappedRuntimeException(cnfe);
  }
  freeStack = new ArrayList();
}
 
Example 10
Source File: ObjectPool.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor ObjectPool
 *
 * @param className Fully qualified name of the type of objects for this pool.
 */
public ObjectPool(String className)
{
  try
  {
    objectType = ObjectFactory.findProviderClass(className, true);
  }
  catch(ClassNotFoundException cnfe)
  {
    throw new WrappedRuntimeException(cnfe);
  }
  freeStack = new ArrayList();
}
 
Example 11
Source File: Extensions.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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'
    Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
    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");
    com.sun.org.apache.xml.internal.utils.Hashtree2Node.appendHashToNode(report, "whichReport",
          resultNode, factoryDocument);

    return resultNode;
  }
  catch (Throwable t)
  {
    // Simply return null; no need to report error
    return null;
  }
}
 
Example 12
Source File: ObjectType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Used to represent a Java Class type such is required to support
 * non-static java functions.
 * @param javaClassName name of the class such as 'com.foo.Processor'
 */
protected ObjectType(String javaClassName) {
    _javaClassName = javaClassName;

    try {
      _clazz = ObjectFactory.findProviderClass(javaClassName, true);
    }
    catch (ClassNotFoundException e) {
      _clazz = null;
    }
}
 
Example 13
Source File: FunctionAvailableCall.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * for external java functions only: reports on whether or not
 * the specified method is found in the specifed class.
 */
private boolean hasMethods() {

    // Get the class name from the namespace uri
    String className = getClassNameFromUri(_namespaceOfFunct);

    // Get the method name from the argument to function-available
    String methodName = null;
    int colonIndex = _nameOfFunct.indexOf(":");
    if (colonIndex > 0) {
      String functionName = _nameOfFunct.substring(colonIndex+1);
      int lastDotIndex = functionName.lastIndexOf('.');
      if (lastDotIndex > 0) {
        methodName = functionName.substring(lastDotIndex+1);
        if (className != null && className.length() != 0)
          className = className + "." + functionName.substring(0, lastDotIndex);
        else
          className = functionName.substring(0, lastDotIndex);
      }
      else
        methodName = functionName;
    }
    else
      methodName = _nameOfFunct;

    if (className == null || methodName == null) {
        return false;
    }

    // Replace the '-' characters in the method name
    if (methodName.indexOf('-') > 0)
      methodName = replaceDash(methodName);

    try {
        final Class<?> clazz = ObjectFactory.findProviderClass(className, true);

        if (clazz == null) {
            return false;
        }

        final Method[] methods = clazz.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final int mods = methods[i].getModifiers();

            if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
                    && methods[i].getName().equals(methodName))
            {
                return true;
            }
        }
    }
    catch (ClassNotFoundException e) {
      return false;
    }
    return false;
}
 
Example 14
Source File: FunctionAvailableCall.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * for external java functions only: reports on whether or not
 * the specified method is found in the specifed class.
 */
private boolean hasMethods() {
    LiteralExpr arg = (LiteralExpr)_arg;

    // Get the class name from the namespace uri
    String className = getClassNameFromUri(_namespaceOfFunct);

    // Get the method name from the argument to function-available
    String methodName = null;
    int colonIndex = _nameOfFunct.indexOf(":");
    if (colonIndex > 0) {
      String functionName = _nameOfFunct.substring(colonIndex+1);
      int lastDotIndex = functionName.lastIndexOf('.');
      if (lastDotIndex > 0) {
        methodName = functionName.substring(lastDotIndex+1);
        if (className != null && !className.equals(""))
          className = className + "." + functionName.substring(0, lastDotIndex);
        else
          className = functionName.substring(0, lastDotIndex);
      }
      else
        methodName = functionName;
    }
    else
      methodName = _nameOfFunct;

    if (className == null || methodName == null) {
        return false;
    }

    // Replace the '-' characters in the method name
    if (methodName.indexOf('-') > 0)
      methodName = replaceDash(methodName);

    try {
        final Class clazz = ObjectFactory.findProviderClass(className, true);

        if (clazz == null) {
            return false;
        }

        final Method[] methods = clazz.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final int mods = methods[i].getModifiers();

            if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
                    && methods[i].getName().equals(methodName))
            {
                return true;
            }
        }
    }
    catch (ClassNotFoundException e) {
      return false;
    }
    return false;
}
 
Example 15
Source File: FunctionAvailableCall.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * for external java functions only: reports on whether or not
 * the specified method is found in the specifed class.
 */
private boolean hasMethods() {

    // Get the class name from the namespace uri
    String className = getClassNameFromUri(_namespaceOfFunct);

    // Get the method name from the argument to function-available
    String methodName = null;
    int colonIndex = _nameOfFunct.indexOf(':');
    if (colonIndex > 0) {
      String functionName = _nameOfFunct.substring(colonIndex+1);
      int lastDotIndex = functionName.lastIndexOf('.');
      if (lastDotIndex > 0) {
        methodName = functionName.substring(lastDotIndex+1);
        if (className != null && className.length() != 0)
          className = className + "." + functionName.substring(0, lastDotIndex);
        else
          className = functionName.substring(0, lastDotIndex);
      }
      else
        methodName = functionName;
    }
    else
      methodName = _nameOfFunct;

    if (className == null || methodName == null) {
        return false;
    }

    // Replace the '-' characters in the method name
    if (methodName.indexOf('-') > 0)
      methodName = replaceDash(methodName);

    try {
        final Class clazz = ObjectFactory.findProviderClass(className, true);

        if (clazz == null) {
            return false;
        }

        final Method[] methods = clazz.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final int mods = methods[i].getModifiers();

            if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
                    && methods[i].getName().equals(methodName))
            {
                return true;
            }
        }
    }
    catch (ClassNotFoundException e) {
      return false;
    }
    return false;
}
 
Example 16
Source File: FunctionAvailableCall.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * for external java functions only: reports on whether or not
 * the specified method is found in the specifed class.
 */
private boolean hasMethods() {
    LiteralExpr arg = (LiteralExpr)_arg;

    // Get the class name from the namespace uri
    String className = getClassNameFromUri(_namespaceOfFunct);

    // Get the method name from the argument to function-available
    String methodName = null;
    int colonIndex = _nameOfFunct.indexOf(":");
    if (colonIndex > 0) {
      String functionName = _nameOfFunct.substring(colonIndex+1);
      int lastDotIndex = functionName.lastIndexOf('.');
      if (lastDotIndex > 0) {
        methodName = functionName.substring(lastDotIndex+1);
        if (className != null && !className.equals(""))
          className = className + "." + functionName.substring(0, lastDotIndex);
        else
          className = functionName.substring(0, lastDotIndex);
      }
      else
        methodName = functionName;
    }
    else
      methodName = _nameOfFunct;

    if (className == null || methodName == null) {
        return false;
    }

    // Replace the '-' characters in the method name
    if (methodName.indexOf('-') > 0)
      methodName = replaceDash(methodName);

    try {
        final Class clazz = ObjectFactory.findProviderClass(className, true);

        if (clazz == null) {
            return false;
        }

        final Method[] methods = clazz.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final int mods = methods[i].getModifiers();

            if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
                    && methods[i].getName().equals(methodName))
            {
                return true;
            }
        }
    }
    catch (ClassNotFoundException e) {
      return false;
    }
    return false;
}
 
Example 17
Source File: IncrementalSAXSource_Xerces.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** Create a IncrementalSAXSource_Xerces, and create a SAXParser
 * to go with it. Xerces2 incremental parsing is only supported if
 * this constructor is used, due to limitations in the Xerces2 API (as of
 * Beta 3). If you don't like that restriction, tell the Xerces folks that
 * there should be a simpler way to request incremental SAX parsing.
 * */
public IncrementalSAXSource_Xerces()
              throws NoSuchMethodException
      {
              try
              {
                      // Xerces-2 incremental parsing support (as of Beta 3)
                      // ContentHandlers still get set on fIncrementalParser (to get
                      // conversion from XNI events to SAX events), but
                      // _control_ for incremental parsing must be exercised via the config.
                      //
                      // At this time there's no way to read the existing config, only
                      // to assert a new one... and only when creating a brand-new parser.
                      //
                      // Reflection is used to allow us to continue to compile against
                      // Xerces1. If/when we can abandon the older versions of the parser,
                      // this will simplify significantly.

                      // If we can't get the magic constructor, no need to look further.
                      Class xniConfigClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",
                          true);
                      Class[] args1={xniConfigClass};
                      Constructor ctor=SAXParser.class.getConstructor(args1);

                      // Build the parser configuration object. StandardParserConfiguration
                      // happens to implement XMLPullParserConfiguration, which is the API
                      // we're going to want to use.
                      Class xniStdConfigClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.parsers.StandardParserConfiguration",
                          true);
                      fPullParserConfig=xniStdConfigClass.newInstance();
                      Object[] args2={fPullParserConfig};
                      fIncrementalParser = (SAXParser)ctor.newInstance(args2);

                      // Preload all the needed the configuration methods... I want to know they're
                      // all here before we commit to trying to use them, just in case the
                      // API changes again.
                      Class fXniInputSourceClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource",
                          true);
                      Class[] args3={fXniInputSourceClass};
                      fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3);

                      Class[] args4={String.class,String.class,String.class};
                      fConfigInputSourceCtor=fXniInputSourceClass.getConstructor(args4);
                      Class[] args5={java.io.InputStream.class};
                      fConfigSetByteStream=fXniInputSourceClass.getMethod("setByteStream",args5);
                      Class[] args6={java.io.Reader.class};
                      fConfigSetCharStream=fXniInputSourceClass.getMethod("setCharacterStream",args6);
                      Class[] args7={String.class};
                      fConfigSetEncoding=fXniInputSourceClass.getMethod("setEncoding",args7);

                      Class[] argsb={Boolean.TYPE};
                      fConfigParse=xniStdConfigClass.getMethod("parse",argsb);
                      Class[] noargs=new Class[0];
                      fReset=fIncrementalParser.getClass().getMethod("reset",noargs);
              }
              catch(Exception e)
              {
          // Fallback if this fails (implemented in createIncrementalSAXSource) is
                      // to attempt Xerces-1 incremental setup. Can't do tail-call in
                      // constructor, so create new, copy Xerces-1 initialization,
                      // then throw it away... Ugh.
                      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
                      this.fParseSomeSetup=dummy.fParseSomeSetup;
                      this.fParseSome=dummy.fParseSome;
                      this.fIncrementalParser=dummy.fIncrementalParser;
              }
}
 
Example 18
Source File: FunctionAvailableCall.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * for external java functions only: reports on whether or not
 * the specified method is found in the specifed class.
 */
private boolean hasMethods() {
    LiteralExpr arg = (LiteralExpr)_arg;

    // Get the class name from the namespace uri
    String className = getClassNameFromUri(_namespaceOfFunct);

    // Get the method name from the argument to function-available
    String methodName = null;
    int colonIndex = _nameOfFunct.indexOf(":");
    if (colonIndex > 0) {
      String functionName = _nameOfFunct.substring(colonIndex+1);
      int lastDotIndex = functionName.lastIndexOf('.');
      if (lastDotIndex > 0) {
        methodName = functionName.substring(lastDotIndex+1);
        if (className != null && !className.equals(""))
          className = className + "." + functionName.substring(0, lastDotIndex);
        else
          className = functionName.substring(0, lastDotIndex);
      }
      else
        methodName = functionName;
    }
    else
      methodName = _nameOfFunct;

    if (className == null || methodName == null) {
        return false;
    }

    // Replace the '-' characters in the method name
    if (methodName.indexOf('-') > 0)
      methodName = replaceDash(methodName);

    try {
        final Class clazz = ObjectFactory.findProviderClass(className, true);

        if (clazz == null) {
            return false;
        }

        final Method[] methods = clazz.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final int mods = methods[i].getModifiers();

            if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
                    && methods[i].getName().equals(methodName))
            {
                return true;
            }
        }
    }
    catch (ClassNotFoundException e) {
      return false;
    }
    return false;
}
 
Example 19
Source File: IncrementalSAXSource_Xerces.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/** Create a IncrementalSAXSource_Xerces, and create a SAXParser
 * to go with it. Xerces2 incremental parsing is only supported if
 * this constructor is used, due to limitations in the Xerces2 API (as of
 * Beta 3). If you don't like that restriction, tell the Xerces folks that
 * there should be a simpler way to request incremental SAX parsing.
 * */
public IncrementalSAXSource_Xerces()
              throws NoSuchMethodException
      {
              try
              {
                      // Xerces-2 incremental parsing support (as of Beta 3)
                      // ContentHandlers still get set on fIncrementalParser (to get
                      // conversion from XNI events to SAX events), but
                      // _control_ for incremental parsing must be exercised via the config.
                      //
                      // At this time there's no way to read the existing config, only
                      // to assert a new one... and only when creating a brand-new parser.
                      //
                      // Reflection is used to allow us to continue to compile against
                      // Xerces1. If/when we can abandon the older versions of the parser,
                      // this will simplify significantly.

                      // If we can't get the magic constructor, no need to look further.
                      Class xniConfigClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",
                          true);
                      Class[] args1={xniConfigClass};
                      Constructor ctor=SAXParser.class.getConstructor(args1);

                      // Build the parser configuration object. StandardParserConfiguration
                      // happens to implement XMLPullParserConfiguration, which is the API
                      // we're going to want to use.
                      Class xniStdConfigClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.parsers.StandardParserConfiguration",
                          true);
                      fPullParserConfig=xniStdConfigClass.newInstance();
                      Object[] args2={fPullParserConfig};
                      fIncrementalParser = (SAXParser)ctor.newInstance(args2);

                      // Preload all the needed the configuration methods... I want to know they're
                      // all here before we commit to trying to use them, just in case the
                      // API changes again.
                      Class fXniInputSourceClass=ObjectFactory.findProviderClass(
                          "com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource",
                          true);
                      Class[] args3={fXniInputSourceClass};
                      fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3);

                      Class[] args4={String.class,String.class,String.class};
                      fConfigInputSourceCtor=fXniInputSourceClass.getConstructor(args4);
                      Class[] args5={java.io.InputStream.class};
                      fConfigSetByteStream=fXniInputSourceClass.getMethod("setByteStream",args5);
                      Class[] args6={java.io.Reader.class};
                      fConfigSetCharStream=fXniInputSourceClass.getMethod("setCharacterStream",args6);
                      Class[] args7={String.class};
                      fConfigSetEncoding=fXniInputSourceClass.getMethod("setEncoding",args7);

                      Class[] argsb={Boolean.TYPE};
                      fConfigParse=xniStdConfigClass.getMethod("parse",argsb);
                      Class[] noargs=new Class[0];
                      fReset=fIncrementalParser.getClass().getMethod("reset",noargs);
              }
              catch(Exception e)
              {
          // Fallback if this fails (implemented in createIncrementalSAXSource) is
                      // to attempt Xerces-1 incremental setup. Can't do tail-call in
                      // constructor, so create new, copy Xerces-1 initialization,
                      // then throw it away... Ugh.
                      IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
                      this.fParseSomeSetup=dummy.fParseSomeSetup;
                      this.fParseSome=dummy.fParseSome;
                      this.fIncrementalParser=dummy.fIncrementalParser;
              }
}
 
Example 20
Source File: EnvironmentCheck.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Report version info from DOM interfaces.
 *
 * Currently distinguishes between pre-DOM level 2, the DOM
 * level 2 working draft, the DOM level 2 final draft,
 * and not found.
 *
 * @param h Map to put information in
 */
protected void checkDOMVersion(Map<String, Object> h)
{

  if (null == h)
    h = new HashMap<>();

  final String DOM_LEVEL2_CLASS = "org.w3c.dom.Document";
  final String DOM_LEVEL2_METHOD = "createElementNS";  // String, String
  final String DOM_LEVEL3_METHOD = "getDoctype";  // no parameter
  final String DOM_LEVEL2WD_CLASS = "org.w3c.dom.Node";
  final String DOM_LEVEL2WD_METHOD = "supported";  // String, String
  final String DOM_LEVEL2FD_CLASS = "org.w3c.dom.Node";
  final String DOM_LEVEL2FD_METHOD = "isSupported";  // String, String
  final Class twoStringArgs[] = { java.lang.String.class,
                                  java.lang.String.class };

  try
  {
    Class clazz = ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, true);

    Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);

    // If we succeeded, we have loaded interfaces from a
    //  level 2 DOM somewhere
    h.put(VERSION + "DOM", "2.0");

    try
    {
      // Check for the working draft version, which is
      //  commonly found, but won't work anymore
      clazz = ObjectFactory.findProviderClass(DOM_LEVEL2WD_CLASS, true);

      method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);

      h.put(ERROR + VERSION + "DOM.draftlevel", "2.0wd");
      h.put(ERROR, ERROR_FOUND);
    }
    catch (Exception e2)
    {
      try
      {
        // Check for the final draft version as well
        clazz = ObjectFactory.findProviderClass(DOM_LEVEL2FD_CLASS, true);

        method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);

        h.put(VERSION + "DOM.draftlevel", "2.0fd");
      }
      catch (Exception e3)
      {
        h.put(ERROR + VERSION + "DOM.draftlevel", "2.0unknown");
        h.put(ERROR, ERROR_FOUND);
      }
    }
  }
  catch (Exception e)
  {
    h.put(ERROR + VERSION + "DOM",
          "ERROR attempting to load DOM level 2 class: " + e.toString());
    h.put(ERROR, ERROR_FOUND);
  }

  //@todo load an actual DOM implmementation and query it as well
  //@todo load an actual DOM implmementation and check if
  //  isNamespaceAware() == true, which is needed to parse
  //  xsl stylesheet files into a DOM
}