You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/09/10 11:42:25 UTC
svn commit: r813331 - in
/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy:
BindyCsvFactory.java BindyKeyValuePairFactory.java
format/DatePatternFormat.java
Author: ningjiang
Date: Thu Sep 10 09:42:25 2009
New Revision: 813331
URL: http://svn.apache.org/viewvc?rev=813331&view=rev
Log:
Fixed CS errors of camel-bindy
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=813331&r1=813330&r2=813331&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java Thu Sep 10 09:42:25 2009
@@ -182,11 +182,11 @@
Object value = null;
if (!data.equals("")) {
- try {
- value = format.parse(data);
- } catch (Exception e) {
- throw new IllegalArgumentException("Parsing error detected for field defined at the position : " + pos, e);
- }
+ try {
+ value = format.parse(data);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Parsing error detected for field defined at the position : " + pos, e);
+ }
} else {
value = getDefaultValueforPrimitive(field.getType());
}
@@ -218,20 +218,22 @@
Map<Integer, DataField> dataFieldsSorted = new TreeMap<Integer, DataField>(dataFields);
Iterator<Integer> it = dataFieldsSorted.keySet().iterator();
-
+
// Map containing the OUT position of the field
- // The key is double and is created using the position of the field and
+ // The key is double and is created using the position of the field and
// location of the class in the message (using section)
Map<Integer, String> positions = new TreeMap<Integer, String>();
// Check if separator exists
- ObjectHelper.notNull(this.separator, "The separator has not been instantiated or property not defined in the @CsvRecord annotation");
-
+ ObjectHelper
+ .notNull(this.separator,
+ "The separator has not been instantiated or property not defined in the @CsvRecord annotation");
+
char separator = Converter.getCharDelimitor(this.getSeparator());
if (LOG.isDebugEnabled()) {
LOG.debug("Separator converted : '0x" + Integer.toHexString(separator) + "', from : "
- + this.getSeparator());
+ + this.getSeparator());
}
while (it.hasNext()) {
@@ -247,13 +249,13 @@
Class type = field.getType();
String pattern = dataField.pattern();
int precision = dataField.precision();
-
+
// Create format
Format format = FormatFactory.getFormat(type, pattern, precision);
-
+
// Get field from model
Object modelField = model.get(field.getDeclaringClass().getName());
-
+
if (modelField != null) {
// Get field value
Object value = field.get(modelField);
@@ -266,20 +268,22 @@
Integer key1 = sections.get(modelField.getClass().getName());
Integer key2 = dataField.position();
Integer keyGenerated = generateKey(key1, key2);
-
+
if (LOG.isDebugEnabled()) {
- LOG.debug("Key generated : " + String.valueOf(keyGenerated) + ", for section : " + key1);
- }
-
+ LOG.debug("Key generated : " + String.valueOf(keyGenerated) + ", for section : "
+ + key1);
+ }
+
if (value != null) {
// Format field value
- try {
- strValue = format.format(value);
- } catch (Exception e) {
- throw new IllegalArgumentException("Formating error detected for the value : " + value, e);
- }
- }
-
+ try {
+ strValue = format.format(value);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Formating error detected for the value : "
+ + value, e);
+ }
+ }
+
// Add the content to the TreeMap according to the
// position defined
positions.put(keyGenerated, strValue);
@@ -287,28 +291,29 @@
if (LOG.isDebugEnabled()) {
LOG.debug("Positions size : " + positions.size());
}
-
+
} else {
// Get field value
- //Object value = field.get(modelField);
- //String strValue = null;
+ // Object value = field.get(modelField);
+ // String strValue = null;
// Add value to the list if not null
if (value != null) {
// Format field value
- try {
- strValue = format.format(value);
- } catch (Exception e) {
- throw new IllegalArgumentException("Formating error detected for the value : " + value, e);
- }
-
+ try {
+ strValue = format.format(value);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Formating error detected for the value : "
+ + value, e);
+ }
+
}
-
+
if (LOG.isDebugEnabled()) {
LOG.debug("Data : " + value + ", value : " + strValue);
}
-
+
builder.append(strValue);
if (it.hasNext()) {
@@ -317,27 +322,27 @@
}
}
}
-
+
// Iterate through the list to generate
// the message according to the order/position
if (this.isMessageOrdered()) {
Iterator<Integer> posit = positions.keySet().iterator();
-
+
while (posit.hasNext()) {
String value = positions.get(posit.next());
-
+
if (LOG.isDebugEnabled()) {
LOG.debug("Value added at the position (" + posit + ") : " + value + separator);
}
-
+
builder.append(value);
if (it.hasNext()) {
builder.append(separator);
}
}
}
-
+
return builder.toString();
}
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=813331&r1=813330&r2=813331&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java Thu Sep 10 09:42:25 2009
@@ -118,63 +118,64 @@
int pos = 0;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Data : " + data);
- }
-
- while (pos < data.size()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Data : " + data);
+ }
- if (!data.get(pos).equals("")) {
+ while (pos < data.size()) {
- // Separate the key from its value
- // e.g 8=FIX 4.1 --> key = 8 and Value = FIX 4.1
- ObjectHelper.notNull(this.keyValuePairSeparator,
- "Key Value Pair not defined in the @Message annotation");
- String[] keyValuePair = data.get(pos).split(this.getKeyValuePairSeparator());
+ if (!data.get(pos).equals("")) {
- int tag = Integer.parseInt(keyValuePair[0]);
- String keyValue = keyValuePair[1];
+ // Separate the key from its value
+ // e.g 8=FIX 4.1 --> key = 8 and Value = FIX 4.1
+ ObjectHelper.notNull(this.keyValuePairSeparator,
+ "Key Value Pair not defined in the @Message annotation");
+ String[] keyValuePair = data.get(pos).split(this.getKeyValuePairSeparator());
- if (LOG.isDebugEnabled()) {
- LOG.debug("Key : " + tag + ", value : " + keyValue);
- }
+ int tag = Integer.parseInt(keyValuePair[0]);
+ String keyValue = keyValuePair[1];
- KeyValuePairField keyValuePairField = keyValuePairFields.get(tag);
- ObjectHelper.notNull(keyValuePairField, "No tag defined for the field : " + tag);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Key : " + tag + ", value : " + keyValue);
+ }
- Field field = annotedFields.get(tag);
- field.setAccessible(true);
+ KeyValuePairField keyValuePairField = keyValuePairFields.get(tag);
+ ObjectHelper.notNull(keyValuePairField, "No tag defined for the field : " + tag);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Tag : " + tag + ", Data : " + keyValue + ", Field type : " + field.getType());
- }
+ Field field = annotedFields.get(tag);
+ field.setAccessible(true);
- Format<?> format;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Tag : " + tag + ", Data : " + keyValue + ", Field type : " + field.getType());
+ }
- // Get pattern defined for the field
- String pattern = keyValuePairField.pattern();
+ Format<?> format;
- // Create format object to format the field
- format = FormatFactory.getFormat(field.getType(), pattern, keyValuePairField.precision());
+ // Get pattern defined for the field
+ String pattern = keyValuePairField.pattern();
- // field object to be set
- Object modelField = model.get(field.getDeclaringClass().getName());
+ // Create format object to format the field
+ format = FormatFactory.getFormat(field.getType(), pattern, keyValuePairField.precision());
- // format the value of the key received
- Object value;
- try {
- value = format.parse(keyValue);
- } catch (Exception e) {
- throw new IllegalArgumentException("Parsing error detected for field defined at the tag : "
- + tag, e);
- }
+ // field object to be set
+ Object modelField = model.get(field.getDeclaringClass().getName());
+
+ // format the value of the key received
+ Object value;
+ try {
+ value = format.parse(keyValue);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Parsing error detected for field defined at the tag : "
+ + tag, e);
+ }
- field.set(modelField, value);
+ field.set(modelField, value);
- }
+ }
- pos++;
- }
+ pos++;
+ }
}
@@ -182,23 +183,25 @@
StringBuilder builder = new StringBuilder();
- Map<Integer, KeyValuePairField> keyValuePairFieldsSorted = new TreeMap<Integer, KeyValuePairField>(keyValuePairFields);
+ Map<Integer, KeyValuePairField> keyValuePairFieldsSorted = new TreeMap<Integer, KeyValuePairField>(
+ keyValuePairFields);
Iterator<Integer> it = keyValuePairFieldsSorted.keySet().iterator();
-
+
// Map containing the OUT position of the field
- // The key is double and is created using the position of the field and
+ // The key is double and is created using the position of the field and
// location of the class in the message (using section)
Map<Integer, String> positions = new TreeMap<Integer, String>();
// Check if separator exists
- ObjectHelper.notNull(this.pairSeparator,
- "The pair separator has not been instantiated or property not defined in the @Message annotation");
+ ObjectHelper
+ .notNull(this.pairSeparator,
+ "The pair separator has not been instantiated or property not defined in the @Message annotation");
char separator = Converter.getCharDelimitor(this.getPairSeparator());
if (LOG.isDebugEnabled()) {
LOG.debug("Separator converted : '0x" + Integer.toHexString(separator) + "', from : "
- + this.getPairSeparator());
+ + this.getPairSeparator());
}
while (it.hasNext()) {
@@ -249,11 +252,12 @@
// Format field value
String valueFormated;
-
+
try {
- valueFormated = format.format(keyValue);
+ valueFormated = format.format(keyValue);
} catch (Exception e) {
- throw new IllegalArgumentException("Formating error detected for the tag : " + keyValuePairField.tag(), e);
+ throw new IllegalArgumentException("Formating error detected for the tag : "
+ + keyValuePairField.tag(), e);
}
// Create the key value string
@@ -275,11 +279,12 @@
// Format field value
String valueFormated;
-
+
try {
- valueFormated = format.format(keyValue);
+ valueFormated = format.format(keyValue);
} catch (Exception e) {
- throw new IllegalArgumentException("Formating error detected for the tag : " + keyValuePairField.tag(), e);
+ throw new IllegalArgumentException("Formating error detected for the tag : "
+ + keyValuePairField.tag(), e);
}
// Create the key value string
@@ -303,19 +308,18 @@
if (this.isMessageOrdered()) {
Iterator<Integer> posit = positions.keySet().iterator();
-
+
while (posit.hasNext()) {
String value = positions.get(posit.next());
-
+
if (LOG.isDebugEnabled()) {
LOG.debug("Value added at the position (" + posit + ") : " + value + separator);
}
-
+
builder.append(value + separator);
}
}
-
return builder.toString();
}
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java?rev=813331&r1=813330&r2=813331&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/DatePatternFormat.java Thu Sep 10 09:42:25 2009
@@ -28,8 +28,8 @@
import org.apache.commons.logging.LogFactory;
public class DatePatternFormat implements PatternFormat<Date> {
-
- private static final transient Log LOG = LogFactory.getLog(DatePatternFormat.class);
+
+ private static final transient Log LOG = LogFactory.getLog(DatePatternFormat.class);
private String pattern;
@@ -47,18 +47,19 @@
public Date parse(String string) throws Exception {
- Date date;
+ Date date;
DateFormat df = this.getDateFormat();
LOG.info("Pattern : " + this.pattern);
ObjectHelper.notNull(this.pattern, "pattern");
-
- // Force the parser to be strict in the syntax of the date to be converted
+
+ // Force the parser to be strict in the syntax of the date to be
+ // converted
df.setLenient(false);
- date = df.parse(string);
+ date = df.parse(string);
+
+ return date;
- return date;
-
}
protected java.text.DateFormat getDateFormat() {