Project Wonder 5.0

er.extensions
Class ERXExtensions

java.lang.Object
  extended by er.extensions.ERXFrameworkPrincipal
      extended by er.extensions.ERXExtensions

public class ERXExtensions
extends ERXFrameworkPrincipal

Principal class of the ERExtensions framework. This class will be loaded at runtime when the ERExtensions bundle is loaded (even before the Application constructor is called) This class has a boat-load of stuff in it that will hopefully be finding better homes in the future. This class serves as the initialization point of this framework, look in the static initializer to see all the stuff that is initially setup when this class is loaded. This class also has a boat load of string, array and EOF utilities as well as the factory methods for creating editing contexts with the default delegates set.


Nested Class Summary
static class ERXExtensions.KeyValueQualifierSQLGenerationSupport
          Support class that listens for EOKeyValueQualifiers that have a selector that was registered and uses their support instead.
 
Nested classes/interfaces inherited from class er.extensions.ERXFrameworkPrincipal
ERXFrameworkPrincipal.Observer
 
Field Summary
static org.apache.log4j.Logger adaptorLogger
          logging support for the adaptor channel
protected  ERXModelGroup defaultModelGroup
          holds the default model group
static java.lang.String eoAdaptorLoggingWillChangeNotification
          Notification name, posted before EOAdaptor debug logging will change its setting.
static java.lang.String objectsWillChangeInEditingContext
          Notification name, posted before object will change in an editing context
static org.apache.log4j.Logger sharedEOadaptorLogger
          logging support for shared object loading
 
Fields inherited from class er.extensions.ERXFrameworkPrincipal
initializedFrameworks, launchingFrameworks, log
 
Constructor Summary
ERXExtensions()
           
 
Method Summary
static boolean adaptorLogging()
          Returns the current state of EOAdaptor logging.
static void addObjectToBothSidesOfPotentialRelationshipFromObjectWithKeyPath(com.webobjects.eocontrol.EOEnterpriseObject to, com.webobjects.eocontrol.EOEnterpriseObject from, java.lang.String keyPath)
          This method handles 3 different cases 1.
static void addRandomizeDirectActionURL(java.lang.StringBuffer daURL)
          This method can be used with Direct Action URLs to make sure that the browser will reload the page.
static java.lang.String addWosidFormValue(java.lang.String url, com.webobjects.appserver.WOSession s)
          Adds the session ID (wosid) for a given session to a given url.
static boolean booleanFlagOnSessionForKeyWithDefault(com.webobjects.appserver.WOSession s, java.lang.String key, boolean defaultValue)
          Retrieves a value from the session's dictionary and evaulates that object using the booleanValue method of ERXUtilities.
 void bundleDidLoad(com.webobjects.foundation.NSNotification n)
           
static byte[] bytesFromFile(java.io.File f)
          Returns the byte array for a given file.
static java.lang.String capitalize(java.lang.String s)
          Deprecated. ERXStringUtilities.capitalize()
static java.lang.String cleanString(java.lang.String newString, com.webobjects.foundation.NSArray toBeCleaneds)
          Given an initial string and an array of substrings, Removes any occurances of any of the substrings from the initial string.
static void configureAdaptorContext()
          This method is called by the delegate when the configuration file is changed.
 void configureAdaptorContext(com.webobjects.foundation.NSNotification n)
          This method is called everytime the configuration file is changed.
static void configureAdaptorContextRapidTurnAround(java.lang.Object anObserver)
          Configures the passed in observer to register a call back when the configuration file is changed.
 com.webobjects.eoaccess.EOModelGroup defaultModelGroup()
          Delegate method for the EOModelGroup class delegate.
 void editingContextDidCreate(com.webobjects.foundation.NSNotification n)
          This is needed for WO pre-5.2 when ec's were not retained by their eos.
 void finishInitialization()
          This method is called when the application has finished launching.
static void forceGC(int maxLoop)
          Forces the garbage collector to run.
static void freeProcessResources(java.lang.Process p)
          Frees all of the resources associated with a given process and then destroys the process.
static ERXSimpleHTMLFormatter htmlFormatter()
           
static void initApp(java.lang.Class applicationSubclass, java.lang.String[] args)
          Initializes your WOApplication programmatically (for use in test cases and main methods) with the assumption that the current directory is your main bundle URL.
