Skip to content

Commit

Permalink
internationalised IllegalArgumentException in hornetq-core
Browse files Browse the repository at this point in the history
  • Loading branch information
andytaylor committed May 22, 2012
1 parent a8c2b97 commit 95aa267
Show file tree
Hide file tree
Showing 38 changed files with 407 additions and 136 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,8 @@ examples/pom-template.xml

native/autom4te.cache
.settings/org.eclipse.core.resources.prefs

*.iml
*/*.iml
*/*/*.iml
*/*/*/*.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hornetq.utils;


import org.jboss.logging.Cause;
import org.jboss.logging.Message;
import org.jboss.logging.MessageBundle;
import org.jboss.logging.Messages;
Expand All @@ -22,4 +23,13 @@ public interface HornetQUtilBundle

@Message(id = 209001, value = "invalid property: {0}" , format = Message.Format.MESSAGE_FORMAT)
org.hornetq.api.core.IllegalStateException invalidProperty(String part);

@Message(id = 209002, value = "Invalid type: {0}", format = Message.Format.MESSAGE_FORMAT)
IllegalStateException invalidType(Byte type);

@Message(id = 209003, value = "the specified string is too long ({0})", format = Message.Format.MESSAGE_FORMAT)
IllegalStateException stringTooLong(Integer length);

@Message(id = 209004, value = "Error instantiating codec {0}", format = Message.Format.MESSAGE_FORMAT)
IllegalArgumentException errorCreatingCodec(@Cause Exception e, String codecClassName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SensitiveDataCodec<String> run()
}
catch (Exception e)
{
throw new IllegalArgumentException("Error instantiating codec \"" + codecClassName + "\"", e);
throw HornetQUtilBundle.BUNDLE.errorCreatingCodec(e, codecClassName);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public synchronized void decode(final HornetQBuffer buffer)
}
default:
{
throw new IllegalArgumentException("Invalid type: " + type);
throw HornetQUtilBundle.BUNDLE.invalidType(type);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public static void saveUTF(final HornetQBuffer out, final String str)

if (str.length() > 0xffff)
{
throw new IllegalArgumentException("the specified string is too long (" + str.length() + ")");
throw HornetQUtilBundle.BUNDLE.stringTooLong(str.length());
}

final int len = UTF8Util.calculateUTFSize(str, buffer);

if (len > 0xffff)
{
throw new IllegalArgumentException("the encoded string is too long (" + len + ")");
throw HornetQUtilBundle.BUNDLE.stringTooLong(len);
}

out.writeShort((short)len);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.Map;

import org.hornetq.core.server.HornetQMessageBundle;
import org.hornetq.utils.UUIDGenerator;

/**
Expand Down Expand Up @@ -283,7 +284,7 @@ else if (val instanceof String)
}
else
{
throw new IllegalArgumentException("Invalid type " + val);
throw HornetQMessageBundle.BUNDLE.invalidEncodeType(val);
}
}
}
Expand Down Expand Up @@ -351,7 +352,7 @@ public void decode(final HornetQBuffer buffer)
}
default:
{
throw new IllegalArgumentException("Invalid type " + type);
throw HornetQMessageBundle.BUNDLE.invalidType(type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.hornetq.api.core.Message;
import org.hornetq.api.core.SimpleString;
import org.hornetq.core.server.HornetQMessageBundle;
import org.hornetq.utils.json.JSONArray;
import org.hornetq.utils.json.JSONObject;

Expand Down Expand Up @@ -289,9 +290,7 @@ private static void checkType(final Object param)
param instanceof Byte == false &&
param instanceof Short == false)
{
throw new IllegalArgumentException("Params for management operations must be of the following type: " + "int long double String boolean Map or array thereof " +
" but found " +
param.getClass().getName());
throw HornetQMessageBundle.BUNDLE.invalidManagementParam(param.getClass().getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ else if (windowSize > 1)
}
else
{
throw new IllegalArgumentException("Invalid window size " + windowSize);
throw HornetQMessageBundle.BUNDLE.invalidWindowSize(windowSize);
}

return clientWindowSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.server.HornetQMessageBundle;

/**
* A ClusterConnectionConfiguration
Expand Down Expand Up @@ -123,7 +124,7 @@ public ClusterConnectionConfiguration(final String name,
this.clientFailureCheckPeriod = clientFailureCheckPeriod;
this.connectionTTL = connectionTTL;
if (retryInterval <= 0)
throw new IllegalArgumentException("retry interval must be positive, was " + retryInterval);
throw HornetQMessageBundle.BUNDLE.invalidRetryInterval(retryInterval);
this.retryInterval = retryInterval;
this.retryIntervalMultiplier = retryIntervalMultiplier;
this.maxRetryInterval = maxRetryInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.hornetq.core.config.impl;

import org.hornetq.core.server.HornetQMessageBundle;
import org.hornetq.core.server.JournalType;
import org.hornetq.core.settings.impl.AddressFullMessagePolicy;

Expand Down Expand Up @@ -43,7 +44,7 @@ public void validate(final String name, final Object value)
String str = (String)value;
if (str == null || str.length() == 0)
{
throw new IllegalArgumentException(String.format("%s must neither be null nor empty", name));
throw HornetQMessageBundle.BUNDLE.emptyOrNull(name);
}
}
};
Expand All @@ -59,7 +60,7 @@ public void validate(final String name, final Object value)
}
else
{
throw new IllegalArgumentException(String.format("%s must be greater than 0 (actual value: %s)", name, val));
throw HornetQMessageBundle.BUNDLE.greaterThanZero(name, val);
}
}
};
Expand All @@ -71,9 +72,7 @@ public void validate(final String name, final Object value)
Number val = (Number)value;
if (val == null || (val.intValue() < 0 || val.intValue() > 100))
{
throw new IllegalArgumentException(String.format("%s must be a valid percentual value between 0 and 100 (actual value: %s)",
name,
val));
throw HornetQMessageBundle.BUNDLE.notPercent(name, val);
}
}
};
Expand All @@ -89,9 +88,7 @@ public void validate(final String name, final Object value)
}
else
{
throw new IllegalArgumentException(String.format("%s must be greater or equals than 0 (actual value: %s)",
name,
val));
throw HornetQMessageBundle.BUNDLE.greaterThanZero(name, val);
}
}
};
Expand All @@ -107,9 +104,7 @@ public void validate(final String name, final Object value)
}
else
{
throw new IllegalArgumentException(String.format("%s must be equals to -1 or greater than 0 (actual value: %s)",
name,
val));
throw HornetQMessageBundle.BUNDLE.greaterThanMinusOne(name, val);
}
}
};
Expand All @@ -125,9 +120,7 @@ public void validate(final String name, final Object value)
}
else
{
throw new IllegalArgumentException(String.format("%s must be equals to -1 or greater or equals to 0 (actual value: %s)",
name,
val));
throw HornetQMessageBundle.BUNDLE.greaterThanZeroOrMinusOne(name, val);
}
}
};
Expand All @@ -143,11 +136,7 @@ public void validate(final String name, final Object value)
}
else
{
throw new IllegalArgumentException(String.format("%s must be betwen %s and %s inclusive (actual value: %s)",
name,
Thread.MIN_PRIORITY,
Thread.MAX_PRIORITY,
value));
throw HornetQMessageBundle.BUNDLE.mustbeBetween(name, Thread.MIN_PRIORITY, Thread.MAX_PRIORITY, value);
}
}
};
Expand All @@ -159,7 +148,7 @@ public void validate(final String name, final Object value)
String val = (String)value;
if (val == null || !val.equals(JournalType.NIO.toString()) && !val.equals(JournalType.ASYNCIO.toString()))
{
throw new IllegalArgumentException("Invalid journal type " + val);
throw HornetQMessageBundle.BUNDLE.invalidJournalType(val);
}
}
};
Expand All @@ -173,7 +162,7 @@ public void validate(final String name, final Object value)
!val.equals(AddressFullMessagePolicy.DROP.toString()) &&
!val.equals(AddressFullMessagePolicy.BLOCK.toString()))
{
throw new IllegalArgumentException("Invalid address full message policy type " + val);
throw HornetQMessageBundle.BUNDLE.invalidAddressFullPolicyType(val);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;

import org.hornetq.api.core.SimpleString;
import org.hornetq.core.server.HornetQMessageBundle;

/**
* Implementations of the operators used in HornetQ filter expressions
Expand Down Expand Up @@ -1294,7 +1295,7 @@ public Object apply() throws Exception
case NOT_IN:
return not_in();
default:
throw new IllegalArgumentException("No operation mapped to int " + operation);
throw HornetQMessageBundle.BUNDLE.noOperationMapped(operation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,7 @@ public synchronized void setMessageCounterSamplePeriod(final long newPeriod)
{
if (newPeriod < MessageCounterManagerImpl.MIN_SAMPLE_PERIOD)
{
throw new IllegalArgumentException("Cannot set MessageCounterSamplePeriod < " + MessageCounterManagerImpl.MIN_SAMPLE_PERIOD +
" ms");
throw HornetQMessageBundle.BUNDLE.invalidMessageCounterPeriod(MessageCounterManagerImpl.MIN_SAMPLE_PERIOD);
}

if (messageCounterManager != null && newPeriod != messageCounterManager.getSamplePeriod())
Expand Down Expand Up @@ -888,7 +887,7 @@ public void setMessageCounterMaxDayCount(final int count)
{
if (count <= 0)
{
throw new IllegalArgumentException("invalid value: count must be greater than 0");
throw HornetQMessageBundle.BUNDLE.greaterThanZero(count);
}
messageCounterManager.setMaxDayCount(count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.PostOffice;
import org.hornetq.core.server.Consumer;
import org.hornetq.core.server.MessageReference;
import org.hornetq.core.server.Queue;
import org.hornetq.core.server.ServerConsumer;
import org.hornetq.core.server.*;
import org.hornetq.core.settings.HierarchicalRepository;
import org.hornetq.core.settings.impl.AddressSettings;
import org.hornetq.utils.LinkedListIterator;
Expand Down Expand Up @@ -568,7 +565,7 @@ public boolean moveMessage(final long messageID, final String otherQueueName, fi

if (binding == null)
{
throw new IllegalArgumentException("No queue found for " + otherQueueName);
throw HornetQMessageBundle.BUNDLE.noQueueFound(otherQueueName);
}

return queue.moveReference(messageID, binding.getAddress(), rejectDuplicates);
Expand Down Expand Up @@ -598,7 +595,7 @@ public int moveMessages(final String filterStr, final String otherQueueName, fin

if (binding == null)
{
throw new IllegalArgumentException("No queue found for " + otherQueueName);
throw HornetQMessageBundle.BUNDLE.noQueueFound(otherQueueName);
}

int retValue = queue.moveReferences(filter, binding.getAddress(), rejectDuplicates);
Expand Down Expand Up @@ -653,8 +650,7 @@ public int changeMessagesPriority(final String filterStr, final int newPriority)
{
if (newPriority < 0 || newPriority > 9)
{
throw new IllegalArgumentException("invalid newPriority value: " + newPriority +
". It must be between 0 and 9 (both included)");
throw HornetQMessageBundle.BUNDLE.invalidNewPriority(newPriority);
}
Filter filter = FilterImpl.createFilter(filterStr);

Expand All @@ -675,8 +671,7 @@ public boolean changeMessagePriority(final long messageID, final int newPriority
{
if (newPriority < 0 || newPriority > 9)
{
throw new IllegalArgumentException("invalid newPriority value: " + newPriority +
". It must be between 0 and 9 (both included)");
throw HornetQMessageBundle.BUNDLE.invalidNewPriority(newPriority);
}
return queue.changeReferencePriority(messageID, (byte)newPriority);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public JournalStorageManager(final Configuration config, final ExecutorFactory e

if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO)
{
throw new IllegalArgumentException("Only NIO and AsyncIO are supported journals");
throw HornetQMessageBundle.BUNDLE.invalidJournal();
}

bindingsDir = config.getBindingsDirectory();
Expand Down Expand Up @@ -314,7 +314,7 @@ else if (config.getJournalType() == JournalType.NIO)
}
else
{
throw new IllegalArgumentException("Unsupported journal type " + config.getJournalType());
throw HornetQMessageBundle.BUNDLE.invalidJournalType2(config.getJournalType());
}

idGenerator = new BatchingIDGenerator(0, JournalStorageManager.CHECKPOINT_BATCH_SIZE, bindingsJournal);
Expand Down Expand Up @@ -2360,7 +2360,7 @@ private void checkAndCreateDir(final String dir, final boolean create)
}
else
{
throw new IllegalArgumentException("Directory " + dir + " does not exist and will not create it");
throw HornetQMessageBundle.BUNDLE.cannotCreateDir(dir);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package org.hornetq.core.postoffice;

import org.hornetq.core.server.HornetQMessageBundle;

/**
* A BindingType
*
Expand Down Expand Up @@ -50,7 +52,7 @@ public static BindingType fromOrdinal(final int index)
}
default:
{
throw new IllegalArgumentException("Invalid index " + index);
throw HornetQMessageBundle.BUNDLE.invalidIndex(index);
}
}
}
Expand All @@ -71,7 +73,7 @@ else if (equals(BindingType.DIVERT))
}
else
{
throw new IllegalArgumentException("Cannot convert");
throw HornetQMessageBundle.BUNDLE.cannotConvertToInt();
}
}

Expand Down
Loading

0 comments on commit 95aa267

Please sign in to comment.