extensionhandlerjavaclass.java
来自「java jdk 1.4的源码」· Java 代码 · 共 459 行 · 第 1/2 页
JAVA
459 行
try { if (funcName.equals("new")) { // Handle constructor call methodArgs = new Object[args.size()]; convertedArgs = new Object[1][]; for (int i = 0; i < methodArgs.length; i++) { methodArgs[i] = args.elementAt(i); } Constructor c = (Constructor) getFromCache(methodKey, null, methodArgs); if (c != null) { try { paramTypes = c.getParameterTypes(); MethodResolver.convertParams(methodArgs, convertedArgs, paramTypes, exprContext); return c.newInstance(convertedArgs[0]); } catch (InvocationTargetException ite) { throw ite; } catch(Exception e) { // Must not have been the right one } } c = MethodResolver.getConstructor(m_classObj, methodArgs, convertedArgs, exprContext); putToCache(methodKey, null, methodArgs, c); return c.newInstance(convertedArgs[0]); } else { int resolveType; Object targetObject = null; methodArgs = new Object[args.size()]; convertedArgs = new Object[1][]; for (int i = 0; i < methodArgs.length; i++) { methodArgs[i] = args.elementAt(i); } Method m = (Method) getFromCache(methodKey, null, methodArgs); if (m != null) { try { paramTypes = m.getParameterTypes(); MethodResolver.convertParams(methodArgs, convertedArgs, paramTypes, exprContext); if (Modifier.isStatic(m.getModifiers())) return m.invoke(null, convertedArgs[0]); else { // This is tricky. We get the actual number of target arguments (excluding any // ExpressionContext). If we passed in the same number, we need the implied object. int nTargetArgs = convertedArgs[0].length; if (ExpressionContext.class.isAssignableFrom(paramTypes[0])) nTargetArgs--; if (methodArgs.length <= nTargetArgs) return m.invoke(m_defaultInstance, convertedArgs[0]); else { targetObject = methodArgs[0]; if (targetObject instanceof XObject) targetObject = ((XObject) targetObject).object(); return m.invoke(targetObject, convertedArgs[0]); } } } catch (InvocationTargetException ite) { throw ite; } catch(Exception e) { // Must not have been the right one } } if (args.size() > 0) { targetObject = methodArgs[0]; if (targetObject instanceof XObject) targetObject = ((XObject) targetObject).object(); if (m_classObj.isAssignableFrom(targetObject.getClass())) resolveType = MethodResolver.DYNAMIC; else resolveType = MethodResolver.STATIC_AND_INSTANCE; } else { targetObject = null; resolveType = MethodResolver.STATIC_AND_INSTANCE; } m = MethodResolver.getMethod(m_classObj, funcName, methodArgs, convertedArgs, exprContext, resolveType); putToCache(methodKey, null, methodArgs, m); if (MethodResolver.DYNAMIC == resolveType) // First argument was object type return m.invoke(targetObject, convertedArgs[0]); else // First arg was not object. See if we need the implied object. { if (Modifier.isStatic(m.getModifiers())) return m.invoke(null, convertedArgs[0]); else { if (null == m_defaultInstance) { m_defaultInstance = m_classObj.newInstance(); } return m.invoke(m_defaultInstance, convertedArgs[0]); } } } } catch (InvocationTargetException ite) { Throwable resultException = ite; Throwable targetException = ite.getTargetException(); if (targetException instanceof TransformerException) throw ((TransformerException)targetException); else if (targetException != null) resultException = targetException; throw new TransformerException(resultException); } catch (Exception e) { // e.printStackTrace(); throw new TransformerException(e); } } /** * Process a call to this extension namespace via an element. As a side * effect, the results are sent to the TransformerImpl's result tree. * We invoke the static or instance method in the class represented by * by the namespace URI. If we don't already have an instance of this class, * we create one upon the first call. * * @param localPart Element name's local part. * @param element The extension element being processed. * @param transformer Handle to TransformerImpl. * @param stylesheetTree The compiled stylesheet tree. * @param sourceTree The root of the source tree (but don't assume * it's a Document). * @param sourceNode The current context node. * @param mode The current mode. * @param methodKey A key that uniquely identifies this element call. * @throws IOException if loading trouble * @throws TransformerException if parsing trouble */ public void processElement(String localPart, ElemTemplateElement element, TransformerImpl transformer, Stylesheet stylesheetTree, Object methodKey) throws TransformerException, IOException { Object result = null; Method m = (Method) getFromCache(methodKey, null, null); if (null == m) { try { m = MethodResolver.getElementMethod(m_classObj, localPart); if ( (null == m_defaultInstance) && !Modifier.isStatic(m.getModifiers()) ) m_defaultInstance = m_classObj.newInstance(); } catch (Exception e) { // e.printStackTrace (); throw new TransformerException (e.getMessage (), e); } putToCache(methodKey, null, null, m); } XSLProcessorContext xpc = new XSLProcessorContext(transformer, stylesheetTree); try { result = m.invoke(m_defaultInstance, new Object[] {xpc, element}); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof TransformerException) throw (TransformerException)targetException; else if (targetException != null) throw new TransformerException (targetException.getMessage (), targetException); else throw new TransformerException (e.getMessage (), e); } catch (Exception e) { // e.printStackTrace (); throw new TransformerException (e.getMessage (), e); } if (result != null) { xpc.outputToResultTree (stylesheetTree, result); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?