Java Doc for ContextFactory.java in  » Scripting » rhino » org » mozilla » javascript » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » rhino » org.mozilla.javascript 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.mozilla.javascript.ContextFactory

All known Subclasses:   org.mozilla.javascript.tools.shell.ShellContextFactory,
ContextFactory
public class ContextFactory (Code)
Factory class that Rhino runtime uses to create new Context instances. A ContextFactory can also notify listeners about context creation and release.

When the Rhino runtime needs to create new Context instance during execution of Context.enter or Context , it will call ContextFactory.makeContext() of the current global ContextFactory. See ContextFactory.getGlobal() and ContextFactory.initGlobal(ContextFactory) .

It is also possible to use explicit ContextFactory instances for Context creation. This is useful to have a set of independent Rhino runtime instances under single JVM. See ContextFactory.call(ContextAction) .

The following example demonstrates Context customization to terminate scripts running more then 10 seconds and to provide better compatibility with JavaScript code using MSIE-specific features.

 import org.mozilla.javascript.*;
 class MyFactory extends ContextFactory
 {
 // Custom 
Context  to store execution time.
 private static class MyContext extends Context
 {
 long startTime;
 }
 static {
 // Initialize GlobalFactory with custom factory
 ContextFactory.initGlobal(new MyFactory());
 }
 // Override 
ContextFactory.makeContext() protected Context makeContext()
 {
 MyContext cx = new MyContext();
 // Use pure interpreter mode to allow for
 // 
ContextFactory.observeInstructionCount(Context,int)  to work
 cx.setOptimizationLevel(-1);
 // Make Rhino runtime to call observeInstructionCount
 // each 10000 bytecode instructions
 cx.setInstructionObserverThreshold(10000);
 return cx;
 }
 // Override 
ContextFactory.hasFeature(Context,int) public boolean hasFeature(Context cx, int featureIndex)
 {
 // Turn on maximum compatibility with MSIE scripts
 switch (featureIndex) {
 case 
Context.FEATURE_NON_ECMA_GET_YEAR :
 return true;
 case 
Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME :
 return true;
 case 
Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER :
 return true;
 case 
Context.FEATURE_PARENT_PROTO_PROPERTIES :
 return false;
 }
 return super.hasFeature(cx, featureIndex);
 }
 // Override 
ContextFactory.observeInstructionCount(Context,int) protected void observeInstructionCount(Context cx, int instructionCount)
 {
 MyContext mcx = (MyContext)cx;
 long currentTime = System.currentTimeMillis();
 if (currentTime - mcx.startTime > 10*1000) {
 // More then 10 seconds from Context creation time:
 // it is time to stop the script.
 // Throw Error instance to ensure that script will never
 // get control back through catch or finally.
 throw new Error();
 }
 }
 // Override 
ContextFactory.doTopCall(Callable,Context,Scriptable,Scriptable,Object[]) protected Object doTopCall(Callable callable,
 Context cx, Scriptable scope,
 Scriptable thisObj, Object[] args)
 {
 MyContext mcx = (MyContext)cx;
 mcx.startTime = System.currentTimeMillis();
 return super.doTopCall(callable, cx, scope, thisObj, args);
 }
 }
 

Inner Class :public interface Listener



Method Summary
final public  voidaddListener(Listener listener)
    
final public  Objectcall(ContextAction action)
     Call ContextAction.run(Context cx) using the Context instance associated with the current thread. If no Context is associated with the thread, then ContextFactory.makeContext() will be called to construct new Context instance.
final protected  voidcheckNotSealed()
    
protected  GeneratedClassLoadercreateClassLoader(ClassLoader parent)
     Create class loader for generated classes. This method creates an instance of the default implementation of GeneratedClassLoader .
final  voiddisableContextListening()
    
protected  ObjectdoTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
     Execute top call to script or function. When the runtime is about to execute a script or function that will create the first stack frame with scriptable code, it calls this method to perform the real call.
final public  Contextenter()
    
public  ContextenterContext()
     Get a context associated with the current thread, creating one if need be.
final public  ContextenterContext(Context cx)
     Get a Context associated with the current thread, using the given Context if need be.
final public  voidexit()
    
final public  ClassLoadergetApplicationClassLoader()
     Get ClassLoader to use when searching for Java classes.
protected  org.mozilla.javascript.xml.XMLLib.FactorygetE4xImplementationFactory()
     Provides a default org.mozilla.javascript.xml.XMLLib.Factory XMLLib.Factory to be used by the Context instances produced by this factory.
public static  ContextFactorygetGlobal()
     Get global ContextFactory.
public static  booleanhasExplicitGlobal()
     Check if global factory was set.
protected  booleanhasFeature(Context cx, int featureIndex)
     Implementation of Context.hasFeature(int featureIndex) .
final public  voidinitApplicationClassLoader(ClassLoader loader)
     Set explicit class loader to use when searching for Java classes.
public static synchronized  voidinitGlobal(ContextFactory factory)
     Set global ContextFactory.
final public  booleanisSealed()
     Checks if this is a sealed ContextFactory.
protected  ContextmakeContext()
     Create new Context instance to be associated with the current thread. This is a callback method used by Rhino to create Context instance when it is necessary to associate one with the current execution thread.
protected  voidobserveInstructionCount(Context cx, int instructionCount)
     Implementation of Context.observeInstructionCount(int instructionCount) .
protected  voidonContextCreated(Context cx)
    
protected  voidonContextReleased(Context cx)
    
final public  voidremoveListener(Listener listener)
    
final public  voidseal()
     Seal this ContextFactory so any attempt to modify it like to add or remove its listeners will throw an exception.



Method Detail
addListener
final public void addListener(Listener listener)(Code)



