argStart = 0;
{ argArray = new Object[1]; Object o = args.elementAt (0); argArray[0] = (o instanceof XObject) ? ((XObject)o).object () : o; }
  public Object callFunction (String funcName,                               Vector args,                               Object methodKey, Class javaClass,                               ExpressionContext exprContext)    throws SAXException   {    if (!componentStarted)     {      startupComponent (javaClass);    }    boolean isJava = false;    try     {      com.ibm.bsf.BSFEngine e;      Object[] argArray;      int argStart;            if(null == mgr)      {        mgr = new com.ibm.bsf.BSFManager ();      }      // we want to use the xslt-javaclass engine to handle the javaclass      // case 'cause of the funky method selection rules. That engine       // expects the first arg to be the object on which to make the call.      boolean isCTorCall = false;      // System.out.println("scriptLang: "+scriptLang);      if (scriptLang.equals ("javaclass") || scriptLang.equals ("xslt-javaclass"))       {        isJava = true;        // isCTorCall = funcName.equals("new");        isCTorCall = funcName.endsWith(".new") || funcName.equals("new");        e = mgr.loadScriptingEngine ("xslt-javaclass");        if(isCTorCall)        {          argArray = new Object[args.size ()];          argStart = 0;          if(null != this.classObject)          {            funcName = this.classObject.getName()+".new";          }          javaObject = null;          hasCalledCTor = true;        }        else        {          if(!hasCalledCTor)          {            if(null == javaObject)            {              javaObject = this.classObject.newInstance();            }                        argArray = new Object[args.size () + 1];                        argArray[0] = javaObject;            argStart = 1;            // argArray = new Object[args.size ()];            // argStart = 0;          }          else          {            argArray = new Object[args.size ()];            if(args.size() > 0)            {              Object o = args.elementAt (0);              argArray[0] = (o instanceof XObject) ? ((XObject)o).object () : o;              argStart = 1;            }            else              argStart = 0;          }        }      }      else       {        e = ((com.ibm.bsf.BSFManager)mgr).loadScriptingEngine (scriptLang);        argArray = new Object[args.size ()];        argStart = 0;      }      if(isJava)      {        // TODO: Fix all this.        for (int i = argStart; i < args.size (); i++)         {          Object o = args.elementAt (i);          argArray[i] = o;        }        return callJava(javaObject, funcName, argArray, methodKey, exprContext);      }      else      {        // convert the xobject args to their object forms        for (int i = 0; i < args.size (); i++)         {          Object o = args.elementAt (i);          argArray[i+argStart] =                                 (o instanceof XObject) ? ((XObject)o).object () : o;        }                return e.call (null, funcName, argArray);      }    }    catch (Exception e)     {      String msg = e.getMessage();      if(null != msg)      {        if(msg.startsWith("Stopping after fatal error:"))        {          msg = msg.substring("Stopping after fatal error:".length());        }        // System.out.println("Call to extension function failed: "+msg);        throw new SAXException (e);      }      else      {        // Should probably make a TRaX Extension Exception.        throw new SAXException ("Could not create extension: "+funcName+" because of: "+e);      }    }    // return new XNull();  }