Throwable realException = ite.getTargetException(); if (realException instanceof Exception) throw new TransformerException((Exception) realException); else throw new TransformerException(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);
  public Object callFunction (String funcName,                               Vector args,                               Object methodKey,                              ExpressionContext exprContext)    throws TransformerException   {    String className;    String methodName;    Class  classObj;    Object targetObject;    int lastDot = funcName.lastIndexOf(".");    Object[] methodArgs;    Object[][] convertedArgs;    Class[] paramTypes;    try    {      if (funcName.endsWith(".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(Exception e)          {            // Must not have been the right one          }        }        className = m_className + funcName.substring(0, lastDot);        try        {          classObj = getClassForName(className);        }        catch (ClassNotFoundException e)         {          throw new TransformerException(e);        }        c = MethodResolver.getConstructor(classObj,                                           methodArgs,                                          convertedArgs,                                          exprContext);        putToCache(methodKey, null, methodArgs, c);        return c.newInstance(convertedArgs[0]);      }      else if (-1 != lastDot) {                         // Handle static method call        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);            return m.invoke(null, convertedArgs[0]);          }          catch(Exception e)          {            // Must not have been the right one          }        }        className = m_className + funcName.substring(0, lastDot);        methodName = funcName.substring(lastDot + 1);        try        {          classObj = getClassForName(className);        }        catch (ClassNotFoundException e)         {          throw new TransformerException(e);        }        m = MethodResolver.getMethod(classObj,                                     methodName,                                     methodArgs,                                      convertedArgs,                                     exprContext,                                     MethodResolver.STATIC_ONLY);        putToCache(methodKey, null, methodArgs, m);        return m.invoke(null, convertedArgs[0]);      }      else {                                            // Handle instance method call        if (args.size() < 1)        {          throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_INSTANCE_MTHD_CALL_REQUIRES, new Object[]{funcName })); //"Instance method call to method " + funcName                                    //+ " requires an Object instance as first argument");        }        targetObject = args.elementAt(0);        if (targetObject instanceof XObject)          // Next level down for XObjects          targetObject = ((XObject) targetObject).object();        methodArgs = new Object[args.size() - 1];        convertedArgs = new Object[1][];        for (int i = 0; i < methodArgs.length; i++)        {          methodArgs[i] = args.elementAt(i+1);        }        Method m = (Method) getFromCache(methodKey, targetObject, methodArgs);        if (m != null)        {          try          {            paramTypes = m.getParameterTypes();            MethodResolver.convertParams(methodArgs, convertedArgs, paramTypes, exprContext);            return m.invoke(targetObject, convertedArgs[0]);          }          catch(Exception e)          {            // Must not have been the right one          }        }        classObj = targetObject.getClass();        m = MethodResolver.getMethod(classObj,                                     funcName,                                     methodArgs,                                      convertedArgs,                                     exprContext,                                     MethodResolver.INSTANCE_ONLY);        putToCache(methodKey, targetObject, methodArgs, m);        return m.invoke(targetObject, convertedArgs[0]);      }    }    catch (InvocationTargetException ite)    {      Throwable realException = ite.getTargetException();      if (realException instanceof Exception)        throw new TransformerException((Exception) realException);      else        throw new TransformerException(ite);    }    catch (Exception e)    {      // e.printStackTrace();      throw new TransformerException(e);    }  }