call
final public Object call(ContextAction action)(Code)
Call ContextAction.run(Context cx) using the Context instance associated with the current thread. If no Context is associated with the thread, then ContextFactory.makeContext() will be called to construct new Context instance. The instance will be temporary associated with the thread during call to ContextAction.run(Context) .
See Also:   ContextFactory.call(ContextAction)
See Also:   Context.call(ContextFactory factoryCallable callableScriptable scopeScriptable thisObjObject[] args)



checkNotSealed
final protected void checkNotSealed()(Code)



createClassLoader
protected GeneratedClassLoader createClassLoader(ClassLoader parent)(Code)
Create class loader for generated classes. This method creates an instance of the default implementation of GeneratedClassLoader . Rhino uses this interface to load generated JVM classes when no SecurityController is installed. Application can override the method to provide custom class loading.



disableContextListening
final void disableContextListening()(Code)
The method is used only to implement Context.disableStaticContextListening()



doTopCall
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)(Code)
Execute top call to script or function. When the runtime is about to execute a script or function that will create the first stack frame with scriptable code, it calls this method to perform the real call. In this way execution of any script happens inside this function.



enter
final public Context enter()(Code)
ContextFactory.enterContext() a Context associated with the current thread



enterContext
public Context enterContext()(Code)
Get a context associated with the current thread, creating one if need be. The Context stores the execution state of the JavaScript engine, so it is required that the context be entered before execution may begin. Once a thread has entered a Context, then getCurrentContext() may be called to find the context that is associated with the current thread.

Calling enterContext() will return either the Context currently associated with the thread, or will create a new context and associate it with the current thread. Each call to enterContext() must have a matching call to Context.exit .

 Context cx = contextFactory.enterContext();
 try {
 ...
 cx.evaluateString(...);
 } finally {
 Context.exit();
 }
 
Instead of using enterContext(), exit() pair consider using ContextFactory.call(ContextAction) which guarantees proper association of Context instances with the current thread. With this method the above example becomes:
 ContextFactory.call(new ContextAction() {
 public Object run(Context cx) {
 ...
 cx.evaluateString(...);
 return null;
 }
 });
 
a Context associated with the current thread
See Also:   Context.getCurrentContext
See Also:   Context.exit
See Also:   ContextFactory.call(ContextAction)



enterContext
final public Context enterContext(Context cx)(Code)
Get a Context associated with the current thread, using the given Context if need be.

The same as enterContext() except that cx is associated with the current thread and returned if the current thread has no associated context and cx is not associated with any other thread.
Parameters:
  cx - a Context to associate with the thread if possible a Context associated with the current thread
See Also:   ContextFactory.enterContext()
See Also:   ContextFactory.call(ContextAction)
throws:
  IllegalStateException - if cx is already associatedwith a different thread




exit
final public void exit()(Code)
Context.exit



getApplicationClassLoader
final public ClassLoader getApplicationClassLoader()(Code)
Get ClassLoader to use when searching for Java classes. Unless it was explicitly initialized with ContextFactory.initApplicationClassLoader(ClassLoader) the method returns null to indicate that Thread.getContextClassLoader() should be used.



getE4xImplementationFactory
protected org.mozilla.javascript.xml.XMLLib.Factory getE4xImplementationFactory()(Code)
Provides a default org.mozilla.javascript.xml.XMLLib.Factory XMLLib.Factory to be used by the Context instances produced by this factory. See Context.getE4xImplementationFactory for details. May return null, in which case E4X functionality is not supported in Rhino. The default implementation now prefers the DOM3 E4X implementation.



getGlobal
public static ContextFactory getGlobal()(Code)
Get global ContextFactory.
See Also:   ContextFactory.hasExplicitGlobal()
See Also:   ContextFactory.initGlobal(ContextFactory)



hasExplicitGlobal
public static boolean hasExplicitGlobal()(Code)
Check if global factory was set. Return true to indicate that ContextFactory.initGlobal(ContextFactory) was already called and false to indicate that the global factory was not explicitly set.
See Also:   ContextFactory.getGlobal()
See Also:   ContextFactory.initGlobal(ContextFactory)



hasFeature
protected boolean hasFeature(Context cx, int featureIndex)(Code)
Implementation of Context.hasFeature(int featureIndex) . This can be used to customize Context without introducing additional subclasses.



initApplicationClassLoader
final public void initApplicationClassLoader(ClassLoader loader)(Code)
Set explicit class loader to use when searching for Java classes.
See Also:   ContextFactory.getApplicationClassLoader()



initGlobal
public static synchronized void initGlobal(ContextFactory factory)(Code)
Set global ContextFactory. The method can only be called once.
See Also:   ContextFactory.getGlobal()
See Also:   ContextFactory.hasExplicitGlobal()



isSealed
final public boolean isSealed()(Code)
Checks if this is a sealed ContextFactory.
See Also:   ContextFactory.seal()



makeContext
protected Context makeContext()(Code)
Create new Context instance to be associated with the current thread. This is a callback method used by Rhino to create Context instance when it is necessary to associate one with the current execution thread. makeContext() is allowed to call Context.seal(Object) on the result to prevent Context changes by hostile scripts or applets.



observeInstructionCount
protected void observeInstructionCount(Context cx, int instructionCount)(Code)
Implementation of Context.observeInstructionCount(int instructionCount) . This can be used to customize Context without introducing additional subclasses.



onContextCreated
protected void onContextCreated(Context cx)(Code)



onContextReleased
protected void onContextReleased(Context cx)(Code)



removeListener
final public void removeListener(Listener listener)(Code)



seal
final public void seal()(Code)
Seal this ContextFactory so any attempt to modify it like to add or remove its listeners will throw an exception.
See Also:   ContextFactory.isSealed()



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.