Esempio n. 1
0
        /// <exception cref="TjsException"></exception>
        public virtual void Write()
        {
            string classname = mName + "Class";
            string filename  = mName + "Class.java";
            TextWriteStreamInterface stream = Tjs.mStorage.CreateTextWriteStream(filename, "utf-8"
                                                                                 );

            stream.Write("package jp.kirikiri.tjs2java;\n");
            stream.Write("import jp.kirikiri.tjs2.*;\n");
            stream.Write("import jp.kirikiri.tjs2.Error;\n");
            stream.Write("import jp.kirikiri.tvp2.base.ScriptsClass;\n");
            stream.Write("import jp.kirikiri.tvp2.msg.Message;\n");
            stream.Write("public class " + classname + " extends ExtendableNativeClass {\n");
            stream.Write("static public int ClassID = -1;\n");
            stream.Write("static public final String CLASS_NAME = \"" + mName + "\";\n");
            stream.Write("public " + classname + "() throws VariantException, TJSException {\n"
                         );
            stream.Write("super( CLASS_NAME );\n");
            stream.Write("final int NCM_CLASSID = TJS.registerNativeClass(CLASS_NAME);\n");
            stream.Write("setClassID( NCM_CLASSID );\n");
            stream.Write("ClassID = NCM_CLASSID;\n");
            stream.Write("TJS engine = ScriptsClass.getEngine();\n");
            int count = mMembers.Count;

            for (int i = 0; i < count; i++)
            {
                mMembers[i].Write(mName, stream);
            }
            stream.Write("}\n}\n");
            stream.Destruct();
        }
Esempio n. 2
0
            /// <exception cref="TjsException"></exception>
            public virtual void Write(string classname, TextWriteStreamInterface stream)
            {
                if (mType == ContextType.FUNCTION)
                {
                    if (mName.Equals(classname))
                    {
                        stream.Write("registerNCM( \"" + mName + "\", new NativeConvertedClassConstructor(engine) {\n@Override\n"
                                     );
                    }
                    else
                    {
                        stream.Write("registerNCM( \"" + mName + "\", new NativeConvertedClassMethod(engine) {\n@Override\n"
                                     );
                    }
                }
                AList <string> ca    = mCode;
                int            count = ca.Count;

                for (int i = 0; i < count; i++)
                {
                    string line = ca[i];
                    if (line != null)
                    {
                        stream.Write(ca[i]);
                        stream.Write("\n");
                    }
                }
                if (mType == ContextType.FUNCTION)
                {
                    stream.Write("}, CLASS_NAME, Interface.nitMethod, 0 );\n\n");
                }
            }
 public SaveStructCallback(AList <Dispatch2> stack, TextWriteStreamInterface stream
                           , string indent)
 {
     mStack     = stack;
     mStream    = stream;
     mIndentStr = indent;
 }
Esempio n. 4
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public virtual void SaveStructuredData(AList <Dispatch2> stack, TextWriteStreamInterface
                                               stream, string indentstr)
        {
            stream.Write("(const) [\n");
            string indentstr2 = indentstr + " ";
            int    count      = mItems.Count;

            for (int i = 0; i < count; i++)
            {
                Variant v = mItems[i];
                stream.Write(indentstr2);
                if (v.IsObject())
                {
                    // object
                    VariantClosure clo = v.AsObjectClosure();
                    SaveStructuredDataForObject(clo.SelectObject(), stack, stream, indentstr2);
                }
                else
                {
                    stream.Write(Utils.VariantToExpressionString(v));
                }
                if (i != mItems.Count - 1)
                {
                    // unless last
                    stream.Write(",\n");
                }
                else
                {
                    stream.Write("\n");
                }
            }
            stream.Write(indentstr);
            stream.Write("]");
        }
