Skip to content

Commit

Permalink
Support For Type Matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris W. Waguia committed Jun 7, 2012
1 parent 425e576 commit 8e3424d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.adorsys.waguia.lightxls.core.EasyMatching;
import org.adorsys.waguia.lightxls.core.Finder;
import org.adorsys.waguia.lightxls.loader.ClassInSheetFinder;
import org.adorsys.waguia.lightxls.loader.ExelPropertyReader;
import org.adorsys.waguia.lightxls.loader.FieldToColumnComparator;
import org.adorsys.waguia.lightxls.loader.SheetColumnToClazzFieldMatching;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -49,7 +50,7 @@ public class EasyXlsClazzLoader<T> implements EasyClazzLoader<T> {
private Finder classInSheetFinder;
private EasyMatching sheetColumnToClazzFieldMatching;
private EasyComparator fieldToColumnComparator;

private ExelPropertyReader exelPropertyReader ;
public EasyXlsClazzLoader(Workbook workbook, Class<T> clazz) {
this.workbook = workbook;
this.clazz = clazz;
Expand Down Expand Up @@ -131,8 +132,18 @@ public List<T> loadClazz() throws IllegalArgumentException,
//Find the correct field's range in the list of columns.
for (String string : columnNames) {
if (fieldToColumnComparator.compare(field.getName(),string) == 0) {
// if(field.getType().getClass().equals(Integer.class))
method.invoke(newInstance, nextRow.getCell(index).getStringCellValue());
Class<?> type = field.getType();
if(exelPropertyReader == null){
exelPropertyReader = new ExelPropertyReader(field, type, newInstance, nextRow.getCell(index), method);
exelPropertyReader.readProperty();
}else {
exelPropertyReader.setField(field);
exelPropertyReader.setCell(nextRow.getCell(index));
exelPropertyReader.setMethod(method);
exelPropertyReader.setNewInstance(newInstance);
exelPropertyReader.setType(type);
exelPropertyReader.readProperty();
}
index++;
continue ;
}
Expand All @@ -145,7 +156,8 @@ public List<T> loadClazz() throws IllegalArgumentException,
}
return result;
}

public void checkTypeAndLoadData(Class<?> type,Object newInstance,Cell cell){
}
public Finder getClassInSheetFinder() {
return classInSheetFinder;
}
Expand All @@ -172,4 +184,12 @@ public void setFieldToColumnComparator(
this.fieldToColumnComparator = fieldToColumnComparator;
}

public ExelPropertyReader getExelPropertyReader() {
return exelPropertyReader;
}

public void setExelPropertyReader(ExelPropertyReader exelPropertyReader) {
this.exelPropertyReader = exelPropertyReader;
}

}
13 changes: 11 additions & 2 deletions src/main/java/org/adorsys/waguia/lightxls/loader/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Person {
private String personKeyBk;
private String firstName;
private String address ;

private int age ;
private String ckeck ;
public String getPersonKeyBk() {
return personKeyBk;
Expand All @@ -49,10 +49,19 @@ public String getCkeck() {
public void setCkeck(String ckeck) {
this.ckeck = ckeck;
}

public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

@Override
public String toString() {
return "Person [personKeyBk=" + personKeyBk + ", firstName="
+ firstName + ", address=" + address + ", ckeck=" + ckeck + "]";
+ firstName + ", address=" + address + ", age=" + age
+ ", ckeck=" + ckeck + "]";
}


Expand Down
Binary file modified src/test/resources/test.xls
Binary file not shown.

0 comments on commit 8e3424d

Please sign in to comment.