<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0) on Thu Mar 06 17:19:15 EST 2008 -->
<TITLE>
WrapFactory (Rhino)
</TITLE>
<META NAME="date" CONTENT="2008-03-06">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="WrapFactory (Rhino)";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../org/mozilla/javascript/Synchronizer.html" title="class in org.mozilla.javascript"><B>PREV CLASS</B></A>
<A HREF="../../../org/mozilla/javascript/WrappedException.html" title="class in org.mozilla.javascript"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?org/mozilla/javascript/WrapFactory.html" target="_top"><B>FRAMES</B></A>
<A HREF="WrapFactory.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
org.mozilla.javascript</FONT>
<BR>
Class WrapFactory</H2>
<PRE>
java.lang.Object
<IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>org.mozilla.javascript.WrapFactory</B>
</PRE>
<HR>
<DL>
<DT><PRE>public class <B>WrapFactory</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
Embeddings that wish to provide their own custom wrappings for Java
objects may extend this class and call
<A HREF="../../../org/mozilla/javascript/Context.html#setWrapFactory(org.mozilla.javascript.WrapFactory)"><CODE>Context.setWrapFactory(WrapFactory)</CODE></A>
Once an instance of this class or an extension of this class is enabled
for a given context (by calling setWrapFactory on that context), Rhino
will call the methods of this class whenever it needs to wrap a value
resulting from a call to a Java method or an access to a Java field.
<P>
<P>
<DL>
<DT><B>Since:</B></DT>
<DD>1.5 Release 4</DD>
<DT><B>See Also:</B><DD><A HREF="../../../org/mozilla/javascript/Context.html#setWrapFactory(org.mozilla.javascript.WrapFactory)"><CODE>Context.setWrapFactory(WrapFactory)</CODE></A></DL>
<HR>
<P>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#WrapFactory()">WrapFactory</A></B>()</CODE>
<BR>
</TD>
</TR>
</TABLE>
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#isJavaPrimitiveWrap()">isJavaPrimitiveWrap</A></B>()</CODE>
<BR>
Return <code>false</code> if result of Java method, which is instance of
<code>String</code>, <code>Number</code>, <code>Boolean</code> and
<code>Character</code>, should be used directly as JavaScript primitive
type.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#setJavaPrimitiveWrap(boolean)">setJavaPrimitiveWrap</A></B>(boolean value)</CODE>
<BR>
</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> java.lang.Object</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#wrap(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)">wrap</A></B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object obj,
java.lang.Class staticType)</CODE>
<BR>
Wrap the object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#wrapAsJavaObject(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)">wrapAsJavaObject</A></B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object javaObject,
java.lang.Class staticType)</CODE>
<BR>
Wrap Java object as Scriptable instance to allow full access to its
methods and fields from JavaScript.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/mozilla/javascript/WrapFactory.html#wrapNewObject(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object)">wrapNewObject</A></B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object obj)</CODE>
<BR>
Wrap an object newly created by a constructor call.</TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
<P>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="WrapFactory()"><!-- --></A><H3>
WrapFactory</H3>
<PRE>
public <B>WrapFactory</B>()</PRE>
<DL>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="wrap(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)"><!-- --></A><H3>
wrap</H3>
<PRE>
public java.lang.Object <B>wrap</B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object obj,
java.lang.Class staticType)</PRE>
<DL>
<DD>Wrap the object.
<p>
The value returned must be one of
<UL>
<LI>java.lang.Boolean</LI>
<LI>java.lang.String</LI>
<LI>java.lang.Number</LI>
<LI>org.mozilla.javascript.Scriptable objects</LI>
<LI>The value returned by Context.getUndefinedValue()</LI>
<LI>null</LI>
</UL>
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>cx</CODE> - the current Context for this thread<DD><CODE>scope</CODE> - the scope of the executing script<DD><CODE>obj</CODE> - the object to be wrapped. Note it can be null.<DD><CODE>staticType</CODE> - type hint. If security restrictions prevent to wrap
object based on its class, staticType will be used instead.
<DT><B>Returns:</B><DD>the wrapped value.</DL>
</DD>
</DL>
<HR>
<A NAME="wrapNewObject(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object)"><!-- --></A><H3>
wrapNewObject</H3>
<PRE>
public <A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> <B>wrapNewObject</B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object obj)</PRE>
<DL>
<DD>Wrap an object newly created by a constructor call.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>cx</CODE> - the current Context for this thread<DD><CODE>scope</CODE> - the scope of the executing script<DD><CODE>obj</CODE> - the object to be wrapped
<DT><B>Returns:</B><DD>the wrapped value.</DL>
</DD>
</DL>
<HR>
<A NAME="wrapAsJavaObject(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)"><!-- --></A><H3>
wrapAsJavaObject</H3>
<PRE>
public <A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> <B>wrapAsJavaObject</B>(<A HREF="../../../org/mozilla/javascript/Context.html" title="class in org.mozilla.javascript">Context</A> cx,
<A HREF="../../../org/mozilla/javascript/Scriptable.html" title="interface in org.mozilla.javascript">Scriptable</A> scope,
java.lang.Object javaObject,
java.lang.Class staticType)</PRE>
<DL>
<DD>Wrap Java object as Scriptable instance to allow full access to its
methods and fields from JavaScript.
<p>
<A HREF="../../../org/mozilla/javascript/WrapFactory.html#wrap(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)"><CODE>wrap(Context, Scriptable, Object, Class)</CODE></A> and
<A HREF="../../../org/mozilla/javascript/WrapFactory.html#wrapNewObject(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object)"><CODE>wrapNewObject(Context, Scriptable, Object)</CODE></A> call this method
when they can not convert <tt>javaObject</tt> to JavaScript primitive
value or JavaScript array.
<p>
Subclasses can override the method to provide custom wrappers
for Java objects.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>cx</CODE> - the current Context for this thread<DD><CODE>scope</CODE> - the scope of the executing script<DD><CODE>javaObject</CODE> - the object to be wrapped<DD><CODE>staticType</CODE> - type hint. If security restrictions prevent to wrap
object based on its class, staticType will be used instead.
<DT><B>Returns:</B><DD>the wrapped value which shall not be null</DL>
</DD>
</DL>
<HR>
<A NAME="isJavaPrimitiveWrap()"><!-- --></A><H3>
isJavaPrimitiveWrap</H3>
<PRE>
public final boolean <B>isJavaPrimitiveWrap</B>()</PRE>
<DL>
<DD>Return <code>false</code> if result of Java method, which is instance of
<code>String</code>, <code>Number</code>, <code>Boolean</code> and
<code>Character</code>, should be used directly as JavaScript primitive
type.
By default the method returns true to indicate that instances of
<code>String</code>, <code>Number</code>, <code>Boolean</code> and
<code>Character</code> should be wrapped as any other Java object and
scripts can access any Java method available in these objects.
Use <A HREF="../../../org/mozilla/javascript/WrapFactory.html#setJavaPrimitiveWrap(boolean)"><CODE>setJavaPrimitiveWrap(boolean)</CODE></A> to change this.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="setJavaPrimitiveWrap(boolean)"><!-- --></A><H3>
setJavaPrimitiveWrap</H3>
<PRE>
public final void <B>setJavaPrimitiveWrap</B>(boolean value)</PRE>
<DL>
<DD><DL>
<DT><B>See Also:</B><DD><A HREF="../../../org/mozilla/javascript/WrapFactory.html#isJavaPrimitiveWrap()"><CODE>isJavaPrimitiveWrap()</CODE></A></DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../org/mozilla/javascript/Synchronizer.html" title="class in org.mozilla.javascript"><B>PREV CLASS</B></A>
<A HREF="../../../org/mozilla/javascript/WrappedException.html" title="class in org.mozilla.javascript"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?org/mozilla/javascript/WrapFactory.html" target="_top"><B>FRAMES</B></A>
<A HREF="WrapFactory.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
</BODY>
</HTML>