static void initApp(java.lang.String mainBundleName, java.lang.Class applicationSubclass, java.lang.String[] args)
          Initializes your WOApplication programmatically (for use in test cases and main methods).
static void initApp(java.lang.String mainBundleName, java.net.URL mainBundleURL, java.lang.Class applicationSubclass, java.lang.String[] args)
          Initializes your WOApplication programmatically (for use in test cases and main methods).
static void initEOF(java.io.File mainBundleFolder, java.lang.String[] args)
          Initializes Wonder EOF programmatically (for use in test cases and main methods).
static void initEOF(java.io.File mainBundleFile, java.lang.String[] args, boolean assertsBundleExists)
           Initializes Wonder EOF programmatically (for use in test cases and main methods).
static void initEOF(java.io.File mainBundleFile, java.lang.String[] args, boolean assertsBundleExists, boolean assertsBundleIsWOApplicationFolder, boolean fallbackToUserDirAsBundle)
           Initializes Wonder EOF programmatically (for use in test cases and main methods).
static void initEOF(java.lang.String[] args)
          Initializes Wonder EOF programmatically (for use in test cases and main methods).
protected  void initialize()
          Configures the framework.
static int intFromParseableIntegerString(java.lang.String s)
          Returns an integer from a parsable string.
static long lastModifiedDateForFileInFramework(java.lang.String fileName, java.lang.String frameworkName)
          Deprecated. use ERXFileUtilities.lastModifiedDateForFileInFramework()
static boolean objectImplementsMethod(java.lang.Object object, java.lang.String methodName, java.lang.Class[] parameters)
          Determines if a given object implements a method given the name and the array of input parameters.
static java.lang.String plurify(java.lang.String s, int howMany, java.lang.String language)
          Deprecated. use ERXLocalizer.localizerForLanguage(language).plurifiedString(s, howMany)
static java.lang.String randomizeDirectActionURL(java.lang.String daURL)
          This method can be used with Direct Action URLs to make sure that the browser will reload the page.
static java.lang.Object readPropertyListFromFileinFramework(java.lang.String fileName, java.lang.String aFrameWorkName)
          Deprecated. use ERXFileUtilities.readPropertyListFromFileInFramework()
static java.lang.Object readPropertyListFromFileInFramework(java.lang.String fileName, java.lang.String aFrameWorkName, com.webobjects.foundation.NSArray languageList)
          Deprecated. use ERXFileUtilities.readPropertyListFromFileInFramework()
static void refreshSharedObjectsWithName(java.lang.String entityName)
          Refreshes all of the shared enterprise objects for a given shared entity, then notifies the entity's class by calling the static method sharedEntityDataWasRefreshed() if the shared entity implements it.
static void refreshSharedObjectsWithNames(com.webobjects.foundation.NSArray names)
          Refreshes all of the objects for an array of entity names.
static void registerSQLSupportForSelector(com.webobjects.foundation.NSSelector selector, com.webobjects.eoaccess.EOQualifierSQLGeneration.Support support)
           
static java.lang.String removeHTMLTagsFromString(java.lang.String s)
          Removes all of the HTML tags from a given string.
static java.lang.String resolveUnit(java.lang.String userInfoUnitString, com.webobjects.eocontrol.EOEnterpriseObject object, java.lang.String prefixKeyPath)
          Resolves a given user info unit string for a given object.
static void retainEditingContextForCurrentSession(com.webobjects.eocontrol.EOEditingContext ec)
          Retains an editing context for the current session.
static boolean safeDifferent(java.lang.Object v1, java.lang.Object v2)
          A safe different comparison method that first checks to see if either of the objects are null before comparing them with the equals method.

Note that if both objects are null then they will be considered equal.
static boolean safeEquals(java.lang.Object v1, java.lang.Object v2)
          A safe comparison method that first checks to see if either of the objects are null before comparing them with the equals method.

Note that if both objects are null then they will be considered equal.
static ERXSession session()
          Deprecated. use ERXSession.session() instead
 void sessionDidTimeOut(com.webobjects.foundation.NSNotification n)
          This method is called every time a session times out.
