wt.prefs
Class PreferenceHelper

java.lang.Object
  extended bywt.prefs.PreferenceHelper

public class PreferenceHelper
extends Object

The PreferenceHelper class may be used by both the client and server for obtaining utlity and helper methods for the Preferences Framework. This includes the creation of Edit and Search Context Masks, and translating contexts.

The methods of this class ( createEditMask() and createContextMask() ) replace those found in the PrefsUtil class.

This class is safe to provide to the client and will be able to communicate with a Windchill Method Server over RMI if client side communication is required.

To assist in the usage of the Preferences Framework, the helper creation context methods will return context masks in the form as defined below. It is important to ensure any code utilizes the correct context in order to be 'well-formed' in a multi-level preference heirarchy.

Context Mask Format

The form of the context mask will be in a String Array using the following order: (order from 1 (top) to bottom in the Preference Heirarchy )



Supported API: true

See Also:
WTPreferences, PreferenceDelegate, UserDelegate

Field Summary
private static boolean DEBUG
           
private static RemoteMethodServer server
          Static method server instance used for the client
 
Constructor Summary
PreferenceHelper()
           
 
Method Summary
static String[] createContextMask()
          This method will create a Context Mask for the current logged in user.
static String[] createContextMask(String division)
          This method will create a Context Mask for the current logged in user.
static String[] createContextMask(String aContainer, String division)
          This method will create a Context Mask for the current logged in user.
static String[] createContextMask(String aDivision, WTUser aUser)
          This method will create a Context Mask for the named user.
static String[] createContextMask(WTContainerRef aContainer, String aDivision, WTUser aUser)
          This method will create a Context Mask for the named user.
static String createEditMask()
          This method will attempt to create the Edit Mask for the current user.
static String createEditMask(String division, boolean policy)
          This method will attempt to create the Edit Mask for the current user at a given division node in the Heirarchy.
static String createEditMask(String division, WTUser aUser, boolean policy)
          This method will attempt to create the Edit Mask for a given user at a given division node in the Heirarchy.
static String createEditMask(WTContainerRef aContainer, WTUser aUser, boolean policy)
          This method will attempt to create the Edit Mask for a given user at the given container node in the Heirarchy.
static String createFullyQualifiedPreferenceName(String aNode, String aKey)
          This method will create a full path name attribute from a Parent, Node and Key much like the Database view.
static String createFullyQualifiedPreferenceName(String aParent, String aNode, String aKey)
          This method will create a full path name attribute from a Parent, Node and Key much like the Database view.
static String getDisplayNameFromContext(String aContext, Locale aLocale)
          This method will access the delegate for the given context and return the localized string the represents that context within the delegate.
static String[] getDivisionsAsAdministrator()
          This method will return the divisions that the user can administer from the current sesssion context.
static String[] getDivisionsAsAdministrator(String aContainer)
          This method will return the divisions that the session's user can administer from the list of all the delegates in the current heirarchy.
static String[] getDivisionsAsAdministrator(WTContainerRef aContainer)
          This method will return the divisions that the session's user can administer from the list of all the delegates in the current heirarchy.
static String[] getDivisionsAsAdministrator(WTContainerRef aContainer, WTUser user)
          This method will return the divisions that the named user can administer from the list of all the delegates in the current heirarchy.
static String[] getDivisionsAsAdministrator(WTUser user)
          This method will return the divisions that the named user can administer from the list of all the delegates in the current heirarchy.
static HashMap getNodeValues(Preferences pref)
          This method will return a hashmap of key/value pairs for the given Preferences node.
static long getTimeOutInterval()
          

Supported API: false
protected static String joinContextUser(String context, String user)
           
private static void main(String[] args)
           
static void setTimeOutInterval(long time)
          This method will set the timeout interval for the delegate list in Method Server.
static String splitContext(String aContext)
          

Supported API: false
protected static String transformContext(String context)
          Performs transformations on context Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false
protected static String[] transformContext(String[] context)
          Performs transformations on context array Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false
protected static String transformContext(String context, String user)
          Performs transformations on context Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false
static String untransformContext(String aContext)
          This method will take a qualified context such as WTPreferences.USER_CONTEXT or WTPreferences.DIVISION_CONTEXT:Some Division and return the String representation fo the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

private static RemoteMethodServer server
Static method server instance used for the client


DEBUG

private static boolean DEBUG
Constructor Detail

PreferenceHelper

public PreferenceHelper()
Method Detail

getDisplayNameFromContext

public static String getDisplayNameFromContext(String aContext,
                                               Locale aLocale)
                                        throws WTException
This method will access the delegate for the given context and return the localized string the represents that context within the delegate.

NOTE: If the context is a WTPreferences.DIVISION_CONTEXT or WTPreferences.DIVISION_POLICY_CONTEXT, the Macro constant will be stripped before being sent to the delegate. Both a fully defined context (one that has a WTPreferences.DIVISION_CONTEXT) or a delegate context (just the name of the division) are valid parameters.

Supported API: true

