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   {    Object[] methodArgs;    Object[][] convertedArgs;    Class[] paramTypes;    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(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(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 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);    }  }