org.mozilla.jrex.liveconnect
Class JRexLiveConnectSessionImpl

java.lang.Object
  |
  +--org.mozilla.jrex.liveconnect.JRexLiveConnectSessionImpl
All Implemented Interfaces:
JRexLiveConnectSession

public final class JRexLiveConnectSessionImpl
extends Object
implements JRexLiveConnectSession

Implementation of JRexLiveConnectSession. JRexLiveConnectSessionImpl is public for accesibility from jni.

See Also:
JRexLiveConnectSession

Constructor Summary
JRexLiveConnectSessionImpl()
          Creates an instance of JRexLiveConnectSessionImpl.
JRexLiveConnectSessionImpl(JRexCanvas browser)
          Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.
 
Method Summary
 boolean equals(Object obj)
           
 String evalUntrusted(String script)
          Evaluates javascript in the browser.
protected  void finalize()
           
 int getJRexPeerID()
           
 netscape.javascript.JSObject getJSWindow()
          Retrieves a JSObject implementation for the JRexCanvas window.
 int getSessionID()
           
 void grantBrowserAccessToJVM()
          Makes the LiveConnectSession a 2-way session.
 int hashCode()
           
 String invokeStringMethod(String functionName, String arg)
          Invokes a javascript method which accepts a single string and returns a string.
 void setBrowser(JRexCanvas browser)
          Sets the browser and intializes live connect for the browser.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRexLiveConnectSessionImpl

public JRexLiveConnectSessionImpl()
Creates an instance of JRexLiveConnectSessionImpl. The method setBrowser(org.mozilla.jrex.ui.JRexCanvas) must be called before any javascript can be invoked.


JRexLiveConnectSessionImpl

public JRexLiveConnectSessionImpl(JRexCanvas browser)
                           throws JRexException
Creates an instance of JRexLiveConnectSessionImpl and invokes setBrowser.

Parameters:
browser - the JRexCanvas used to access javascript
Throws:
JRexException - if an error occurs while initializing the javascript bridge.
Method Detail

getSessionID

public int getSessionID()

getJRexPeerID

public int getJRexPeerID()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

finalize

protected void finalize()
Overrides:
finalize in class Object

setBrowser

public void setBrowser(JRexCanvas browser)
                throws JRexException
Description copied from interface: JRexLiveConnectSession
Sets the browser and intializes live connect for the browser.

Specified by:
setBrowser in interface JRexLiveConnectSession
Parameters:
browser - the JRexCanvas, which must already be initialized
Throws:
JRexException - if an error occurs while initializing live connect

grantBrowserAccessToJVM

public void grantBrowserAccessToJVM()
                             throws JRexException
Description copied from interface: JRexLiveConnectSession
Makes the LiveConnectSession a 2-way session. Before this method is called, the LiveConnect session is only one-way, meaning that Java can call into javascript using any of the methods defined in this interface except for JRexLiveConnectSession.getJSWindow(). After this method is invoked, the javascript will be able to create java objects and invoke methods on those objects, and the caller will be able to use the method JRexLiveConnectSession.getJSWindow() to retrieve the JSObject instance for the javascript window.

Only call this method if the web page loaded into the JRexCanvas is trusted.

Specified by:
grantBrowserAccessToJVM in interface JRexLiveConnectSession
Throws:
JRexException - if an error occurs while granting access to the JRex JVM

invokeStringMethod

public String invokeStringMethod(String functionName,
                                 String arg)
                          throws JRexException
Description copied from interface: JRexLiveConnectSession
Invokes a javascript method which accepts a single string and returns a string. This method is provided as a simple way of invoking a javascript method and is useful for testing the JRexLiveConnectSession code. Note that for more complex javascript evaulations, the method JRexLiveConnectSession.evalUntrusted(java.lang.String) should be used for untrusted javascript, and the JSObject class returned from JRexLiveConnectSession.getJSWindow() should be used for trusted javascript.

Specified by:
invokeStringMethod in interface JRexLiveConnectSession
Parameters:
functionName - the name of the javascript function
arg - the argument to pass to the javascript function
Returns:
the result from the javascript function call, or null if the call failed
Throws:
JRexException - if an error occurs while invoking the javascript
See Also:
JRexLiveConnectSession.getJSWindow()

evalUntrusted

public String evalUntrusted(String script)
                     throws JRexException
Description copied from interface: JRexLiveConnectSession
Evaluates javascript in the browser. This method will evaluate unstrusted javascript and return the string result. If the javascript is trusted, it is better to call JRexLiveConnectSession.grantBrowserAccessToJVM() followed by JRexLiveConnectSession.getJSWindow() and invoke the eval method on the JSObject instance. Only use this method if the javascript is not trusted.

Specified by:
evalUntrusted in interface JRexLiveConnectSession
Parameters:
script - the javascript to evaluate
Returns:
the result of the evaulation as a string
Throws:
JRexException - if an error occurs while evaulating

getJSWindow

public netscape.javascript.JSObject getJSWindow()
                                         throws JRexException
Description copied from interface: JRexLiveConnectSession
Retrieves a JSObject implementation for the JRexCanvas window. The return JSObject can be used to make function calls and evaluate javascript. This method must be invoked after the document has been fully loaded into the browser. Failure to do so will result in unexpected errors.

Note that this method will throw a security violation exception unless the method JRexLiveConnectSession.grantBrowserAccessToJVM() is invoked before this method. Make sure to invoke JRexLiveConnectSession.grantBrowserAccessToJVM() before invoking this method.

Specified by:
getJSWindow in interface JRexLiveConnectSession
Returns:
a JSObject for invoking and manipulating javascript
Throws:
JRexException - if an error prevents the JSObject from being created
See Also:
JRexLiveConnectSession.grantBrowserAccessToJVM()


Copyright © 2004 C.N.Medappa. All Rights Reserved.