com.pega.pegarules.pub.util
Class PerThreadCache

java.lang.Object
  extended by com.pega.pegarules.pub.util.PerThreadCache
Direct Known Subclasses:
PRDateFormat, PRNumberFormat

public abstract class PerThreadCache
extends java.lang.Object

PerThreadCache Abstract class that implements a a cache of objects maintained in ThreadLocal storage. Intended for use with Format and TimeZone objects for dates, times, numbers since these are inherently not thread-safe.

Uses a two-level map, initially keyed by Locale and then by a String naming a specific instance. If the requested element does not exist, a subclassing method is called to construct the object so that it can be cached.

Some algorithms were inspired by those used in the com.mousepushers.date.DateFormats class written by Mark McNamee ([email protected]) and distributed under the following license terms: Copyright (c) 2002, MousePushers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of MousePushers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Version:
$Revision: 31 $ $Date: 2009-06-24 09:38:04 -0400 (Wed, 24 Jun 2009) $
Author:
olsok

Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String USE_DEFAULT_TIMEZONE
          Indicator to use timezone defaulting mechanism.
static java.lang.String USE_DEFAULT_TIMEZONE_PRE42SP6
          Indicator to use timezone defaulting mechanism (in parseAsDate/parseAsTime from pre-4.2SP6).
static java.lang.String VERSION
           
 
Constructor Summary
PerThreadCache()
           
 
Method Summary
static java.lang.String getDefaultTimeZone()
          returns the name of the default timezone used for format and parse.
static java.util.Locale getLocale(int aLocaleType, java.lang.String aFullName)
          Give the programatic name of a Locale, return a Locale object
static java.lang.String getLocaleName(int aLocaleType, java.lang.String aFullName)
          Returns the name of the Locale to be used under the indicated situation.
static com.pega.ibm.icu.util.TimeZone getTimeZone(java.lang.String aKey)
          Retrieve a thread-local instance of the desired TimeZone object.
static void setDefaultTimeZone(java.lang.String aName)
          Sets the default timezone name used for date parsing and formatting.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION

USE_DEFAULT_TIMEZONE

public static final java.lang.String USE_DEFAULT_TIMEZONE
Indicator to use timezone defaulting mechanism.

See Also:
Constant Field Values

USE_DEFAULT_TIMEZONE_PRE42SP6

public static final java.lang.String USE_DEFAULT_TIMEZONE_PRE42SP6
Indicator to use timezone defaulting mechanism (in parseAsDate/parseAsTime from pre-4.2SP6).

See Also:
Constant Field Values
Constructor Detail

PerThreadCache

public PerThreadCache()
Method Detail

getTimeZone

public static final com.pega.ibm.icu.util.TimeZone getTimeZone(java.lang.String aKey)
Retrieve a thread-local instance of the desired TimeZone object. Since each Thread will get a unique instance, no further synchronization is needed when using the Format object.

If the desired instance does not yet exist, the subclass will be invoked to construct the instance so that it can be inserted into the cache.

Parameters:
aKey - String key to the specific instance
Returns:
thread-specific copy of the desired instance

getLocaleName

public static final java.lang.String getLocaleName(int aLocaleType,
                                                   java.lang.String aFullName)
Returns the name of the Locale to be used under the indicated situation.

Parameters:
aLocaleType - use for which a Locale is needed
aFullName - provisional name of locale
Returns:
aFullName or user specific default value

getLocale

public static final java.util.Locale getLocale(int aLocaleType,
                                               java.lang.String aFullName)
Give the programatic name of a Locale, return a Locale object

Parameters:
aLocaleType -
aFullName - name of locale (language_country_variant)
Returns:
Locale instance for this name

getDefaultTimeZone

public static final java.lang.String getDefaultTimeZone()
returns the name of the default timezone used for format and parse.

Returns:
name of default timezone

setDefaultTimeZone

public static final void setDefaultTimeZone(java.lang.String aName)
Sets the default timezone name used for date parsing and formatting. This method is intended for internal use (in conjunction with JUnit tests) and is NOT a general purpose interface. Changing this setting will NOT alter the JVM's default timezone.

Parameters:
aName - name of timezone to use as default during format and parse


Copyright © 2012 Pegasystems Inc. All Rights Reserved.