/** * Returns a vector with all constructors named <code>_fname</code> after stripping its namespace * or <code>null</code> if no such methods exist. */ private Vector findConstructors() { Vector result = null; final String namespace = _fname.getNamespace(); final int nArgs = _arguments.size(); try { if (_clazz == null) { _clazz = ObjectFactory.findProviderClass(_className, ObjectFactory.findClassLoader(), true); if (_clazz == null) { final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className); getParser().reportError(Constants.ERROR, msg); } } final Constructor[] constructors = _clazz.getConstructors(); for (int i = 0; i < constructors.length; i++) { final int mods = constructors[i].getModifiers(); // Is it public, static and same number of args ? if (Modifier.isPublic(mods) && constructors[i].getParameterTypes().length == nArgs) { if (result == null) { result = new Vector(); } result.addElement(constructors[i]); } } } catch (ClassNotFoundException e) { final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className); getParser().reportError(Constants.ERROR, msg); } return result; }
/** * 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, ObjectFactory.findClassLoader(), 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"); 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; } }
private void createXalanTransformerFactory() { final String xalanMessage = "org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl " + "could not create an " + "org.apache.xalan.processor.TransformerFactoryImpl."; // try to create instance of Xalan factory... try { Class xalanFactClass = ObjectFactory.findProviderClass( "org.apache.xalan.processor.TransformerFactoryImpl", ObjectFactory.findClassLoader(), true); _xalanFactory = (SAXTransformerFactory) xalanFactClass.newInstance(); } catch (ClassNotFoundException e) { System.err.println(xalanMessage); } catch (InstantiationException e) { System.err.println(xalanMessage); } catch (IllegalAccessException e) { System.err.println(xalanMessage); } _currFactory = _xalanFactory; }
/** * Creates a NodeSortRecord producing object. The DOM specifies which tree to get the nodes to * sort from, the class name specifies what auxillary class to use to sort the nodes (this class * is generated by the Sort class), and the translet parameter is needed for methods called by * this object. */ public NodeSortRecordFactory( DOM dom, String className, Translet translet, String order[], String type[], String lang[], String caseOrder[]) throws TransletException { try { _dom = dom; _className = className; // This should return a Class definition if using TrAX _class = translet.getAuxiliaryClass(className); // This code is only run when the native API is used if (_class == null) { _class = ObjectFactory.findProviderClass(className, ObjectFactory.findClassLoader(), true); } int levels = order.length; int[] iOrder = new int[levels]; int[] iType = new int[levels]; for (int i = 0; i < levels; i++) { if (order[i].length() == DESCENDING) { iOrder[i] = NodeSortRecord.COMPARE_DESCENDING; } if (type[i].length() == NUMBER) { iType[i] = NodeSortRecord.COMPARE_NUMERIC; } } // Old NodeSortRecordFactory constructor had no lang or case_order // arguments. Provide default values in that case for binary // compatibility. String[] emptyStringArray = null; if (lang == null || caseOrder == null) { int numSortKeys = order.length; emptyStringArray = new String[numSortKeys]; // Set up array of zero-length strings as default values // of lang and case_order for (int i = 0; i < numSortKeys; i++) { emptyStringArray[i] = ""; } } if (lang == null) { lang = emptyStringArray; } if (caseOrder == null) { caseOrder = emptyStringArray; } final int length = lang.length; Locale[] locales = new Locale[length]; Collator[] collators = new Collator[length]; for (int i = 0; i < length; i++) { locales[i] = LocaleUtility.langToLocale(lang[i]); collators[i] = Collator.getInstance(locales[i]); } _sortSettings = new SortSettings( (AbstractTranslet) translet, iOrder, iType, locales, collators, caseOrder); } catch (ClassNotFoundException e) { throw new TransletException(e); } }
/** * Type check a function call. Since different type conversions apply, type checking is different * for standard and external (Java) functions. */ public Type typeCheck(SymbolTable stable) throws TypeCheckError { if (_type != null) return _type; final String namespace = _fname.getNamespace(); String local = _fname.getLocalPart(); if (isExtension()) { _fname = new QName(null, null, local); return typeCheckStandard(stable); } else if (isStandard()) { return typeCheckStandard(stable); } // Handle extension functions (they all have a namespace) else { try { _className = getClassNameFromUri(namespace); final int pos = local.lastIndexOf('.'); if (pos > 0) { _isStatic = true; if (_className != null && _className.length() > 0) { _namespace_format = NAMESPACE_FORMAT_PACKAGE; _className = _className + "." + local.substring(0, pos); } else { _namespace_format = NAMESPACE_FORMAT_JAVA; _className = local.substring(0, pos); } _fname = new QName(namespace, null, local.substring(pos + 1)); } else { if (_className != null && _className.length() > 0) { try { _clazz = ObjectFactory.findProviderClass( _className, ObjectFactory.findClassLoader(), true); _namespace_format = NAMESPACE_FORMAT_CLASS; } catch (ClassNotFoundException e) { _namespace_format = NAMESPACE_FORMAT_PACKAGE; } } else _namespace_format = NAMESPACE_FORMAT_JAVA; if (local.indexOf('-') > 0) { local = replaceDash(local); } String extFunction = (String) _extensionFunctionTable.get(namespace + ":" + local); if (extFunction != null) { _fname = new QName(null, null, extFunction); return typeCheckStandard(stable); } else _fname = new QName(namespace, null, local); } return typeCheckExternal(stable); } catch (TypeCheckError e) { ErrorMsg errorMsg = e.getErrorMsg(); if (errorMsg == null) { final String name = _fname.getLocalPart(); errorMsg = new ErrorMsg(ErrorMsg.METHOD_NOT_FOUND_ERR, name); } getParser().reportError(ERROR, errorMsg); return _type = Type.Void; } } }