@@ -0,0 +1,2768 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-%0A *%0A * The contents of this file are subject to the Netscape Public%0A * License Version 1.1 (the %22License%22); you may not use this file%0A * except in compliance with the License. You may obtain a copy of%0A * the License at http://www.mozilla.org/NPL/%0A *%0A * Software distributed under the License is distributed on an %22AS%0A * IS%22 basis, WITHOUT WARRANTY OF ANY KIND, either express or%0A * implied. See the License for the specific language governing%0A * rights and limitations under the License.%0A *%0A * The Original Code is Rhino code, released%0A * May 6, 1998.%0A *%0A * The Initial Developer of the Original Code is Netscape%0A * Communications Corporation.  Portions created by Netscape are%0A * Copyright (C) 1997-1999 Netscape Communications Corporation. All%0A * Rights Reserved.%0A *%0A * Contributor(s): %0A * Norris Boyd%0A *%0A * Alternatively, the contents of this file may be used under the%0A * terms of the GNU Public License (the %22GPL%22), in which case the%0A * provisions of the GPL are applicable instead of those above.%0A * If you wish to allow use of your version of this file only%0A * under the terms of the GPL and not to allow others to use your%0A * version of this file under the NPL, indicate your decision by%0A * deleting the provisions above and replace them with the notice%0A * and other provisions required by the GPL.  If you do not delete%0A * the provisions above, a recipient may use your version of this%0A * file under either the NPL or the GPL.%0A */%0A%0Aimport org.mozilla.javascript.*;%0A%0A/**%0A * An example WrapFactory that can be used to avoid wrapping of Java types%0A * that can be converted to ECMA primitive values.%0A * So java.lang.String is mapped to ECMA string, all java.lang.Numbers are%0A * mapped to ECMA numbers, and java.lang.Booleans are mapped to ECMA booleans%0A * instead of being wrapped as objects. Additionally java.lang.Characters are%0A * converted to ECMA strings. Other types have the default behavior.%0A * %3Cp%3E%0A * Note that calling %22new java.lang.String('foo')%22 in JavaScript with this%0A * wrap factory enabled will still produce a wrapped Java object since the %0A * WrapFactory.wrapNewObject method is not overridden.%0A * %3Cp%3E%0A * The PrimitiveWrapFactory is enabled on a Context by calling setWrapFactory%0A * on that context.%0A */%0Apublic class PrimitiveWrapFactory extends WrapFactory %7B%0A%0A  public Object wrap(Context cx, Scriptable scope, Object obj, %0A                     Class staticType) %0A  %7B%0A    if (obj instanceof String %7C%7C obj instanceof Number %7C%7C%0A        obj instanceof Boolean)%0A    %7B%0A      return obj;%0A    %7D else if (obj instanceof Character) %7B%0A      char%5B%5D a = %7B ((Character)obj).charValue() %7D;%0A      return new String(a);%0A    %7D%0A    return super.wrap(cx, scope, obj, staticType);%0A  %7D%0A%7D%0A

Add example of the use of a WrapFactory.