Parameters:
aLocale - The locale of the current browser
aContext - The context name or Division to localize.
Returns:
String The display name or empty is no name was found.
Throws:
WTException

getTimeOutInterval

public static long getTimeOutInterval()


Supported API: false


setTimeOutInterval

public static void setTimeOutInterval(long time)
This method will set the timeout interval for the delegate list in Method Server.

Supported API: false

Parameters:
time - The time in milliseconds for the timeout to be set too.

getDivisionsAsAdministrator

public static String[] getDivisionsAsAdministrator(WTUser user)
This method will return the divisions that the named user can administer from the list of all the delegates in the current heirarchy.

Supported API: true

Parameters:
user - The user which wants administration rights.
Returns:
String[] The array of Divisions which are administerable.

getDivisionsAsAdministrator

public static String[] getDivisionsAsAdministrator(WTContainerRef aContainer,
                                                   WTUser user)
This method will return the divisions that the named user can administer from the list of all the delegates in the current heirarchy. For container delegate, the named container aContainer and its ancestors will be checked for administrative rights of the user.

Supported API: true

Parameters:
aContainer - The container to check adminitrative rights (for container delegate)
user - The user which wants administration rights.
Returns:
String[] The array of Divisions which are administerable.

getDivisionsAsAdministrator

public static String[] getDivisionsAsAdministrator(WTContainerRef aContainer)
This method will return the divisions that the session's user can administer from the list of all the delegates in the current heirarchy. For container delegate, the named container aContainer and its ancestors will be checked for administrative rights of the user.

Supported API: true

Parameters:
aContainer - The container to check adminitrative rights for the current session's user (for container delegate)
Returns:
String[] The array of Divisions which are administerable.

getDivisionsAsAdministrator

public static String[] getDivisionsAsAdministrator()
This method will return the divisions that the user can administer from the current sesssion context. The user is obtained from the Session on the MethodServer via the SessionHelper.

Supported API: true

Returns:
String[] Array of Divisions which are administerable.

getDivisionsAsAdministrator

public static String[] getDivisionsAsAdministrator(String aContainer)
This method will return the divisions that the session's user can administer from the list of all the delegates in the current heirarchy. For container delegate, the named container aContainer and its ancestors will be checked for administrative rights of the user.

Supported API: true

Parameters:
aContainer - Reference String of the container to check adminitrative rightsfor the current session's user (for container delegate)
Returns:
String[] The array of Divisions which are administerable.

createEditMask

public static final String createEditMask()
This method will attempt to create the Edit Mask for the current user. With this context, a call to

Will edit a preference at the user level upon a



Supported API: true

Returns:
String The correct Edit Mask

createEditMask

public static String createEditMask(String division,
                                    boolean policy)
This method will attempt to create the Edit Mask for the current user at a given division node in the Heirarchy. If the user can not administrate preferences at that division (ie. edit the value) then this method will return a null String. If the user is a valid user to edit at this level, then the correct context will be returned. With this context, a call to

Will edit a preference at this level upon a



Supported API: true

Parameters:
division - The division node in the heirarchy that is to be edited.
policy - Whether the Editmask is a policy (WTPreferences.DIVISION_POLICY_CONTEXT)
Returns:
String The correct Edit Mask or null if the user can not edit the value at this division node.

createEditMask

public static String createEditMask(String division,
                                    WTUser aUser,
                                    boolean policy)
This method will attempt to create the Edit Mask for a given user at a given division node in the Heirarchy. If the user can not administrate preferences at that division (ie. edit the value) then this method will return a null String. If the user is a valid user to edit at this level, then the correct context will be returned. With this context, a call to

Will edit a preference at this level upon a



Supported API: true

Parameters:
division - The division node in the heirarchy that is to be edited.
aUser - The user requesting editing permissions.
policy - Whether the Editmask is a policy (WTPreferences.DIVISION_POLICY_CONTEXT)
Returns:
String The correct Edit Mask or null if the user can not edit the value at this division node.

createEditMask

public static String createEditMask(WTContainerRef aContainer,
                                    WTUser aUser,
                                    boolean policy)
This method will attempt to create the Edit Mask for a given user at the given container node in the Heirarchy. If the user can not administrate preferences at that container (ie. edit the value) then this method will return a null String. If the user is a valid user to edit at this level, then the correct context will be returned. * With this context, a call to

Will edit a preference at this level upon a



Supported API: true

Parameters:
aContainer - The container in the heirarchy that is to be edited.
aUser - The user requesting editing permissions.
policy - Whether the Editmask is a policy (WTPreferences.CONTAINER_POLICY_CONTEXT)
Returns:
String The correct Edit Mask or null if the user can not edit the value at this container.

createContextMask

public static String[] createContextMask(String division)
This method will create a Context Mask for the current logged in user. The mask that is created with the named division being taken in precedence over the normal ordering of the context mask. For example, if the normal order was:

and Division.1 was passed in as the division parameter then the new order would be

Please see Context Mask Format for details on the proper format of the context mask.

Supported API: true

Parameters:
division - The division to take higher priority
Returns:
String[] array of contexts in the order above.