static void sessionDidTimeOut(java.lang.String sessionID)
          This method is called when a session times out.
static void setAdaptorLogging(boolean onOff)
          Turn EOAdaptor logging on and off.
static void setBooleanFlagOnSessionForKey(com.webobjects.appserver.WOSession s, java.lang.String key, boolean newValue)
          Uses the setObjectForKey method of the WOSession class to push a Boolean object onto the session for a given key.
static void setSession(ERXSession session)
          Deprecated. use ERXSession.setSession(session) instead
 void sharedEditingContextWasInitialized(com.webobjects.foundation.NSNotification n)
          This method is called for the following notification EOSharedEditingContext.DefaultSharedEditingContextWasInitializedNotification
static java.lang.String stringFromFile(java.io.File f)
          Returns a string from the file using the default encoding.
static java.lang.String stringFromFile(java.io.File f, java.lang.String encoding)
          Returns a string from the file using the specified encoding.
static boolean stringIsParseableInteger(java.lang.String s)
          Tests if a given string object can be parsed into an integer.
static java.lang.String substituteStringByStringInString(java.lang.String s1, java.lang.String s2, java.lang.String s)
           
static java.lang.String userInfoUnit(com.webobjects.eocontrol.EOEnterpriseObject object, java.lang.String key)
          For a given enterprise object and key path, will return what the key 'unit' returns from the userInfo dictionary of the last property of the key path's EOAttribute or EORelationship.
static java.lang.String userPreferencesKeyFromContext(java.lang.String key, com.webobjects.foundation.NSKeyValueCoding context)
          Constructs a unique key based on a context.
 
Methods inherited from class er.extensions.ERXFrameworkPrincipal
didFinishInitialization, setUpFrameworkPrincipalClass, sharedInstance, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

objectsWillChangeInEditingContext

public static final java.lang.String objectsWillChangeInEditingContext
Notification name, posted before object will change in an editing context

See Also:
Constant Field Values

eoAdaptorLoggingWillChangeNotification

public static final java.lang.String eoAdaptorLoggingWillChangeNotification
Notification name, posted before EOAdaptor debug logging will change its setting.

See Also:
Constant Field Values

defaultModelGroup

protected volatile ERXModelGroup defaultModelGroup
holds the default model group


adaptorLogger

public static org.apache.log4j.Logger adaptorLogger
logging support for the adaptor channel


sharedEOadaptorLogger

public static org.apache.log4j.Logger sharedEOadaptorLogger
logging support for shared object loading

Constructor Detail

ERXExtensions

public ERXExtensions()
Method Detail

defaultModelGroup

public com.webobjects.eoaccess.EOModelGroup defaultModelGroup()
Delegate method for the EOModelGroup class delegate.

Returns:
a fixed ERXModelGroup

initialize

protected void initialize()
Configures the framework. All the bits and pieces that need to be configured are configured, those that need to happen later are delayed by registering an observer for notifications that are posted when the application is finished launching. This public observer is used to perform basic functions in response to notifications. Specifically it handles configuring the adapator context so that SQL debugging can be enabled and disabled on the fly throgh the log4j system. Handling cleanup issues when sessions timeout, i.e. releasing all references to editing contexts created for that session. Handling call all of the did* methods on ERXGenericRecord subclasses after an editing context has been saved. This delegate is also responsible for configuring the ERXCompilerProxy and ERXValidationFactory. This delegate is configured when this framework is loaded.

Overrides:
initialize in class ERXFrameworkPrincipal

bundleDidLoad

public void bundleDidLoad(com.webobjects.foundation.NSNotification n)

finishInitialization

public void finishInitialization()
This method is called when the application has finished launching. Here is where log4j is configured for rapid turn around and the validation template system is configured.

Specified by:
finishInitialization in class ERXFrameworkPrincipal

registerSQLSupportForSelector

public static void registerSQLSupportForSelector(com.webobjects.foundation.NSSelector selector,
                                                 com.webobjects.eoaccess.EOQualifierSQLGeneration.Support support)

configureAdaptorContext

public void configureAdaptorContext(com.webobjects.foundation.NSNotification n)
This method is called everytime the configuration file is changed. This allows for turning SQL debuging on and off at runtime.

Parameters:
n - notification posted when the configuration file changes.

