2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _JNI_INSTANCE_H_
26 #define _JNI_INSTANCE_H_
28 #include <CoreFoundation/CoreFoundation.h>
30 #include <JavaVM/jni.h>
32 #include <JavaScriptCore/runtime.h>
42 friend class JavaArray;
43 friend class JavaInstance;
44 friend class JavaMethod;
47 JObjectWrapper(jobject instance);
48 void ref() { _ref++; }
64 class JavaInstance : public Instance
67 JavaInstance (jobject instance, const RootObject *r);
71 virtual Class *getClass() const;
73 JavaInstance (const JavaInstance &other);
75 JavaInstance &operator=(const JavaInstance &other){
79 JObjectWrapper *_oldInstance = _instance;
80 _instance = other._instance;
82 _oldInstance->deref();
84 // Classes are kept around forever.
85 _class = other._class;
93 virtual KJS::Value valueOf() const;
94 virtual KJS::Value defaultValue (KJS::Type hint) const;
96 virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args);
98 virtual void setExecutionContext (RootObject *r);
99 virtual const RootObject *executionContext() const;
101 jobject javaInstance() const { return _instance->_instance; }
103 KJS::Value stringValue() const;
104 KJS::Value numberValue() const;
105 KJS::Value booleanValue() const;
108 JObjectWrapper *_instance;
109 mutable JavaClass *_class;
110 const RootObject *_root;
113 } // namespace Bindings