/* This file belongs to the Servoy development and deployment environment, Copyright (C) 1997-2010 Servoy BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the Free Software Foundation,Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 */ package com.servoy.j2db.scripting; import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.Scriptable; /** * @author jcompagner * */ public class InstanceOfScope implements Scriptable { private final String name; private final Class cls; public InstanceOfScope(String name, Class cls) { this.name = name; this.cls = cls; } /** * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) */ public boolean hasInstance(Scriptable instance) { if (instance instanceof NativeJavaObject) { Object unwrap = ((NativeJavaObject)instance).unwrap(); return cls.isInstance(unwrap); } else if (instance instanceof RecordingScriptable) { Object unwrap = ((RecordingScriptable)instance).unwrap(); return cls.isInstance(unwrap); } else if (instance instanceof IInstanceOf) { return ((IInstanceOf)instance).isInstance(name); } return cls.isInstance(instance); } /** * @see org.mozilla.javascript.Scriptable#getClassName() */ public String getClassName() { return name; } /** * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) */ public void delete(String name) { } /** * @see org.mozilla.javascript.Scriptable#delete(int) */ public void delete(int index) { } /** * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) */ public Object get(String name, Scriptable start) { return null; } /** * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) */ public Object get(int index, Scriptable start) { return null; } /** * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) */ public Object getDefaultValue(Class hint) { return name; } /** * @see org.mozilla.javascript.Scriptable#getIds() */ public Object[] getIds() { return new Object[0]; } /** * @see org.mozilla.javascript.Scriptable#getParentScope() */ public Scriptable getParentScope() { return null; } /** * @see org.mozilla.javascript.Scriptable#getPrototype() */ public Scriptable getPrototype() { return null; } /** * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) */ public boolean has(String name, Scriptable start) { return false; } /** * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) */ public boolean has(int index, Scriptable start) { return false; } /** * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) */ public void put(String name, Scriptable start, Object value) { } /** * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) */ public void put(int index, Scriptable start, Object value) { } /** * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) */ public void setParentScope(Scriptable parent) { } /** * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) */ public void setPrototype(Scriptable prototype) { } }