sessionDidTimeOut

public void sessionDidTimeOut(com.webobjects.foundation.NSNotification n)
This method is called every time a session times out. It allows us to release references to all the editing contexts that were created when that particular session was active. Not used in WO 5.2+

Parameters:
n - notification that contains the session ID.

editingContextDidCreate

public void editingContextDidCreate(com.webobjects.foundation.NSNotification n)
This is needed for WO pre-5.2 when ec's were not retained by their eos. Not called in 5.2+ systems.

Parameters:
n - notification posted when an ec is created

sharedEditingContextWasInitialized

public void sharedEditingContextWasInitialized(com.webobjects.foundation.NSNotification n)
This method is called for the following notification EOSharedEditingContext.DefaultSharedEditingContextWasInitializedNotification

Parameters:
n - the notification.

configureAdaptorContextRapidTurnAround

public static void configureAdaptorContextRapidTurnAround(java.lang.Object anObserver)
Configures the passed in observer to register a call back when the configuration file is changed. This allows one to change a logger's setting and have that changed value change the NSLog setting to log the generated SQL. This method is called as part of the framework initialization process.

Parameters:
anObserver - object to register the call back with.

configureAdaptorContext

public static void configureAdaptorContext()
This method is called by the delegate when the configuration file is changed. It's sole purpose is to map a logging logger to a debug group. Hopefully in the future we will have a more generic solution.


adaptorLogging

public static boolean adaptorLogging()
Returns the current state of EOAdaptor logging.


setAdaptorLogging

public static void setAdaptorLogging(boolean onOff)
Turn EOAdaptor logging on and off.

Parameters:
onOff -

sessionDidTimeOut

public static void sessionDidTimeOut(java.lang.String sessionID)
This method is called when a session times out. Calling this method will release references to all editing contexts that were created when this session was active. This method is only called in pre-WO 5.2 versions of WebObjects.

Parameters:
sessionID - of the session that timed out

retainEditingContextForCurrentSession

public static void retainEditingContextForCurrentSession(com.webobjects.eocontrol.EOEditingContext ec)
Retains an editing context for the current session. This is only needed or used for versions of WO pre-5.2. If you use ERXEC to create your editing contexts then you never need to call this method yourself.

Parameters:
ec - to be retained.

removeHTMLTagsFromString

public static java.lang.String removeHTMLTagsFromString(java.lang.String s)
Removes all of the HTML tags from a given string. Note: this is a very simplistic implementation and will most likely not work with complex HTML. Note: for actual conversion of HTML tags into regular strings have a look at ERXSimpleHTMLFormatter

Parameters:
s - html string
Returns:
string with all of its html tags removed

forceGC

public static void forceGC(int maxLoop)
Forces the garbage collector to run. The max loop parameter determines the maximum number of times to run the garbage collector if the memory footprint is still going down. In normal cases you would just need to call this method with the parameter 1. If called with the parameter 0 the garbage collector will continue to run until no more free memory is available to collect.

Note: This can be a very costly operation and should only be used in extreme circumstances.

Parameters:
maxLoop - maximum times to run the garbage collector. Passing in 0 will cause the collector to run until all free objects have been collected.

capitalize

public static java.lang.String capitalize(java.lang.String s)
Deprecated. ERXStringUtilities.capitalize()

Capitalizes the given string.

Parameters:
s - string to capitalize
Returns:
capitalized string if the first char is a lowercase character.

plurify

public static java.lang.String plurify(java.lang.String s,
                                       int howMany,
                                       java.lang.String language)
Deprecated. use ERXLocalizer.localizerForLanguage(language).plurifiedString(s, howMany)

Pluralizes a given string for a given language. See ERXLocalizer for more information.

Parameters:
s - string to pluralize
howMany - number of its
language - target language
Returns:
plurified string

safeEquals

public static boolean safeEquals(java.lang.Object v1,
                                 java.lang.Object v2)
A safe comparison method that first checks to see if either of the objects are null before comparing them with the equals method.

Note that if both objects are null then they will be considered equal.

Parameters:
v1 - first object
v2 - second object
Returns:
true if they are equal, false if not

safeDifferent

public static boolean safeDifferent(java.lang.Object v1,
                                    java.lang.Object v2)