Esempio n. 5
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public static void SaveStructuredDataForObject(Dispatch2 dsp, AList <Dispatch2> stack
                                                       , TextWriteStreamInterface stream, string indentstr)
        {
            // check object recursion
            int count = stack.Count;

            for (int i = 0; i < count; i++)
            {
                Dispatch2 d = stack[i];
                if (d == dsp)
                {
                    // object recursion detected
                    stream.Write("null /* object recursion detected */");
                    return;
                }
            }
            // determin dsp's object type
            DictionaryNI dicni;
            ArrayNI      arrayni;

            if (dsp != null)
            {
                dicni = (DictionaryNI)dsp.GetNativeInstance(DictionaryClass.ClassID);
                if (dicni != null)
                {
                    // dictionary
                    stack.AddItem(dsp);
                    dicni.SaveStructuredData(stack, stream, indentstr);
                    stack.Remove(stack.Count - 1);
                    return;
                }
                else
                {
                    arrayni = (ArrayNI)dsp.GetNativeInstance(ArrayClass.ClassID);
                    if (arrayni != null)
                    {
                        // array
                        stack.AddItem(dsp);
                        arrayni.SaveStructuredData(stack, stream, indentstr);
                        stack.Remove(stack.Count - 1);
                        return;
                    }
                    else
                    {
                        // other objects
                        stream.Write("null /* (object) \"");
                        // stored as a null
                        Variant val = new Variant(dsp, dsp);
                        stream.Write(LexBase.EscapeC(val.AsString()));
                        stream.Write("\" */");
                        return;
                    }
                }
            }
            stream.Write("null");
        }
Esempio n. 6
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public static void SaveStructuredDataForObject(Dispatch2 dsp, AList<Dispatch2> stack
     , TextWriteStreamInterface stream, string indentstr)
 {
     // check object recursion
     int count = stack.Count;
     for (int i = 0; i < count; i++)
     {
         Dispatch2 d = stack[i];
         if (d == dsp)
         {
             // object recursion detected
             stream.Write("null /* object recursion detected */");
             return;
         }
     }
     // determin dsp's object type
     DictionaryNI dicni;
     ArrayNI arrayni;
     if (dsp != null)
     {
         dicni = (DictionaryNI)dsp.GetNativeInstance(DictionaryClass.ClassID);
         if (dicni != null)
         {
             // dictionary
             stack.AddItem(dsp);
             dicni.SaveStructuredData(stack, stream, indentstr);
             stack.Remove(stack.Count - 1);
             return;
         }
         else
         {
             arrayni = (ArrayNI)dsp.GetNativeInstance(ArrayClass.ClassID);
             if (arrayni != null)
             {
                 // array
                 stack.AddItem(dsp);
                 arrayni.SaveStructuredData(stack, stream, indentstr);
                 stack.Remove(stack.Count - 1);
                 return;
             }
             else
             {
                 // other objects
                 stream.Write("null /* (object) \"");
                 // stored as a null
                 Variant val = new Variant(dsp, dsp);
                 stream.Write(LexBase.EscapeC(val.AsString()));
                 stream.Write("\" */");
                 return;
             }
         }
     }
     stream.Write("null");
 }
