Package nexj.core.scripting

Examples of nexj.core.scripting.GlobalEnvironment


    */
   public XMLUpgradeMetadataLoader(XMLMetadata metadata, XMLMetadataHelper helper)
   {
      m_metadata = metadata;
      m_helper = helper;
      m_env = new GlobalEnvironment(m_metadata.getGlobalEnvironment());
      m_machine = new Machine(m_env, (InvocationContext)null);
   }
View Full Code Here


   {
      ThreadContextHolder.setContext(this);

      if (env == null)
      {
         env = new GlobalEnvironment(m_metadata.getGlobalEnvironment());
      }

      if (m_machine != null)
      {
         complete(false);
View Full Code Here

      if (m_machine == null || env != null)
      {
         if (env == null)
         {
            env = new GlobalEnvironment();
         }

         m_machine = new Machine(env, this);
      }
View Full Code Here

            s_logger.error("Error receiving the JMS message on channel \"" +
               m_channel.getName() + "\"", t);
           
            if (contextSaved != null)
            {
               GlobalEnvironment env = contextSaved.getMachine().getGlobalEnvironment();

               if (env.findVariable(ASYNC_EXCEPTION, Undefined.VALUE) != Undefined.VALUE)
               {
                  env.setVariable(ASYNC_EXCEPTION, t);
               }
            }
         }
         finally
         {
View Full Code Here

    */
   public XMLUnitTestMetadataLoader(XMLMetadata metadata, XMLMetadataHelper helper)
   {
      m_metadata = metadata;
      m_helper = helper;
      m_env = new GlobalEnvironment(m_metadata.getGlobalEnvironment());
      m_machine = new Machine(m_env, (InvocationContext)null);

      InputStream istream = null;
      Reader reader = null;

View Full Code Here

    */
   protected Function compile(Object fun, final String sName, final String sQualifier, Machine machine)
   {
      if (!(fun instanceof Function))
      {
         GlobalEnvironment env = machine.getGlobalEnvironment();
         Lookup posMap = env.getTextPositionMap();

         env.defineVariable(SYS_CURRENT_CLASS, this);

         try
         {
            if (sName != null && posMap != null && posMap.size() != 0)
            {
               TextPosition pos = (TextPosition)posMap.valueIterator().next();
               StringBuilder buf = new StringBuilder(64);
               String sURL = pos.getURL();

               if (sURL != null)
               {
                  int i = sURL.indexOf('#');

                  buf.append(sURL, 0, (i < 0) ? sURL.length() : i);
               }

               buf.append('#');
               buf.append(getName());
               buf.append(' ');
               buf.append(sName);

               if (sQualifier != null)
               {
                  buf.append(sQualifier);
               }
               else
               {
                  if (fun instanceof Pair)
                  {
                     Pair pair = (Pair)fun;

                     if (pair.getHead() == Symbol.LAMBDA && pair.getTail() instanceof Pair)
                     {
                        pair = pair.getNext();

                        int nCount = -1;

                        for (Object obj = pair.getHead(); obj instanceof Pair; obj = ((Pair)obj).getTail())
                        {
                           ++nCount;
                        }

                        if (nCount >= 0)
                        {
                           buf.append('/');
                           buf.append(nCount);
                        }
                     }
                  }
               }

               Compiler.setPosURLs(fun, buf.toString(), posMap);
            }

            fun = machine.invoke(new Compiler().compile(fun, posMap, machine, true),
               (Pair)null);
         }
         finally
         {
            env.removeVariable(SYS_CURRENT_CLASS);
         }
      }

      return (Function)fun;
   }
View Full Code Here

         {
            boolean bInit = m_globalEnv == null;

            if (bInit)
            {
               m_globalEnv = new GlobalEnvironment(metadata.getGlobalEnvironment());
            }

            InvocationContext context = (InvocationContext)metadata.getComponent("System.InvocationContext").getInstance(null);

            context.setAudited(false);
            context.initialize(null, m_globalEnv);
            context.setLocale(m_locale);

            Machine machine = context.getMachine();

            if (bInit)
            {
               InputStream istream = null;
               Reader reader = null;

               try
               {
                  istream = URLUtil.openResource(UnitTest.class, INITIAL_SCRIPT);
                  reader = new BufferedReader(new InputStreamReader(istream, XMLUtil.ENCODING));
                  Intrinsic.load(reader, INITIAL_SCRIPT_URL, machine);
               }
               catch (IOException e)
               {
                  throw new MetadataException("err.meta.resourceOpen", new Object[]{INITIAL_SCRIPT}, e);
               }
               finally
               {
                  IOUtil.close(reader);
                  IOUtil.close(istream);
               }
            }

            UnitTest utest = (UnitTest)m_unitTestList.get(nUnitTest);

            for (Iterator argItr = new ArgumentIterator(context, utest); argItr.hasNext(); )
            {
               Object[] variableArray = (Object[])argItr.next();
               String sTestArguments = formatLoopVariables(variableArray, utest.getLoopCount());
               DataLoader dataLoader = new DataLoader(context);
               URL dumpURL = getDumpURL(utest);
               boolean bResetDB = dumpURL != null;

               m_unitTestLogger.begin(utest, sTestArguments);

               if (bResetDB && !bReady)
               {
                  if (m_container != null)
                  {
                     m_container.suspend();
                  }

                  bReady = true;

                  if (nUnitTest == 0)
                  {
                     try
                     {
                        dataLoader.recreateSchema((Set)null);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                  }
                  else
                  {
                     bFirstRun = false;
                  }
               }

               byte nMode = utest.getMode();
               int nTestCase = 0;

               if (utest.hasInitializer())
               {
                  ++nTestCase;
               }

               if (utest.hasFinalizer())
               {
                  ++nTestCase;
               }

               Object[] functionObjArray = null;

               if (utest.getFunction() != null)
               {
                  functionObjArray = (Object[])context.getMachine().invoke(utest.getFunction(), variableArray);
               }

               boolean bFirstTestCase = true;

               for (Iterator itr = utest.getUnitTestCaseIterator(); itr.hasNext();
                  bFirstRun = false, bFirstTestCase = false, bResetDB = dumpURL != null && nMode != UnitTest.MODE_DIRTY)
               {
                  UnitTestCase testCase = (UnitTestCase)itr.next();

                  if (!isEnabled(utest, testCase))
                  {
                     nTestCase++;
                     continue;
                  }

                  if (bResetDB)
                  {
                     if (!bFirstTestCase && m_container != null)
                     {
                        m_container.suspend();
                     }

                     if (!bFirstRun)
                     {
                        try
                        {
                           dataLoader.deleteData((Set)null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(utest, e);

                           return;
                        }
                     }

                     InputStream in = null;

                     try
                     {
                        in = new BufferedInputStream(URLUtil.openStream(dumpURL));
                        dataLoader.importData(in, true);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                     finally
                     {
                        IOUtil.close(in);
                        in = null;
                     }
                  }

                  context.complete(true);
                  context.getMachine().cleanup();
                  context.initUnitOfWork();

                  final InvocationContext testContext = (InvocationContext)metadata
                     .getComponent("System.InvocationContext").getInstance(null);

                  try
                  {
                     testContext.setAudited(false);
                     testContext.getGlobalCache().clear();
                     testContext.initialize((m_sSystemUser == null) ? null : new SimplePrincipal(m_sSystemUser),
                        new GlobalEnvironment(m_globalEnv));

                     if (m_container != null && m_sSystemUser != null)
                     {
                        Event grantDebugEvent = testContext.getUserClass().findEvent(GRANT_DEBUG, 0);
View Full Code Here

    * @return The class object state (with lazy construction).
    */
   private final Object[] getState()
   {
      Machine machine = ThreadContextHolder.getContext().getMachine();
      GlobalEnvironment env = machine.getGlobalEnvironment();
      Object[] values = (Object[])env.getState(this);

      if (values == null)
      {
         values = new Object[getStaticAttributeCount()];
         Arrays.fill(values, Undefined.VALUE);
         env.setState(this, values);

         int nCount = getInitializedStaticAttributeCount();

         if (nCount != 0)
         {
View Full Code Here

   /**
    * @see junit.framework.TestCase#setUp()
    */
   protected void setUp() throws Exception
   {
      m_env = new GlobalEnvironment();
   }
View Full Code Here

    */
   protected void setUp() throws Exception
   {
      super.setUp();
     
      m_env = new GlobalEnvironment();
      m_context = new InvocationContext(Repository.getMetadata());
   }
View Full Code Here

TOP

Related Classes of nexj.core.scripting.GlobalEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.