[svn r289] implemented annotation validators, and removed all info logging
This commit is contained in:
parent
78a76fa12e
commit
fdd0af9597
16 changed files with 380 additions and 109 deletions
|
|
@ -32,8 +32,12 @@ import java.util.List;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.hibernate.validator.ClassValidator;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
|
||||
import com.idcanet.vasc.annotations.VascAnnotationParser;
|
||||
import com.idcanet.vasc.core.VascEventListener;
|
||||
import com.idcanet.vasc.core.VascExceptionListener;
|
||||
import com.idcanet.vasc.core.VascTable;
|
||||
import com.idcanet.vasc.core.VascTableController;
|
||||
import com.idcanet.vasc.core.column.VascAnnotationTableColumn;
|
||||
|
|
@ -51,9 +55,13 @@ import com.idcanet.vasc.impl.column.BeanPropertyVascColumnValue;
|
|||
public class DefaultVascTableController implements VascTableController {
|
||||
|
||||
private Logger logger = null;
|
||||
private List<VascEventListener> eventListeners = null;
|
||||
private List<VascExceptionListener> exceptionListeners = null;
|
||||
|
||||
public DefaultVascTableController() {
|
||||
logger = Logger.getLogger(DefaultVascTableController.class.getName());
|
||||
eventListeners = new ArrayList<VascEventListener>(2);
|
||||
exceptionListeners = new ArrayList<VascExceptionListener>(2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,12 +172,19 @@ public class DefaultVascTableController implements VascTableController {
|
|||
}
|
||||
|
||||
public void handleException(Exception e,VascTable table) {
|
||||
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e);
|
||||
if (exceptionListeners.isEmpty()) {
|
||||
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e);
|
||||
return;
|
||||
}
|
||||
for(VascExceptionListener ee:exceptionListeners) {
|
||||
try {
|
||||
ee.handleException(e, table);
|
||||
} catch (Exception eee) {
|
||||
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,"Error in ExceptionListener: "+eee.getMessage(),eee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<VascEventListener> eventListeners = new ArrayList<VascEventListener>(2);
|
||||
|
||||
public void addEventListener(VascEventListener e) {
|
||||
eventListeners.add(e);
|
||||
}
|
||||
|
|
@ -182,4 +197,52 @@ public class DefaultVascTableController implements VascTableController {
|
|||
e.vascEvent(type, data);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean setUIComponentsBeanErrors(VascTable table,Object bean) {
|
||||
boolean error = false;
|
||||
if(bean==null) {
|
||||
logger.finest("No bean to check.");
|
||||
return true; // nothing to check
|
||||
}
|
||||
|
||||
ClassValidator val = new ClassValidator(bean.getClass());
|
||||
InvalidValue[] ival = val.getInvalidValues(bean);
|
||||
logger.fine("Got invaliled value: "+ival.length);
|
||||
|
||||
for(VascTableColumn col:table.getTableColumns()) {
|
||||
if(col.getVascUIComponent()==null) {
|
||||
continue; // we only DISPLAY user input errors !!
|
||||
}
|
||||
if (col instanceof VascAnnotationTableColumn) {
|
||||
VascAnnotationTableColumn column = (VascAnnotationTableColumn)col;
|
||||
|
||||
InvalidValue iv = findInvalidValueByProperty(ival,column.getBeanProperty());
|
||||
if(iv==null) {
|
||||
column.getVascUIComponent().setErrorText(null);
|
||||
continue; // no error on this property
|
||||
}
|
||||
error = true;
|
||||
column.getVascUIComponent().setErrorText(iv.getMessage());
|
||||
}
|
||||
}
|
||||
logger.finest("Checked for errors: "+error);
|
||||
return error;
|
||||
}
|
||||
private InvalidValue findInvalidValueByProperty(InvalidValue[] ival,String property) {
|
||||
for(InvalidValue iv:ival) {
|
||||
if(iv.getPropertyName().equals(property)) {
|
||||
return iv;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addExceptionListener(VascExceptionListener listener) {
|
||||
exceptionListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeExceptionListener(VascExceptionListener listener) {
|
||||
exceptionListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue