Package nexj.core.scripting

Examples of nexj.core.scripting.Function


   public static void addMembers(ClassObject classObject)
   {
      NamedObject.addMembers(classObject);
      addOptionsMethod(classObject, "err.scripting.classOption");

      classObject.addMethod(":public?", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Boolean.valueOf(((ClassObject)machine.getArg(0, nArgCount)).isPublic()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":public", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            boolean bPublic = !Boolean.FALSE.equals(machine.getArg(1, nArgCount));

            ((ClassObject)machine.getArg(0, nArgCount)).setPublic(bPublic);
            machine.returnValue(Boolean.valueOf(bPublic), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":base", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .getBase(((Number)machine.getArg(1, nArgCount)).intValue()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":base-count", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Primitive.createInteger(((ClassObject)machine.getArg(0, nArgCount))
               .getBaseCount()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":add-base", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ((ClassObject)machine.getArg(0, nArgCount)).addBase((ClassObject)machine.getArg(1, nArgCount));
            machine.returnValue(null, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":remove-base", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ClassObject clazz = (ClassObject)machine.getArg(0, nArgCount);
            Object base = machine.getArg(1, nArgCount);

            machine.returnValue(
               (base instanceof ClassObject) ?
                  clazz.removeBase((ClassObject)base) :
                  clazz.removeBase((Symbol)base), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":add-derived", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ((ClassObject)machine.getArg(1, nArgCount)).addBase((ClassObject)machine.getArg(0, nArgCount));
            machine.returnValue(null, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":derived", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .getDerived(((Number)machine.getArg(1, nArgCount)).intValue()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":derived-count", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Primitive.createInteger(((ClassObject)machine.getArg(0, nArgCount))
               .getDerivedCount()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":add-attribute", 3, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ClassObject classObject = (ClassObject)machine.getArg(0, nArgCount);
            Object attribute = machine.getArg(1, nArgCount);
            AttributeObject attributeObject = (attribute instanceof AttributeObject) ?
                  (AttributeObject)attribute :
                  classObject.getMetaclass().createAttribute(classObject, (Symbol)attribute);

            machine.invoke(attributeObject, ADD_OPTIONS_SYMBOL,
               new Pair(machine.getArg(2, nArgCount)));

            ((ClassObject)machine.getArg(0, nArgCount)).addAttribute(
               attributeObject, !Boolean.FALSE.equals(machine.getArg(3, nArgCount)));

            machine.returnValue(attributeObject, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":remove-attribute", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .removeAttribute((Symbol)machine.getArg(1, nArgCount)), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":add-method", 2, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            MethodObject methodObject = (MethodObject)machine.getArg(1, nArgCount);

            ((ClassObject)machine.getArg(0, nArgCount)).addMethod(
               methodObject, !Boolean.FALSE.equals(machine.getArg(2, nArgCount)));

            machine.returnValue(methodObject, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":add-method", 4, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ClassObject classObject = (ClassObject)machine.getArg(0, nArgCount);
            Symbol symbol = (Symbol)machine.getArg(1, nArgCount);

            MethodObject methodObject = classObject.createMethod(symbol,
               (PCodeFunction)classObject.compile(machine.getArg(3, nArgCount),
                  symbol.getName(), null, machine));

            machine.invoke(methodObject, ADD_OPTIONS_SYMBOL,
               new Pair(machine.getArg(2, nArgCount)));

            classObject.addMethod(
               methodObject, !Boolean.FALSE.equals(machine.getArg(4, nArgCount)));

            machine.returnValue(methodObject, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":direct-method-count", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Primitive.createInteger(((ClassObject)machine.getArg(0, nArgCount))
               .getMethodCount()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":direct-method", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .getMethod(((Number)machine.getArg(1, nArgCount)).intValue()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":direct-class-method-count", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Primitive.createInteger(((ClassObject)machine.getArg(0, nArgCount))
               .getMetaclass().getMethodCount()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":direct-class-method", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .getMetaclass().getMethod(((Number)machine.getArg(1, nArgCount)).intValue()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":remove-method", 2, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount))
               .removeMethod((Symbol)machine.getArg(1, nArgCount),
                  ((Number)machine.getArg(2, nArgCount)).intValue()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":forward?", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Boolean.valueOf(((ClassObject)machine.getArg(0, nArgCount))
               .isForward()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":reset", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ((ClassObject)machine.getArg(0, nArgCount)).reset();
            machine.returnValue(null, nArgCount);

            return false;
         }
      });

      classObject.addMethod(":is-a?", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Boolean.valueOf(((ClassObject)machine.getArg(0, nArgCount))
               .isA((ClassObject)machine.getArg(1, nArgCount))), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":has-member?", 2, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            int nMemberArgCount = ((Number)machine.getArg(2, nArgCount)).intValue();

            machine.returnValue(Boolean.valueOf(nMemberArgCount >= 0 &&
               ((ClassObject)machine.getArg(0, nArgCount)).resolveFunction(
               (Symbol)machine.getArg(1, nArgCount), nMemberArgCount) != null),
               nArgCount);

            return false;
         }
      });

      classObject.addMethod(":new", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ClassObject)machine.getArg(0, nArgCount)).createObject(), nArgCount);

            return false;
         }
      });

      classObject.addMethod("new", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            ObjectOriented obj = ((ClassObject)machine.getArg(0, nArgCount)).createObject();
View Full Code Here


    * @param classObject The destination class object.
    * @param sErrCode The error code.
    */
   public static void addOptionsMethod(ClassObject classObject, final String sErrCode)
   {
      classObject.addMethod(ADD_OPTIONS_SYMBOL.getName(), 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            NamedObject obj = (NamedObject)machine.getArg(0, nArgCount);
            Pair arg = null;
View Full Code Here

    */
   public static void addMembers(ClassObject classObject)
   {
      NamedObject.addMembers(classObject);

      classObject.addMethod(":public?", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(Boolean.valueOf(((MemberObject)machine.getArg(0, nArgCount)).isPublic()), nArgCount);

            return false;
         }
      });

      classObject.addMethod(":public", 1, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            boolean bPublic = !Boolean.FALSE.equals(machine.getArg(1, nArgCount));

View Full Code Here

   /**
    * @see nexj.core.scripting.object.BasicMetaclassObject#addObjectMembers(nexj.core.scripting.object.ClassObject)
    */
   protected void addObjectMembers(ClassObject classObject)
   {
      classObject.addMethod("code", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ObjectException)machine.getArg(0, nArgCount)).getErrorCode(), nArgCount);

            return false;
         }
      });

      classObject.addMethod("args", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ObjectException)machine.getArg(0, nArgCount)).getErrorArgs(), nArgCount);

            return false;
         }
      });

      classObject.addMethod("cause", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            machine.returnValue(((ObjectException)machine.getArg(0, nArgCount)).getCause(), nArgCount);

            return false;
         }
      });

      classObject.addMethod("throw", 0, false, new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            throw (ObjectException)machine.getArg(0, nArgCount);
         }
