113 lines
2.9 KiB
Java
113 lines
2.9 KiB
Java
package com.foundation.attribute;
|
|
|
|
import com.common.thread.*;
|
|
import com.common.debug.*;
|
|
import com.foundation.controller.ViewController;
|
|
import com.foundation.view.IViewContext;
|
|
import com.foundation.view.IViewRequestHandler;
|
|
import com.foundation.view.ViewSystemMetadata;
|
|
|
|
/**
|
|
* Copyright Wynne Crisman 2005<p>
|
|
*/
|
|
public class SimulatedViewController extends ViewController {
|
|
/**
|
|
* Copyright Wynne Crisman 2005<p>
|
|
* Wrappres a runnable and allows the creating thread to wait for the runnable to complete execution.
|
|
*/
|
|
public static class Task implements Runnable {
|
|
private IRunnable runnable = null;
|
|
private boolean isComplete = false;
|
|
private Object result = null;
|
|
|
|
/**
|
|
* Task constructor.
|
|
* @param runnable
|
|
*/
|
|
public Task(IRunnable runnable) {
|
|
this.runnable = runnable;
|
|
}//Task()//
|
|
/* (non-Javadoc)
|
|
* @see java.lang.Runnable#run()
|
|
*/
|
|
public void run() {
|
|
result = runnable.run();
|
|
|
|
synchronized(this) {
|
|
isComplete = true;
|
|
notifyAll();
|
|
}//synchronized//
|
|
}//run()//
|
|
/**
|
|
* Waits for and retreives the result.
|
|
* @return The result of the wrappered runnable.
|
|
*/
|
|
public Object waitForResult() {
|
|
synchronized(this) {
|
|
while(!isComplete) {
|
|
try {
|
|
wait(0);
|
|
}//try//
|
|
catch(Throwable e) {
|
|
Debug.handle(e);
|
|
}//catch//
|
|
}//while//
|
|
}//synchronized//
|
|
|
|
return result;
|
|
}//waitForResult()//
|
|
}//Task//
|
|
|
|
/**
|
|
* SimulatedViewController constructor.
|
|
*/
|
|
public SimulatedViewController() {
|
|
super(new IViewContext() {
|
|
SimpleEventLoop loop = new SimpleEventLoop();
|
|
|
|
public void setApplicationData(Object applicationData) {
|
|
}
|
|
public Object getApplicationData() {
|
|
return null;
|
|
}
|
|
public IViewRequestHandler getRequestHandler() {
|
|
return loop;
|
|
}
|
|
public ViewSystemMetadata getViewSystemMetadata() {
|
|
return null;
|
|
}
|
|
public Object getApplicationData(Object key) {
|
|
return null;
|
|
}
|
|
public void setApplicationData(Object key, Object applicationData) {
|
|
}
|
|
});
|
|
//Start the event thread simulation.//
|
|
//eventThread = new EventThread();
|
|
//ThreadService.run(eventThread);
|
|
}//SimualtedViewController()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.controller.ViewController#validate()
|
|
*/
|
|
public boolean validate() {
|
|
return true;
|
|
}//validate()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.controller.AbstractViewController#getViewClass()
|
|
*/
|
|
protected Class getViewClass() {
|
|
return null;
|
|
}//getViewClass()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.controller.ViewController#execute(com.common.thread.IRunnable)
|
|
*/
|
|
public Object execute(IRunnable runnable) {
|
|
return getContext().getRequestHandler().execute(runnable, true);
|
|
}//execute()//
|
|
/* (non-Javadoc)
|
|
* @see com.foundation.controller.ViewController#executeAsynch(com.common.thread.IRunnable)
|
|
*/
|
|
public void executeAsynch(IRunnable runnable) {
|
|
getContext().getRequestHandler().execute(runnable, false);
|
|
}//executeAsynch()//
|
|
}//SimulatedViewController// |