createContextMask

public static String[] createContextMask(String aContainer,
                                         String division)
This method will create a Context Mask for the current logged in user. The mask that is created with the named division being taken in precedence over the normal ordering of the context mask. For example, if the normal order was:

and Division.1 was passed in as the division parameter then the new order would be

Please see Context Mask Format for details on the proper format of the context mask.

Supported API: true

Parameters:
aContainer - The container string to create the hierarchy for
division - The division to take higher priority
Returns:
String[] array of contexts in the order above.

createContextMask

public static String[] createContextMask(String aDivision,
                                         WTUser aUser)
This method will create a Context Mask for the named user. The mask that is created, if a fully expanded context mask (except for the WTPreferences.USER_CONTEXT which is expanded during Preferences calls). The mask will have a proper heirarchy list for a given user.

The mask that is created with the named division being taken in precedence over the normal ordering of the context mask. For example, if the normal order was:

and Division.1 was passed in as the division parameter then the new order would be

Please see Context Mask Format for details on the proper format of the context mask.

Supported API: true

@param aUser The user to create the mask for.

Parameters:
aDivision - The division to create the Context Mask with.
Returns:
String[] array of contexts in the order above.

createContextMask

public static String[] createContextMask(WTContainerRef aContainer,
                                         String aDivision,
                                         WTUser aUser)
This method will create a Context Mask for the named user. The mask that is created, if a fully expanded context mask (except for the WTPreferences.USER_CONTEXT which is expanded during Preferences calls). The mask will have a proper heirarchy list for a given user.

The mask that is created with the named division being taken in precedence over the normal ordering of the context mask. For example, if the normal order was:

and Division.1 was passed in as the container parameter then the new order would be

Please see Context Mask Format for details on the proper format of the context mask.

Supported API: true

Parameters:
aContainer - The container to create the context mask with, for container delegate.
aDivision - The preferred division to create the Context Mask with.
aUser - The user to create the mask for.
Returns:
String[] array of contexts in the order above.

createContextMask

public static String[] createContextMask()
This method will create a Context Mask for the current logged in user. The mask that is created, if a fully expanded context mask (except for the WTPreferences.USER_CONTEXT which is expanded during Preferences calls). The mask will have a proper heirarchy list for a given user. The user is taken from the current session context managed on the Method Server.

Please see Context Mask Format for details on the proper format of the context mask.



Supported API: true

Returns:
String[] array of contexts in the order above.
See Also:
PreferenceHelper

transformContext

protected static String transformContext(String context)
Performs transformations on context Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false

Parameters:
context - The context to convert
Returns:
The converted context

transformContext

protected static String transformContext(String context,
                                         String user)
Performs transformations on context Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false

Parameters:
context - The context to convert
user - The string user to append
Returns:
The converted context

joinContextUser

protected static String joinContextUser(String context,
                                        String user)

transformContext

protected static String[] transformContext(String[] context)
Performs transformations on context array Transforms WTPreferences.USER_CONTEXT to WTPreferences.USER_CONTEXT + identity

Supported API: false

Parameters:
context - An array of contexts to convert.
Returns:
The array of converted contexts.

untransformContext

public static final String untransformContext(String aContext)
This method will take a qualified context such as WTPreferences.USER_CONTEXT or WTPreferences.DIVISION_CONTEXT:Some Division and return the String representation fo the context. For example, stripping either a WTPreferences.USER_CONTEXT or WTPreferences.DEFAULT_CONTEXT will return that constant context, however stripping a WTPreferences.DIVISION_CONTEXT or WTPreferences.DIVISION_POLICY_CONTEXT will result in just the name portion of the context (in the above example "Some Division").

Supported API: false

Parameters:
aContext - The fully macro-defined context.
Returns:
The reduced (unexpanded) context name.

getNodeValues

public static HashMap getNodeValues(Preferences pref)
This method will return a hashmap of key/value pairs for the given Preferences node. If the default value used in the get( ) method is null, therefore any value that contains a null should be assumed to have used the default, indicating the value does not exist.

Note: The contextMask should be set first using the PrefsUtil.createContextMask( ) method to ensure that the Preference node will be searched using the proper context.



Supported API: false

Parameters:
pref - The preference node.
Returns:
the HashMap containing the key/value pairs of preference values. The map may be empty.

splitContext

public static final String splitContext(String aContext)


Supported API: false


createFullyQualifiedPreferenceName

public static final String createFullyQualifiedPreferenceName(String aNode,
                                                              String aKey)
This method will create a full path name attribute from a Parent, Node and Key much like the Database view.

Supported API: false

Parameters:
aNode - The preference node
aKey - The preference key
Returns:
The full path name

createFullyQualifiedPreferenceName

public static String createFullyQualifiedPreferenceName(String aParent,
                                                        String aNode,
                                                        String aKey)
This method will create a full path name attribute from a Parent, Node and Key much like the Database view.

Supported API: false

Parameters:
aParent - The parent preference
aNode - The preference node
aKey - The preference key
Returns:
The full path name

main

private static void main(String[] args)