Author: tchemit Date: 2008-10-18 11:29:08 +0000 (Sat, 18 Oct 2008) New Revision: 975 Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java Log: improve coherence Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 11:28:25 UTC (rev 974) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 11:29:08 UTC (rev 975) @@ -98,6 +98,7 @@ } String bean = info.getBean(); + boolean error = false; if (bean != null) { if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) { String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler); @@ -105,23 +106,37 @@ // add generic type to validator JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler); info.setGenericTypes(new String[]{beanInfo.getJAXXBeanDescriptor().getClassDescriptor().getName()}); + } else { + error=true; } - } - if (info.getAutoField()) { - if (bean == null) { - compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode"); - } else { + //TODO: checkthe bean is not already used in another validator + if (!error && compiler.isBeanUsedByValidator(bean)) { + compiler.reportError("the bean '" + bean + "' is already used in another the validator, can not used it in '" + tag + "'"); + error = true; + } + + if (!error && info.getAutoField()) { + //if (bean == null) { + // compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode"); + //} else { registerAutoFieldBean(tag, compiler, info); + // } } - } - // add fieldrepresentation invocations - addFieldRepresentations(tag, compiler, info); + if (!error && info.getBeanDescriptor(compiler) != null) { - // register the validator in compiler - compiler.registerValidator(info); + // add fieldrepresentation invocations + addFieldRepresentations(tag, compiler, info); + // register the validator in compiler + compiler.registerValidator(info); + } + + } else { + compiler.reportError("tag '" + tag + "' requires a bean attribute"); + } + // close the compiled object compiler.closeComponent(info); } @@ -178,7 +193,7 @@ } if (compiler.isComponentUsedByValidator(component)) { // component is already used by another validator - compiler.reportError("component '"+component+"' is already used by another validator."); + compiler.reportError("component '" + component + "' is already used by another validator."); continue; } String keyCode = TypeManager.getJavaCode(propertyName); @@ -300,7 +315,12 @@ public JAXXBeanInfo getBeanDescriptor(JAXXCompiler compiler) { if (beanDescriptor == null && bean != null) { try { - ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(compiler.getSymbolTable().getClassTagIds().get(bean)); + String beanClassName = compiler.getSymbolTable().getClassTagIds().get(bean); + if (beanClassName == null) { + compiler.reportError("could not find class of the bean '" + bean + "'"); + return null; + } + ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(beanClassName); beanDescriptor = getJAXXBeanInfo(beanClassDescriptor); } catch (ClassNotFoundException e) { compiler.reportError("could not load class " + bean);