WebObjects 5.1

com.webobjects.appserver
Class WODirectAction

java.lang.Object
  |
  +--com.webobjects.appserver.WODirectAction
All Implemented Interfaces:
NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions, NSValidation
Direct Known Subclasses:
D2WActions, WOAdminAction, WOEventDisplay, WOEventSetup, WOProjectBuilderAction, WOStats

public class WODirectAction
extends Object
implements NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions, NSValidation

WODirectAction is an abstract class that defines the interface for direct action classes. You subclass WODirectAction to provide an object that is a repository for action methods.

WODirectAction provides the simplest interface for adding logic and custom code to your WebObjects application. WODirectAction objects are instantiated when a URL requested by a client browser is sent to the WebObjects application. The WODirectActionRequestHandler determines the proper class and action to be invoked and then passes control to the WODirectAction subclass.

In contrast to a WOComponent-based action, a direct action is well-defined by the URL that invokes it. For example, the following URL will invoke the method findEmployeeAction on the subclass of WODirectAction called Common:

http://localhost/cgi-bin/WebObjects/Myapp.woa/wa/Common/findEmployee

A subclass of WODirectAction is a repository for action methods. New WebObjects applications contain a default implementation of WODirectAction subclass called DirectAction. The DirectAction class is used when no class is specified in the URL.

In summary, here are some URLs and actions they invoke:
This URL... Invokes this method...
../MyApp.woa/wa/ defaultAction on class DirectAction
../MyApp.woa/wa/find findAction on class DirectAction, if it exists, or defaultAction on class find otherwise
../MyApp.woa/wa/Common/find findAction on class Common

WODirectActionRequestHandler only invokes methods on subclasses of WODirectAction. If the specified class or action doesn't exist, WODirectActionRequestHandler throws an exception.


Inner classes inherited from class com.webobjects.foundation.NSKeyValueCoding
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor
 
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility
 
Inner classes inherited from class com.webobjects.foundation.NSValidation
NSValidation.DefaultImplementation, NSValidation.Utility, NSValidation.ValidationException
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
NullValue
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
KeyPathSeparator
 
Constructor Summary
WODirectAction(WORequest aRequest)
          Subclasses must override to provide any additional initialization.
 
Method Summary
static boolean canAccessFieldsDirectly()
          WODirectAction's implementation of this static method returns true, indicating that key-value coding is allowed to access fields in this object if an appropriate method isn't present.
 WOContext context()
          Returns the current WOContext object.
static void debugString(String string)
          Deprecated. use NSLog instead.
 WOActionResults defaultAction()
          Returns a WOActionResults object that is the result of sending generateResponse() to the page named "Main".
 WOSession existingSession()
          Restores the session based on the request.
 Object handleQueryWithUnboundKey(String key)
          Conformance to NSKeyValueCoding.ErrorHandling.
 void handleTakeValueForUnboundKey(Object value, String key)
          Conformance to NSKeyValueCoding.ErrorHandling.
static void logString(String string)
          This is simply a cover method for NSLog.err.appendln(string).
 WOComponent pageWithName(String aComponentName)
          Returns the page with given name.
 WOActionResults performActionNamed(String anActionName)
          Performs the action with the specified name and returns the result of that action.
 WORequest request()
          Returns the WORequest that created this DirectAction object.
 WOSession session()
          If there is no session, this method first tries to restore the session that the request's session ID refers to.
 void takeFormValueArraysForKeyArray(NSArray aKeyArray)
          Performs takeValueForKey on each key in aKeyArray using values from the receiver's request.
 void takeFormValuesForKeyArray(NSArray aKeyArray)
          Performs takeValueForKey on the each key in aKeyArray using values from the receiver's request.
 void takeValueForKey(Object value, String key)
          Conformance to NSKeyValueCoding.
 void takeValueForKeyPath(Object value, String keyPath)
          Conformance to NSKeyValueCodingAdditions.
 String toString()
           
 void unableToSetNullForKey(String key)
          Conformance to NSKeyValueCoding.ErrorHandling.
 Object validateTakeValueForKeyPath(Object value, String keyPath)
          Conformance to NSValidation
 Object validateValueForKey(Object value, String key)
          Conformance to NSValidation.
 Object valueForKey(String key)
          Conformance to NSKeyValueCoding.
 Object valueForKeyPath(String keyPath)
          Conformance to NSKeyValueCodingAdditions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WODirectAction

public WODirectAction(WORequest aRequest)
Subclasses must override to provide any additional initialization.
Parameters:
aRequest - a new context object for a given request
Method Detail

canAccessFieldsDirectly

public static boolean canAccessFieldsDirectly()
WODirectAction's implementation of this static method returns true, indicating that key-value coding is allowed to access fields in this object if an appropriate method isn't present.
Returns:
true only if key can access fields directly, false otherwise

context

public WOContext context()
Returns the current WOContext object.
Returns:
the WODirectAction's current WOContext

debugString

public static void debugString(String string)
Deprecated. use NSLog instead.

Deprecated. Use NSLog instead.
Parameters:
string - message to be logged
See Also:
NSLog

defaultAction

public WOActionResults defaultAction()
Returns a WOActionResults object that is the result of sending generateResponse() to the page named "Main".
Returns:
a WOActionResults containing the generated response.

existingSession

public WOSession existingSession()
Restores the session based on the request. If the request did not have a session ID or the session ID referred to a non-existent session, then this method returns null. To determine if a session failed to restore, check the request's session ID to see if it non-null and if so, call this method to check its result.
Returns:
a WOSession object which represents periods during which access to a WebObjects application and its resources is granted to a particular client
See Also:
session()

handleQueryWithUnboundKey

