/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JSAdapter is java.lang.reflect.Proxy equivalent for JavaScript. JSAdapter
* calls specially named JavaScript methods on an adaptee object when property
* access is attempted on it.
*
* Example:
*
* var y = {
* __get__ : function (name) { ... }
* __has__ : function (name) { ... }
* __put__ : function (name, value) {...}
* __delete__ : function (name) { ... }
* __getIds__ : function () { ... }
* };
*
* var x = new JSAdapter(y);
*
* x.i; // calls y.__get__
* i in x; // calls y.__has__
* x.p = 10; // calls y.__put__
* delete x.p; // calls y.__delete__
* for (i in x) { print(i); } // calls y.__getIds__
*
* If a special JavaScript method is not found in the adaptee, then JSAdapter
* forwards the property access to the adaptee itself.
*
* JavaScript caller of adapter object is isolated from the fact that
* JavaScript methods on adaptee. Use cases include 'smart'
* easy client access - in short JavaScript becomes more "Self" like.
*
* Note that Rhino already supports special properties like __proto__
* (to set, get prototype), __parent__ (to set, get parent scope). We
* follow the same double underscore nameing convention here. Similarly
* the name JSAdapter is derived from JavaAdapter -- which is a facility
* to extend, implement Java classes/interfaces by JavaScript.
*
* @author A. Sundararajan
* @since 1.6
*/
}
// initializer to setup JSAdapter prototype in the given scope
throws RhinoException {
obj.isPrototype = true;
}
return "JSAdapter";
}
} else {
start = getAdaptee();
}
}
} else {
start = getAdaptee();
}
}
} else {
start = getAdaptee();
}
}
} else {
start = getAdaptee();
}
}
if (start == this) {
} else {
start = getAdaptee();
}
} else {
}
}
if (start == this) {
} else {
start = getAdaptee();
}
} else {
}
}
} else {
}
}
} else {
}
}
return prototype;
}
}
return parent;
}
}
// in most cases, adaptee would return native JS array
if (val instanceof NativeArray) {
}
return res;
} else if (val instanceof NativeJavaArray) {
// may be attempt wrapped Java array
}
} else {
// just return an empty array
}
return res;
} else {
// some other return type, just return empty array
}
} else {
return getAdaptee().getIds();
}
}
if (scriptable instanceof JSAdapter) {
return true;
} else {
}
return false;
}
}
}
throws RhinoException {
if (isPrototype) {
} else {
} else {
}
}
}
throws RhinoException {
if (isPrototype) {
} else {
}
return newObj;
} else {
} else {
}
}
}
return adaptee;
}
throw new NullPointerException("adaptee can not be null");
}
}
//-- internals only below this point
// map a property id. Property id can only be an Integer or String
} else {
}
}
}
}
try {
} catch (RhinoException re) {
}
}
private boolean isPrototype;
// names of adaptee JavaScript functions
}