1 /* 2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. 3 * Copyright 2009, The Android Open Source Project 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _JNI_RUNTIME_H_ 28 #define _JNI_RUNTIME_H_ 29 30 #include "jni_utility.h" 31 #include "jni_instance.h" 32 33 #include "CString.h" 34 35 namespace JSC 36 { 37 38 namespace Bindings 39 { 40 41 class JavaString 42 { 43 public: JavaString()44 JavaString() { } 45 _commonInit(JNIEnv * e,jstring s)46 void _commonInit (JNIEnv *e, jstring s) 47 { 48 int size = e->GetStringLength(s); 49 const char* cs = getCharactersFromJStringInEnv(e, s); 50 { 51 _utf8String = WebCore::CString(cs, size); 52 } 53 releaseCharactersForJStringInEnv (e, s, cs); 54 } 55 JavaString(JNIEnv * e,jstring s)56 JavaString (JNIEnv *e, jstring s) { 57 _commonInit (e, s); 58 } 59 JavaString(jstring s)60 JavaString (jstring s) { 61 _commonInit (getJNIEnv(), s); 62 } 63 ~JavaString()64 ~JavaString() { } 65 length()66 int length() const { return _utf8String.length(); } 67 UTF8String()68 const char* UTF8String() const { 69 return _utf8String.data(); 70 } 71 72 private: 73 WebCore::CString _utf8String; 74 }; 75 76 77 class JavaParameter 78 { 79 public: JavaParameter()80 JavaParameter () : _JNIType(invalid_type) {}; 81 JavaParameter (JNIEnv *env, jstring type); ~JavaParameter()82 virtual ~JavaParameter() { } 83 type()84 const char* type() const { return _type.UTF8String(); } getJNIType()85 JNIType getJNIType() const { return _JNIType; } 86 87 private: 88 JavaString _type; 89 JNIType _JNIType; 90 }; 91 92 93 class JavaField 94 { 95 public: 96 JavaField (JNIEnv *env, jobject aField); 97 name()98 const char* name() const { return _name.UTF8String(); } type()99 const char* type() const { return _type.UTF8String(); } 100 getJNIType()101 JNIType getJNIType() const { return _JNIType; } 102 103 private: 104 JavaString _name; 105 JavaString _type; 106 JNIType _JNIType; 107 RefPtr<JObjectWrapper> _field; 108 }; 109 110 111 class JavaMethod 112 { 113 public: 114 JavaMethod(JNIEnv* env, jobject aMethod); 115 ~JavaMethod(); 116 name()117 const char* name() const { return _name.UTF8String(); } returnType()118 const char* returnType() const { return _returnType.UTF8String(); }; parameterAt(int i)119 JavaParameter* parameterAt(int i) const { return &_parameters[i]; }; numParameters()120 int numParameters() const { return _numParameters; }; 121 122 const char *signature() const; 123 JNIType JNIReturnType() const; 124 125 jmethodID methodID (jobject obj) const; 126 isStatic()127 bool isStatic() const { return _isStatic; } 128 129 private: 130 JavaParameter* _parameters; 131 int _numParameters; 132 JavaString _name; 133 mutable char* _signature; 134 JavaString _returnType; 135 JNIType _JNIReturnType; 136 mutable jmethodID _methodID; 137 bool _isStatic; 138 }; 139 140 } // namespace Bindings 141 142 } // namespace JSC 143 144 #endif // _JNI_RUNTIME_H_ 145