Package de.innovationgate.wga.model

Examples of de.innovationgate.wga.model.ValidationError


                                    ((ConfigBean) value).validate(errors, integrityCheckOnly);
                                }
                            }
                        }
                        else {
                            errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "' bc. it is not accessible via getMethod.",
                                    new String[] { desc.getName() }));
                        }
                    }
                    catch (Exception e) {
                        errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "'.", new String[] { desc.getName() }));
                    }
                }
                else if (List.class.isAssignableFrom(desc.getPropertyType())) {
                    try {
                        Method readMethod = desc.getReadMethod();
                        if (readMethod != null) {
                            if (readMethod.getAnnotation(SkipValidation.class) == null) {
                                Object value = readMethod.invoke(this, new Object[0]);
                                if (value != null) {
                                    Iterator it = ((List) value).iterator();
                                    Type[] typeArguments = retrieveGenericsOfReturnType(readMethod);
                                    while (it.hasNext()) {
                                        Object listValue = it.next();

                                        // check list value against generics
                                        if (listValue != null) {
                                            if (typeArguments != null && typeArguments.length > 0) {
                                                Class typeArgClass = (Class) typeArguments[0];
                                                if (!typeArgClass.isAssignableFrom(listValue.getClass())) {
                                                    errors
                                                            .add(new ValidationError("Unsupported type '" + listValue.getClass() + "' in list '" + desc.getName() + "'.",
                                                                    new String[] { desc.getName() }));
                                                }
                                            }
                                        }

                                        if (listValue instanceof ConfigBean) {
                                            ((ConfigBean) listValue).validate(errors, integrityCheckOnly);
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "' bc. it is not accessible via getMethod.",
                                    new String[] { desc.getName() }));
                        }
                    }
                    catch (Exception e) {
                        errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "'.", new String[] { desc.getName() }));
                    }
                }
                else if (Map.class.isAssignableFrom(desc.getPropertyType())) {
                    try {
                        Method readMethod = desc.getReadMethod();
                        if (readMethod != null) {
                            if (readMethod.getAnnotation(SkipValidation.class) == null) {
                                Object value = readMethod.invoke(this, new Object[0]);
                                if (value != null) {

                                    Type[] typeArguments = retrieveGenericsOfReturnType(readMethod);
                                    Iterator it = ((Map) value).keySet().iterator();
                                    while (it.hasNext()) {
                                        Object mapKey = it.next();
                                        Object mapValue = ((Map) value).get(mapKey);

                                        // check mapKey against generics
                                        if (mapKey != null) {
                                            if (typeArguments != null && typeArguments.length > 0) {
                                                Class typeArgClass = (Class) typeArguments[0];
                                                if (!typeArgClass.isAssignableFrom(mapKey.getClass())) {
                                                    errors
                                                            .add(new ValidationError("Unsupported keytype '" + mapKey.getClass() + "' in map '" + desc.getName() + "'.",
                                                                    new String[] { desc.getName() }));
                                                }
                                            }
                                        }

                                        // check mapValue against generics
                                        if (mapValue != null) {
                                            if (typeArguments != null && typeArguments.length > 1) {
                                                Class typeArgClass = (Class) typeArguments[1];
                                                if (!typeArgClass.isAssignableFrom(mapValue.getClass())) {
                                                    errors.add(new ValidationError("Unsupported value '" + mapValue.getClass() + "' in map '" + desc.getName() + "' for key '" + mapKey + "'.",
                                                            new String[] { desc.getName() }));
                                                }
                                            }
                                        }

                                        if (mapValue instanceof ConfigBean) {
                                            ((ConfigBean) mapValue).validate(errors, integrityCheckOnly);
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "' bc. it is not accessible via getMethod.",
                                    new String[] { desc.getName() }));
                        }
                    }
                    catch (Exception e) {
                        errors.add(new ValidationError("Unable to validate field '" + desc.getName() + "' of '" + this.getClass().getName() + "'.", new String[] { desc.getName() }));
                    }
                }
            }
        }
        catch (IntrospectionException e) {
View Full Code Here


                    if (field.getName().equals(desc.getName())) {
                        Method readMethod = desc.getReadMethod();
                        if (readMethod != null) {
                            Object value = readMethod.invoke(this, new Object[0]);
                            if (normalize(value) == null) {
                                errors.add(new ValidationError("Field '" + field.getName() + "' of '" + this.getClass().getName() + "' cannot be 'null'.", new String[] { field.getName() }));
                            }
                        }
                        else {
                            errors.add(new ValidationError("Unable to validate field '" + field.getName() + "' of '" + this.getClass().getName() + "' bc. it is not accessible via getMethod.",
                                    new String[] { field.getName() }));
                        }
                    }
                }
            }
            catch (Exception e) {
                errors.add(new ValidationError("Unable to validate field '" + field.getName() + "' of '" + this.getClass().getName() + "' " + e.getMessage() + ".", new String[] { field.getName() }));
            }
        }
        else if (annotation.annotationType().equals(NormalizeEmptyValue.class)) {
            try {
                PropertyDescriptor[] descs = Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors();
                for (PropertyDescriptor desc : descs) {
                    if (field.getName().equals(desc.getName())) {
                        Method readMethod = desc.getReadMethod();
                        Method writeMethod = desc.getWriteMethod();
                        if (readMethod != null && writeMethod != null) {
                            Object value = readMethod.invoke(this, new Object[0]);
                            value = normalize(value);
                            writeMethod.invoke(this, value);
                        }
                        else {
                            errors.add(new ValidationError("Unable to normalize field '" + field.getName() + "' of '" + this.getClass().getName() + "' bc. setter or getter is not accessible.",
                                    new String[] { field.getName() }));
                        }
                    }
                }
            }
            catch (Exception e) {
                errors.add(new ValidationError("Unable to normalize field '" + field.getName() + "' of '" + this.getClass().getName() + "' " + e.getMessage() + ".", new String[] { field.getName() }));
            }
        }
    }
View Full Code Here

TOP

Related Classes of de.innovationgate.wga.model.ValidationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.