php.java.bridge.http
Class SimpleContextFactory

java.lang.Object
  extended by php.java.bridge.http.SimpleContextFactory
All Implemented Interfaces:
IContextFactory, IContextFactoryVisitor, IJavaBridgeFactory
Direct Known Subclasses:
PhpScriptContextFactory, ServletContextFactory

public class SimpleContextFactory
extends java.lang.Object
implements IContextFactoryVisitor

Base of a set of visitors which can extend the standard ContextFactory.

See Also:
ServletContextFactory, PhpScriptContextFactory

Method Summary
 void destroy()
          Removes the context factory from the classloader's list of context factories and destroys its content.
 void finishContext()
          Called by recycle at the end of the script
 JavaBridge getBridge()
          Return an instance of the PHP/Java Bridge.
 java.lang.ClassLoader getClassLoader()
          Return the current class loader.
 IContext getContext()
          Return a JSR223 context
 java.lang.String getId()
          Return the serializable ID of the context factory
 ISession getSession(java.lang.String name, boolean clientIsNew, int timeout)
           
 void recycle(ContextFactory visited)
           
 void recycle(java.lang.String id)
           Update the context factory with the new JavaBridge obtained from the servlet.
 void recycleLegacy(java.lang.String id)
           
 void remove()
          Deprecated. Use destroy() instead
 void removeOrphaned()
          Removes the unused context factory from the classloader's list of context factories.
 void setClassLoader(java.lang.ClassLoader loader)
          Set the current class loader
 void setContext(IContext context)
          Set the Context into this factory.
 void setIsLegacyClient(boolean legacyClient)
          Will be called by the PhpJavaServlet and by the JavaBridgeRunner when the client is not the pure PHP client.
 java.lang.String toString()
           
 void visit(ContextFactory visited)
          Called when a visitor has been attached.
 void waitFor()
          Wait for the context factory to finish.
 void waitFor(long timeout)
          Wait for the context factory to finish.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

recycle

public void recycle(java.lang.String id)
             throws java.lang.SecurityException
Description copied from interface: IContextFactory

Update the context factory with the new JavaBridge obtained from the servlet.

Since version 4.1.1 both, the C and the pure PHP implementation pass the context factory via a protocol header. This procedure must obtain the factory for id and pass the bridge to the current context factory. Furthermore it must update the currentThreadContextClassLoader. After the request is done, the ContextFactory#recycle() method is called, which must restore the currentThreadContextClassLoader and the old context factory.

Specified by:
recycle in interface IContextFactory
Parameters:
id - The fresh id
Throws:
java.lang.SecurityException
See Also:
ContextFactory.recycle(), Request.setBridge(php.java.bridge.JavaBridge), Request.recycle()

destroy

public void destroy()
Description copied from interface: IContextFactory
Removes the context factory from the classloader's list of context factories and destroys its content.

Specified by:
destroy in interface IContextFactory

waitFor

public void waitFor()
             throws java.lang.InterruptedException
Wait for the context factory to finish. The default implementation does nothing. Call visited.waitFor() if you want to wait.

Specified by:
waitFor in interface IContextFactory
Throws:
java.lang.InterruptedException
See Also:
ContextRunner

waitFor

public void waitFor(long timeout)
             throws java.lang.InterruptedException
Wait for the context factory to finish. The default implementation does nothing. Call visited.waitFor() if you want to wait.

Specified by:
waitFor in interface IContextFactory
Parameters:
timeout - The timeout
Throws:
java.lang.InterruptedException
See Also:
ContextRunner

getId

public java.lang.String getId()
Description copied from interface: IContextFactory
Return the serializable ID of the context factory

Specified by:
getId in interface IContextFactory
Returns:
The ID

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getContext

public IContext getContext()
Description copied from interface: IContextFactory
Return a JSR223 context

Specified by:
getContext in interface IContextFactory
Returns:
The context
See Also:
getContext(), Context

getBridge

public JavaBridge getBridge()
Description copied from interface: IJavaBridgeFactory
Return an instance of the PHP/Java Bridge.

Specified by:
getBridge in interface IJavaBridgeFactory
Returns:
an instance of the JavaBridge

visit

public void visit(ContextFactory visited)
Description copied from interface: IContextFactoryVisitor
Called when a visitor has been attached.

Specified by:
visit in interface IContextFactoryVisitor
Parameters:
visited - The context factory

getSession

public ISession getSession(java.lang.String name,
                           boolean clientIsNew,
                           int timeout)
Specified by:
getSession in interface IContextFactory
Parameters:
name - The session name. If name is null, the name PHPSESSION will be used.
clientIsNew - true if the client wants a new session
timeout - timeout in seconds. If 0 the session does not expire.
Returns:
The session
See Also:
ISession

setContext

public void setContext(IContext context)
Description copied from interface: IContextFactory
Set the Context into this factory. Should be called by Context.addNew() only.

Specified by:
setContext in interface IContextFactory
See Also:
ContextFactory.addNew(String)

recycle

public void recycle(ContextFactory visited)
Specified by:
recycle in interface IContextFactory

removeOrphaned

public void removeOrphaned()
Description copied from interface: IContextFactory
Removes the unused context factory from the classloader's list of context factories.

Specified by:
removeOrphaned in interface IContextFactory

remove

public void remove()
Deprecated. Use destroy() instead


finishContext

public void finishContext()
Called by recycle at the end of the script

Specified by:
finishContext in interface IContextFactory

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the current class loader.

Specified by:
getClassLoader in interface IContextFactory
Returns:
the current DynamicJavaBridgeClassLoader

setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Set the current class loader

Specified by:
setClassLoader in interface IContextFactory
Parameters:
loader - The DynamicJavaBridgeClassLoader

setIsLegacyClient

public void setIsLegacyClient(boolean legacyClient)
Description copied from interface: IContextFactory
Will be called by the PhpJavaServlet and by the JavaBridgeRunner when the client is not the pure PHP client.

Specified by:
setIsLegacyClient in interface IContextFactory

recycleLegacy

public void recycleLegacy(java.lang.String id)
                   throws java.lang.SecurityException
Specified by:
recycleLegacy in interface IContextFactory
Throws:
java.lang.SecurityException