Esempio n. 7
0
            /// <exception cref="TjsException"></exception>
            protected internal override int Process(Variant result, Variant[] param, Dispatch2
                                                    objthis)
            {
                ArrayNI ni = (ArrayNI)objthis.GetNativeInstance(ArrayClass.ClassID);

                if (ni == null)
                {
                    return(Error.E_NATIVECLASSCRASH);
                }
                if (param.Length < 1)
                {
                    return(Error.E_BADPARAMCOUNT);
                }
                string name = param[0].AsString();
                string mode = null;

                if (param.Length >= 2 && param[1].IsVoid() == false)
                {
                    mode = param[1].AsString();
                }
                TextWriteStreamInterface stream = Tjs.mStorage.CreateTextWriteStream(name, mode);

                try
                {
                    Iterator <Variant> i = ni.mItems.Iterator();
                    while (i.HasNext())
                    {
                        Variant o = i.Next();
                        if (o != null && (o.IsString() || o.IsNumber()))
                        {
                            stream.Write(o.AsString());
                        }
                        stream.Write("\n");
                    }
                }
                finally
                {
                    stream.Destruct();
                }
                if (result != null)
                {
                    result.Set(new Variant(objthis, objthis));
                }
                return(Error.S_OK);
            }
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public virtual void SaveStructuredData(AList <Dispatch2> stack, TextWriteStreamInterface
                                               stream, string indentstr)
        {
            stream.Write("(const) %[\n");
            string indentstr2 = indentstr + " ";

            DictionaryNI.SaveStructCallback callback = new DictionaryNI.SaveStructCallback(stack
                                                                                           , stream, indentstr2);
            CustomObject owner = mOwner.Get();

            owner.EnumMembers(Interface.IGNOREPROP, callback, owner);
            if (callback.mCalled)
            {
                stream.Write("\n");
            }
            stream.Write(indentstr);
            stream.Write("]");
        }
            /// <exception cref="TjsException"></exception>
            protected internal override int Process(Variant result, Variant[] param, Dispatch2
                                                    objthis)
            {
                DictionaryNI ni = (DictionaryNI)objthis.GetNativeInstance(DictionaryClass
                                                                          .ClassID);

                if (ni == null)
                {
                    return(Error.E_NATIVECLASSCRASH);
                }
                if (!ni.IsValid())
                {
                    return(Error.E_INVALIDOBJECT);
                }
                if (param.Length < 1)
                {
                    return(Error.E_BADPARAMCOUNT);
                }
                string name = param[0].AsString();
                string mode = null;

                if (param.Length >= 2 && param[1].IsVoid() != true)
                {
                    mode = param[1].AsString();
                }
                TextWriteStreamInterface stream = Tjs.mStorage.CreateTextWriteStream(name, mode);

                try
                {
                    AList <Dispatch2> stack = new AList <Dispatch2>();
                    stack.AddItem(objthis);
                    ni.SaveStructuredData(stack, stream, string.Empty);
                }
                finally
                {
                    stream.Destruct();
                }
                if (result != null)
                {
                    result.Set(new Variant(objthis, objthis));
                }
                return(Error.S_OK);
            }
Esempio n. 10
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void SaveStructuredData(AList<Dispatch2> stack, TextWriteStreamInterface
     stream, string indentstr)
 {
     stream.Write("(const) [\n");
     string indentstr2 = indentstr + " ";
     int count = mItems.Count;
     for (int i = 0; i < count; i++)
     {
         Variant v = mItems[i];
         stream.Write(indentstr2);
         if (v.IsObject())
         {
             // object
             VariantClosure clo = v.AsObjectClosure();
             SaveStructuredDataForObject(clo.SelectObject(), stack, stream, indentstr2);
         }
         else
         {
             stream.Write(Utils.VariantToExpressionString(v));
         }
         if (i != mItems.Count - 1)
         {
             // unless last
             stream.Write(",\n");
         }
         else
         {
             stream.Write("\n");
         }
     }
     stream.Write(indentstr);
     stream.Write("]");
 }
Esempio n. 11
0
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void Write(string classname, TextWriteStreamInterface stream)
 {
     if (mType == ContextType.FUNCTION)
     {
         if (mName.Equals(classname))
         {
             stream.Write("registerNCM( \"" + mName + "\", new NativeConvertedClassConstructor(engine) {\n@Override\n"
                 );
         }
         else
         {
             stream.Write("registerNCM( \"" + mName + "\", new NativeConvertedClassMethod(engine) {\n@Override\n"
                 );
         }
     }
     AList<string> ca = mCode;
     int count = ca.Count;
     for (int i = 0; i < count; i++)
     {
         string line = ca[i];
         if (line != null)
         {
             stream.Write(ca[i]);
             stream.Write("\n");
         }
     }
     if (mType == ContextType.FUNCTION)
     {
         stream.Write("}, CLASS_NAME, Interface.nitMethod, 0 );\n\n");
     }
 }
Esempio n. 12
0
 public SaveStructCallback(AList<Dispatch2> stack, TextWriteStreamInterface stream
     , string indent)
 {
     mStack = stack;
     mStream = stream;
     mIndentStr = indent;
 }
Esempio n. 13
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void SaveStructuredData(AList<Dispatch2> stack, TextWriteStreamInterface
     stream, string indentstr)
 {
     stream.Write("(const) %[\n");
     string indentstr2 = indentstr + " ";
     DictionaryNI.SaveStructCallback callback = new DictionaryNI.SaveStructCallback(stack
         , stream, indentstr2);
     CustomObject owner = mOwner.Get();
     owner.EnumMembers(Interface.IGNOREPROP, callback, owner);
     if (callback.mCalled)
     {
         stream.Write("\n");
     }
     stream.Write(indentstr);
     stream.Write("]");
 }