src/jdk.packager/share/native/library/common/Java.h
branchJDK-8200758-branch
changeset 56982 e094d5483bd6
parent 56963 eaca4369b068
child 56983 01decb67d4f0
equal deleted inserted replaced
56963:eaca4369b068 56982:e094d5483bd6
     1 /*
       
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 #ifndef JAVA_H
       
    27 #define JAVA_H
       
    28 
       
    29 #include "Platform.h"
       
    30 #include "Messages.h"
       
    31 
       
    32 #include "jni.h"
       
    33 
       
    34 
       
    35 class JavaClass;
       
    36 class JavaStaticMethod;
       
    37 class JavaMethod;
       
    38 class JavaStringArray;
       
    39 
       
    40 
       
    41 class JavaException : public Exception {
       
    42 // Prohibit Heap-Based Classes.
       
    43 private:
       
    44     static void *operator new(size_t size);
       
    45 
       
    46 private:
       
    47 #ifdef DEBUG
       
    48     static TString CreateExceptionMessage(JNIEnv* Env, jthrowable Exception,
       
    49         jmethodID GetCauseMethod, jmethodID GetStackTraceMethod, jmethodID ThrowableToStringMethod,
       
    50         jmethodID FrameToStringMethod);
       
    51 #endif //DEBUG
       
    52 
       
    53     jthrowable FException;
       
    54     JNIEnv *FEnv;
       
    55 
       
    56 public:
       
    57     explicit JavaException();
       
    58     explicit JavaException(JNIEnv *Env, const TString message);
       
    59     virtual ~JavaException() throw() {}
       
    60 
       
    61     void Rethrow();
       
    62 };
       
    63 
       
    64 
       
    65 class JavaStaticMethod {
       
    66 // Prohibit Heap-Based Classes.
       
    67 private:
       
    68     static void *operator new(size_t size);
       
    69     static void operator delete(void *ptr);
       
    70 
       
    71 private:
       
    72     JNIEnv *FEnv;
       
    73     jmethodID FMethod;
       
    74     jclass FClass;
       
    75 public:
       
    76     JavaStaticMethod(JNIEnv *Env, jclass Class, jmethodID Method);
       
    77 
       
    78     void CallVoidMethod(int Count, ...);
       
    79     operator jmethodID ();
       
    80 };
       
    81 
       
    82 
       
    83 class JavaMethod {
       
    84 // Prohibit Heap-Based Classes.
       
    85 private:
       
    86     static void *operator new(size_t size);
       
    87     static void operator delete(void *ptr);
       
    88 
       
    89     JavaMethod(JavaMethod const&); // Don't Implement.
       
    90     void operator=(JavaMethod const&); // Don't implement
       
    91 
       
    92 private:
       
    93     JNIEnv *FEnv;
       
    94     jmethodID FMethod;
       
    95     jobject FObj;
       
    96 public:
       
    97     JavaMethod(JNIEnv *Env, jobject Obj, jmethodID Method);
       
    98 
       
    99     void CallVoidMethod(int Count, ...);
       
   100     operator jmethodID ();
       
   101 };
       
   102 
       
   103 
       
   104 class JavaClass {
       
   105 // Prohibit Heap-Based Classes.
       
   106 private:
       
   107     static void *operator new(size_t size);
       
   108     static void operator delete(void *ptr);
       
   109 
       
   110     JavaClass(JavaClass const&); // Don't Implement.
       
   111     void operator=(JavaClass const&); // Don't implement
       
   112 
       
   113 private:
       
   114     JNIEnv *FEnv;
       
   115     jclass FClass;
       
   116     TString FClassName;
       
   117 
       
   118 public:
       
   119     JavaClass(JNIEnv *Env, TString Name);
       
   120     ~JavaClass();
       
   121 
       
   122     JavaStaticMethod GetStaticMethod(TString Name, TString Signature);
       
   123     operator jclass ();
       
   124 };
       
   125 
       
   126 
       
   127 class JavaStringArray {
       
   128 // Prohibit Heap-Based Classes.
       
   129 private:
       
   130     static void *operator new(size_t size);
       
   131     static void operator delete(void *ptr);
       
   132 
       
   133     JavaStringArray(JavaStringArray const&); // Don't Implement.
       
   134     void operator=(JavaStringArray const&); // Don't implement
       
   135 
       
   136 private:
       
   137     JNIEnv *FEnv;
       
   138     jobjectArray FData;
       
   139 
       
   140     void Initialize(size_t Size);
       
   141 
       
   142 public:
       
   143     JavaStringArray(JNIEnv *Env, size_t Size);
       
   144     JavaStringArray(JNIEnv *Env, jobjectArray Data);
       
   145     JavaStringArray(JNIEnv *Env, std::list<TString> Array);
       
   146 
       
   147     jobjectArray GetData();
       
   148     void SetValue(jsize Index, jstring Item);
       
   149     jstring GetValue(jsize Index);
       
   150     unsigned int Count();
       
   151 };
       
   152 
       
   153 #endif //JAVA_H