public Object handleQueryWithUnboundKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling.
Specified by:
handleQueryWithUnboundKey in interface NSKeyValueCoding.ErrorHandling
Parameters:
key - one of the attributes of the receiver's request
Returns:
can return a value, in which case that value is returned by the corresponding valueForKey invocation

handleTakeValueForUnboundKey

public void handleTakeValueForUnboundKey(Object value,
                                         String key)
Conformance to NSKeyValueCoding.ErrorHandling.
Specified by:
handleTakeValueForUnboundKey in interface NSKeyValueCoding.ErrorHandling
Parameters:
value - the property identified by key is set to this
key - identifies the property of an object

logString

public static void logString(String string)
This is simply a cover method for NSLog.err.appendln(string). You should use NSLog instead.
Parameters:
string - message to be logged
See Also:
NSLog

pageWithName

public WOComponent pageWithName(String aComponentName)
Returns the page with given name. This is equivalent to calling pageWithName on the WOApplication object.
Parameters:
aComponentName - the name of the WOComponent
Returns:
the WOComponent with the specified name

performActionNamed

public WOActionResults performActionNamed(String anActionName)
Performs the action with the specified name and returns the result of that action. The default implementation appends "Action" to anActionName and tries to invoke the resulting method name. Override this method to change how actions are dispatched.
Parameters:
anActionName - name of the action
Returns:
a WOActionResults containing the result of the direct action

request

public WORequest request()
Returns the WORequest that created this DirectAction object.
Returns:
WORequest object that started the action in the first place

session

public WOSession session()
If there is no session, this method first tries to restore the session that the request's session ID refers to. If the request has no session ID -- which is a possibility if the application is written entirely with direct actions -- this method creates a new session and returns it. If the session ID refers to a session that doesn't exist or cannot be restored, this method returns null.

This method may call WOApplication's restoreSessionWithID, which posts a SessionDidRestoreNotification. If the session does not exist or cannot be restored, the notification is posted with a null session for parameter (the only indication that a session time out has occurred), and a new session object is created.

This method may also call WOApplication's createSessionForRequest If the session can not be created, an IllegalStateException is thrown, otherwise, a SessionDidCreateNotification is posted and the new session is returned.

Returns:
the current session or null if the the session ID is incorrect
See Also:
existingSession(), WOSession.SessionDidRestoreNotification

takeFormValueArraysForKeyArray

public void takeFormValueArraysForKeyArray(NSArray aKeyArray)
Performs takeValueForKey on each key in aKeyArray using values from the receiver's request.

This method uses an NSArray for each form value. This is useful when a user can select multiple items for a form value, such as a WOBrowser. If a form value contains only one item, this method uses an NSArray with one object. To use single objects as form values use takeFormValuesForKeyArray.

Parameters:
aKeyArray - an array of keys
See Also:
takeValueForKey(Object value, String key), takeFormValuesForKeyArray(NSArray aKeyArray)

takeFormValuesForKeyArray

public void takeFormValuesForKeyArray(NSArray aKeyArray)
Performs takeValueForKey on the each key in aKeyArray using values from the receiver's request. This method uses an a single object for each form value. If a form value contains more than one item, such as a WOBrowser, this method uses the first item in the array. To use arrays of objects as form values, use takeFormValueArraysForKeyArray.
Parameters:
aKeyArray - an array of keys
See Also:
takeValueForKey(Object value, String key), takeFormValueArraysForKeyArray(NSArray aKeyArray)

takeValueForKey

public void takeValueForKey(Object value,
                            String key)
Conformance to NSKeyValueCoding.
Specified by:
takeValueForKey in interface NSKeyValueCoding
Parameters:
key - identifies the property to be set
value - the value to which the property specified by key should be set

takeValueForKeyPath

public void takeValueForKeyPath(Object value,
                                String keyPath)
Conformance to NSKeyValueCodingAdditions.
Specified by:
takeValueForKeyPath in interface NSKeyValueCodingAdditions
Parameters:
keyPath - identifies a derived property of the receiver
value - value to which the derived property identified by keyPath will be set

toString

public String toString()
Overrides:
toString in class Object
Returns:
a String representation of the receiver

unableToSetNullForKey

public void unableToSetNullForKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling.
Specified by:
unableToSetNullForKey in interface NSKeyValueCoding.ErrorHandling
Parameters:
key - one of the keys in receiver's request

validateTakeValueForKeyPath

public Object validateTakeValueForKeyPath(Object value,
                                          String keyPath)
                                   throws NSValidation.ValidationException
Conformance to NSValidation
Specified by:
validateTakeValueForKeyPath in interface NSValidation
Parameters:
value - value of receiver's request
keyPath - the string to identify each key in the keyarray
Returns:
the validated value if it's legal
Throws:
NSValidation.ValidationException - when value isn't legal

validateValueForKey

public Object validateValueForKey(Object value,
                                  String key)
                           throws NSValidation.ValidationException
Conformance to NSValidation.
Specified by:
validateValueForKey in interface NSValidation
Parameters:
value - the receiver's property named by key
key - identifies the property of an object
Returns:
the validated value if it's legal
Throws:
NSValidation.ValidationException - when value isn't legal

valueForKey

public Object valueForKey(String key)
Conformance to NSKeyValueCoding.
Specified by:
valueForKey in interface NSKeyValueCoding
Parameters:
key - identifies the property of an object
Returns:
the receiver's value for the property identified by key

valueForKeyPath

public Object valueForKeyPath(String keyPath)
Conformance to NSKeyValueCodingAdditions.
Specified by:
valueForKeyPath in interface NSKeyValueCodingAdditions
Parameters:
keyPath - identifies the derived property of an object
Returns:
receiver's value for the derived property identified by keyPath

Last updated Thu Jan 10 18:10:21 PST 2002.

Copyright © 2002 Apple Computer, Inc.