wt.clients.util
Class TaskDelegateFactory

java.lang.Object
  extended bywt.clients.util.TaskDelegateFactory

public class TaskDelegateFactory
extends Object

Class TaskDelegateFactory is a utility class which contains factory methods for instantiating TaskDelegate objects. This class instantiates task delegate objects based upon either a given class or the class of a given object.

The TaskDelegateFactory assumes a specific naming convention when trying to instantiate a TaskDelegate for a given class or object. If the fully-qualified class of the business object for which to instantiate a delegate is mysite.mypackage.MyBusinessObject, this factory will attempt to find a task delegate class whose fully-qualified class name is mysite.clients.mypackage.MyBusinessObjectTaskDelegate. For example, when attempting to instantiate a task delegate for wt.doc.WTDocument objects, the factory will look for a class whose fully-qualified name is wt.clients.doc.WTDocument. Given the fully-qualified class name of apkg.bpkg.cpkg.dpkg.Eobject, this factory will follow the following search algorithm to try and find a corresponding task delegate class:

  1. apkg.clients.bpkg.cpkg.dpkg.EobjectTaskDelegate
  2. apkg.bpkg.clients.cpkg.dpkg.EobjectTaskDelegate
  3. apkg.bpkg.cpkg.clients.dpkg.EobjectTaskDelegate
  4. apkg.bpkg.cpkg.dpkg.clients.EobjectTaskDelegate
If no delegate is found using this algorithm, the same algorithm will be applied to the parent of the given class. If no delegate is found applying this algorithm to the parent class, the same algorithm will be applied to the interfaces implemented by the given class. The TaskDelegateFactory class together with the TaskDelegate class form in a system in which business objects can be created, updated, viewed and deleted without knowing the specific type of the business object. For example:
    public class MyDisplay extends Frame {
       ...
       public void handleViewEvent( Event evt ) {
          Object obj_to_view = evt.getSource();
          TaskDelegate delegate =
	               TaskDelegateFactory.instantiateTaskDelegate( obj_to_view );
		      if( delegate != null ) {
		         delegate.setParentApplet( getParentApplet() );
		         delegate.setParentFrame( this );
		         delegate.setObject( obj_to_view );

	         try {
  		      delegate.launchViewTask();
  		   } catch (TaskDelegateException tde) {
             // Handle Exception
 		   }
       }
       ...
    }
  


Supported API: true

Extendable: false


Field Summary
protected static boolean VERBOSE
           
 
Constructor Summary
TaskDelegateFactory()
           
 
Method Summary
private static String formClassName(StringTokenizer tokens, int index)
           
private static Class formDelegateClass(Class object_class)
           
static TaskDelegate instantiateTaskDelegate(Class object_class)
          Returns an instance of the TaskDelegate which is associated with the given class.
static TaskDelegate instantiateTaskDelegate(Object obj)
          Returns an instance of the TaskDelegate which is associated with the given object.
static TaskDelegate instantiateTaskDelegate(String class_name)
          Returns an instance of the TaskDelegate which is associated with the given string classname.
private static Class loadClass(String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

protected static boolean VERBOSE
Constructor Detail

TaskDelegateFactory

public TaskDelegateFactory()
Method Detail

instantiateTaskDelegate

public static TaskDelegate instantiateTaskDelegate(Object obj)
Returns an instance of the TaskDelegate which is associated with the given object. This method uses the class of the given object to search for a corresponding task delegate. Given an object whose fully-qualified class name is apkg.bpkg.cpkg.dpkg.Eobject, the following search path is used to search for a task delegate:
  1. apkg.clients.bpkg.cpkg.dpkg.EobjectTaskDelegate
  2. apkg.bpkg.clients.cpkg.dpkg.EobjectTaskDelegate
  3. apkg.bpkg.cpkg.clients.dpkg.EobjectTaskDelegate
  4. apkg.bpkg.cpkg.dpkg.clients.EobjectTaskDelegate
If no delegate is found using this algorithm, the same algorithm will be applied to the parent of the given class. If no delegate is found applying this algorithm to the parent class, the same algorithm will be applied to the interfaces implemented by the given class. If no such TaskDelegate class exists, null is returned.

Parameters:
obj - the Object for which a corresponding task delegate is returned
Returns:
the TaskDelegate object associated with the given object; if no such TaskDelegate is found, null is returned

instantiateTaskDelegate

public static TaskDelegate instantiateTaskDelegate(String class_name)
Returns an instance of the TaskDelegate which is associated with the given string classname. This method uses the class specified by the fully-qualified String classname to search for a corresponding task delegate. Given a String specifying the fully-qualified class name, apkg.bpkg.cpkg.dpkg.Eobject, the following search path is used to search for a task delegate:
  1. apkg.clients.bpkg.cpkg.dpkg.EobjectTaskDelegate
  2. apkg.bpkg.clients.cpkg.dpkg.EobjectTaskDelegate
  3. apkg.bpkg.cpkg.clients.dpkg.EobjectTaskDelegate
  4. apkg.bpkg.cpkg.dpkg.clients.EobjectTaskDelegate
If no delegate is found using this algorithm, the same algorithm will be applied to the parent of the given class. If no delegate is found applying this algorithm to the parent class, the same algorithm will be applied to the interfaces implemented by the given class. If no such TaskDelegate class exists, null is returned.

Parameters:
class_name - the String representation of the fully-qualified class for which a corresponding task delegate is returned
Returns:
the TaskDelegate object associated with the given object; if no such TaskDelegate is found, null is returned

instantiateTaskDelegate

public static TaskDelegate instantiateTaskDelegate(Class object_class)
Returns an instance of the TaskDelegate which is associated with the given class. Given a fully-qualified class name of apkg.bpkg.cpkg.dpkg.Eobject, the following search path is used to search for a task delegate:
  1. apkg.clients.bpkg.cpkg.dpkg.EobjectTaskDelegate
  2. apkg.bpkg.clients.cpkg.dpkg.EobjectTaskDelegate
  3. apkg.bpkg.cpkg.clients.dpkg.EobjectTaskDelegate
  4. apkg.bpkg.cpkg.dpkg.clients.EobjectTaskDelegate
If no delegate is found using this algorithm, the same algorithm will be applied to the parent of the given class. If no delegate is found applying this algorithm to the parent class, the same algorithm will be applied to the interfaces implemented by the given class. If no such TaskDelegate class exists, null is returned.

Parameters:
object_class - the Class for which a corresponding task delegate is returned
Returns:
the TaskDelegate object associated with the given class; if no such TaskDelegate is found, null is returned

formDelegateClass

private static Class formDelegateClass(Class object_class)

formClassName

private static String formClassName(StringTokenizer tokens,
                                    int index)

loadClass

private static Class loadClass(String name)
                        throws ClassFormatError,
                               ClassNotFoundException,
                               Exception
Throws:
ClassFormatError
ClassNotFoundException
Exception