old python needs __main__ to call a module
[pylucene.git] / jcc / _jcc / java / io / PrintWriter.cpp
1 /*
2  *   Licensed under the Apache License, Version 2.0 (the "License");
3  *   you may not use this file except in compliance with the License.
4  *   You may obtain a copy of the License at
5  *
6  *       http://www.apache.org/licenses/LICENSE-2.0
7  *
8  *   Unless required by applicable law or agreed to in writing, software
9  *   distributed under the License is distributed on an "AS IS" BASIS,
10  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  *   See the License for the specific language governing permissions and
12  *   limitations under the License.
13  */
14
15 #include <jni.h>
16 #include "JCCEnv.h"
17 #include "java/lang/Object.h"
18 #include "java/lang/Class.h"
19 #include "java/io/PrintWriter.h"
20
21 namespace java {
22     namespace io {
23
24         enum {
25             mid__init_,
26             max_mid
27         };
28
29         java::lang::Class *PrintWriter::class$ = NULL;
30         jmethodID *PrintWriter::_mids = NULL;
31
32         jclass PrintWriter::initializeClass()
33         {
34             if (!class$)
35             {
36                 jclass cls = env->findClass("java/io/PrintWriter");
37
38                 _mids = new jmethodID[max_mid];
39                 _mids[mid__init_] =
40                     env->getMethodID(cls, "<init>", "(Ljava/io/Writer;)V");
41
42                 class$ = (java::lang::Class *) new JObject(cls);
43             }
44
45             return (jclass) class$->this$;
46         }
47
48         PrintWriter::PrintWriter(Writer writer) : Writer(env->newObject(initializeClass, &_mids, mid__init_, writer.this$)) {
49         }
50     }
51 }
52
53
54 #include "structmember.h"
55 #include "functions.h"
56 #include "macros.h"
57
58 namespace java {
59     namespace io {
60
61         static int t_PrintWriter_init(t_PrintWriter *self,
62                                       PyObject *args, PyObject *kwds);
63
64         static PyMethodDef t_PrintWriter__methods_[] = {
65             { NULL, NULL, 0, NULL }
66         };
67
68         DECLARE_TYPE(PrintWriter, t_PrintWriter, Writer,
69                      java::io::PrintWriter, t_PrintWriter_init,
70                      0, 0, 0, 0, 0);
71
72         static int t_PrintWriter_init(t_PrintWriter *self,
73                                       PyObject *args, PyObject *kwds)
74         {
75             Writer writer((jobject) NULL);
76
77             if (!parseArgs(args, "j", Writer::class$, &writer))
78             {
79                 INT_CALL(self->object = PrintWriter(writer));
80                 return 0;
81             }
82
83             PyErr_SetString(PyExc_ValueError, "invalid args");
84             return -1;
85         }
86     }
87 }