View Full Code Here

               su.apply(Upgrade.getState(stateMap, su));
            }
         }
         else if (u instanceof ScriptUpgrade)
         {
            Function fun = ((ScriptUpgrade)u).getFunction();

            if (fun != null)
            {
               if (u.getNext() == null)
               {
View Full Code Here

         {
            Iterator itr = m_iteratorStack[nCurrentLoop];

            if (itr == null)
            {
               Function loopFunction = m_utest.getLoopFunction(nCurrentLoop);
               Object[] loopFunctionArgumentArray = new Object[nCurrentLoop];

               System.arraycopy(m_nextValueArray, 0, loopFunctionArgumentArray, 0, nCurrentLoop);

               Object result = m_context.getMachine().invoke(loopFunction, loopFunctionArgumentArray);
View Full Code Here

   /**
    * @see nexj.core.meta.workflow.FunctionStep#getFunction()
    */
   protected Function getFunction()
   {
      return new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            assert nArgCount == 2;

View Full Code Here

   /**
    * @see nexj.core.meta.workflow.FunctionStep#getFunction()
    */
   protected Function getFunction()
   {
      return new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            assert nArgCount == 2;

View Full Code Here

   /**
    * @see nexj.core.meta.workflow.FunctionStep#getFunction()
    */
   protected Function getFunction()
   {
      return new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            Object cleanupToken = null;
            Logger logger = null;
View Full Code Here

   /**
    * @see nexj.core.meta.workflow.FunctionStep#getFunction()
    */
   protected Function getFunction()
   {
      return new Function()
      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            assert nArgCount == 2;

View Full Code Here

TOP

Related Classes of nexj.core.scripting.Function

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.