Author: rhauch
Date: 2008-06-12 13:36:18 -0400 (Thu, 12 Jun 2008)
New Revision: 273
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
trunk/dna-common/src/main/java/org/jboss/dna/common/SystemFailureException.java
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/UnmodifiableProperties.java
trunk/dna-common/src/main/java/org/jboss/dna/common/component/AbstractComponent.java
trunk/dna-common/src/main/java/org/jboss/dna/common/i18n/I18n.java
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/ClassUtil.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/Logger.java
trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
trunk/dna-common/src/main/java/org/jboss/dna/common/xml/SimpleNamespaceContext.java
trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/I18nTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java
trunk/dna-common/src/test/java/org/jboss/dna/common/util/LoggerTest.java
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenRepositoryException.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationException.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/InvalidRuleSetException.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/InvalidSequencerPathExpression.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerException.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerPathExpression.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/IoException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
Log:
Corrected several compiler warnings regarding serializable classes and improper use of
generics.
Modified:
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
---
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -56,6 +56,9 @@
@ThreadSafe
public class JBossCacheSource implements RepositorySource, ObjectFactory {
+ /**
+ */
+ private static final long serialVersionUID = 1530716494560375111L;
public static final String DEFAULT_UUID_PROPERTY_NAMESPACE =
"http://www.jboss.org/dna/connector/jbosscache";
public static final String DEFAULT_UUID_PROPERTY_NAME = "uuid";
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/SystemFailureException.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/SystemFailureException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/SystemFailureException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -30,6 +30,10 @@
public class SystemFailureException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = 8281373010920861138L;
+
+ /**
*
*/
public SystemFailureException() {
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/UnmodifiableProperties.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/UnmodifiableProperties.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/collection/UnmodifiableProperties.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -39,6 +39,9 @@
*/
public class UnmodifiableProperties extends Properties {
+ /**
+ */
+ private static final long serialVersionUID = -4670639332874922546L;
private Properties delegate;
public UnmodifiableProperties( Properties props ) {
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/component/AbstractComponent.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/component/AbstractComponent.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/component/AbstractComponent.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -21,24 +21,23 @@
*/
package org.jboss.dna.common.component;
-
/**
- *
+ * @param <T> the type of configuration
* @author Randall Hauch
*/
-public class AbstractComponent implements Component {
+public class AbstractComponent<T extends ComponentConfig> implements
Component<T> {
/**
* {@inheritDoc}
*/
- public ComponentConfig getConfiguration() {
+ public T getConfiguration() {
return null;
}
/**
* {@inheritDoc}
*/
- public void setConfiguration( ComponentConfig configuration ) {
+ public void setConfiguration( T configuration ) {
}
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/i18n/I18n.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/i18n/I18n.java 2008-06-11 19:21:19
UTC (rev 272)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/i18n/I18n.java 2008-06-12 17:36:18
UTC (rev 273)
@@ -46,391 +46,395 @@
/**
* Manages the initialization of internationalization (i18n) files, substitution of
values within i18n message placeholders, and
* dynamically reading properties from i18n property files.
- *
+ *
* @author John Verhaeg
* @author Randall Hauch
*/
@ThreadSafe
public final class I18n {
- private static final LocalizationRepository DEFAULT_LOCALIZATION_REPOSITORY = new
ClasspathLocalizationRepository();
+ private static final LocalizationRepository DEFAULT_LOCALIZATION_REPOSITORY = new
ClasspathLocalizationRepository();
- /**
- * The first level of this map indicates whether an i18n class has been localized to a
particular locale. The second level
- * contains any problems encountered during localization.
- */
- static final ConcurrentMap<Locale, Map<Class, Set<String>>>
LOCALE_TO_CLASS_TO_PROBLEMS_MAP = new ConcurrentHashMap<Locale, Map<Class,
Set<String>>>();
+ /**
+ * The first level of this map indicates whether an i18n class has been localized to
a particular locale. The second level
+ * contains any problems encountered during localization.
+ */
+ static final ConcurrentMap<Locale, Map<Class<?>,
Set<String>>> LOCALE_TO_CLASS_TO_PROBLEMS_MAP = new
ConcurrentHashMap<Locale, Map<Class<?>, Set<String>>>();
- private static LocalizationRepository localizationRepository =
DEFAULT_LOCALIZATION_REPOSITORY;
+ private static LocalizationRepository localizationRepository =
DEFAULT_LOCALIZATION_REPOSITORY;
- /**
- * Note, calling this method will <em>not</em> trigger localization of the
supplied internationalization class.
- *
- * @param i18nClass The internalization class for which localization problem locales
should be returned.
- * @return The locales for which localization problems were encountered while localizing
the supplied internationalization
- * class; never <code>null</code>.
- */
- public static Set<Locale> getLocalizationProblemLocales( Class i18nClass ) {
- ArgCheck.isNotNull(i18nClass, "i18nClass");
- Set<Locale> locales = new
HashSet<Locale>(LOCALE_TO_CLASS_TO_PROBLEMS_MAP.size());
- for (Entry<Locale, Map<Class, Set<String>>> localeEntry :
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
- for (Entry<Class, Set<String>> classEntry :
localeEntry.getValue().entrySet()) {
- if (!classEntry.getValue().isEmpty()) {
- locales.add(localeEntry.getKey());
- break;
- }
- }
- }
- return locales;
- }
+ /**
+ * Note, calling this method will <em>not</em> trigger localization of
the supplied internationalization class.
+ *
+ * @param i18nClass The internalization class for which localization problem locales
should be returned.
+ * @return The locales for which localization problems were encountered while
localizing the supplied internationalization
+ * class; never <code>null</code>.
+ */
+ public static Set<Locale> getLocalizationProblemLocales( Class<?>
i18nClass ) {
+ ArgCheck.isNotNull(i18nClass, "i18nClass");
+ Set<Locale> locales = new
HashSet<Locale>(LOCALE_TO_CLASS_TO_PROBLEMS_MAP.size());
+ for (Entry<Locale, Map<Class<?>, Set<String>>>
localeEntry : LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
+ for (Entry<Class<?>, Set<String>> classEntry :
localeEntry.getValue().entrySet()) {
+ if (!classEntry.getValue().isEmpty()) {
+ locales.add(localeEntry.getKey());
+ break;
+ }
+ }
+ }
+ return locales;
+ }
- /**
- * Note, calling this method will <em>not</em> trigger localization of the
supplied internationalization class.
- *
- * @param i18nClass The internalization class for which localization problems should be
returned.
- * @return The localization problems encountered while localizing the supplied
internationalization class to the default
- * locale; never <code>null</code>.
- */
- public static Set<String> getLocalizationProblems( Class i18nClass ) {
- return getLocalizationProblems(i18nClass, null);
- }
+ /**
+ * Note, calling this method will <em>not</em> trigger localization of
the supplied internationalization class.
+ *
+ * @param i18nClass The internalization class for which localization problems should
be returned.
+ * @return The localization problems encountered while localizing the supplied
internationalization class to the default
+ * locale; never <code>null</code>.
+ */
+ public static Set<String> getLocalizationProblems( Class<?> i18nClass )
{
+ return getLocalizationProblems(i18nClass, null);
+ }
- /**
- * Note, calling this method will <em>not</em> trigger localization of the
supplied internationalization class.
- *
- * @param i18nClass The internalization class for which localization problems should be
returned.
- * @param locale The locale for which localization problems should be returned. If
<code>null</code>, the default locale
- * will be used.
- * @return The localization problems encountered while localizing the supplied
internationalization class to the supplied
- * locale; never <code>null</code>.
- */
- public static Set<String> getLocalizationProblems( Class i18nClass,
- Locale locale ) {
- ArgCheck.isNotNull(i18nClass, "i18nClass");
- Map<Class, Set<String>> classToProblemsMap =
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.get(locale == null ? Locale.getDefault() : locale);
- if (classToProblemsMap == null) {
- return Collections.emptySet();
- }
- Set<String> problems = classToProblemsMap.get(i18nClass);
- if (problems == null) {
- return Collections.emptySet();
- }
- return problems;
- }
+ /**
+ * Note, calling this method will <em>not</em> trigger localization of
the supplied internationalization class.
+ *
+ * @param i18nClass The internalization class for which localization problems should
be returned.
+ * @param locale The locale for which localization problems should be returned. If
<code>null</code>, the default locale
+ * will be used.
+ * @return The localization problems encountered while localizing the supplied
internationalization class to the supplied
+ * locale; never <code>null</code>.
+ */
+ public static Set<String> getLocalizationProblems( Class<?> i18nClass,
+ Locale locale ) {
+ ArgCheck.isNotNull(i18nClass, "i18nClass");
+ Map<Class<?>, Set<String>> classToProblemsMap =
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.get(locale == null ? Locale.getDefault() : locale);
+ if (classToProblemsMap == null) {
+ return Collections.emptySet();
+ }
+ Set<String> problems = classToProblemsMap.get(i18nClass);
+ if (problems == null) {
+ return Collections.emptySet();
+ }
+ return problems;
+ }
- /**
- * Get the repository of localized messages. By default, this instance uses a {@link
ClasspathLocalizationRepository} that
- * uses this class' classloader.
- *
- * @return localizationRepository
- */
- public static LocalizationRepository getLocalizationRepository() {
- return localizationRepository;
- }
+ /**
+ * Get the repository of localized messages. By default, this instance uses a {@link
ClasspathLocalizationRepository} that
+ * uses this class' classloader.
+ *
+ * @return localizationRepository
+ */
+ public static LocalizationRepository getLocalizationRepository() {
+ return localizationRepository;
+ }
- /**
- * Set the repository of localized messages. If <code>null</code>, a {@link
ClasspathLocalizationRepository} instance that
- * uses this class loader will be used.
- *
- * @param localizationRepository the localization repository to use; may be
<code>null</code> if the default repository
- * should be used.
- */
- public static void setLocalizationRepository( LocalizationRepository
localizationRepository ) {
- I18n.localizationRepository = localizationRepository != null ? localizationRepository :
DEFAULT_LOCALIZATION_REPOSITORY;
- }
+ /**
+ * Set the repository of localized messages. If <code>null</code>, a
{@link ClasspathLocalizationRepository} instance that
+ * uses this class loader will be used.
+ *
+ * @param localizationRepository the localization repository to use; may be
<code>null</code> if the default repository
+ * should be used.
+ */
+ public static void setLocalizationRepository( LocalizationRepository
localizationRepository ) {
+ I18n.localizationRepository = localizationRepository != null ?
localizationRepository : DEFAULT_LOCALIZATION_REPOSITORY;
+ }
- /**
- * Initializes the internationalization fields declared on the supplied class.
Internationalization fields must be public,
- * static, not final, and of type <code>I18n</code>. The supplied class must
not be an interface (of course), but has no
- * restrictions as to what class it may extend or what interfaces it must implement.
- *
- * @param i18nClass A class declaring one or more public, static, non-final fields of
type <code>I18n</code>.
- */
- public static void initialize( Class i18nClass ) {
- ArgCheck.isNotNull(i18nClass, "i18nClass");
- if (i18nClass.isInterface()) {
- throw new
IllegalArgumentException(CommonI18n.i18nClassInterface.text(i18nClass.getName()));
- }
+ /**
+ * Initializes the internationalization fields declared on the supplied class.
Internationalization fields must be public,
+ * static, not final, and of type <code>I18n</code>. The supplied class
must not be an interface (of course), but has no
+ * restrictions as to what class it may extend or what interfaces it must implement.
+ *
+ * @param i18nClass A class declaring one or more public, static, non-final fields of
type <code>I18n</code>.
+ */
+ public static void initialize( Class<?> i18nClass ) {
+ ArgCheck.isNotNull(i18nClass, "i18nClass");
+ if (i18nClass.isInterface()) {
+ throw new
IllegalArgumentException(CommonI18n.i18nClassInterface.text(i18nClass.getName()));
+ }
- synchronized (i18nClass) {
- // Find all public static non-final String fields in the supplied class and
instantiate an I18n object for each.
- try {
- for (Field fld : i18nClass.getDeclaredFields()) {
+ synchronized (i18nClass) {
+ // Find all public static non-final String fields in the supplied class and
instantiate an I18n object for each.
+ try {
+ for (Field fld : i18nClass.getDeclaredFields()) {
- // Ensure field is of type I18n
- if (fld.getType() == I18n.class) {
+ // Ensure field is of type I18n
+ if (fld.getType() == I18n.class) {
- // Ensure field is public
- if ((fld.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC) {
- throw new SystemFailureException(CommonI18n.i18nFieldNotPublic.text(fld.getName(),
i18nClass));
- }
+ // Ensure field is public
+ if ((fld.getModifiers() & Modifier.PUBLIC) !=
Modifier.PUBLIC) {
+ throw new
SystemFailureException(CommonI18n.i18nFieldNotPublic.text(fld.getName(), i18nClass));
+ }
- // Ensure field is static
- if ((fld.getModifiers() & Modifier.STATIC) != Modifier.STATIC) {
- throw new SystemFailureException(CommonI18n.i18nFieldNotStatic.text(fld.getName(),
i18nClass));
- }
+ // Ensure field is static
+ if ((fld.getModifiers() & Modifier.STATIC) !=
Modifier.STATIC) {
+ throw new
SystemFailureException(CommonI18n.i18nFieldNotStatic.text(fld.getName(), i18nClass));
+ }
- // Ensure field is not final
- if ((fld.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
- throw new SystemFailureException(CommonI18n.i18nFieldFinal.text(fld.getName(),
i18nClass));
- }
+ // Ensure field is not final
+ if ((fld.getModifiers() & Modifier.FINAL) == Modifier.FINAL)
{
+ throw new
SystemFailureException(CommonI18n.i18nFieldFinal.text(fld.getName(), i18nClass));
+ }
- // Ensure we can access field even if it's in a private class
- ClassUtil.makeAccessible(fld);
+ // Ensure we can access field even if it's in a private
class
+ ClassUtil.makeAccessible(fld);
- // Initialize field. Do this every time the class is initialized (or
re-initialized)
- fld.set(null, new I18n(fld.getName(), i18nClass));
- }
- }
+ // Initialize field. Do this every time the class is initialized
(or re-initialized)
+ fld.set(null, new I18n(fld.getName(), i18nClass));
+ }
+ }
- // Remove all entries for the supplied i18n class to indicate it has not been
localized.
- for (Entry<Locale, Map<Class, Set<String>>> entry :
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
- entry.getValue().remove(i18nClass);
- }
- } catch (IllegalAccessException err) {
- // If this happens, it will happen with the first field visited in the above loop
- throw new IllegalArgumentException(CommonI18n.i18nClassNotPublic.text(i18nClass));
- }
- }
- }
+ // Remove all entries for the supplied i18n class to indicate it has not
been localized.
+ for (Entry<Locale, Map<Class<?>, Set<String>>>
entry : LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
+ entry.getValue().remove(i18nClass);
+ }
+ } catch (IllegalAccessException err) {
+ // If this happens, it will happen with the first field visited in the
above loop
+ throw new
IllegalArgumentException(CommonI18n.i18nClassNotPublic.text(i18nClass));
+ }
+ }
+ }
- /**
- * Synchronized on the supplied internalization class.
- *
- * @param i18nClass The internalization class being localized
- * @param locale The locale to which the supplied internationalization class should be
localized.
- */
- private static void localize( final Class i18nClass,
- final Locale locale ) {
- assert i18nClass != null;
- assert locale != null;
- // Create a class-to-problem map for this locale if one doesn't exist, else get the
existing one.
- Map<Class, Set<String>> classToProblemsMap = new
ConcurrentHashMap<Class, Set<String>>();
- Map<Class, Set<String>> existingClassToProblemsMap =
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.putIfAbsent(locale,
-
classToProblemsMap);
- if (existingClassToProblemsMap != null) {
- classToProblemsMap = existingClassToProblemsMap;
- }
- // Check if already localized outside of synchronization block for 99% use-case
- if (classToProblemsMap.get(i18nClass) != null) {
- return;
- }
- synchronized (i18nClass) {
- // Return if the supplied i18n class has already been localized to the supplied
locale, despite the check outside of
- // the synchronization block (1% use-case), else create a class-to-problems map for
the class.
- Set<String> problems = classToProblemsMap.get(i18nClass);
- if (problems == null) {
- problems = new CopyOnWriteArraySet<String>();
- classToProblemsMap.put(i18nClass, problems);
- } else {
- return;
- }
- // Get the URL to the localization properties file ...
- final LocalizationRepository repos = getLocalizationRepository();
- final String localizationBaseName = i18nClass.getName();
- URL url = repos.getLocalizationBundle(localizationBaseName, locale);
- if (url == null) {
- // Nothing was found, so try the default locale
- Locale defaultLocale = Locale.getDefault();
- if (!defaultLocale.equals(locale)) {
- url = repos.getLocalizationBundle(localizationBaseName, defaultLocale);
- }
- // Return if no applicable localization file could be found
- if (url == null) {
- problems.add(CommonI18n.i18nLocalizationFileNotFound.text(localizationBaseName));
- return;
- }
- }
- // Initialize i18n map
- final URL finalUrl = url;
- final Set<String> finalProblems = problems;
- Properties props = new Properties() {
+ /**
+ * Synchronized on the supplied internalization class.
+ *
+ * @param i18nClass The internalization class being localized
+ * @param locale The locale to which the supplied internationalization class should
be localized.
+ */
+ private static void localize( final Class<?> i18nClass,
+ final Locale locale ) {
+ assert i18nClass != null;
+ assert locale != null;
+ // Create a class-to-problem map for this locale if one doesn't exist, else
get the existing one.
+ Map<Class<?>, Set<String>> classToProblemsMap = new
ConcurrentHashMap<Class<?>, Set<String>>();
+ Map<Class<?>, Set<String>> existingClassToProblemsMap =
LOCALE_TO_CLASS_TO_PROBLEMS_MAP.putIfAbsent(locale,
+
classToProblemsMap);
+ if (existingClassToProblemsMap != null) {
+ classToProblemsMap = existingClassToProblemsMap;
+ }
+ // Check if already localized outside of synchronization block for 99% use-case
+ if (classToProblemsMap.get(i18nClass) != null) {
+ return;
+ }
+ synchronized (i18nClass) {
+ // Return if the supplied i18n class has already been localized to the
supplied locale, despite the check outside of
+ // the synchronization block (1% use-case), else create a class-to-problems
map for the class.
+ Set<String> problems = classToProblemsMap.get(i18nClass);
+ if (problems == null) {
+ problems = new CopyOnWriteArraySet<String>();
+ classToProblemsMap.put(i18nClass, problems);
+ } else {
+ return;
+ }
+ // Get the URL to the localization properties file ...
+ final LocalizationRepository repos = getLocalizationRepository();
+ final String localizationBaseName = i18nClass.getName();
+ URL url = repos.getLocalizationBundle(localizationBaseName, locale);
+ if (url == null) {
+ // Nothing was found, so try the default locale
+ Locale defaultLocale = Locale.getDefault();
+ if (!defaultLocale.equals(locale)) {
+ url = repos.getLocalizationBundle(localizationBaseName,
defaultLocale);
+ }
+ // Return if no applicable localization file could be found
+ if (url == null) {
+
problems.add(CommonI18n.i18nLocalizationFileNotFound.text(localizationBaseName));
+ return;
+ }
+ }
+ // Initialize i18n map
+ final URL finalUrl = url;
+ final Set<String> finalProblems = problems;
+ Properties props = new Properties() {
- @Override
- public synchronized Object put( Object key,
- Object value ) {
- String id = (String)key;
- String text = (String)value;
+ /**
+ */
+ private static final long serialVersionUID = 3920620306881072843L;
- try {
- Field fld = i18nClass.getDeclaredField(id);
- if (fld.getType() != I18n.class) {
- // Invalid field type
- finalProblems.add(CommonI18n.i18nFieldInvalidType.text(id, finalUrl,
getClass().getName()));
- } else {
- I18n i18n = (I18n)fld.get(null);
- if (i18n.localeToTextMap.putIfAbsent(locale, text) != null) {
- // Duplicate id encountered
- String prevProblem = i18n.localeToProblemMap.putIfAbsent(locale,
-
CommonI18n.i18nPropertyDuplicate.text(id,
-
finalUrl));
- assert prevProblem == null;
- }
- }
- } catch (NoSuchFieldException err) {
- // No corresponding field exists
- finalProblems.add(CommonI18n.i18nPropertyUnused.text(id, finalUrl));
- } catch (IllegalAccessException notPossible) {
- // Would have already occurred in initialize method, but allowing for the
impossible...
- finalProblems.add(notPossible.getMessage());
- }
+ @Override
+ public synchronized Object put( Object key,
+ Object value ) {
+ String id = (String)key;
+ String text = (String)value;
- return null;
- }
- };
+ try {
+ Field fld = i18nClass.getDeclaredField(id);
+ if (fld.getType() != I18n.class) {
+ // Invalid field type
+ finalProblems.add(CommonI18n.i18nFieldInvalidType.text(id,
finalUrl, getClass().getName()));
+ } else {
+ I18n i18n = (I18n)fld.get(null);
+ if (i18n.localeToTextMap.putIfAbsent(locale, text) != null)
{
+ // Duplicate id encountered
+ String prevProblem =
i18n.localeToProblemMap.putIfAbsent(locale,
+
CommonI18n.i18nPropertyDuplicate.text(id,
+
finalUrl));
+ assert prevProblem == null;
+ }
+ }
+ } catch (NoSuchFieldException err) {
+ // No corresponding field exists
+ finalProblems.add(CommonI18n.i18nPropertyUnused.text(id,
finalUrl));
+ } catch (IllegalAccessException notPossible) {
+ // Would have already occurred in initialize method, but allowing
for the impossible...
+ finalProblems.add(notPossible.getMessage());
+ }
- try {
- InputStream propStream = url.openStream();
- try {
- props.load(propStream);
- // Check for uninitialized fields
- for (Field fld : i18nClass.getDeclaredFields()) {
- if (fld.getType() == I18n.class) {
- try {
- I18n i18n = (I18n)fld.get(null);
- if (i18n.localeToTextMap.get(locale) == null) {
- i18n.localeToProblemMap.put(locale,
CommonI18n.i18nPropertyMissing.text(fld.getName(), url));
- }
- } catch (IllegalAccessException notPossible) {
- // Would have already occurred in initialize method, but allowing for the
impossible...
- finalProblems.add(notPossible.getMessage());
- }
- }
- }
- } finally {
- propStream.close();
- }
- } catch (IOException err) {
- finalProblems.add(err.getMessage());
- }
- }
- }
+ return null;
+ }
+ };
- private final String id;
- private final Class i18nClass;
- final ConcurrentHashMap<Locale, String> localeToTextMap = new
ConcurrentHashMap<Locale, String>();
- final ConcurrentHashMap<Locale, String> localeToProblemMap = new
ConcurrentHashMap<Locale, String>();
+ try {
+ InputStream propStream = url.openStream();
+ try {
+ props.load(propStream);
+ // Check for uninitialized fields
+ for (Field fld : i18nClass.getDeclaredFields()) {
+ if (fld.getType() == I18n.class) {
+ try {
+ I18n i18n = (I18n)fld.get(null);
+ if (i18n.localeToTextMap.get(locale) == null) {
+ i18n.localeToProblemMap.put(locale,
CommonI18n.i18nPropertyMissing.text(fld.getName(), url));
+ }
+ } catch (IllegalAccessException notPossible) {
+ // Would have already occurred in initialize method, but
allowing for the impossible...
+ finalProblems.add(notPossible.getMessage());
+ }
+ }
+ }
+ } finally {
+ propStream.close();
+ }
+ } catch (IOException err) {
+ finalProblems.add(err.getMessage());
+ }
+ }
+ }
- private I18n( String id,
- Class i18nClass ) {
- this.id = id;
- this.i18nClass = i18nClass;
- }
+ private final String id;
+ private final Class<?> i18nClass;
+ final ConcurrentHashMap<Locale, String> localeToTextMap = new
ConcurrentHashMap<Locale, String>();
+ final ConcurrentHashMap<Locale, String> localeToProblemMap = new
ConcurrentHashMap<Locale, String>();
- /**
- * @return This internationalization object's ID, which will match both the name of
the relevant static field in the
- * internationalization class and the relevant property name in the associated
localization files.
- */
- public String id() {
- return id;
- }
+ private I18n( String id,
+ Class<?> i18nClass ) {
+ this.id = id;
+ this.i18nClass = i18nClass;
+ }
- /**
- * @return <code>true</code> if a problem was encountered while localizing
this internationalization object to the default
- * locale.
- */
- public boolean hasProblem() {
- return (problem() != null);
- }
+ /**
+ * @return This internationalization object's ID, which will match both the name
of the relevant static field in the
+ * internationalization class and the relevant property name in the
associated localization files.
+ */
+ public String id() {
+ return id;
+ }
- /**
- * @param locale The locale for which to check whether a problem was encountered.
- * @return <code>true</code> if a problem was encountered while localizing
this internationalization object to the supplied
- * locale.
- */
- public boolean hasProblem( Locale locale ) {
- return (problem(locale) != null);
- }
+ /**
+ * @return <code>true</code> if a problem was encountered while
localizing this internationalization object to the default
+ * locale.
+ */
+ public boolean hasProblem() {
+ return (problem() != null);
+ }
- /**
- * @return The problem encountered while localizing this internationalization object to
the default locale, or
- * <code>null</code> if none was encountered.
- */
- public String problem() {
- return problem(null);
- }
+ /**
+ * @param locale The locale for which to check whether a problem was encountered.
+ * @return <code>true</code> if a problem was encountered while
localizing this internationalization object to the supplied
+ * locale.
+ */
+ public boolean hasProblem( Locale locale ) {
+ return (problem(locale) != null);
+ }
- /**
- * @param locale The locale for which to return the problem.
- * @return The problem encountered while localizing this internationalization object to
the supplied locale, or
- * <code>null</code> if none was encountered.
- */
- public String problem( Locale locale ) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- localize(i18nClass, locale);
- // Check for field/property error
- String problem = localeToProblemMap.get(locale);
- if (problem != null) {
- return problem;
- }
- // Check if text exists
- if (localeToTextMap.get(locale) != null) {
- // If so, no problem exists
- return null;
- }
- // If we get here, which will be at most once, there was at least one global
localization error, so just return a message
- // indicating to look them up.
- problem = CommonI18n.i18nLocalizationProblems.text(i18nClass, locale);
- localeToProblemMap.put(locale, problem);
- return problem;
- }
+ /**
+ * @return The problem encountered while localizing this internationalization object
to the default locale, or
+ * <code>null</code> if none was encountered.
+ */
+ public String problem() {
+ return problem(null);
+ }
- private String rawText( Locale locale ) {
- assert locale != null;
- localize(i18nClass, locale);
- // Check if text exists
- String text = localeToTextMap.get(locale);
- if (text != null) {
- return text;
- }
- // If not, there was a problem, so throw it within an exception so upstream callers can
tell the difference between normal
- // text and problem text.
- throw new SystemFailureException(problem(locale));
- }
+ /**
+ * @param locale The locale for which to return the problem.
+ * @return The problem encountered while localizing this internationalization object
to the supplied locale, or
+ * <code>null</code> if none was encountered.
+ */
+ public String problem( Locale locale ) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+ localize(i18nClass, locale);
+ // Check for field/property error
+ String problem = localeToProblemMap.get(locale);
+ if (problem != null) {
+ return problem;
+ }
+ // Check if text exists
+ if (localeToTextMap.get(locale) != null) {
+ // If so, no problem exists
+ return null;
+ }
+ // If we get here, which will be at most once, there was at least one global
localization error, so just return a message
+ // indicating to look them up.
+ problem = CommonI18n.i18nLocalizationProblems.text(i18nClass, locale);
+ localeToProblemMap.put(locale, problem);
+ return problem;
+ }
- /**
- * Get the localized text for the {@link Locale#getDefault() current (default) locale},
replacing the parameters in the text
- * with those supplied.
- *
- * @param arguments the arguments for the parameter replacement; may be
<code>null</code> or empty
- * @return the localized text
- */
- public String text( Object... arguments ) {
- return text(null, arguments);
- }
+ private String rawText( Locale locale ) {
+ assert locale != null;
+ localize(i18nClass, locale);
+ // Check if text exists
+ String text = localeToTextMap.get(locale);
+ if (text != null) {
+ return text;
+ }
+ // If not, there was a problem, so throw it within an exception so upstream
callers can tell the difference between normal
+ // text and problem text.
+ throw new SystemFailureException(problem(locale));
+ }
- /**
- * Get the localized text for the supplied locale, replacing the parameters in the text
with those supplied.
- *
- * @param locale the locale, or <code>null</code> if the {@link
Locale#getDefault() current (default) locale} should be used
- * @param arguments the arguments for the parameter replacement; may be
<code>null</code> or empty
- * @return the localized text
- */
- public String text( Locale locale,
- Object... arguments ) {
- try {
- String rawText = rawText(locale == null ? Locale.getDefault() : locale);
- return StringUtil.createString(rawText, arguments);
- } catch (IllegalArgumentException err) {
- throw new
IllegalArgumentException(CommonI18n.i18nRequiredToSuppliedParameterMismatch.text(id,
-
i18nClass,
-
err.getMessage()));
- } catch (SystemFailureException err) {
- return '<' + err.getMessage() + '>';
- }
- }
+ /**
+ * Get the localized text for the {@link Locale#getDefault() current (default)
locale}, replacing the parameters in the text
+ * with those supplied.
+ *
+ * @param arguments the arguments for the parameter replacement; may be
<code>null</code> or empty
+ * @return the localized text
+ */
+ public String text( Object... arguments ) {
+ return text(null, arguments);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- try {
- return rawText(Locale.getDefault());
- } catch (SystemFailureException err) {
- return '<' + err.getMessage() + '>';
- }
- }
+ /**
+ * Get the localized text for the supplied locale, replacing the parameters in the
text with those supplied.
+ *
+ * @param locale the locale, or <code>null</code> if the {@link
Locale#getDefault() current (default) locale} should be used
+ * @param arguments the arguments for the parameter replacement; may be
<code>null</code> or empty
+ * @return the localized text
+ */
+ public String text( Locale locale,
+ Object... arguments ) {
+ try {
+ String rawText = rawText(locale == null ? Locale.getDefault() : locale);
+ return StringUtil.createString(rawText, arguments);
+ } catch (IllegalArgumentException err) {
+ throw new
IllegalArgumentException(CommonI18n.i18nRequiredToSuppliedParameterMismatch.text(id,
+
i18nClass,
+
err.getMessage()));
+ } catch (SystemFailureException err) {
+ return '<' + err.getMessage() + '>';
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ try {
+ return rawText(Locale.getDefault());
+ } catch (SystemFailureException err) {
+ return '<' + err.getMessage() + '>';
+ }
+ }
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/monitor/ProgressStatus.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -34,6 +34,9 @@
@Immutable
public class ProgressStatus implements Serializable, Comparable<ProgressStatus> {
+ /**
+ */
+ private static final long serialVersionUID = -7771764546193063275L;
protected static final String PERCENTAGE_PATTERN = "##0.0"; // percentage
should always fit
protected static final double PERCENT_PRECISION = 0.001d;
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -36,12 +36,15 @@
/**
* Check that the argument is not less than the supplied value
+ *
* @param argument The argument
* @param notLessThanValue the value that is to be used to check the value
* @param name The name of the argument
* @throws IllegalArgumentException If argument is negative (<0)
*/
- public static void isNotLessThan( int argument, int notLessThanValue, String name )
{
+ public static void isNotLessThan( int argument,
+ int notLessThanValue,
+ String name ) {
if (argument < notLessThanValue) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeLessThan.text(name, argument,
notLessThanValue));
}
@@ -49,12 +52,15 @@
/**
* Check that the argument is not greater than the supplied value
+ *
* @param argument The argument
* @param notGreaterThanValue the value that is to be used to check the value
* @param name The name of the argument
* @throws IllegalArgumentException If argument is negative (<0)
*/
- public static void isNotGreaterThan( int argument, int notGreaterThanValue, String
name ) {
+ public static void isNotGreaterThan( int argument,
+ int notGreaterThanValue,
+ String name ) {
if (argument < notGreaterThanValue) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeGreaterThan.text(name, argument,
notGreaterThanValue));
}
@@ -62,11 +68,13 @@
/**
* Check that the argument is non-negative (>=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is negative (<0)
*/
- public static void isNonNegative( int argument, String name ) {
+ public static void isNonNegative( int argument,
+ String name ) {
if (argument < 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNegative.text(name, argument));
}
@@ -74,11 +82,13 @@
/**
* Check that the argument is non-positive (<=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is positive (>0)
*/
- public static void isNonPositive( int argument, String name ) {
+ public static void isNonPositive( int argument,
+ String name ) {
if (argument > 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBePositive.text(name, argument));
}
@@ -86,11 +96,13 @@
/**
* Check that the argument is negative (<0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-negative (>=0)
*/
- public static void isNegative( int argument, String name ) {
+ public static void isNegative( int argument,
+ String name ) {
if (argument >= 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBeNegative.text(name, argument));
}
@@ -98,11 +110,13 @@
/**
* Check that the argument is positive (>0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-positive (<=0)
*/
- public static void isPositive( int argument, String name ) {
+ public static void isPositive( int argument,
+ String name ) {
if (argument <= 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBePositive.text(name, argument));
}
@@ -112,11 +126,13 @@
/**
* Check that the argument is non-negative (>=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is negative (<0)
*/
- public static void isNonNegative( long argument, String name ) {
+ public static void isNonNegative( long argument,
+ String name ) {
if (argument < 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNegative.text(name, argument));
}
@@ -124,11 +140,13 @@
/**
* Check that the argument is non-positive (<=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is positive (>0)
*/
- public static void isNonPositive( long argument, String name ) {
+ public static void isNonPositive( long argument,
+ String name ) {
if (argument > 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBePositive.text(name, argument));
}
@@ -136,11 +154,13 @@
/**
* Check that the argument is negative (<0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-negative (>=0)
*/
- public static void isNegative( long argument, String name ) {
+ public static void isNegative( long argument,
+ String name ) {
if (argument >= 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBeNegative.text(name, argument));
}
@@ -148,11 +168,13 @@
/**
* Check that the argument is positive (>0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-positive (<=0)
*/
- public static void isPositive( long argument, String name ) {
+ public static void isPositive( long argument,
+ String name ) {
if (argument <= 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBePositive.text(name, argument));
}
@@ -162,11 +184,13 @@
/**
* Check that the argument is non-negative (>=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is negative (<0)
*/
- public static void isNonNegative( double argument, String name ) {
+ public static void isNonNegative( double argument,
+ String name ) {
if (argument < 0.0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNegative.text(name, argument));
}
@@ -174,11 +198,13 @@
/**
* Check that the argument is non-positive (<=0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is positive (>0)
*/
- public static void isNonPositive( double argument, String name ) {
+ public static void isNonPositive( double argument,
+ String name ) {
if (argument > 0.0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBePositive.text(name, argument));
}
@@ -186,11 +212,13 @@
/**
* Check that the argument is negative (<0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-negative (>=0)
*/
- public static void isNegative( double argument, String name ) {
+ public static void isNegative( double argument,
+ String name ) {
if (argument >= 0.0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBeNegative.text(name, argument));
}
@@ -198,11 +226,13 @@
/**
* Check that the argument is positive (>0).
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is non-positive (<=0)
*/
- public static void isPositive( double argument, String name ) {
+ public static void isPositive( double argument,
+ String name ) {
if (argument <= 0.0) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBePositive.text(name, argument));
}
@@ -210,11 +240,13 @@
/**
* Check that the argument is not NaN.
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is NaN
*/
- public static void isNotNan( double argument, String name ) {
+ public static void isNotNan( double argument,
+ String name ) {
if (Double.isNaN(argument)) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBeNumber.text(name));
}
@@ -224,11 +256,13 @@
/**
* Check that the string is non-null and has length > 0
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If value is null or length == 0
*/
- public static void isNotZeroLength( String argument, String name ) {
+ public static void isNotZeroLength( String argument,
+ String name ) {
isNotNull(argument, name);
if (argument.length() <= 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNullOrZeroLength.text(name));
@@ -237,11 +271,13 @@
/**
* Check that the string is not empty, is not null, and does not contain only
whitespace.
+ *
* @param argument String
* @param name The name of the argument
* @throws IllegalArgumentException If string is null or empty
*/
- public static void isNotEmpty( String argument, String name ) {
+ public static void isNotEmpty( String argument,
+ String name ) {
isNotZeroLength(argument, name);
if (argument != null && argument.trim().length() == 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNullOrZeroLengthOrEmpty.text(name));
@@ -252,11 +288,13 @@
/**
* Check that the specified argument is non-null
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If argument is null
*/
- public static void isNotNull( Object argument, String name ) {
+ public static void isNotNull( Object argument,
+ String name ) {
if (argument == null) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeNull.text(name));
}
@@ -264,24 +302,28 @@
/**
* Returns the specified argument if it is not <code>null</code>.
+ *
* @param <T>
* @param argument The argument
* @param name The name of the argument
* @return The argument
* @throws IllegalArgumentException If argument is <code>null</code>
*/
- public static <T> T getNotNull( T argument, String name ) {
+ public static <T> T getNotNull( T argument,
+ String name ) {
isNotNull(argument, name);
return argument;
}
/**
* Check that the argument is null
+ *
* @param argument The argument
* @param name The name of the argument
* @throws IllegalArgumentException If value is non-null
*/
- public static void isNull( Object argument, String name ) {
+ public static void isNull( Object argument,
+ String name ) {
if (argument != null) {
throw new
IllegalArgumentException(CommonI18n.argumentMustBeNull.text(name));
}
@@ -289,21 +331,28 @@
/**
* Check that the object is an instance of the specified Class
+ *
+ * @param <T> the class type
* @param argument Value
* @param expectedClass Class
* @param name The name of the argument
* @throws IllegalArgumentException If value is null
*/
- public static void isInstanceOf( Object argument, Class expectedClass, String name )
{
+ public static <T> void isInstanceOf( Object argument,
+ Class<T> expectedClass,
+ String name ) {
isNotNull(argument, name);
if (!expectedClass.isInstance(argument)) {
- throw new
IllegalArgumentException(CommonI18n.argumentMustBeInstanceOf.text(name,
argument.getClass(), expectedClass.getName()));
+ throw new
IllegalArgumentException(CommonI18n.argumentMustBeInstanceOf.text(name,
+
argument.getClass(),
+
expectedClass.getName()));
}
}
/**
* Checks that the object is an instance of the specified Class and then returns the
object cast to the specified Class
- * @param <C>
+ *
+ * @param <C> the class type
* @param argument Value
* @param expectedClass Class
* @param name The name of the argument
@@ -312,23 +361,29 @@
*/
@SuppressWarnings( "unchecked" )
// due to cast in return
- public static <C> C getInstanceOf( Object argument, Class<C>
expectedClass, String name ) {
+ public static <C> C getInstanceOf( Object argument,
+ Class<C> expectedClass,
+ String name ) {
isInstanceOf(argument, expectedClass, name);
return (C)argument;
}
/**
* Asserts that the specified first object is the same as (==) the specified second
object.
+ *
* @param <T>
* @param argument The argument to assert as the same as
<code>object</code>.
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as the same as
<code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and <code>object</code> is
not <code>null</code>, <code>object.toString()</code> will
- * be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
+ * will be used.
* @throws IllegalArgumentException If the specified objects are not the same.
*/
- public static <T> void isSame( final T argument, String argumentName, final T
object, String objectName ) {
+ public static <T> void isSame( final T argument,
+ String argumentName,
+ final T object,
+ String objectName ) {
if (argument != object) {
if (objectName == null) objectName = getObjectName(object);
throw new
IllegalArgumentException(CommonI18n.argumentMustBeSameAs.text(argumentName, objectName));
@@ -337,16 +392,20 @@
/**
* Asserts that the specified first object is not the same as (==) the specified
second object.
+ *
* @param <T>
* @param argument The argument to assert as not the same as
<code>object</code>.
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as not the same as
<code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and <code>object</code> is
not <code>null</code>, <code>object.toString()</code> will
- * be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
+ * will be used.
* @throws IllegalArgumentException If the specified objects are the same.
*/
- public static <T> void isNotSame( final T argument, String argumentName, final
T object, String objectName ) {
+ public static <T> void isNotSame( final T argument,
+ String argumentName,
+ final T object,
+ String objectName ) {
if (argument == object) {
if (objectName == null) objectName = getObjectName(object);
throw new
IllegalArgumentException(CommonI18n.argumentMustNotBeSameAs.text(argumentName,
objectName));
@@ -355,16 +414,20 @@
/**
* Asserts that the specified first object is {@link Object#equals(Object) equal to}
the specified second object.
+ *
* @param <T>
* @param argument The argument to assert equal to <code>object</code>.
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as equal to <code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and <code>object</code> is
not <code>null</code>, <code>object.toString()</code> will
- * be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
+ * will be used.
* @throws IllegalArgumentException If the specified objects are not equal.
*/
- public static <T> void isEquals( final T argument, String argumentName, final T
object, String objectName ) {
+ public static <T> void isEquals( final T argument,
+ String argumentName,
+ final T object,
+ String objectName ) {
if (!argument.equals(object)) {
if (objectName == null) objectName = getObjectName(object);
throw new
IllegalArgumentException(CommonI18n.argumentMustBeEquals.text(argumentName, objectName));
@@ -373,16 +436,20 @@
/**
* Asserts that the specified first object is not {@link Object#equals(Object) equal
to} the specified second object.
+ *
* @param <T>
* @param argument The argument to assert equal to <code>object</code>.
* @param argumentName The name that will be used within the exception message for
the argument should an exception be thrown
* @param object The object to assert as equal to <code>argument</code>.
* @param objectName The name that will be used within the exception message for
<code>object</code> should an exception be
- * thrown; if <code>null</code> and <code>object</code> is
not <code>null</code>, <code>object.toString()</code> will
- * be used.
+ * thrown; if <code>null</code> and
<code>object</code> is not <code>null</code>,
<code>object.toString()</code>
+ * will be used.
* @throws IllegalArgumentException If the specified objects are equals.
*/
- public static <T> void isNotEquals( final T argument, String argumentName,
final T object, String objectName ) {
+ public static <T> void isNotEquals( final T argument,
+ String argumentName,
+ final T object,
+ String objectName ) {
if (argument.equals(object)) {
if (objectName == null) objectName = getObjectName(object);
throw new
IllegalArgumentException(CommonI18n.argumentMustNotBeEquals.text(argumentName,
objectName));
@@ -393,11 +460,13 @@
/**
* Checks that the iterator is not empty, and throws an exception if it is.
+ *
* @param argument the iterator to check
* @param name The name of the argument
* @throws IllegalArgumentException If iterator is empty (i.e., iterator.hasNext()
returns false)
*/
- public static void isNotEmpty( Iterator argument, String name ) {
+ public static void isNotEmpty( Iterator<?> argument,
+ String name ) {
isNotNull(argument, name);
if (!argument.hasNext()) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name));
@@ -408,11 +477,13 @@
/**
* Check that the collection is not empty
+ *
* @param argument Collection
* @param name The name of the argument
* @throws IllegalArgumentException If collection is null or empty
*/
- public static void isNotEmpty( Collection argument, String name ) {
+ public static void isNotEmpty( Collection<?> argument,
+ String name ) {
isNotNull(argument, name);
if (argument.isEmpty()) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name));
@@ -421,11 +492,13 @@
/**
* Check that the map is not empty
+ *
* @param argument Map
* @param name The name of the argument
* @throws IllegalArgumentException If map is null or empty
*/
- public static void isNotEmpty( Map argument, String name ) {
+ public static void isNotEmpty( Map<?, ?> argument,
+ String name ) {
isNotNull(argument, name);
if (argument.isEmpty()) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name));
@@ -434,11 +507,13 @@
/**
* Check that the array is not empty
+ *
* @param argument Array
* @param name The name of the argument
* @throws IllegalArgumentException If array is null or empty
*/
- public static void isNotEmpty( Object[] argument, String name ) {
+ public static void isNotEmpty( Object[] argument,
+ String name ) {
isNotNull(argument, name);
if (argument.length == 0) {
throw new
IllegalArgumentException(CommonI18n.argumentMayNotBeEmpty.text(name));
@@ -451,12 +526,15 @@
/**
* Check that the collection contains the value
+ *
* @param argument Collection to check
* @param value Value to check for, may be null
* @param name The name of the argument
* @throws IllegalArgumentException If collection is null or doesn't contain
value
*/
- public static void contains( Collection argument, Object value, String name ) {
+ public static void contains( Collection<?> argument,
+ Object value,
+ String name ) {
isNotNull(argument, name);
if (!argument.contains(value)) {
throw new
IllegalArgumentException(CommonI18n.argumentDidNotContainObject.text(name,
getObjectName(value)));
@@ -465,12 +543,15 @@
/**
* Check that the map contains the key
+ *
* @param argument Map to check
* @param key Key to check for, may be null
* @param name The name of the argument
* @throws IllegalArgumentException If map is null or doesn't contain key
*/
- public static void containsKey( Map argument, Object key, String name ) {
+ public static void containsKey( Map<?, ?> argument,
+ Object key,
+ String name ) {
isNotNull(argument, name);
if (!argument.containsKey(key)) {
throw new
IllegalArgumentException(CommonI18n.argumentDidNotContainKey.text(name,
getObjectName(key)));
@@ -479,11 +560,13 @@
/**
* Check that the collection is not null and contains no nulls
+ *
* @param argument Array
* @param name The name of the argument
* @throws IllegalArgumentException If array is null or has null values
*/
- public static void containsNoNulls( Collection argument, String name ) {
+ public static void containsNoNulls( Collection<?> argument,
+ String name ) {
isNotNull(argument, name);
int i = 0;
for (Object object : argument) {
@@ -496,11 +579,13 @@
/**
* Check that the array is not null and contains no nulls
+ *
* @param argument Array
* @param name The name of the argument
* @throws IllegalArgumentException If array is null or has null values
*/
- public static void containsNoNulls( Object[] argument, String name ) {
+ public static void containsNoNulls( Object[] argument,
+ String name ) {
isNotNull(argument, name);
int i = 0;
for (Object object : argument) {
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/ClassUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/ClassUtil.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/ClassUtil.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -31,11 +31,15 @@
/**
* Static utilities for working with classes.
+ *
* @author John Verhaeg
*/
public final class ClassUtil {
- private static void addObjectString( Object object, int includeInheritedFieldDepth,
Class clazz, StringBuffer text ) {
+ private static void addObjectString( Object object,
+ int includeInheritedFieldDepth,
+ Class<?> clazz,
+ StringBuffer text ) {
// Add class's name
text.append(nonPackageQualifiedName(clazz));
@@ -85,7 +89,8 @@
text.append(')');
}
- private static boolean addSeparator( boolean separatorNeeded, StringBuffer text ) {
+ private static boolean addSeparator( boolean separatorNeeded,
+ StringBuffer text ) {
if (separatorNeeded) {
text.append(", "); //$NON-NLS-1$
}
@@ -114,9 +119,9 @@
/**
* @param clazz A class.
* @return The non-package-qualified name of the specified class. Note, inner class
names will still be qualified by their
- * enclosing class names and a "$" delimiter.
+ * enclosing class names and a "$" delimiter.
*/
- public static String nonPackageQualifiedName( final Class clazz ) {
+ public static String nonPackageQualifiedName( final Class<?> clazz ) {
// if (clazz == null) {
// throw new IllegalArgumentException(I18n.format(CommonI18n.mustNotBeNull,
"Class")); //$NON-NLS-1$
// }
@@ -127,7 +132,7 @@
/**
* @param object An object.
* @return The non-package-qualified name of the class of the specified object. Note,
inner class names will still be
- * qualified by their enclosing class names and a "$" delimiter.
+ * qualified by their enclosing class names and a "$" delimiter.
*/
public static String nonPackageQualifiedName( final Object object ) {
// if (object == null) {
@@ -141,7 +146,8 @@
* @param includeInheritedFieldDepth
* @return A string representation of the specified object, consisting of its class
name, properties, and property values.
*/
- public static String toString( Object object, int includeInheritedFieldDepth ) {
+ public static String toString( Object object,
+ int includeInheritedFieldDepth ) {
StringBuffer text = new StringBuffer();
addObjectString(object, includeInheritedFieldDepth, object.getClass(), text);
return text.toString();
@@ -150,6 +156,7 @@
/**
* Determine whether the supplied string represents a well-formed fully-qualified
Java classname. This utility method enforces
* no conventions (e.g., packages are all lowercase) nor checks whether the class is
available on the classpath.
+ *
* @param classname
* @return true if the string is a fully-qualified class name
*/
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/Logger.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/Logger.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/Logger.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -36,391 +36,391 @@
@ThreadSafe
public final class Logger {
- public enum Level {
- OFF,
- ERROR,
- WARNING,
- INFO,
- DEBUG,
- TRACE;
- }
+ public enum Level {
+ OFF,
+ ERROR,
+ WARNING,
+ INFO,
+ DEBUG,
+ TRACE;
+ }
- private static final AtomicReference<Locale> LOGGING_LOCALE = new
AtomicReference<Locale>(null);
+ private static final AtomicReference<Locale> LOGGING_LOCALE = new
AtomicReference<Locale>(null);
- /**
- * Get the locale used for the logs. If null, the {@link Locale#getDefault() default
locale} is used.
- *
- * @return the current locale used for logging, or null if the system locale is used
- * @see #setLoggingLocale(Locale)
- */
- public static Locale getLoggingLocale() {
- return LOGGING_LOCALE.get();
- }
+ /**
+ * Get the locale used for the logs. If null, the {@link Locale#getDefault() default
locale} is used.
+ *
+ * @return the current locale used for logging, or null if the system locale is used
+ * @see #setLoggingLocale(Locale)
+ */
+ public static Locale getLoggingLocale() {
+ return LOGGING_LOCALE.get();
+ }
- /**
- * Set the locale used for the logs. This should be used when the logs are to be written
is a specific locale, independent of
- * the {@link Locale#getDefault() default locale}. To use the default locale, call this
method with a null value.
- *
- * @param locale the desired locale to use for the logs, or null if the system locale
should be used
- * @return the previous locale
- * @see #getLoggingLocale()
- */
- public static Locale setLoggingLocale( Locale locale ) {
- return LOGGING_LOCALE.getAndSet(locale != null ? locale : Locale.getDefault());
- }
+ /**
+ * Set the locale used for the logs. This should be used when the logs are to be
written is a specific locale, independent of
+ * the {@link Locale#getDefault() default locale}. To use the default locale, call
this method with a null value.
+ *
+ * @param locale the desired locale to use for the logs, or null if the system locale
should be used
+ * @return the previous locale
+ * @see #getLoggingLocale()
+ */
+ public static Locale setLoggingLocale( Locale locale ) {
+ return LOGGING_LOCALE.getAndSet(locale != null ? locale : Locale.getDefault());
+ }
- /**
- * Return a logger named corresponding to the class passed as parameter, using the
statically bound {@link ILoggerFactory}
- * instance.
- *
- * @param clazz the returned logger will be named after clazz
- * @return logger
- */
- public static Logger getLogger( Class clazz ) {
- return new Logger(LoggerFactory.getLogger(clazz));
- }
+ /**
+ * Return a logger named corresponding to the class passed as parameter, using the
statically bound {@link ILoggerFactory}
+ * instance.
+ *
+ * @param clazz the returned logger will be named after clazz
+ * @return logger
+ */
+ public static Logger getLogger( Class<?> clazz ) {
+ return new Logger(LoggerFactory.getLogger(clazz));
+ }
- /**
- * Return a logger named according to the name parameter using the statically bound
{@link ILoggerFactory} instance.
- *
- * @param name The name of the logger.
- * @return logger
- */
- public static Logger getLogger( String name ) {
- return new Logger(LoggerFactory.getLogger(name));
- }
+ /**
+ * Return a logger named according to the name parameter using the statically bound
{@link ILoggerFactory} instance.
+ *
+ * @param name The name of the logger.
+ * @return logger
+ */
+ public static Logger getLogger( String name ) {
+ return new Logger(LoggerFactory.getLogger(name));
+ }
- private final org.slf4j.Logger delegate;
+ private final org.slf4j.Logger delegate;
- private Logger( org.slf4j.Logger delegate ) {
- this.delegate = delegate;
- }
+ private Logger( org.slf4j.Logger delegate ) {
+ this.delegate = delegate;
+ }
- /**
- * Return the name of this logger instance.
- *
- * @return the logger's name
- */
- public String getName() {
- return this.delegate.getName();
- }
+ /**
+ * Return the name of this logger instance.
+ *
+ * @return the logger's name
+ */
+ public String getName() {
+ return this.delegate.getName();
+ }
- /**
- * Log a message at the suplied level according to the specified format and (optional)
parameters. The message should contain
- * a pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is
- * efficient and avoids superfluous object creation when the logger is disabled for the
desired level.
- *
- * @param level the level at which to log
- * @param message the (localized) message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void log( Level level,
- I18n message,
- Object... params ) {
- if (message == null) return;
- switch (level) {
- case DEBUG:
- debug(message.text(LOGGING_LOCALE.get(), params));
- break;
- case ERROR:
- error(message, params);
- break;
- case INFO:
- info(message, params);
- break;
- case TRACE:
- trace(message.text(LOGGING_LOCALE.get(), params));
- break;
- case WARNING:
- warn(message, params);
- break;
- case OFF:
- break;
- }
- }
+ /**
+ * Log a message at the suplied level according to the specified format and
(optional) parameters. The message should contain
+ * a pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is
+ * efficient and avoids superfluous object creation when the logger is disabled for
the desired level.
+ *
+ * @param level the level at which to log
+ * @param message the (localized) message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void log( Level level,
+ I18n message,
+ Object... params ) {
+ if (message == null) return;
+ switch (level) {
+ case DEBUG:
+ debug(message.text(LOGGING_LOCALE.get(), params));
+ break;
+ case ERROR:
+ error(message, params);
+ break;
+ case INFO:
+ info(message, params);
+ break;
+ case TRACE:
+ trace(message.text(LOGGING_LOCALE.get(), params));
+ break;
+ case WARNING:
+ warn(message, params);
+ break;
+ case OFF:
+ break;
+ }
+ }
- /**
- * Log an exception (throwable) at the supplied level with an accompanying message. If
the exception is null, then this method
- * calls {@link #debug(String, Object...)}.
- *
- * @param level the level at which to log
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void log( Level level,
- Throwable t,
- I18n message,
- Object... params ) {
- if (message == null) return;
- switch (level) {
- case DEBUG:
- debug(t, message.text(LOGGING_LOCALE.get(), params));
- break;
- case ERROR:
- error(t, message, params);
- break;
- case INFO:
- info(t, message, params);
- break;
- case TRACE:
- trace(t, message.text(LOGGING_LOCALE.get(), params));
- break;
- case WARNING:
- warn(t, message, params);
- break;
- case OFF:
- break;
- }
- }
+ /**
+ * Log an exception (throwable) at the supplied level with an accompanying message.
If the exception is null, then this method
+ * calls {@link #debug(String, Object...)}.
+ *
+ * @param level the level at which to log
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void log( Level level,
+ Throwable t,
+ I18n message,
+ Object... params ) {
+ if (message == null) return;
+ switch (level) {
+ case DEBUG:
+ debug(t, message.text(LOGGING_LOCALE.get(), params));
+ break;
+ case ERROR:
+ error(t, message, params);
+ break;
+ case INFO:
+ info(t, message, params);
+ break;
+ case TRACE:
+ trace(t, message.text(LOGGING_LOCALE.get(), params));
+ break;
+ case WARNING:
+ warn(t, message, params);
+ break;
+ case OFF:
+ break;
+ }
+ }
- /**
- * Log a message at the DEBUG level according to the specified format and (optional)
parameters. The message should contain a
- * pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is efficient
- * and avoids superfluous object creation when the logger is disabled for the DEBUG
level.
- *
- * @param message the message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void debug( String message,
- Object... params ) {
- if (!isDebugEnabled()) return;
- if (message == null) return;
- this.delegate.debug(StringUtil.createString(message, params));
- }
+ /**
+ * Log a message at the DEBUG level according to the specified format and (optional)
parameters. The message should contain a
+ * pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is efficient
+ * and avoids superfluous object creation when the logger is disabled for the DEBUG
level.
+ *
+ * @param message the message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void debug( String message,
+ Object... params ) {
+ if (!isDebugEnabled()) return;
+ if (message == null) return;
+ this.delegate.debug(StringUtil.createString(message, params));
+ }
- /**
- * Log an exception (throwable) at the DEBUG level with an accompanying message. If the
exception is null, then this method
- * calls {@link #debug(String, Object...)}.
- *
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void debug( Throwable t,
- String message,
- Object... params ) {
- if (!isDebugEnabled()) return;
- if (t == null) {
- debug(message, params);
- return;
- }
- if (message == null) {
- this.delegate.debug(null, t);
- return;
- }
- this.delegate.debug(StringUtil.createString(message, params), t);
- }
+ /**
+ * Log an exception (throwable) at the DEBUG level with an accompanying message. If
the exception is null, then this method
+ * calls {@link #debug(String, Object...)}.
+ *
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void debug( Throwable t,
+ String message,
+ Object... params ) {
+ if (!isDebugEnabled()) return;
+ if (t == null) {
+ debug(message, params);
+ return;
+ }
+ if (message == null) {
+ this.delegate.debug(null, t);
+ return;
+ }
+ this.delegate.debug(StringUtil.createString(message, params), t);
+ }
- /**
- * Log a message at the ERROR level according to the specified format and (optional)
parameters. The message should contain a
- * pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is efficient
- * and avoids superfluous object creation when the logger is disabled for the ERROR
level.
- *
- * @param message the message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void error( I18n message,
- Object... params ) {
- if (!isErrorEnabled()) return;
- if (message == null) return;
- this.delegate.error(message.text(LOGGING_LOCALE.get(), params));
- }
+ /**
+ * Log a message at the ERROR level according to the specified format and (optional)
parameters. The message should contain a
+ * pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is efficient
+ * and avoids superfluous object creation when the logger is disabled for the ERROR
level.
+ *
+ * @param message the message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void error( I18n message,
+ Object... params ) {
+ if (!isErrorEnabled()) return;
+ if (message == null) return;
+ this.delegate.error(message.text(LOGGING_LOCALE.get(), params));
+ }
- /**
- * Log an exception (throwable) at the ERROR level with an accompanying message. If the
exception is null, then this method
- * calls {@link #error(I18n, Object...)}.
- *
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void error( Throwable t,
- I18n message,
- Object... params ) {
- if (!isErrorEnabled()) return;
- if (t == null) {
- error(message, params);
- return;
- }
- if (message == null) {
- this.delegate.error(null, t);
- return;
- }
- this.delegate.error(message.text(LOGGING_LOCALE.get(), params), t);
- }
+ /**
+ * Log an exception (throwable) at the ERROR level with an accompanying message. If
the exception is null, then this method
+ * calls {@link #error(I18n, Object...)}.
+ *
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void error( Throwable t,
+ I18n message,
+ Object... params ) {
+ if (!isErrorEnabled()) return;
+ if (t == null) {
+ error(message, params);
+ return;
+ }
+ if (message == null) {
+ this.delegate.error(null, t);
+ return;
+ }
+ this.delegate.error(message.text(LOGGING_LOCALE.get(), params), t);
+ }
- /**
- * Log a message at the INFO level according to the specified format and (optional)
parameters. The message should contain a
- * pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is efficient
- * and avoids superfluous object creation when the logger is disabled for the INFO
level.
- *
- * @param message the message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void info( I18n message,
- Object... params ) {
- if (!isInfoEnabled()) return;
- if (message == null) return;
- this.delegate.info(message.text(LOGGING_LOCALE.get(), params));
- }
+ /**
+ * Log a message at the INFO level according to the specified format and (optional)
parameters. The message should contain a
+ * pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is efficient
+ * and avoids superfluous object creation when the logger is disabled for the INFO
level.
+ *
+ * @param message the message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void info( I18n message,
+ Object... params ) {
+ if (!isInfoEnabled()) return;
+ if (message == null) return;
+ this.delegate.info(message.text(LOGGING_LOCALE.get(), params));
+ }
- /**
- * Log an exception (throwable) at the INFO level with an accompanying message. If the
exception is null, then this method
- * calls {@link #info(I18n, Object...)}.
- *
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void info( Throwable t,
- I18n message,
- Object... params ) {
- if (!isInfoEnabled()) return;
- if (t == null) {
- info(message, params);
- return;
- }
- if (message == null) {
- this.delegate.info(null, t);
- return;
- }
- this.delegate.info(message.text(LOGGING_LOCALE.get(), params), t);
- }
+ /**
+ * Log an exception (throwable) at the INFO level with an accompanying message. If
the exception is null, then this method
+ * calls {@link #info(I18n, Object...)}.
+ *
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void info( Throwable t,
+ I18n message,
+ Object... params ) {
+ if (!isInfoEnabled()) return;
+ if (t == null) {
+ info(message, params);
+ return;
+ }
+ if (message == null) {
+ this.delegate.info(null, t);
+ return;
+ }
+ this.delegate.info(message.text(LOGGING_LOCALE.get(), params), t);
+ }
- /**
- * Log a message at the TRACE level according to the specified format and (optional)
parameters. The message should contain a
- * pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is efficient
- * and avoids superfluous object creation when the logger is disabled for the TRACE
level.
- *
- * @param message the message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void trace( String message,
- Object... params ) {
- if (!isTraceEnabled()) return;
- if (message == null) return;
- this.delegate.trace(StringUtil.createString(message, params));
- }
+ /**
+ * Log a message at the TRACE level according to the specified format and (optional)
parameters. The message should contain a
+ * pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is efficient
+ * and avoids superfluous object creation when the logger is disabled for the TRACE
level.
+ *
+ * @param message the message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void trace( String message,
+ Object... params ) {
+ if (!isTraceEnabled()) return;
+ if (message == null) return;
+ this.delegate.trace(StringUtil.createString(message, params));
+ }
- /**
- * Log an exception (throwable) at the TRACE level with an accompanying message. If the
exception is null, then this method
- * calls {@link #trace(String, Object...)}.
- *
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void trace( Throwable t,
- String message,
- Object... params ) {
- if (!isTraceEnabled()) return;
- if (t == null) {
- this.trace(message, params);
- return;
- }
- if (message == null) {
- this.delegate.trace(null, t);
- return;
- }
- this.delegate.trace(StringUtil.createString(message, params), t);
- }
+ /**
+ * Log an exception (throwable) at the TRACE level with an accompanying message. If
the exception is null, then this method
+ * calls {@link #trace(String, Object...)}.
+ *
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void trace( Throwable t,
+ String message,
+ Object... params ) {
+ if (!isTraceEnabled()) return;
+ if (t == null) {
+ this.trace(message, params);
+ return;
+ }
+ if (message == null) {
+ this.delegate.trace(null, t);
+ return;
+ }
+ this.delegate.trace(StringUtil.createString(message, params), t);
+ }
- /**
- * Log a message at the WARNING level according to the specified format and (optional)
parameters. The message should contain
- * a pair of empty curly braces for each of the parameter, which should be passed in the
correct order. This method is
- * efficient and avoids superfluous object creation when the logger is disabled for the
WARNING level.
- *
- * @param message the message string
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void warn( I18n message,
- Object... params ) {
- if (!isWarnEnabled()) return;
- if (message == null) return;
- this.delegate.warn(message.text(LOGGING_LOCALE.get(), params));
- }
+ /**
+ * Log a message at the WARNING level according to the specified format and
(optional) parameters. The message should contain
+ * a pair of empty curly braces for each of the parameter, which should be passed in
the correct order. This method is
+ * efficient and avoids superfluous object creation when the logger is disabled for
the WARNING level.
+ *
+ * @param message the message string
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void warn( I18n message,
+ Object... params ) {
+ if (!isWarnEnabled()) return;
+ if (message == null) return;
+ this.delegate.warn(message.text(LOGGING_LOCALE.get(), params));
+ }
- /**
- * Log an exception (throwable) at the WARNING level with an accompanying message. If
the exception is null, then this method
- * calls {@link #warn(I18n, Object...)}.
- *
- * @param t the exception (throwable) to log
- * @param message the message accompanying the exception
- * @param params the parameter values that are to replace the variables in the format
string
- */
- public void warn( Throwable t,
- I18n message,
- Object... params ) {
- if (!isWarnEnabled()) return;
- if (t == null) {
- warn(message, params);
- return;
- }
- if (message == null) {
- this.delegate.warn(null, t);
- return;
- }
- this.delegate.warn(message.text(LOGGING_LOCALE.get(), params), t);
- }
+ /**
+ * Log an exception (throwable) at the WARNING level with an accompanying message. If
the exception is null, then this method
+ * calls {@link #warn(I18n, Object...)}.
+ *
+ * @param t the exception (throwable) to log
+ * @param message the message accompanying the exception
+ * @param params the parameter values that are to replace the variables in the format
string
+ */
+ public void warn( Throwable t,
+ I18n message,
+ Object... params ) {
+ if (!isWarnEnabled()) return;
+ if (t == null) {
+ warn(message, params);
+ return;
+ }
+ if (message == null) {
+ this.delegate.warn(null, t);
+ return;
+ }
+ this.delegate.warn(message.text(LOGGING_LOCALE.get(), params), t);
+ }
- /**
- * Return whether messages at the INFORMATION level are being logged.
- *
- * @return true if INFORMATION log messages are currently being logged, or false
otherwise.
- */
- public boolean isInfoEnabled() {
- return this.delegate.isInfoEnabled();
- }
+ /**
+ * Return whether messages at the INFORMATION level are being logged.
+ *
+ * @return true if INFORMATION log messages are currently being logged, or false
otherwise.
+ */
+ public boolean isInfoEnabled() {
+ return this.delegate.isInfoEnabled();
+ }
- /**
- * Return whether messages at the WARNING level are being logged.
- *
- * @return true if WARNING log messages are currently being logged, or false otherwise.
- */
- public boolean isWarnEnabled() {
- return this.delegate.isWarnEnabled();
- }
+ /**
+ * Return whether messages at the WARNING level are being logged.
+ *
+ * @return true if WARNING log messages are currently being logged, or false
otherwise.
+ */
+ public boolean isWarnEnabled() {
+ return this.delegate.isWarnEnabled();
+ }
- /**
- * Return whether messages at the ERROR level are being logged.
- *
- * @return true if ERROR log messages are currently being logged, or false otherwise.
- */
- public boolean isErrorEnabled() {
- return this.delegate.isErrorEnabled();
- }
+ /**
+ * Return whether messages at the ERROR level are being logged.
+ *
+ * @return true if ERROR log messages are currently being logged, or false
otherwise.
+ */
+ public boolean isErrorEnabled() {
+ return this.delegate.isErrorEnabled();
+ }
- /**
- * Return whether messages at the DEBUG level are being logged.
- *
- * @return true if DEBUG log messages are currently being logged, or false otherwise.
- */
- public boolean isDebugEnabled() {
- return this.delegate.isDebugEnabled();
- }
+ /**
+ * Return whether messages at the DEBUG level are being logged.
+ *
+ * @return true if DEBUG log messages are currently being logged, or false
otherwise.
+ */
+ public boolean isDebugEnabled() {
+ return this.delegate.isDebugEnabled();
+ }
- /**
- * Return whether messages at the TRACE level are being logged.
- *
- * @return true if TRACE log messages are currently being logged, or false otherwise.
- */
- public boolean isTraceEnabled() {
- return this.delegate.isTraceEnabled();
- }
+ /**
+ * Return whether messages at the TRACE level are being logged.
+ *
+ * @return true if TRACE log messages are currently being logged, or false
otherwise.
+ */
+ public boolean isTraceEnabled() {
+ return this.delegate.isTraceEnabled();
+ }
- /**
- * Get the logging level at which this logger is current set.
- *
- * @return the current logging level
- */
- public Level getLevel() {
- if (this.isTraceEnabled()) return Level.TRACE;
- if (this.isDebugEnabled()) return Level.DEBUG;
- if (this.isInfoEnabled()) return Level.INFO;
- if (this.isWarnEnabled()) return Level.WARNING;
- if (this.isErrorEnabled()) return Level.ERROR;
- return Level.OFF;
- }
+ /**
+ * Get the logging level at which this logger is current set.
+ *
+ * @return the current logging level
+ */
+ public Level getLevel() {
+ if (this.isTraceEnabled()) return Level.TRACE;
+ if (this.isDebugEnabled()) return Level.DEBUG;
+ if (this.isInfoEnabled()) return Level.INFO;
+ if (this.isWarnEnabled()) return Level.WARNING;
+ if (this.isErrorEnabled()) return Level.ERROR;
+ return Level.OFF;
+ }
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/StringUtil.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -45,611 +45,611 @@
*/
public class StringUtil {
- public static final String[] EMPTY_STRING_ARRAY = new String[0];
- private static final Pattern NORMALIZE_PATTERN = Pattern.compile("\\s+");
- private static final Pattern PARAMETER_COUNT_PATTERN =
Pattern.compile("\\{(\\d+)\\}");
+ public static final String[] EMPTY_STRING_ARRAY = new String[0];
+ private static final Pattern NORMALIZE_PATTERN = Pattern.compile("\\s+");
+ private static final Pattern PARAMETER_COUNT_PATTERN =
Pattern.compile("\\{(\\d+)\\}");
- /**
- * Split the supplied content into lines, returning each line as an element in the
returned list.
- *
- * @param content the string content that is to be split
- * @return the list of lines; never null but may be an empty (unmodifiable) list if the
supplied content is null or empty
- */
- public static List<String> splitLines( final String content ) {
- if (content == null || content.length() == 0) return Collections.emptyList();
- String[] lines = content.split("[\\r]?\\n");
- return Arrays.asList(lines);
- }
+ /**
+ * Split the supplied content into lines, returning each line as an element in the
returned list.
+ *
+ * @param content the string content that is to be split
+ * @return the list of lines; never null but may be an empty (unmodifiable) list if
the supplied content is null or empty
+ */
+ public static List<String> splitLines( final String content ) {
+ if (content == null || content.length() == 0) return Collections.emptyList();
+ String[] lines = content.split("[\\r]?\\n");
+ return Arrays.asList(lines);
+ }
- /**
- * Create a string by substituting the parameters into all key occurrences in the
supplied format. The pattern consists of
- * zero or more keys of the form <code>{n}</code>, where
<code>n</code> is an integer starting at 1. Therefore, the first
- * parameter replaces all occurrences of "{1}", the second parameter replaces
all occurrences of "{2}", etc.
- * <p>
- * If any parameter is null, the corresponding key is replaced with the string
"null". Therefore, consider using an empty
- * string when keys are to be removed altogether.
- * </p>
- * <p>
- * If there are no parameters, this method does nothing and returns the supplied pattern
as is.
- * </p>
- *
- * @param pattern the pattern
- * @param parameters the parameters used to replace keys
- * @return the string with all keys replaced (or removed)
- */
- public static String createString( String pattern,
- Object... parameters ) {
- ArgCheck.isNotNull(pattern, "pattern");
- if (parameters == null) parameters = EMPTY_STRING_ARRAY;
- Matcher matcher = PARAMETER_COUNT_PATTERN.matcher(pattern);
- StringBuffer text = new StringBuffer();
- int requiredParameterCount = 0;
- boolean err = false;
- while (matcher.find()) {
- int ndx = Integer.valueOf(matcher.group(1));
- if (requiredParameterCount <= ndx) {
- requiredParameterCount = ndx + 1;
- }
- if (ndx >= parameters.length) {
- err = true;
- matcher.appendReplacement(text, matcher.group());
- } else {
- Object parameter = parameters[ndx];
- matcher.appendReplacement(text, Matcher.quoteReplacement(parameter == null ?
"null" : parameter.toString()));
- }
- }
- if (err || requiredParameterCount < parameters.length) {
- throw new IllegalArgumentException(
-
CommonI18n.requiredToSuppliedParameterMismatch.text(parameters.length,
-
parameters.length == 1 ? "" : "s",
-
requiredParameterCount,
-
requiredParameterCount == 1 ? "" : "s",
-
pattern,
-
text.toString()));
- }
- matcher.appendTail(text);
+ /**
+ * Create a string by substituting the parameters into all key occurrences in the
supplied format. The pattern consists of
+ * zero or more keys of the form <code>{n}</code>, where
<code>n</code> is an integer starting at 1. Therefore, the first
+ * parameter replaces all occurrences of "{1}", the second parameter
replaces all occurrences of "{2}", etc.
+ * <p>
+ * If any parameter is null, the corresponding key is replaced with the string
"null". Therefore, consider using an empty
+ * string when keys are to be removed altogether.
+ * </p>
+ * <p>
+ * If there are no parameters, this method does nothing and returns the supplied
pattern as is.
+ * </p>
+ *
+ * @param pattern the pattern
+ * @param parameters the parameters used to replace keys
+ * @return the string with all keys replaced (or removed)
+ */
+ public static String createString( String pattern,
+ Object... parameters ) {
+ ArgCheck.isNotNull(pattern, "pattern");
+ if (parameters == null) parameters = EMPTY_STRING_ARRAY;
+ Matcher matcher = PARAMETER_COUNT_PATTERN.matcher(pattern);
+ StringBuffer text = new StringBuffer();
+ int requiredParameterCount = 0;
+ boolean err = false;
+ while (matcher.find()) {
+ int ndx = Integer.valueOf(matcher.group(1));
+ if (requiredParameterCount <= ndx) {
+ requiredParameterCount = ndx + 1;
+ }
+ if (ndx >= parameters.length) {
+ err = true;
+ matcher.appendReplacement(text, matcher.group());
+ } else {
+ Object parameter = parameters[ndx];
+ matcher.appendReplacement(text, Matcher.quoteReplacement(parameter ==
null ? "null" : parameter.toString()));
+ }
+ }
+ if (err || requiredParameterCount < parameters.length) {
+ throw new IllegalArgumentException(
+
CommonI18n.requiredToSuppliedParameterMismatch.text(parameters.length,
+
parameters.length == 1 ? "" : "s",
+
requiredParameterCount,
+
requiredParameterCount == 1 ? "" : "s",
+
pattern,
+
text.toString()));
+ }
+ matcher.appendTail(text);
- return text.toString();
- }
+ return text.toString();
+ }
- /**
- * Create a new string containing the specified character repeated a specific number of
times.
- *
- * @param charToRepeat the character to repeat
- * @param numberOfRepeats the number of times the character is to repeat in the result;
must be greater than 0
- * @return the resulting string
- */
- public static String createString( final char charToRepeat,
- int numberOfRepeats ) {
- assert numberOfRepeats >= 0;
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < numberOfRepeats; ++i) {
- sb.append(charToRepeat);
- }
- return sb.toString();
- }
+ /**
+ * Create a new string containing the specified character repeated a specific number
of times.
+ *
+ * @param charToRepeat the character to repeat
+ * @param numberOfRepeats the number of times the character is to repeat in the
result; must be greater than 0
+ * @return the resulting string
+ */
+ public static String createString( final char charToRepeat,
+ int numberOfRepeats ) {
+ assert numberOfRepeats >= 0;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < numberOfRepeats; ++i) {
+ sb.append(charToRepeat);
+ }
+ return sb.toString();
+ }
- /**
- * Set the length of the string, padding with the supplied character if the supplied
string is shorter than desired, or
- * truncating the string if it is longer than desired. Unlike {@link
#justifyLeft(String, int, char)}, this method does not
- * remove leading and trailing whitespace.
- *
- * @param original the string for which the length is to be set; may not be null
- * @param length the desired length; must be positive
- * @param padChar the character to use for padding, if the supplied string is not long
enough
- * @return the string of the desired length
- * @see #justifyLeft(String, int, char)
- */
- public static String setLength( String original,
- int length,
- char padChar ) {
- return justifyLeft(original, length, padChar, false);
- }
+ /**
+ * Set the length of the string, padding with the supplied character if the supplied
string is shorter than desired, or
+ * truncating the string if it is longer than desired. Unlike {@link
#justifyLeft(String, int, char)}, this method does not
+ * remove leading and trailing whitespace.
+ *
+ * @param original the string for which the length is to be set; may not be null
+ * @param length the desired length; must be positive
+ * @param padChar the character to use for padding, if the supplied string is not
long enough
+ * @return the string of the desired length
+ * @see #justifyLeft(String, int, char)
+ */
+ public static String setLength( String original,
+ int length,
+ char padChar ) {
+ return justifyLeft(original, length, padChar, false);
+ }
- /**
- * Right justify the contents of the string, ensuring that the string ends at the last
character. If the supplied string is
- * longer than the desired width, the leading characters are removed so that the last
character in the supplied string at the
- * last position. If the supplied string is shorter than the desired width, the padding
character is inserted one or more
- * times such that the last character in the supplied string appears as the last
character in the resulting string and that
- * the length matches that specified.
- *
- * @param str the string to be right justified; if null, an empty string is used
- * @param width the desired width of the string; must be positive
- * @param padWithChar the character to use for padding, if needed
- * @return the right justified string
- */
- public static String justifyRight( String str,
- final int width,
- char padWithChar ) {
- assert width > 0;
- // Trim the leading and trailing whitespace ...
- str = str != null ? str.trim() : "";
+ /**
+ * Right justify the contents of the string, ensuring that the string ends at the
last character. If the supplied string is
+ * longer than the desired width, the leading characters are removed so that the last
character in the supplied string at the
+ * last position. If the supplied string is shorter than the desired width, the
padding character is inserted one or more
+ * times such that the last character in the supplied string appears as the last
character in the resulting string and that
+ * the length matches that specified.
+ *
+ * @param str the string to be right justified; if null, an empty string is used
+ * @param width the desired width of the string; must be positive
+ * @param padWithChar the character to use for padding, if needed
+ * @return the right justified string
+ */
+ public static String justifyRight( String str,
+ final int width,
+ char padWithChar ) {
+ assert width > 0;
+ // Trim the leading and trailing whitespace ...
+ str = str != null ? str.trim() : "";
- final int length = str.length();
- int addChars = width - length;
- if (addChars < 0) {
- // truncate the first characters, keep the last
- return str.subSequence(length - width, length).toString();
- }
- // Prepend the whitespace ...
- final StringBuilder sb = new StringBuilder();
- while (addChars > 0) {
- sb.append(padWithChar);
- --addChars;
- }
+ final int length = str.length();
+ int addChars = width - length;
+ if (addChars < 0) {
+ // truncate the first characters, keep the last
+ return str.subSequence(length - width, length).toString();
+ }
+ // Prepend the whitespace ...
+ final StringBuilder sb = new StringBuilder();
+ while (addChars > 0) {
+ sb.append(padWithChar);
+ --addChars;
+ }
- // Write the content ...
- sb.append(str);
- return sb.toString();
- }
+ // Write the content ...
+ sb.append(str);
+ return sb.toString();
+ }
- /**
- * Left justify the contents of the string, ensuring that the supplied string begins at
the first character and that the
- * resulting string is of the desired length. If the supplied string is longer than the
desired width, it is truncated to the
- * specified length. If the supplied string is shorter than the desired width, the
padding character is added to the end of
- * the string one or more times such that the length is that specified. All leading and
trailing whitespace is removed.
- *
- * @param str the string to be left justified; if null, an empty string is used
- * @param width the desired width of the string; must be positive
- * @param padWithChar the character to use for padding, if needed
- * @return the left justified string
- * @see #setLength(String, int, char)
- */
- public static String justifyLeft( String str,
- final int width,
- char padWithChar ) {
- return justifyLeft(str, width, padWithChar, true);
- }
+ /**
+ * Left justify the contents of the string, ensuring that the supplied string begins
at the first character and that the
+ * resulting string is of the desired length. If the supplied string is longer than
the desired width, it is truncated to the
+ * specified length. If the supplied string is shorter than the desired width, the
padding character is added to the end of
+ * the string one or more times such that the length is that specified. All leading
and trailing whitespace is removed.
+ *
+ * @param str the string to be left justified; if null, an empty string is used
+ * @param width the desired width of the string; must be positive
+ * @param padWithChar the character to use for padding, if needed
+ * @return the left justified string
+ * @see #setLength(String, int, char)
+ */
+ public static String justifyLeft( String str,
+ final int width,
+ char padWithChar ) {
+ return justifyLeft(str, width, padWithChar, true);
+ }
- protected static String justifyLeft( String str,
- final int width,
- char padWithChar,
- boolean trimWhitespace ) {
- // Trim the leading and trailing whitespace ...
- str = str != null ? (trimWhitespace ? str.trim() : str) : "";
+ protected static String justifyLeft( String str,
+ final int width,
+ char padWithChar,
+ boolean trimWhitespace ) {
+ // Trim the leading and trailing whitespace ...
+ str = str != null ? (trimWhitespace ? str.trim() : str) : "";
- int addChars = width - str.length();
- if (addChars < 0) {
- // truncate
- return str.subSequence(0, width).toString();
- }
- // Write the content ...
- final StringBuilder sb = new StringBuilder();
- sb.append(str);
+ int addChars = width - str.length();
+ if (addChars < 0) {
+ // truncate
+ return str.subSequence(0, width).toString();
+ }
+ // Write the content ...
+ final StringBuilder sb = new StringBuilder();
+ sb.append(str);
- // Append the whitespace ...
- while (addChars > 0) {
- sb.append(padWithChar);
- --addChars;
- }
+ // Append the whitespace ...
+ while (addChars > 0) {
+ sb.append(padWithChar);
+ --addChars;
+ }
- return sb.toString();
- }
+ return sb.toString();
+ }
- /**
- * Center the contents of the string. If the supplied string is longer than the desired
width, it is truncated to the
- * specified length. If the supplied string is shorter than the desired width, padding
characters are added to the beginning
- * and end of the string such that the length is that specified; one additional padding
character is prepended if required.
- * All leading and trailing whitespace is removed before centering.
- *
- * @param str the string to be left justified; if null, an empty string is used
- * @param width the desired width of the string; must be positive
- * @param padWithChar the character to use for padding, if needed
- * @return the left justified string
- * @see #setLength(String, int, char)
- */
- public static String justifyCenter( String str,
- final int width,
- char padWithChar ) {
- // Trim the leading and trailing whitespace ...
- str = str != null ? str.trim() : "";
+ /**
+ * Center the contents of the string. If the supplied string is longer than the
desired width, it is truncated to the
+ * specified length. If the supplied string is shorter than the desired width,
padding characters are added to the beginning
+ * and end of the string such that the length is that specified; one additional
padding character is prepended if required.
+ * All leading and trailing whitespace is removed before centering.
+ *
+ * @param str the string to be left justified; if null, an empty string is used
+ * @param width the desired width of the string; must be positive
+ * @param padWithChar the character to use for padding, if needed
+ * @return the left justified string
+ * @see #setLength(String, int, char)
+ */
+ public static String justifyCenter( String str,
+ final int width,
+ char padWithChar ) {
+ // Trim the leading and trailing whitespace ...
+ str = str != null ? str.trim() : "";
- int addChars = width - str.length();
- if (addChars < 0) {
- // truncate
- return str.subSequence(0, width).toString();
- }
- // Write the content ...
- int prependNumber = addChars / 2;
- int appendNumber = prependNumber;
- if ((prependNumber + appendNumber) != addChars) {
- ++prependNumber;
- }
+ int addChars = width - str.length();
+ if (addChars < 0) {
+ // truncate
+ return str.subSequence(0, width).toString();
+ }
+ // Write the content ...
+ int prependNumber = addChars / 2;
+ int appendNumber = prependNumber;
+ if ((prependNumber + appendNumber) != addChars) {
+ ++prependNumber;
+ }
- final StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
- // Prepend the pad character(s) ...
- while (prependNumber > 0) {
- sb.append(padWithChar);
- --prependNumber;
- }
+ // Prepend the pad character(s) ...
+ while (prependNumber > 0) {
+ sb.append(padWithChar);
+ --prependNumber;
+ }
- // Add the actual content
- sb.append(str);
+ // Add the actual content
+ sb.append(str);
- // Append the pad character(s) ...
- while (appendNumber > 0) {
- sb.append(padWithChar);
- --appendNumber;
- }
+ // Append the pad character(s) ...
+ while (appendNumber > 0) {
+ sb.append(padWithChar);
+ --appendNumber;
+ }
- return sb.toString();
- }
+ return sb.toString();
+ }
- /**
- * Truncate the supplied string to be no more than the specified length. This method
returns an empty string if the supplied
- * object is null.
- *
- * @param obj the object from which the string is to be obtained using {@link
Object#toString()}.
- * @param maxLength the maximum length of the string being returned
- * @return the supplied string if no longer than the maximum length, or the supplied
string truncated to be no longer than the
- * maximum length (including the suffix)
- * @throws IllegalArgumentException if the maximum length is negative
- */
- public static String truncate( Object obj,
- int maxLength ) {
- return truncate(obj, maxLength, null);
- }
+ /**
+ * Truncate the supplied string to be no more than the specified length. This method
returns an empty string if the supplied
+ * object is null.
+ *
+ * @param obj the object from which the string is to be obtained using {@link
Object#toString()}.
+ * @param maxLength the maximum length of the string being returned
+ * @return the supplied string if no longer than the maximum length, or the supplied
string truncated to be no longer than the
+ * maximum length (including the suffix)
+ * @throws IllegalArgumentException if the maximum length is negative
+ */
+ public static String truncate( Object obj,
+ int maxLength ) {
+ return truncate(obj, maxLength, null);
+ }
- /**
- * Truncate the supplied string to be no more than the specified length. This method
returns an empty string if the supplied
- * object is null.
- *
- * @param obj the object from which the string is to be obtained using {@link
Object#toString()}.
- * @param maxLength the maximum length of the string being returned
- * @param suffix the suffix that should be added to the content if the string must be
truncated, or null if the default suffix
- * of "..." should be used
- * @return the supplied string if no longer than the maximum length, or the supplied
string truncated to be no longer than the
- * maximum length (including the suffix)
- * @throws IllegalArgumentException if the maximum length is negative
- */
- public static String truncate( Object obj,
- int maxLength,
- String suffix ) {
- ArgCheck.isNonNegative(maxLength, "maxLength");
- if (obj == null || maxLength == 0) {
- return "";
- }
- String str = obj.toString();
- if (str.length() <= maxLength) return str;
- if (suffix == null) suffix = "...";
- int maxNumChars = maxLength - suffix.length();
- if (maxNumChars < 0) {
- // Then the max length is actually shorter than the suffix ...
- str = suffix.substring(0, maxLength);
- } else if (str.length() > maxNumChars) {
- str = str.substring(0, maxNumChars) + suffix;
- }
- return str;
- }
+ /**
+ * Truncate the supplied string to be no more than the specified length. This method
returns an empty string if the supplied
+ * object is null.
+ *
+ * @param obj the object from which the string is to be obtained using {@link
Object#toString()}.
+ * @param maxLength the maximum length of the string being returned
+ * @param suffix the suffix that should be added to the content if the string must be
truncated, or null if the default suffix
+ * of "..." should be used
+ * @return the supplied string if no longer than the maximum length, or the supplied
string truncated to be no longer than the
+ * maximum length (including the suffix)
+ * @throws IllegalArgumentException if the maximum length is negative
+ */
+ public static String truncate( Object obj,
+ int maxLength,
+ String suffix ) {
+ ArgCheck.isNonNegative(maxLength, "maxLength");
+ if (obj == null || maxLength == 0) {
+ return "";
+ }
+ String str = obj.toString();
+ if (str.length() <= maxLength) return str;
+ if (suffix == null) suffix = "...";
+ int maxNumChars = maxLength - suffix.length();
+ if (maxNumChars < 0) {
+ // Then the max length is actually shorter than the suffix ...
+ str = suffix.substring(0, maxLength);
+ } else if (str.length() > maxNumChars) {
+ str = str.substring(0, maxNumChars) + suffix;
+ }
+ return str;
+ }
- /**
- * Read and return the entire contents of the supplied {@link Reader}. This method
always closes the reader when finished
- * reading.
- *
- * @param reader the reader of the contents; may be null
- * @return the contents, or an empty string if the supplied reader is null
- * @throws IOException if there is an error reading the content
- */
- public static String read( Reader reader ) throws IOException {
- return IoUtil.read(reader);
- }
+ /**
+ * Read and return the entire contents of the supplied {@link Reader}. This method
always closes the reader when finished
+ * reading.
+ *
+ * @param reader the reader of the contents; may be null
+ * @return the contents, or an empty string if the supplied reader is null
+ * @throws IOException if there is an error reading the content
+ */
+ public static String read( Reader reader ) throws IOException {
+ return IoUtil.read(reader);
+ }
- /**
- * Read and return the entire contents of the supplied {@link InputStream}. This method
always closes the stream when
- * finished reading.
- *
- * @param stream the streamed contents; may be null
- * @return the contents, or an empty string if the supplied stream is null
- * @throws IOException if there is an error reading the content
- */
- public static String read( InputStream stream ) throws IOException {
- return IoUtil.read(stream);
- }
+ /**
+ * Read and return the entire contents of the supplied {@link InputStream}. This
method always closes the stream when
+ * finished reading.
+ *
+ * @param stream the streamed contents; may be null
+ * @return the contents, or an empty string if the supplied stream is null
+ * @throws IOException if there is an error reading the content
+ */
+ public static String read( InputStream stream ) throws IOException {
+ return IoUtil.read(stream);
+ }
- /**
- * Write the entire contents of the supplied string to the given stream. This method
always flushes and closes the stream when
- * finished.
- *
- * @param content the content to write to the stream; may be null
- * @param stream the stream to which the content is to be written
- * @throws IOException
- * @throws IllegalArgumentException if the stream is null
- */
- public static void write( String content,
- OutputStream stream ) throws IOException {
- IoUtil.write(content, stream);
- }
+ /**
+ * Write the entire contents of the supplied string to the given stream. This method
always flushes and closes the stream when
+ * finished.
+ *
+ * @param content the content to write to the stream; may be null
+ * @param stream the stream to which the content is to be written
+ * @throws IOException
+ * @throws IllegalArgumentException if the stream is null
+ */
+ public static void write( String content,
+ OutputStream stream ) throws IOException {
+ IoUtil.write(content, stream);
+ }
- /**
- * Write the entire contents of the supplied string to the given writer. This method
always flushes and closes the writer when
- * finished.
- *
- * @param content the content to write to the writer; may be null
- * @param writer the writer to which the content is to be written
- * @throws IOException
- * @throws IllegalArgumentException if the writer is null
- */
- public static void write( String content,
- Writer writer ) throws IOException {
- IoUtil.write(content, writer);
- }
+ /**
+ * Write the entire contents of the supplied string to the given writer. This method
always flushes and closes the writer when
+ * finished.
+ *
+ * @param content the content to write to the writer; may be null
+ * @param writer the writer to which the content is to be written
+ * @throws IOException
+ * @throws IllegalArgumentException if the writer is null
+ */
+ public static void write( String content,
+ Writer writer ) throws IOException {
+ IoUtil.write(content, writer);
+ }
- /**
- * Create a human-readable form of the supplied object by choosing the representation
format based upon the object type.
- * <p>
- * <ul>
- * <li>A null reference results in the "null" string.</li>
- * <li>A string is written wrapped by double quotes.</li>
- * <li>A boolean is written using {@link Boolean#toString()}.</li>
- * <li>A {@link Number number} is written using the standard {@link
Number#toString() toString()} method.</li>
- * <li>A {@link java.util.Date date} is written using the the {@link
DateUtil#getDateAsStandardString(java.util.Date)}
- * utility method.</li>
- * <li>A {@link java.sql.Date SQL date} is written using the the {@link
DateUtil#getDateAsStandardString(java.util.Date)}
- * utility method.</li>
- * <li>A {@link Calendar Calendar instance} is written using the the {@link
DateUtil#getDateAsStandardString(Calendar)}
- * utility method.</li>
- * <li>An array of bytes is written with a leading "[ " and trailing
" ]" surrounding the bytes written as UTF-8.
- * <li>An array of objects is written with a leading "[ " and trailing
" ]", and with all objects sent through
- * {@link #readableString(Object)} and separated by ", ".</li>
- * <li>A collection of objects (e.g, <code>Collection<?></code>)
is written with a leading "[ " and trailing " ]", and
- * with all objects sent through {@link #readableString(Object)} and separated by
", ".</li>
- * <li>A map of objects (e.g, <code>Map<?></code>) is written
with a leading "{ " and trailing " }", and with all map
- * entries written in the form "key => value" and separated by ",
". All key and value objects are sent through the
- * {@link #readableString(Object)} method.</li>
- * <li>Any other object is written using the object's {@link Object#toString()
toString()} method.</li>
- * </ul>
- * </p>
- * <p>
- * This method is capable of generating strings for nested objects. For example, a
<code>Map<Date,Object[]></code> would be
- * written in the form:
- *
- * <pre>
- * { 2008-02-03T14:22:49 => [ "description", 3, [
003459de7389g23aef, true ] ] }
- * </pre>
- *
- * </p>
- *
- * @param obj the object that is to be converted to a string.
- * @return the string representation that is to be human readable
- */
- public static String readableString( Object obj ) {
- if (obj == null) return "null";
- if (obj instanceof Boolean) return ((Boolean)obj).toString();
- if (obj instanceof String) return "\"" + obj.toString() +
"\"";
- if (obj instanceof Number) return obj.toString();
- if (obj instanceof Map) return readableString((Map)obj);
- if (obj instanceof Collection) return readableString((Collection)obj);
- if (obj instanceof byte[]) return readableString((byte[])obj);
- if (obj instanceof boolean[]) return readableString((boolean[])obj);
- if (obj instanceof short[]) return readableString((short[])obj);
- if (obj instanceof int[]) return readableString((int[])obj);
- if (obj instanceof long[]) return readableString((long[])obj);
- if (obj instanceof float[]) return readableString((float[])obj);
- if (obj instanceof double[]) return readableString((double[])obj);
- if (obj instanceof Object[]) return readableString((Object[])obj);
- if (obj instanceof Calendar) return DateUtil.getDateAsStandardString((Calendar)obj);
- if (obj instanceof java.util.Date) return
DateUtil.getDateAsStandardString((java.util.Date)obj);
- if (obj instanceof java.sql.Date) return
DateUtil.getDateAsStandardString((java.sql.Date)obj);
- return obj.toString();
- }
+ /**
+ * Create a human-readable form of the supplied object by choosing the representation
format based upon the object type.
+ * <p>
+ * <ul>
+ * <li>A null reference results in the "null" string.</li>
+ * <li>A string is written wrapped by double quotes.</li>
+ * <li>A boolean is written using {@link Boolean#toString()}.</li>
+ * <li>A {@link Number number} is written using the standard {@link
Number#toString() toString()} method.</li>
+ * <li>A {@link java.util.Date date} is written using the the {@link
DateUtil#getDateAsStandardString(java.util.Date)}
+ * utility method.</li>
+ * <li>A {@link java.sql.Date SQL date} is written using the the {@link
DateUtil#getDateAsStandardString(java.util.Date)}
+ * utility method.</li>
+ * <li>A {@link Calendar Calendar instance} is written using the the {@link
DateUtil#getDateAsStandardString(Calendar)}
+ * utility method.</li>
+ * <li>An array of bytes is written with a leading "[ " and trailing
" ]" surrounding the bytes written as UTF-8.
+ * <li>An array of objects is written with a leading "[ " and
trailing " ]", and with all objects sent through
+ * {@link #readableString(Object)} and separated by ", ".</li>
+ * <li>A collection of objects (e.g,
<code>Collection<?></code>) is written with a leading "[ " and
trailing " ]", and
+ * with all objects sent through {@link #readableString(Object)} and separated by
", ".</li>
+ * <li>A map of objects (e.g, <code>Map<?></code>) is written
with a leading "{ " and trailing " }", and with all map
+ * entries written in the form "key => value" and separated by ",
". All key and value objects are sent through the
+ * {@link #readableString(Object)} method.</li>
+ * <li>Any other object is written using the object's {@link
Object#toString() toString()} method.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * This method is capable of generating strings for nested objects. For example, a
<code>Map<Date,Object[]></code> would be
+ * written in the form:
+ *
+ * <pre>
+ * { 2008-02-03T14:22:49 => [ "description", 3, [
003459de7389g23aef, true ] ] }
+ * </pre>
+ *
+ * </p>
+ *
+ * @param obj the object that is to be converted to a string.
+ * @return the string representation that is to be human readable
+ */
+ public static String readableString( Object obj ) {
+ if (obj == null) return "null";
+ if (obj instanceof Boolean) return ((Boolean)obj).toString();
+ if (obj instanceof String) return "\"" + obj.toString() +
"\"";
+ if (obj instanceof Number) return obj.toString();
+ if (obj instanceof Map<?, ?>) return readableString((Map<?, ?>)obj);
+ if (obj instanceof Collection<?>) return
readableString((Collection<?>)obj);
+ if (obj instanceof byte[]) return readableString((byte[])obj);
+ if (obj instanceof boolean[]) return readableString((boolean[])obj);
+ if (obj instanceof short[]) return readableString((short[])obj);
+ if (obj instanceof int[]) return readableString((int[])obj);
+ if (obj instanceof long[]) return readableString((long[])obj);
+ if (obj instanceof float[]) return readableString((float[])obj);
+ if (obj instanceof double[]) return readableString((double[])obj);
+ if (obj instanceof Object[]) return readableString((Object[])obj);
+ if (obj instanceof Calendar) return
DateUtil.getDateAsStandardString((Calendar)obj);
+ if (obj instanceof java.util.Date) return
DateUtil.getDateAsStandardString((java.util.Date)obj);
+ if (obj instanceof java.sql.Date) return
DateUtil.getDateAsStandardString((java.sql.Date)obj);
+ return obj.toString();
+ }
- protected static String readableEmptyArray( Class arrayClass ) {
- assert arrayClass != null;
- Class componentType = arrayClass.getComponentType();
- if (componentType.isArray()) return "[" + readableEmptyArray(componentType) +
"]";
- return "[]";
- }
+ protected static String readableEmptyArray( Class<?> arrayClass ) {
+ assert arrayClass != null;
+ Class<?> componentType = arrayClass.getComponentType();
+ if (componentType.isArray()) return "[" +
readableEmptyArray(componentType) + "]";
+ return "[]";
+ }
- protected static String readableString( Object[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (Object value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( Object[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (Object value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( int[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (int value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( int[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (int value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( short[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (short value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( short[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (short value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( long[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (long value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( long[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (long value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( boolean[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (boolean value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( boolean[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (boolean value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( float[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (float value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( float[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (float value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( double[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (double value : array) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( double[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (double value : array) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( byte[] array ) {
- assert array != null;
- if (array.length == 0) return readableEmptyArray(array.getClass());
- StringBuilder sb = new StringBuilder();
- sb.append("[ ");
- try {
- sb.append(new String(array, "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- throw new SystemFailureException(e);
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( byte[] array ) {
+ assert array != null;
+ if (array.length == 0) return readableEmptyArray(array.getClass());
+ StringBuilder sb = new StringBuilder();
+ sb.append("[ ");
+ try {
+ sb.append(new String(array, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new SystemFailureException(e);
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( Collection<?> collection ) {
- assert collection != null;
- if (collection.isEmpty()) return "[]";
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("[ ");
- for (Object value : collection) {
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(value));
- }
- sb.append(" ]");
- return sb.toString();
- }
+ protected static String readableString( Collection<?> collection ) {
+ assert collection != null;
+ if (collection.isEmpty()) return "[]";
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("[ ");
+ for (Object value : collection) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(value));
+ }
+ sb.append(" ]");
+ return sb.toString();
+ }
- protected static String readableString( Map<?, ?> map ) {
- assert map != null;
- if (map.isEmpty()) return "{}";
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- sb.append("{ ");
- for (Map.Entry<?, ?> entry : map.entrySet()) {
- Object key = entry.getKey();
- Object value = entry.getValue();
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
- sb.append(readableString(key));
- sb.append(" => ");
- sb.append(readableString(value));
- }
- sb.append(" }");
- return sb.toString();
- }
+ protected static String readableString( Map<?, ?> map ) {
+ assert map != null;
+ if (map.isEmpty()) return "{}";
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ sb.append("{ ");
+ for (Map.Entry<?, ?> entry : map.entrySet()) {
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(readableString(key));
+ sb.append(" => ");
+ sb.append(readableString(value));
+ }
+ sb.append(" }");
+ return sb.toString();
+ }
- /**
- * Get the stack trace of the supplied exception.
- *
- * @param throwable the exception for which the stack trace is to be returned
- * @return the stack trace, or null if the supplied exception is null
- */
- public static String getStackTrace( Throwable throwable ) {
- if (throwable == null) return null;
- final ByteArrayOutputStream bas = new ByteArrayOutputStream();
- final PrintWriter pw = new PrintWriter(bas);
- throwable.printStackTrace(pw);
- pw.close();
- return bas.toString();
- }
+ /**
+ * Get the stack trace of the supplied exception.
+ *
+ * @param throwable the exception for which the stack trace is to be returned
+ * @return the stack trace, or null if the supplied exception is null
+ */
+ public static String getStackTrace( Throwable throwable ) {
+ if (throwable == null) return null;
+ final ByteArrayOutputStream bas = new ByteArrayOutputStream();
+ final PrintWriter pw = new PrintWriter(bas);
+ throwable.printStackTrace(pw);
+ pw.close();
+ return bas.toString();
+ }
- /**
- * Removes leading and trailing whitespace from the supplied text, and reduces other
consecutive whitespace characters to a
- * single space. Whitespace includes line-feeds.
- *
- * @param text the text to be normalized
- * @return the normalized text
- */
- public static String normalize( String text ) {
- ArgCheck.isNotNull(text, "text");
- // This could be much more efficient.
- return NORMALIZE_PATTERN.matcher(text).replaceAll(" ").trim();
- }
+ /**
+ * Removes leading and trailing whitespace from the supplied text, and reduces other
consecutive whitespace characters to a
+ * single space. Whitespace includes line-feeds.
+ *
+ * @param text the text to be normalized
+ * @return the normalized text
+ */
+ public static String normalize( String text ) {
+ ArgCheck.isNotNull(text, "text");
+ // This could be much more efficient.
+ return NORMALIZE_PATTERN.matcher(text).replaceAll(" ").trim();
+ }
- private StringUtil() {
- // Prevent construction
- }
+ private StringUtil() {
+ // Prevent construction
+ }
}
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/xml/SimpleNamespaceContext.java
===================================================================
---
trunk/dna-common/src/main/java/org/jboss/dna/common/xml/SimpleNamespaceContext.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/main/java/org/jboss/dna/common/xml/SimpleNamespaceContext.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -50,7 +50,8 @@
return null;
}
- public SimpleNamespaceContext setNamespace( String prefix, String namespaceUri ) {
+ public SimpleNamespaceContext setNamespace( String prefix,
+ String namespaceUri ) {
this.prefixToNamespace.put(prefix, namespaceUri);
return this;
}
@@ -58,7 +59,7 @@
/**
* {@inheritDoc}
*/
- public Iterator getPrefixes( String namespaceURI ) {
+ public Iterator<String> getPrefixes( String namespaceURI ) {
return this.prefixToNamespace.keySet().iterator();
}
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/AbstractI18nTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -37,9 +37,9 @@
*/
public abstract class AbstractI18nTest {
- private Class i18nClass;
+ private Class<?> i18nClass;
- protected AbstractI18nTest( Class i18nClass ) {
+ protected AbstractI18nTest( Class<?> i18nClass ) {
this.i18nClass = i18nClass;
}
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/component/ComponentLibraryTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -62,7 +62,7 @@
@Test
public void shouldBeInstantiableWithDefaultConstructor() {
- new ComponentLibrary();
+ new ComponentLibrary<SampleComponent, SampleComponentConfig>();
}
@Test
@@ -146,7 +146,7 @@
components = library.getInstances();
assertThat(components.size(), is(2));
assertThat(components.get(0), instanceOf(MockComponentA.class));
- assertThat(components.get(0), is(sameInstance((Component)secondComponentA)));
+ assertThat(components.get(0),
is(sameInstance((Component<SampleComponentConfig>)secondComponentA)));
assertThat(components.get(1), instanceOf(MockComponentB.class));
MockComponentB firstComponentB = (MockComponentB)components.get(1);
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/I18nTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/I18nTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/i18n/I18nTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -59,8 +59,8 @@
clearFields(TestI18nNotStaticField.class);
clearFields(TestI18nPrivate.class);
clearFields(TestI18nUnusedProperty.class);
- for (Entry<Locale, Map<Class, Set<String>>> localeToMapEntry :
I18n.LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
- for (Iterator<Entry<Class, Set<String>>> iter =
localeToMapEntry.getValue().entrySet().iterator(); iter.hasNext();) {
+ for (Entry<Locale, Map<Class<?>, Set<String>>>
localeToMapEntry : I18n.LOCALE_TO_CLASS_TO_PROBLEMS_MAP.entrySet()) {
+ for (Iterator<Entry<Class<?>, Set<String>>> iter =
localeToMapEntry.getValue().entrySet().iterator(); iter.hasNext();) {
if (iter.next().getKey() != CommonI18n.class) {
iter.remove();
}
@@ -68,7 +68,7 @@
}
}
- private void clearFields( Class i18nClass ) throws Exception {
+ private void clearFields( Class<?> i18nClass ) throws Exception {
for (Field fld : i18nClass.getDeclaredFields()) {
if (fld.getType() == I18n.class && (fld.getModifiers() &
Modifier.PUBLIC) == Modifier.PUBLIC
&& (fld.getModifiers() & Modifier.STATIC) == Modifier.STATIC
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/ArgCheckTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -259,7 +259,7 @@
@Test( expected = IllegalArgumentException.class )
public void isNotEmptyCollectionShouldThrowExceptionIfGivenNullCollection() {
- ArgCheck.isNotEmpty((Collection)null, "test");
+ ArgCheck.isNotEmpty((Collection<?>)null, "test");
}
@Test( expected = IllegalArgumentException.class )
@@ -274,7 +274,7 @@
@Test( expected = IllegalArgumentException.class )
public void isNotEmptyMapShouldThrowExceptionIfGivenNullMap() {
- ArgCheck.isNotEmpty((Map)null, "test");
+ ArgCheck.isNotEmpty((Map<?, ?>)null, "test");
}
@Test( expected = IllegalArgumentException.class )
@@ -382,7 +382,7 @@
@Test( expected = IllegalArgumentException.class )
public void containsNoNullsCollectionShouldThrowExceptionIfGivenNullCollection() {
- ArgCheck.containsNoNulls((Collection)null, "test");
+ ArgCheck.containsNoNulls((Collection<?>)null, "test");
}
@Test
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/util/LoggerTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/util/LoggerTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/util/LoggerTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -96,7 +96,7 @@
org.apache.log4j.Logger theLogger = log4jLogger;
while (theLogger != null) {
List<Appender> appenders = new ArrayList<Appender>();
- Enumeration previousAppenders = theLogger.getAllAppenders();
+ Enumeration<?> previousAppenders = theLogger.getAllAppenders();
while (previousAppenders.hasMoreElements()) {
appenders.add((Appender)previousAppenders.nextElement());
}
@@ -436,7 +436,7 @@
*/
public void removeFirst( Logger.Level expectedLevel,
String expectedMessageExpression,
- Class expectedExceptionClass ) {
+ Class<?> expectedExceptionClass ) {
if (!hasEvents()) {
fail("Expected log message but found none: " + expectedLevel +
" - " + expectedMessageExpression);
}
Modified:
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenRepositoryException.java
===================================================================
---
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenRepositoryException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenRepositoryException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -28,6 +28,10 @@
public class MavenRepositoryException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = -9198687929215916061L;
+
+ /**
*
*/
public MavenRepositoryException() {
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -43,6 +43,10 @@
@ThreadSafe
public class FederatedRepositorySource implements RepositorySource {
+ /**
+ */
+ private static final long serialVersionUID = 7587346948013486977L;
+
public static final int DEFAULT_RETRY_LIMIT = 0;
protected static final String USERNAME = "username";
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationException.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -29,6 +29,10 @@
public class FederationException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = -27536888064529864L;
+
+ /**
*
*/
public FederationException() {
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/InvalidRuleSetException.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/InvalidRuleSetException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/rules/InvalidRuleSetException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -27,6 +27,10 @@
public class InvalidRuleSetException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = 6739445071678626125L;
+
+ /**
*
*/
public InvalidRuleSetException() {
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/InvalidSequencerPathExpression.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/InvalidSequencerPathExpression.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/InvalidSequencerPathExpression.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -29,6 +29,10 @@
public class InvalidSequencerPathExpression extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = -2814638971450551156L;
+
+ /**
*
*/
public InvalidSequencerPathExpression() {
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerException.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -28,6 +28,10 @@
/**
*/
+ private static final long serialVersionUID = -7610898771539657335L;
+
+ /**
+ */
public SequencerException() {
}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerPathExpression.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerPathExpression.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerPathExpression.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -53,6 +53,10 @@
public class SequencerPathExpression implements Serializable {
/**
+ */
+ private static final long serialVersionUID = 229464314137494765L;
+
+ /**
* The pattern used to break the initial input string into the two major parts, the
selection and output expressions. Group 1
* contains the selection expression, and group 2 contains the output expression.
*/
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -27,6 +27,10 @@
public class InvalidPathException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = 6034512896518552227L;
+
+ /**
*
*/
public InvalidPathException() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/IoException.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/IoException.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/IoException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -28,6 +28,10 @@
public class IoException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = -2015526722307950714L;
+
+ /**
*
*/
public IoException() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -27,6 +27,10 @@
public class NamespaceException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = 1300642242538881207L;
+
+ /**
*
*/
public NamespaceException() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -27,6 +27,10 @@
public class PathNotFoundException extends RuntimeException {
/**
+ */
+ private static final long serialVersionUID = -3703984046286975978L;
+
+ /**
*
*/
public PathNotFoundException() {
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -49,18 +49,18 @@
OBJECT("Object", ValueComparators.OBJECT_COMPARATOR, Object.class);
private final String name;
- private final Comparator comparator;
- private final Class valueClass;
+ private final Comparator<?> comparator;
+ private final Class<?> valueClass;
private PropertyType( String name,
- Comparator comparator,
- Class valueClass ) {
+ Comparator<?> comparator,
+ Class<?> valueClass ) {
this.name = name;
this.comparator = comparator;
this.valueClass = valueClass;
}
- public Class getValueClass() {
+ public Class<?> getValueClass() {
return this.valueClass;
}
@@ -68,7 +68,7 @@
return this.name;
}
- public Comparator getComparator() {
+ public Comparator<?> getComparator() {
return this.comparator;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -41,7 +41,8 @@
*/
public static final Comparator<String> STRING_COMPARATOR = new
Comparator<String>() {
- public int compare( String o1, String o2 ) {
+ public int compare( String o1,
+ String o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -53,7 +54,8 @@
*/
public static final Comparator<Long> LONG_COMPARATOR = new
Comparator<Long>() {
- public int compare( Long o1, Long o2 ) {
+ public int compare( Long o1,
+ Long o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -65,7 +67,8 @@
*/
public static final Comparator<Double> DOUBLE_COMPARATOR = new
Comparator<Double>() {
- public int compare( Double o1, Double o2 ) {
+ public int compare( Double o1,
+ Double o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -77,7 +80,8 @@
*/
public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new
Comparator<BigDecimal>() {
- public int compare( BigDecimal o1, BigDecimal o2 ) {
+ public int compare( BigDecimal o1,
+ BigDecimal o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -91,7 +95,8 @@
*/
public static final Comparator<Binary> BINARY_COMPARATOR = new
Comparator<Binary>() {
- public int compare( Binary o1, Binary o2 ) {
+ public int compare( Binary o1,
+ Binary o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -155,7 +160,8 @@
*/
public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new
Comparator<Boolean>() {
- public int compare( Boolean o1, Boolean o2 ) {
+ public int compare( Boolean o1,
+ Boolean o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -167,7 +173,8 @@
*/
public static final Comparator<DateTime> DATE_TIME_COMPARATOR = new
Comparator<DateTime>() {
- public int compare( DateTime o1, DateTime o2 ) {
+ public int compare( DateTime o1,
+ DateTime o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -179,7 +186,8 @@
*/
public static final Comparator<Date> DATE_COMPARATOR = new
Comparator<Date>() {
- public int compare( Date o1, Date o2 ) {
+ public int compare( Date o1,
+ Date o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -191,7 +199,8 @@
*/
public static final Comparator<Calendar> CALENDAR_COMPARATOR = new
Comparator<Calendar>() {
- public int compare( Calendar o1, Calendar o2 ) {
+ public int compare( Calendar o1,
+ Calendar o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -203,7 +212,8 @@
*/
public static final Comparator<Name> NAME_COMPARATOR = new
Comparator<Name>() {
- public int compare( Name o1, Name o2 ) {
+ public int compare( Name o1,
+ Name o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -215,7 +225,8 @@
*/
public static final Comparator<Path> PATH_COMPARATOR = new
Comparator<Path>() {
- public int compare( Path o1, Path o2 ) {
+ public int compare( Path o1,
+ Path o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -227,7 +238,8 @@
*/
public static final Comparator<URI> URI_COMPARATOR = new
Comparator<URI>() {
- public int compare( URI o1, URI o2 ) {
+ public int compare( URI o1,
+ URI o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -239,7 +251,8 @@
*/
public static final Comparator<Reference> REFERENCE_COMPARATOR = new
Comparator<Reference>() {
- public int compare( Reference o1, Reference o2 ) {
+ public int compare( Reference o1,
+ Reference o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
@@ -252,21 +265,22 @@
public static final Comparator<Object> OBJECT_COMPARATOR = new
Comparator<Object>() {
@SuppressWarnings( "unchecked" )
- public int compare( Object o1, Object o2 ) {
+ public int compare( Object o1,
+ Object o2 ) {
if (o1 == o2) return 0;
if (o1 == null) return -1;
if (o2 == null) return 1;
PropertyType type1 = PropertyType.discoverType(o1);
PropertyType type2 = PropertyType.discoverType(o2);
if (type1 != PropertyType.OBJECT && type2 != PropertyType.OBJECT) {
- if (type1 == type2) return type1.getComparator().compare(o1, o2);
+ if (type1 == type2) return
((Comparator<Object>)type1.getComparator()).compare(o1, o2);
// The types are different but the classes are the same ...
if
(type1.getDeclaringClass().isAssignableFrom(type2.getDeclaringClass())) {
- return type1.getComparator().compare(o1, o2);
+ return ((Comparator<Object>)type1.getComparator()).compare(o1,
o2);
}
if
(type2.getDeclaringClass().isAssignableFrom(type1.getDeclaringClass())) {
- return type2.getComparator().compare(o1, o2);
+ return ((Comparator<Object>)type2.getComparator()).compare(o1,
o2);
}
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicCreateNodeCommand.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -34,6 +34,9 @@
@NotThreadSafe
public class BasicCreateNodeCommand extends BasicGraphCommand implements
CreateNodeCommand {
+ /**
+ */
+ private static final long serialVersionUID = -5452285887178397354L;
private final Path path;
private final List<Property> properties;
private CachePolicy cachePolicy;
@@ -43,7 +46,8 @@
* @param path the path to the node; may not be null
* @param properties the properties of the node; may not be null
*/
- public BasicCreateNodeCommand( Path path, List<Property> properties ) {
+ public BasicCreateNodeCommand( Path path,
+ List<Property> properties ) {
super();
assert path != null;
assert properties != null;
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetChildrenCommand.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -37,6 +37,9 @@
@NotThreadSafe
public class BasicGetChildrenCommand extends BasicGraphCommand implements
GetChildrenCommand {
+ /**
+ */
+ private static final long serialVersionUID = -8515194602506918337L;
private List<Segment> children;
private final Path path;
private CachePolicy cachePolicy;
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetNodeCommand.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -38,6 +38,9 @@
@NotThreadSafe
public class BasicGetNodeCommand extends BasicGetPropertiesCommand implements
GetNodeCommand {
+ /**
+ */
+ private static final long serialVersionUID = 5355669032301356873L;
private List<Segment> children;
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicGetPropertiesCommand.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -37,6 +37,9 @@
@NotThreadSafe
public class BasicGetPropertiesCommand extends BasicGraphCommand implements
GetPropertiesCommand {
+ /**
+ */
+ private static final long serialVersionUID = -7816393217506909521L;
private final Map<Name, List<Object>> propertyValues = new
HashMap<Name, List<Object>>();
private final Path path;
private CachePolicy cachePolicy;
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/commands/impl/BasicSetPropertiesCommand.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -34,6 +34,9 @@
@NotThreadSafe
public class BasicSetPropertiesCommand extends BasicGraphCommand implements
SetPropertiesCommand {
+ /**
+ */
+ private static final long serialVersionUID = -2693642411179501304L;
private final Path path;
private final List<Property> properties;
private CachePolicy cachePolicy;
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositorySourceException.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -26,6 +26,9 @@
*/
public class RepositorySourceException extends RuntimeException {
+ /**
+ */
+ private static final long serialVersionUID = -7704170453962924565L;
private final String sourceName;
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -38,7 +38,10 @@
@Immutable
public class BasicName implements Name {
- private final String namespaceUri;
+ /**
+ */
+ private static final long serialVersionUID = -1737537720336990144L;
+ private final String namespaceUri;
private final String localName;
private final int hc;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -46,8 +46,12 @@
@Immutable
public class BasicPath implements Path {
- private static final List<Segment> EMPTY_SEGMENTS = Collections.emptyList();
+ /**
+ */
+ private static final long serialVersionUID = 8488295345524209746L;
+ private static final List<Segment> EMPTY_SEGMENTS = Collections.emptyList();
+
public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -35,6 +35,9 @@
@Immutable
public class BasicPathSegment implements Path.Segment {
+ /**
+ */
+ private static final long serialVersionUID = 4367349287846075157L;
private final Name name;
private final int index;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -35,6 +35,10 @@
@Immutable
public class InMemoryBinary implements Binary {
+ /**
+ */
+ private static final long serialVersionUID = 8792863149767123559L;
+
protected static final byte[] EMPTY_CONTENT = new byte[0];
private final byte[] bytes;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -38,6 +38,10 @@
@Immutable
public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
+ /**
+ */
+ private static final long serialVersionUID = -730188225988292422L;
+
private static final int MILLIS_IN_HOUR = 1000 * 60 * 60;
private final DateTime instance;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-06-11
19:21:19 UTC (rev 272)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -33,6 +33,9 @@
@Immutable
public class UuidReference implements Reference {
+ /**
+ */
+ private static final long serialVersionUID = 2299467578161645109L;
private UUID uuid;
public UuidReference( UUID uuid ) {
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/connection/TimeDelayingRepositorySource.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -41,6 +41,9 @@
@ThreadSafe
public class TimeDelayingRepositorySource implements RepositorySource {
+ /**
+ */
+ private static final long serialVersionUID = -2756725117087437347L;
private final String identifier;
private final AtomicInteger retryLimit = new AtomicInteger(0);
private final AtomicInteger connectionsOpenedCount = new AtomicInteger(0);
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-11
19:21:19 UTC (rev 272)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-12
17:36:18 UTC (rev 273)
@@ -128,7 +128,7 @@
}
}
- private AbstractValueFactory factory;
+ private AbstractValueFactory<?> factory;
@Before
public void beforeEach() {