1 #include "GraphicObjectBuilder.hxx"
2 /* Generated by GIWS (version 2.0.1) with command:
3 giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/graphic_objects.giws.xml
7 This is generated code.
9 This software is a computer program whose purpose is to hide the complexity
10 of accessing Java objects/methods from C++ code.
12 This software is governed by the CeCILL-B license under French law and
13 abiding by the rules of distribution of free software. You can use,
14 modify and/ or redistribute the software under the terms of the CeCILL-B
15 license as circulated by CEA, CNRS and INRIA at the following URL
16 "http://www.cecill.info".
18 As a counterpart to the access to the source code and rights to copy,
19 modify and redistribute granted by the license, users are provided only
20 with a limited warranty and the software's author, the holder of the
21 economic rights, and the successive licensors have only limited
24 In this respect, the user's attention is drawn to the risks associated
25 with loading, using, modifying and/or developing or reproducing the
26 software by the user in light of its specific status of free software,
27 that may mean that it is complicated to manipulate, and that also
28 therefore means that it is reserved for developers and experienced
29 professionals having in-depth computer knowledge. Users are therefore
30 encouraged to load and test the software's suitability as regards their
31 requirements in conditions enabling the security of their systems and/or
32 data to be ensured and, more generally, to use and operate it in the
33 same conditions as regards security.
35 The fact that you are presently reading this means that you have had
36 knowledge of the CeCILL-B license and that you accept its terms.
39 namespace org_scilab_modules_graphic_objects {
41 // Static declarations (if any)
43 // Returns the current env
45 JNIEnv * GraphicObjectBuilder::getCurrentEnv() {
46 JNIEnv * curEnv = NULL;
47 jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
49 throw GiwsException::JniException(getCurrentEnv());
55 GraphicObjectBuilder::~GraphicObjectBuilder() {
56 JNIEnv * curEnv = NULL;
57 this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
59 curEnv->DeleteGlobalRef(this->instance);
60 curEnv->DeleteGlobalRef(this->instanceClass);
63 GraphicObjectBuilder::GraphicObjectBuilder(JavaVM * jvm_) {
64 jmethodID constructObject = NULL ;
65 jobject localInstance ;
68 const std::string construct="<init>";
69 const std::string param="()V";
72 JNIEnv * curEnv = getCurrentEnv();
74 localClass = curEnv->FindClass( this->className().c_str() ) ;
75 if (localClass == NULL) {
76 throw GiwsException::JniClassNotFoundException(curEnv, this->className());
79 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
81 /* localClass is not needed anymore */
82 curEnv->DeleteLocalRef(localClass);
84 if (this->instanceClass == NULL) {
85 throw GiwsException::JniObjectCreationException(curEnv, this->className());
89 constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
90 if(constructObject == NULL){
91 throw GiwsException::JniObjectCreationException(curEnv, this->className());
94 localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
95 if(localInstance == NULL){
96 throw GiwsException::JniObjectCreationException(curEnv, this->className());
99 this->instance = curEnv->NewGlobalRef(localInstance) ;
100 if(this->instance == NULL){
101 throw GiwsException::JniObjectCreationException(curEnv, this->className());
103 /* localInstance not needed anymore */
104 curEnv->DeleteLocalRef(localInstance);
106 /* Methods ID set to NULL */
107 jstringconstructRectanglesjstringjava_lang_StringjdoubledoublejdoubledoublejdoubledoublejdoubledoublejintintjintintjintintjintintID=NULL;
112 GraphicObjectBuilder::GraphicObjectBuilder(JavaVM * jvm_, jobject JObj) {
115 JNIEnv * curEnv = getCurrentEnv();
117 jclass localClass = curEnv->GetObjectClass(JObj);
118 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
119 curEnv->DeleteLocalRef(localClass);
121 if (this->instanceClass == NULL) {
122 throw GiwsException::JniObjectCreationException(curEnv, this->className());
125 this->instance = curEnv->NewGlobalRef(JObj) ;
126 if(this->instance == NULL){
127 throw GiwsException::JniObjectCreationException(curEnv, this->className());
129 /* Methods ID set to NULL */
130 jstringconstructRectanglesjstringjava_lang_StringjdoubledoublejdoubledoublejdoubledoublejdoubledoublejintintjintintjintintjintintID=NULL;
137 void GraphicObjectBuilder::synchronize() {
138 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
139 throw GiwsException::JniMonitorException(getCurrentEnv(), "GraphicObjectBuilder");
143 void GraphicObjectBuilder::endSynchronize() {
144 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
145 throw GiwsException::JniMonitorException(getCurrentEnv(), "GraphicObjectBuilder");
150 char* GraphicObjectBuilder::constructRectangles (JavaVM * jvm_, char const* pparentsubwinUID, double x, double y, double height, double width, int foreground, int background, int isfilled, int isline){
152 JNIEnv * curEnv = NULL;
153 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
154 jclass cls = curEnv->FindClass( className().c_str() );
156 jmethodID jstringconstructRectanglesjstringjava_lang_StringjdoubledoublejdoubledoublejdoubledoublejdoubledoublejintintjintintjintintjintintID = curEnv->GetStaticMethodID(cls, "constructRectangles", "(Ljava/lang/String;DDDDIIII)Ljava/lang/String;" ) ;
157 if (jstringconstructRectanglesjstringjava_lang_StringjdoubledoublejdoubledoublejdoubledoublejdoubledoublejintintjintintjintintjintintID == NULL) {
158 throw GiwsException::JniMethodNotFoundException(curEnv, "constructRectangles");
161 jstring pparentsubwinUID_ = curEnv->NewStringUTF( pparentsubwinUID );
162 if (pparentsubwinUID != NULL && pparentsubwinUID_ == NULL)
164 throw GiwsException::JniBadAllocException(curEnv);
168 jstring res = static_cast<jstring>( curEnv->CallStaticObjectMethod(cls, jstringconstructRectanglesjstringjava_lang_StringjdoubledoublejdoubledoublejdoubledoublejdoubledoublejintintjintintjintintjintintID ,pparentsubwinUID_, x, y, height, width, foreground, background, isfilled, isline));
169 if (curEnv->ExceptionCheck()) {
170 throw GiwsException::JniCallMethodException(curEnv);
173 const char *tempString = curEnv->GetStringUTFChars(res, 0);
174 char * myStringBuffer = new char[strlen(tempString) + 1];
175 strcpy(myStringBuffer, tempString);
176 curEnv->ReleaseStringUTFChars(res, tempString);
177 curEnv->DeleteLocalRef(res);
178 curEnv->DeleteLocalRef(pparentsubwinUID_);
179 curEnv->DeleteLocalRef(cls);
180 if (curEnv->ExceptionCheck()) {
181 delete[] myStringBuffer;
182 throw GiwsException::JniCallMethodException(curEnv);
184 return myStringBuffer;
186 curEnv->DeleteLocalRef(res);