A safe different comparison method that first checks to see if either of the objects are null before comparing them with the equals method.

Note that if both objects are null then they will be considered equal.

Parameters:
v1 - first object
v2 - second object
Returns:
treu if they are not equal, false if they are

stringIsParseableInteger

public static boolean stringIsParseableInteger(java.lang.String s)
Tests if a given string object can be parsed into an integer.

Parameters:
s - string to be parsed
Returns:
if the string can be parsed into an int

intFromParseableIntegerString

public static int intFromParseableIntegerString(java.lang.String s)
Returns an integer from a parsable string. If the string can not be parsed then 0 is returned.

Parameters:
s - string to be parsed.
Returns:
int from the string or 0 if un-parsable.

substituteStringByStringInString

public static java.lang.String substituteStringByStringInString(java.lang.String s1,
                                                                java.lang.String s2,
                                                                java.lang.String s)

htmlFormatter

public static ERXSimpleHTMLFormatter htmlFormatter()

addObjectToBothSidesOfPotentialRelationshipFromObjectWithKeyPath

public static void addObjectToBothSidesOfPotentialRelationshipFromObjectWithKeyPath(com.webobjects.eocontrol.EOEnterpriseObject to,
                                                                                    com.webobjects.eocontrol.EOEnterpriseObject from,
                                                                                    java.lang.String keyPath)
This method handles 3 different cases 1. keyPath is a single key and represents a relationship --> addObjectToBothSidesOfRelationshipWithKey 2. keyPath is a single key and does NOT represents a relationship 3. keyPath is a real key path: break it up, navigate to the last atom --> back to 1. or 2.

Parameters:
to - enterprise object that is having objects added to it
from - enterprise object that is providing the objects
keyPath - that specifies the relationship on the to object to add the objects to.

bytesFromFile

public static byte[] bytesFromFile(java.io.File f)
                            throws java.io.IOException
Returns the byte array for a given file.

Parameters:
f - file to get the bytes from
Returns:
byte array of the file.
Throws:
java.io.IOException - if things go wrong

stringFromFile

public static java.lang.String stringFromFile(java.io.File f)
                                       throws java.io.IOException
Returns a string from the file using the default encoding.

Parameters:
f - file to read
Returns:
string representation of that file.
Throws:
java.io.IOException

stringFromFile

public static java.lang.String stringFromFile(java.io.File f,
                                              java.lang.String encoding)
                                       throws java.io.IOException
Returns a string from the file using the specified encoding.

Parameters:
f - file to read
encoding - to be used, null will use the default
Returns:
string representation of the file.
Throws:
java.io.IOException

lastModifiedDateForFileInFramework

public static long lastModifiedDateForFileInFramework(java.lang.String fileName,
                                                      java.lang.String frameworkName)
Deprecated. use ERXFileUtilities.lastModifiedDateForFileInFramework()

Determines the last modification date for a given file in a framework. Note that this method will only test for the global resource not the localized resources.

Parameters:
fileName - name of the file
frameworkName - name of the framework, null or "app" for the application bundle
Returns:
the lastModified method of the file object

readPropertyListFromFileinFramework

public static java.lang.Object readPropertyListFromFileinFramework(java.lang.String fileName,
                                                                   java.lang.String aFrameWorkName)
Deprecated. use ERXFileUtilities.readPropertyListFromFileInFramework()

Reads a file in from the file system and parses it as if it were a property list.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
Returns:
de-serialized object from the plist formatted file specified.

readPropertyListFromFileInFramework

public static java.lang.Object readPropertyListFromFileInFramework(java.lang.String fileName,
                                                                   java.lang.String aFrameWorkName,
                                                                   com.webobjects.foundation.NSArray languageList)
Deprecated. use ERXFileUtilities.readPropertyListFromFileInFramework()

Reads a file in from the file system for the given set of languages and parses the file as if it were a property list.

Parameters:
fileName - name of the file
aFrameWorkName - name of the framework, null or 'app' for the application bundle.
languageList - language list search order
Returns:
de-serialized object from the plist formatted file specified.

userInfoUnit

public static java.lang.String userInfoUnit(com.webobjects.eocontrol.EOEnterpriseObject object,
                                            java.lang.String key)
