I've created a fileloader that discerns the fieldNames and sizes from the data file. I'm trying to avoid hard-coding as much as possible, but at some point you must make assumptions about the data
string array you read in.
I'm converting the String array into a business object to by-pass the majority of hard-coding, and also plan on passing the field names straight to my table-model. My file reading and writing mechanism doesn't make any assumptions about the data taking all its settings (record length & field sizes) from the schema.
I just can't see how you could make it 100% flexible using this approach, at the end of the day my business object has to know that position n in the String[] its passed is a name/location/size etc.
You could make it a JavaBean and use reflection to set the values, i.e. field name [0] is name, so instantiate a setName(String s) method and call it. But this complexity would be completely by-passed if a new field were to be added, though it would cope with re-ordering.
If I by-passed the idea of this business object, I still need to know that position n is a date that needs to be checked against.
I think that it would be very difficult to write this with 100% flexibility on the data layout. Every system needs to know how the data is stored surely.
So what I've done is to keep all of knowledge about the data layout in my business object, that way should the file change, then yes unfortunately a recompilation would be needed, but it would be an easy piece of maintenance.
Just looking for feedback on this issue. What have others done on this and does my approach sound reasonable? If only we could serialize objects to and from file like Max could
thanks guys!!!
James