diff options
| author | Robert Greig <rgreig@apache.org> | 2007-04-09 16:09:24 +0000 |
|---|---|---|
| committer | Robert Greig <rgreig@apache.org> | 2007-04-09 16:09:24 +0000 |
| commit | 63c1ee312fa77ec98c9fc8eccb0a7aa0a1689fe4 (patch) | |
| tree | 601b91ac9133adab7cc14de411d5c43636735968 /java/common | |
| parent | f966c066fc10c1510c244c41958e343c682dd1a1 (diff) | |
| download | qpid-python-63c1ee312fa77ec98c9fc8eccb0a7aa0a1689fe4.tar.gz | |
Got rid of some uses of System.out instead of log4j logging.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@526803 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
3 files changed, 142 insertions, 216 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java index f94cd4934c..f0cdda487c 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java +++ b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java @@ -7,9 +7,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -23,6 +23,7 @@ package org.apache.qpid.framing; import java.nio.charset.Charset; import org.apache.log4j.Logger; + import org.apache.mina.common.ByteBuffer; public class EncodingUtils @@ -49,96 +50,95 @@ public class EncodingUtils } } - public static int encodedShortStringLength(short s) { - if( s == 0 ) + if (s == 0) { return 1 + 1; } int len = 0; - if(s < 0) + if (s < 0) { - len=1; + len = 1; // sloppy - doesn't work of Integer.MIN_VALUE - s=(short)-s; + s = (short) -s; } - if(s>9999) + if (s > 9999) { - return 1+5; + return 1 + 5; } - else if(s>999) + else if (s > 999) { - return 1+4; + return 1 + 4; } - else if(s>99) + else if (s > 99) { - return 1+3; + return 1 + 3; } - else if(s>9) + else if (s > 9) { - return 1+2; + return 1 + 2; } else { - return 1+1; + return 1 + 1; } } - public static int encodedShortStringLength(int i) { - if( i == 0 ) + if (i == 0) { return 1 + 1; } int len = 0; - if(i < 0) + if (i < 0) { - len=1; + len = 1; // sloppy - doesn't work of Integer.MIN_VALUE - i=-i; + i = -i; } // range is now 1 - 2147483647 - if(i < Short.MAX_VALUE) + if (i < Short.MAX_VALUE) { - return len + encodedShortStringLength((short)i); + return len + encodedShortStringLength((short) i); } else if (i > 999999) { - return len + 6 + encodedShortStringLength((short)(i/1000000)); + return len + 6 + encodedShortStringLength((short) (i / 1000000)); } else // if (i > 99999) { - return len + 5 + encodedShortStringLength((short)(i/100000)); + return len + 5 + encodedShortStringLength((short) (i / 100000)); } } public static int encodedShortStringLength(long l) { - if(l == 0) + if (l == 0) { return 1 + 1; } int len = 0; - if(l < 0) + if (l < 0) { - len=1; + len = 1; // sloppy - doesn't work of Long.MIN_VALUE - l=-l; + l = -l; } - if(l < Integer.MAX_VALUE) + + if (l < Integer.MAX_VALUE) { return len + encodedShortStringLength((int) l); } - else if(l > 9999999999L) + else if (l > 9999999999L) { return len + 10 + encodedShortStringLength((int) (l / 10000000000L)); } @@ -149,7 +149,6 @@ public class EncodingUtils } - public static int encodedShortStringLength(AMQShortString s) { if (s == null) @@ -162,7 +161,6 @@ public class EncodingUtils } } - public static int encodedLongStringLength(String s) { if (s == null) @@ -219,7 +217,6 @@ public class EncodingUtils return 0; } - public static void writeShortStringBytes(ByteBuffer buffer, String s) { if (s != null) @@ -230,6 +227,7 @@ public class EncodingUtils { encodedString[i] = (byte) cha[i]; } + writeBytes(buffer, encodedString); } else @@ -239,7 +237,6 @@ public class EncodingUtils } } - public static void writeShortStringBytes(ByteBuffer buffer, AMQShortString s) { if (s != null) @@ -256,7 +253,7 @@ public class EncodingUtils public static void writeLongStringBytes(ByteBuffer buffer, String s) { - assert s == null || s.length() <= 0xFFFE; + assert (s == null) || (s.length() <= 0xFFFE); if (s != null) { int len = s.length(); @@ -267,6 +264,7 @@ public class EncodingUtils { encodedString[i] = (byte) cha[i]; } + buffer.put(encodedString); } else @@ -277,7 +275,7 @@ public class EncodingUtils public static void writeLongStringBytes(ByteBuffer buffer, char[] s) { - assert s == null || s.length <= 0xFFFE; + assert (s == null) || (s.length <= 0xFFFE); if (s != null) { int len = s.length; @@ -287,6 +285,7 @@ public class EncodingUtils { encodedString[i] = (byte) s[i]; } + buffer.put(encodedString); } else @@ -297,7 +296,7 @@ public class EncodingUtils public static void writeLongStringBytes(ByteBuffer buffer, byte[] bytes) { - assert bytes == null || bytes.length <= 0xFFFE; + assert (bytes == null) || (bytes.length <= 0xFFFE); if (bytes != null) { writeUnsignedInteger(buffer, bytes.length); @@ -330,7 +329,6 @@ public class EncodingUtils } } - public static int unsignedIntegerLength() { return 4; @@ -356,7 +354,6 @@ public class EncodingUtils } } - public static void writeFieldTableBytes(ByteBuffer buffer, FieldTable table) { if (table != null) @@ -400,10 +397,9 @@ public class EncodingUtils if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } - buffer.put(packedValue); } @@ -413,213 +409,181 @@ public class EncodingUtils if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } - buffer.put(packedValue); } - - - public static void writeBooleans(ByteBuffer buffer, - boolean value0, - boolean value1, - boolean value2, - boolean value3) + public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3) { byte packedValue = value0 ? (byte) 1 : (byte) 0; if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } if (value3) { - packedValue = (byte) (packedValue | (byte)(1 << 3)); + packedValue = (byte) (packedValue | (byte) (1 << 3)); } buffer.put(packedValue); } - public static void writeBooleans(ByteBuffer buffer, - boolean value0, - boolean value1, - boolean value2, - boolean value3, - boolean value4) + public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3, + boolean value4) { byte packedValue = value0 ? (byte) 1 : (byte) 0; if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } if (value3) { - packedValue = (byte) (packedValue | (byte)(1 << 3)); + packedValue = (byte) (packedValue | (byte) (1 << 3)); } if (value4) { - packedValue = (byte) (packedValue | (byte)(1 << 4)); + packedValue = (byte) (packedValue | (byte) (1 << 4)); } buffer.put(packedValue); } - public static void writeBooleans(ByteBuffer buffer, - boolean value0, - boolean value1, - boolean value2, - boolean value3, - boolean value4, - boolean value5) + public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3, + boolean value4, boolean value5) { byte packedValue = value0 ? (byte) 1 : (byte) 0; if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } if (value3) { - packedValue = (byte) (packedValue | (byte)(1 << 3)); + packedValue = (byte) (packedValue | (byte) (1 << 3)); } if (value4) { - packedValue = (byte) (packedValue | (byte)(1 << 4)); + packedValue = (byte) (packedValue | (byte) (1 << 4)); } if (value5) { - packedValue = (byte) (packedValue | (byte)(1 << 5)); + packedValue = (byte) (packedValue | (byte) (1 << 5)); } buffer.put(packedValue); } - public static void writeBooleans(ByteBuffer buffer, - boolean value0, - boolean value1, - boolean value2, - boolean value3, - boolean value4, - boolean value5, - boolean value6) + public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3, + boolean value4, boolean value5, boolean value6) { byte packedValue = value0 ? (byte) 1 : (byte) 0; if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } if (value3) { - packedValue = (byte) (packedValue | (byte)(1 << 3)); + packedValue = (byte) (packedValue | (byte) (1 << 3)); } if (value4) { - packedValue = (byte) (packedValue | (byte)(1 << 4)); + packedValue = (byte) (packedValue | (byte) (1 << 4)); } if (value5) { - packedValue = (byte) (packedValue | (byte)(1 << 5)); + packedValue = (byte) (packedValue | (byte) (1 << 5)); } if (value6) { - packedValue = (byte) (packedValue | (byte)(1 << 6)); + packedValue = (byte) (packedValue | (byte) (1 << 6)); } buffer.put(packedValue); } - public static void writeBooleans(ByteBuffer buffer, - boolean value0, - boolean value1, - boolean value2, - boolean value3, - boolean value4, - boolean value5, - boolean value6, - boolean value7) + public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3, + boolean value4, boolean value5, boolean value6, boolean value7) { byte packedValue = value0 ? (byte) 1 : (byte) 0; if (value1) { - packedValue = (byte) (packedValue | (byte)(1 << 1)); + packedValue = (byte) (packedValue | (byte) (1 << 1)); } if (value2) { - packedValue = (byte) (packedValue | (byte)(1 << 2)); + packedValue = (byte) (packedValue | (byte) (1 << 2)); } if (value3) { - packedValue = (byte) (packedValue | (byte)(1 << 3)); + packedValue = (byte) (packedValue | (byte) (1 << 3)); } if (value4) { - packedValue = (byte) (packedValue | (byte)(1 << 4)); + packedValue = (byte) (packedValue | (byte) (1 << 4)); } if (value5) { - packedValue = (byte) (packedValue | (byte)(1 << 5)); + packedValue = (byte) (packedValue | (byte) (1 << 5)); } if (value6) { - packedValue = (byte) (packedValue | (byte)(1 << 6)); + packedValue = (byte) (packedValue | (byte) (1 << 6)); } if (value7) { - packedValue = (byte) (packedValue | (byte)(1 << 7)); + packedValue = (byte) (packedValue | (byte) (1 << 7)); } buffer.put(packedValue); } - - - /** * This is used for writing longstrs. * @@ -647,26 +611,27 @@ public class EncodingUtils public static boolean[] readBooleans(ByteBuffer buffer) { final byte packedValue = buffer.get(); - if(packedValue == 0) + if (packedValue == 0) { return ALL_FALSE_ARRAY; } + final boolean[] result = new boolean[8]; result[0] = ((packedValue & 1) != 0); result[1] = ((packedValue & (1 << 1)) != 0); result[2] = ((packedValue & (1 << 2)) != 0); result[3] = ((packedValue & (1 << 3)) != 0); - if((packedValue & 0xF0) == 0) + if ((packedValue & 0xF0) == 0) { result[0] = ((packedValue & 1) != 0); } + result[4] = ((packedValue & (1 << 4)) != 0); result[5] = ((packedValue & (1 << 5)) != 0); result[6] = ((packedValue & (1 << 6)) != 0); result[7] = ((packedValue & (1 << 7)) != 0); - return result; } @@ -742,6 +707,7 @@ public class EncodingUtils { stringChars[i] = (char) stringBytes[i]; } + return new String(stringChars); } } @@ -757,6 +723,7 @@ public class EncodingUtils { byte[] result = new byte[(int) length]; buffer.get(result); + return result; } } @@ -764,15 +731,14 @@ public class EncodingUtils public static long readTimestamp(ByteBuffer buffer) { // Discard msb from AMQ timestamp - //buffer.getUnsignedInt(); + // buffer.getUnsignedInt(); return buffer.getLong(); } - static byte[] hexToByteArray(String id) { // Should check param for null, long enough for this check, upper-case and trailing char - String s = (id.charAt(1) == 'x') ? id.substring(2) : id; // strip 0x + String s = (id.charAt(1) == 'x') ? id.substring(2) : id; // strip 0x int len = s.length(); int byte_len = len / 2; @@ -786,7 +752,7 @@ public class EncodingUtils byte b1 = Byte.parseByte(s.substring(ch, ch + 1), 16); byte b2 = Byte.parseByte(s.substring(ch + 1, ch + 2), 16); - b[i] = (byte) (b1 * 16 + b2); + b[i] = (byte) ((b1 * 16) + b2); } return (b); @@ -795,7 +761,7 @@ public class EncodingUtils public static char[] convertToHexCharArray(byte[] from) { int length = from.length; - char[] result_buff = new char[length * 2 + 2]; + char[] result_buff = new char[(length * 2) + 2]; result_buff[0] = '0'; result_buff[1] = 'x'; @@ -831,7 +797,7 @@ public class EncodingUtils byte[] from = new byte[size]; // Is this not the same. - //bb.get(from, 0, length); + // bb.get(from, 0, length); for (int i = 0; i < size; i++) { from[i] = bb.get(i); @@ -840,9 +806,9 @@ public class EncodingUtils return (new String(convertToHexCharArray(from))); } - private static char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + private static char[] hex_chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - //**** new methods + // **** new methods // AMQP_BOOLEAN_PROPERTY_PREFIX @@ -854,6 +820,7 @@ public class EncodingUtils public static boolean readBoolean(ByteBuffer buffer) { byte packedValue = buffer.get(); + return (packedValue == 1); } @@ -878,7 +845,6 @@ public class EncodingUtils return 1; } - // AMQP_SHORT_PROPERTY_PREFIX public static void writeShort(ByteBuffer buffer, Short aShort) { @@ -943,7 +909,6 @@ public class EncodingUtils return 4; } - // Double_PROPERTY_PREFIX public static void writeDouble(ByteBuffer buffer, Double aDouble) { @@ -960,7 +925,6 @@ public class EncodingUtils return 8; } - public static byte[] readBytes(ByteBuffer buffer) { short length = buffer.getUnsigned(); @@ -981,7 +945,7 @@ public class EncodingUtils { if (data != null) { - // TODO: check length fits in an unsigned byte + // TODO: check length fits in an unsigned byte writeUnsignedByte(buffer, (short) data.length); buffer.put(data); } @@ -992,7 +956,7 @@ public class EncodingUtils } } - //CHAR_PROPERTY + // CHAR_PROPERTY public static int encodedCharLength() { return encodedByteLength(); @@ -1000,31 +964,29 @@ public class EncodingUtils public static char readChar(ByteBuffer buffer) { - //This is valid as we know that the Character is ASCII 0..127 + // This is valid as we know that the Character is ASCII 0..127 return (char) buffer.get(); } public static void writeChar(ByteBuffer buffer, char character) { - //This is valid as we know that the Character is ASCII 0..127 + // This is valid as we know that the Character is ASCII 0..127 writeByte(buffer, (byte) character); } - - - public static long readLongAsShortString(ByteBuffer buffer) { short length = buffer.getUnsigned(); short pos = 0; - if(length == 0) + if (length == 0) { return 0L; } + byte digit = buffer.get(); boolean isNegative; long result = 0; - if(digit == (byte)'-') + if (digit == (byte) '-') { isNegative = true; pos++; @@ -1034,15 +996,16 @@ public class EncodingUtils { isNegative = false; } - result = digit - (byte)'0'; + + result = digit - (byte) '0'; pos++; - while(pos < length) + while (pos < length) { pos++; digit = buffer.get(); result = (result << 3) + (result << 1); - result += digit - (byte)'0'; + result += digit - (byte) '0'; } return result; @@ -1051,33 +1014,13 @@ public class EncodingUtils public static long readUnsignedInteger(ByteBuffer buffer) { long l = 0xFF & buffer.get(); - l <<=8; + l <<= 8; l = l | (0xFF & buffer.get()); - l <<=8; + l <<= 8; l = l | (0xFF & buffer.get()); - l <<=8; + l <<= 8; l = l | (0xFF & buffer.get()); return l; } - - - public static void main(String[] args) - { - ByteBuffer buf = ByteBuffer.allocate(8); - buf.setAutoExpand(true); - - long l = (long) Integer.MAX_VALUE; - l += 1024L; - - writeUnsignedInteger(buf, l); - - buf.flip(); - - long l2 = readUnsignedInteger(buf); - - System.out.println("before: " + l); - System.out.println("after: " + l2); - } - } diff --git a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java index f558523864..353c0d39c2 100644 --- a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java +++ b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java @@ -7,9 +7,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -24,9 +24,10 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; +import org.apache.log4j.Logger; + import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; -import org.apache.log4j.Logger; public class AMQBindingURL implements BindingURL { @@ -39,10 +40,9 @@ public class AMQBindingURL implements BindingURL AMQShortString _queueName; private HashMap<String, String> _options; - public AMQBindingURL(String url) throws URLSyntaxException { - //format: + // format: // <exch_class>://<exch_name>/[<destination>]/[<queue>]?<option>='<value>'[,<option>='<value>']* _logger.debug("Parsing URL: " + url); _url = url; @@ -61,10 +61,10 @@ public class AMQBindingURL implements BindingURL if (exchangeClass == null) { - _url = ExchangeDefaults.DIRECT_EXCHANGE_CLASS + "://" + - "" + "//" + _url; - //URLHelper.parseError(-1, "Exchange Class not specified.", _url); + _url = ExchangeDefaults.DIRECT_EXCHANGE_CLASS + "://" + "" + "//" + _url; + // URLHelper.parseError(-1, "Exchange Class not specified.", _url); parseBindingURL(); + return; } else @@ -76,7 +76,7 @@ public class AMQBindingURL implements BindingURL if (exchangeName == null) { - if(getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)) + if (getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)) { setExchangeName(""); } @@ -92,11 +92,10 @@ public class AMQBindingURL implements BindingURL String queueName; - if (connection.getPath() == null || - connection.getPath().equals("")) + if ((connection.getPath() == null) || connection.getPath().equals("")) { throw URLHelper.parseError(_url.indexOf(_exchangeName.toString()) + _exchangeName.length(), - "Destination or Queue requried", _url); + "Destination or Queue requried", _url); } else { @@ -104,7 +103,7 @@ public class AMQBindingURL implements BindingURL if (slash == -1) { throw URLHelper.parseError(_url.indexOf(_exchangeName.toString()) + _exchangeName.length(), - "Destination requried", _url); + "Destination requried", _url); } else { @@ -127,9 +126,8 @@ public class AMQBindingURL implements BindingURL setQueueName(queueName); - //Fragment is #string (not used) - //System.out.println(connection.getFragment()); - _logger.debug("URL Parsed: " + this); + // Fragment is #string (not used) + _logger.debug("URL Parsed: " + this); } catch (URISyntaxException uris) @@ -162,7 +160,7 @@ public class AMQBindingURL implements BindingURL private void processOptions() { - //this is where we would parse any options that needed more than just storage. + // this is where we would parse any options that needed more than just storage. } public String getURL() @@ -219,11 +217,13 @@ public class AMQBindingURL implements BindingURL { if (containsOption(BindingURL.OPTION_CLIENTID) && containsOption(BindingURL.OPTION_SUBSCRIPTION)) { - _queueName = new AMQShortString(getOption(BindingURL.OPTION_CLIENTID + ":" + BindingURL.OPTION_SUBSCRIPTION)); + _queueName = + new AMQShortString(getOption(BindingURL.OPTION_CLIENTID + ":" + BindingURL.OPTION_SUBSCRIPTION)); } else { - throw URLHelper.parseError(-1, "Durable subscription must have values for " + BindingURL.OPTION_CLIENTID + " and " + BindingURL.OPTION_SUBSCRIPTION + ".", _url); + throw URLHelper.parseError(-1, "Durable subscription must have values for " + BindingURL.OPTION_CLIENTID + + " and " + BindingURL.OPTION_SUBSCRIPTION + ".", _url); } } @@ -237,7 +237,6 @@ public class AMQBindingURL implements BindingURL _queueName = name; } - } public String getOption(String key) @@ -275,7 +274,6 @@ public class AMQBindingURL implements BindingURL setOption(OPTION_ROUTING_KEY, key.toString()); } - public String toString() { StringBuffer sb = new StringBuffer(); @@ -289,18 +287,7 @@ public class AMQBindingURL implements BindingURL sb.append(_queueName); sb.append(URLHelper.printOptions(_options)); - return sb.toString(); - } - - public static void main(String args[]) throws URLSyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue?option='value',option2='value2'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - System.out.println(url); - System.out.println(dest); + return sb.toString(); } - } diff --git a/java/common/src/main/java/org/apache/qpid/url/URLHelper.java b/java/common/src/main/java/org/apache/qpid/url/URLHelper.java index 806f879818..c08b443acf 100644 --- a/java/common/src/main/java/org/apache/qpid/url/URLHelper.java +++ b/java/common/src/main/java/org/apache/qpid/url/URLHelper.java @@ -7,9 +7,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -30,10 +30,10 @@ public class URLHelper public static void parseOptions(HashMap<String, String> optionMap, String options) throws URLSyntaxException { - //options looks like this - //brokerlist='tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'',failover='method?option='value',option='value'' + // options looks like this + // brokerlist='tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'',failover='method?option='value',option='value'' - if (options == null || options.indexOf('=') == -1) + if ((options == null) || (options.indexOf('=') == -1)) { return; } @@ -49,8 +49,8 @@ public class URLHelper // to store index of final "'" int valueIndex = optionIndex; - //Walk remainder of url. - while (nestedQuotes > 0 || valueIndex < length) + // Walk remainder of url. + while ((nestedQuotes > 0) || (valueIndex < length)) { valueIndex++; @@ -61,27 +61,24 @@ public class URLHelper if (options.charAt(valueIndex) == '\'') { - if (valueIndex + 1 < options.length()) + if ((valueIndex + 1) < options.length()) { - if (options.charAt(valueIndex + 1) == DEFAULT_OPTION_SEPERATOR || - options.charAt(valueIndex + 1) == ALTERNATIVE_OPTION_SEPARATOR || - options.charAt(valueIndex + 1) == BROKER_SEPARATOR || - options.charAt(valueIndex + 1) == '\'') + if ((options.charAt(valueIndex + 1) == DEFAULT_OPTION_SEPERATOR) + || (options.charAt(valueIndex + 1) == ALTERNATIVE_OPTION_SEPARATOR) + || (options.charAt(valueIndex + 1) == BROKER_SEPARATOR) + || (options.charAt(valueIndex + 1) == '\'')) { nestedQuotes--; -// System.out.println( -// options + "\n" + "-" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1)); + if (nestedQuotes == 0) { - //We've found the value of an option + // We've found the value of an option break; } } else { nestedQuotes++; -// System.out.println( -// options + "\n" + "+" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1)); } } else @@ -98,11 +95,11 @@ public class URLHelper } } - if (nestedQuotes != 0 || valueIndex < (optionIndex + 2)) + if ((nestedQuotes != 0) || (valueIndex < (optionIndex + 2))) { int sepIndex = 0; - //Try and identify illegal separator character + // Try and identify illegal separator character if (nestedQuotes > 1) { for (int i = 0; i < nestedQuotes; i++) @@ -112,14 +109,14 @@ public class URLHelper } } - if (sepIndex >= options.length() || sepIndex == 0) + if ((sepIndex >= options.length()) || (sepIndex == 0)) { throw parseError(valueIndex, "Unterminated option", options); } else { - throw parseError(sepIndex, "Unterminated option. Possible illegal option separator:'" + - options.charAt(sepIndex) + "'", options); + throw parseError(sepIndex, "Unterminated option. Possible illegal option separator:'" + + options.charAt(sepIndex) + "'", options); } } @@ -130,12 +127,11 @@ public class URLHelper if (valueIndex < (options.length() - 1)) { - //Recurse to get remaining options + // Recurse to get remaining options parseOptions(optionMap, options.substring(valueIndex + 2)); } } - public static URLSyntaxException parseError(int index, String error, String url) { return parseError(index, 1, error, url); |