For a given enterprise object and key path, will return what the key 'unit' returns from the userInfo dictionary of the last property of the key path's EOAttribute or EORelationship. The userInfo dictionary can be edited via EOModeler, it is that open book looking icon when looking at either an attribute or relationship.

For example if the userInfo dictionary or the attribute 'speed' on the entity Car contained the key-value pair unit=mph, then this method would be able to resolve that unit given either of these keypaths:
userInfoUnit(aCar, "speed");
userInfoUnit(aDrive, "toCar.speed");

Units can be very useful for adding meta information to particular attributes and relationships in models. The ERDirectToWeb framework adds support for displaying units.

Parameters:
object - to resolve the key-path from
key - path off of the object
Returns:
unit information stored in the userInfo dictionary

resolveUnit

public static java.lang.String resolveUnit(java.lang.String userInfoUnitString,
                                           com.webobjects.eocontrol.EOEnterpriseObject object,
                                           java.lang.String prefixKeyPath)
Resolves a given user info unit string for a given object. User info values are stored in an EOAttibute or EORelationship's userInfo dictionary. See the method userInfoUnit for a better description of getting values out of the userInfo dictionary. This method deals with resolving dynamic userInfo keys. These keys need to start with the '@@' symbol. For instance if you have the user info value '@unit' off of an attribute for the entity Movie, then you can either pass in a Movie object or a different object with a prefix key path to a movie object.

Parameters:
userInfoUnitString - string to be resolved, needs to start with '@@'. This keypath will be evaluated against either the object if no prefixKeyPath is specified or the object returned by the prefixKeyPath being evaluated against the object passed in.
object - to resolve either the user info unit or the prefixKeyPath.
prefixKeyPath - used as a prefix for the unit resolution.
Returns:
the resolved unit from the object.

refreshSharedObjectsWithNames

public static void refreshSharedObjectsWithNames(com.webobjects.foundation.NSArray names)
Refreshes all of the objects for an array of entity names.

Parameters:
names - array of shared entity names

refreshSharedObjectsWithName

public static void refreshSharedObjectsWithName(java.lang.String entityName)
Refreshes all of the shared enterprise objects for a given shared entity, then notifies the entity's class by calling the static method sharedEntityDataWasRefreshed() if the shared entity implements it.

Parameters:
entityName - name of the shared entity

randomizeDirectActionURL

public static java.lang.String randomizeDirectActionURL(java.lang.String daURL)
This method can be used with Direct Action URLs to make sure that the browser will reload the page. This is done by adding the parameter [? | &]r=random_number to the end of the url.

Parameters:
daURL - a url to add the randomization to.
Returns:
url with the addition of the randomization key

addRandomizeDirectActionURL

public static void addRandomizeDirectActionURL(java.lang.StringBuffer daURL)
This method can be used with Direct Action URLs to make sure that the browser will reload the page. This is done by adding the parameter [? | &]r=random_number to the end of the url.

Parameters:
daURL - a url to add the randomization to.

addWosidFormValue

public static java.lang.String addWosidFormValue(java.lang.String url,
                                                 com.webobjects.appserver.WOSession s)
Adds the session ID (wosid) for a given session to a given url.

Parameters:
url - to add wosid form value to.
Returns:
url with the addition of wosid form value

cleanString

public static java.lang.String cleanString(java.lang.String newString,
                                           com.webobjects.foundation.NSArray toBeCleaneds)
Given an initial string and an array of substrings, Removes any occurances of any of the substrings from the initial string. Used in conjunction with fuzzy matching.

Parameters:
newString - initial string from which to remove other strings
toBeCleaneds - array of substrings to be removed from the initial string.
Returns:
cleaned string.

setBooleanFlagOnSessionForKey

public static void setBooleanFlagOnSessionForKey(com.webobjects.appserver.WOSession s,
                                                 java.lang.String key,
                                                 boolean newValue)
Uses the setObjectForKey method of the WOSession class to push a Boolean object onto the session for a given key. Note this is not using key value coding, meaning you don't need to have a boolean instance variable corresponding to the given key on your session object. This flag can be retrieved using the method booleanFlagOnSessionForKeyWithDefault.

Parameters:
s - session object on which to set the boolean flag
key - to be used in the session's dictionary
newValue - boolean value to be set on the session

booleanFlagOnSessionForKeyWithDefault

public static boolean booleanFlagOnSessionForKeyWithDefault(com.webobjects.appserver.WOSession s,
                                                            java.lang.String key,
                                                            boolean defaultValue)
Retrieves a value from the session's dictionary and evaulates that object using the booleanValue method of ERXUtilities. If there is no object corresponding to the key passed in, then the default value is returned. The usual way in which boolean values are set on the session object is by using the method setBooleanFlagOnSessionForKey in this class.

Parameters:
s - session object to retrieve the boolean flag from
key - that the boolean is stored under
defaultValue - value to be returned if the object in the dictionary is null
Returns:
boolean value of the object stored in the session's dictionary for the given key.

setSession

public static void setSession(ERXSession session)
Deprecated. use ERXSession.setSession(session) instead

Sets the current session for this thread. This is called from ERXSession's awake and sleep methods.

Parameters:
session - that is currently active for this thread.

session

public static ERXSession session()
Deprecated. use ERXSession.session() instead

Returns the current session object for this thread.

Returns:
current session object for this thread

userPreferencesKeyFromContext

public static java.lang.String userPreferencesKeyFromContext(java.lang.String key,
                                                             com.webobjects.foundation.NSKeyValueCoding context)
Constructs a unique key based on a context. A method used by the preferences mechanism from ERDirectToWeb which needs to be here because it is shared by ERDirectToWeb and ERCoreBusinessLogic.

Parameters:
key - preference key
context - most likely a d2wContext object
Returns:
a unique preference key for storing and retriving preferences

freeProcessResources

public static void freeProcessResources(java.lang.Process p)
Frees all of the resources associated with a given process and then destroys the process.

Parameters:
p - process to destroy

objectImplementsMethod

public static boolean objectImplementsMethod(java.lang.Object object,
                                             java.lang.String methodName,
                                             java.lang.Class[] parameters)
Determines if a given object implements a method given the name and the array of input parameters. Note that this doesn't quite check the method signature since the method return type is not checked.

Parameters:
object - to determine if it implements a method
methodName - name of the method
parameters - array of parameters
Returns:
if the object implements a method with the given name and class parameters

initApp

public static void initApp(java.lang.Class applicationSubclass,
                           java.lang.String[] args)
Initializes your WOApplication programmatically (for use in test cases and main methods) with the assumption that the current directory is your main bundle URL.

Parameters:
applicationSubclass - your Application subclass
args - the commandline arguments for your application

initApp

public static void initApp(java.lang.String mainBundleName,
                           java.lang.Class applicationSubclass,
                           java.lang.String[] args)
Initializes your WOApplication programmatically (for use in test cases and main methods).

Parameters:
mainBundleName - the name of your main bundle
applicationSubclass - your Application subclass
args - the commandline arguments for your application

initApp

public static void initApp(java.lang.String mainBundleName,
                           java.net.URL mainBundleURL,
                           java.lang.Class applicationSubclass,
                           java.lang.String[] args)
Initializes your WOApplication programmatically (for use in test cases and main methods).

Parameters:
mainBundleName - the name of your main bundle (or null to use mainBundleURL)
mainBundleURL - the URL to your main bundle (ignored if mainBundleName is set)
applicationSubclass - your Application subclass
args - the commandline arguments for your application

initEOF

public static void initEOF(java.lang.String[] args)
Initializes Wonder EOF programmatically (for use in test cases and main methods). You do not need to call this method if you already called initApp. This is lighter-weight than initApp, and tries to just get enough configured to make EOF work properly. This method assumes you are running your app from a .woa folder.

This is equivalent to calling initEOF(new File("."), args).

Parameters:
args - the commandline arguments for your application
Throws:
java.lang.IllegalArgumentException - if the current dir or mainBundleFolder is not a *.woa bundle.

initEOF

public static void initEOF(java.io.File mainBundleFolder,
                           java.lang.String[] args)
Initializes Wonder EOF programmatically (for use in test cases and main methods). You do not need to call this method if you already called initApp. This is lighter-weight than initApp, and tries to just get enough configured to make EOF work properly.

This is equivalent to calling initEOF(mainBundleFolder, args, true, true, true).

Parameters:
mainBundleFolder - the folder of your main bundle
args - the commandline arguments for your application
Throws:
java.lang.IllegalArgumentException - if the current dir or mainBundleFolder is not a *.woa bundle.

initEOF

public static void initEOF(java.io.File mainBundleFile,
                           java.lang.String[] args,
                           boolean assertsBundleExists)

Initializes Wonder EOF programmatically (for use in test cases and main methods). You do not need to call this method if you already called initApp. This is lighter-weight than initApp, and tries to just get enough configured to make EOF work properly. This method is also, unlike initEOF(String[]) or initEOF(File, String[]), not so restrictive as to require the name of the bundle be a *.woa, and nor does it require *.framework as the name of the bundle.

It can therefore be useful for, and used with, folder, jar or war bundles -- whichever bundle is referenced by mainBundleURI -- so long as it is bundle-like in content rather than by name. For NSBundle, this usually just requires a Resources folder within the bundle.

For example, if you're build tool compiles sources and puts Resources under target/classes you can call this method via ERXExtensions.initEOF(new File(projectDir, "target/classes"), args, true).

Note 1: this will set the system property webobjects.user.dir to the canonical path of the given bundle uri if, and only if, the bundle uri points to a directory and is schema is file.

Note 2: this will set NSBundle's mainBundle to the referenced bundle loaded via ERXRuntimeUtilities#loadBundleIfNeeded(URI) if found.

This is equivalent to calling initEOF(mainBundleFolder, args, assertsBundleExists, false, true).

Parameters:
mainBundleFile - the archive file or directory of your main bundle
args - the commandline arguments for your application
assertsBundleExists - ensures that the bundle exists and is loaded
Throws:
com.webobjects.foundation.NSForwardException - if the given bundle doesn't satisfy the given assertions or ERXRuntimeUtilities.loadBundleIfNeeded or ERXApplication.setup fails.
See Also:
initEOF(File, String[], boolean, boolean, boolean)

initEOF

public static void initEOF(java.io.File mainBundleFile,
                           java.lang.String[] args,
                           boolean assertsBundleExists,
                           boolean assertsBundleIsWOApplicationFolder,
                           boolean fallbackToUserDirAsBundle)

Initializes Wonder EOF programmatically (for use in test cases and main methods). You do not need to call this method if you already called initApp. This is lighter-weight than initApp, and tries to just get enough configured to make EOF work properly. This method is also, unlike initEOF(String[]) or initEOF(File, String[]), not so restrictive as to require the name of the bundle be a *.woa, and nor does it require *.framework as the name of the bundle.

It can therefore be useful for, and used with, folder, jar or war bundles -- whichever bundle is referenced by mainBundleURI -- so long as it is bundle-like in content rather than by name. For NSBundle, this usually just requires a Resources folder within the bundle.

For example, if you're build tool compiles sources and puts Resources under target/classes you can call this method via ERXExtensions.initEOF(new File(projectDir, "target/classes").toURI(), args).

Note 1: this will set the system property webobjects.user.dir to the canonical path of the given bundle uri if, and only if, the bundle uri points to a directory and is schema is file.

Note 2: this will set NSBundle's mainBundle to the referenced bundle loaded via ERXRuntimeUtilities#loadBundleIfNeeded(URI) if found.

Parameters:
mainBundleFile - the archive file or directory of your main bundle
args - the commandline arguments for your application
assertsBundleExists - ensures that the bundle exists and is loaded
assertsBundleIsWOApplicationFolder - ensures that the bundle referenced by mainBundleFile, or the current dir if fallbackToUserDirAsBundle is true, is a *.woa bundle folder.
fallbackToUserDirAsBundle - falls back to current dir if the mainBundleFile does not exist
Throws:
com.webobjects.foundation.NSForwardException - if the given bundle doesn't satisfy the given assertions or ERXRuntimeUtilities.loadBundleIfNeeded or ERXApplication.setup fails.
See Also:
ERXRuntimeUtilities#loadBundleIfNeeded(URI), NSBundle._setMainBundle(NSBundle), ERXApplication#setup(String[]), bundleDidLoad(NSNotification)

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.