[Buix-commits] r1054 - in lutinjaxx/trunk/jaxx-core: . src/main/java/jaxx/runtime/validator src/main/java/jaxx/tags/swing src/main/java/jaxx/tags/validator
Author: tchemit Date: 2008-12-02 22:25:40 +0000 (Tue, 02 Dec 2008) New Revision: 1054 Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/ExcludeFieldValidatorHandler.java Modified: lutinjaxx/trunk/jaxx-core/changelog lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorTableModel.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java Log: can exclude field from validator Modified: lutinjaxx/trunk/jaxx-core/changelog =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog 2008-12-02 20:59:03 UTC (rev 1053) +++ lutinjaxx/trunk/jaxx-core/changelog 2008-12-02 22:25:40 UTC (rev 1054) @@ -1,4 +1,5 @@ 0.7 chemit 200812?? + - can exclude field from validator * 20081202 [chemit] - add strategy for loading ui in NavigationTreeSelectionAdapter - fix bug when searching for a inner class Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorTableModel.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorTableModel.java 2008-12-02 20:59:03 UTC (rev 1053) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorTableModel.java 2008-12-02 22:25:40 UTC (rev 1054) @@ -79,10 +79,9 @@ // clean errors in model getDataVector().clear(); - Scope scope = validator.getScope(); // reinject in list model, all the errors for (BeanValidatorError error : newErrors) { - addRow(new Object[]{scope, error.getFieldName(), error}); + addRow(new Object[]{error.getScope(), error.getFieldName(), error}); } // notify thaht the model has changed Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java 2008-12-02 20:59:03 UTC (rev 1053) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java 2008-12-02 22:25:40 UTC (rev 1054) @@ -19,6 +19,7 @@ import jaxx.tags.TagManager; import jaxx.tags.validator.BeanValidatorHandler; import jaxx.tags.validator.FieldValidatorHandler; +import jaxx.tags.validator.ExcludeFieldValidatorHandler; import jaxx.types.KeyStrokeConverter; import jaxx.types.TypeManager; @@ -98,6 +99,7 @@ // validator TagManager.registerBean(ClassDescriptorLoader.getClassDescriptor(BeanValidator.class), BeanValidatorHandler.class); - TagManager.registerTag(JAXXCompiler.JAXX_NAMESPACE, FieldValidatorHandler.FIELD_VALIDATOR_TAG, new FieldValidatorHandler()); + TagManager.registerTag(JAXXCompiler.JAXX_NAMESPACE, FieldValidatorHandler.TAG, new FieldValidatorHandler()); + TagManager.registerTag(JAXXCompiler.JAXX_NAMESPACE, ExcludeFieldValidatorHandler.TAG, new FieldValidatorHandler()); } } \ No newline at end of file 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-12-02 20:59:03 UTC (rev 1053) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-12-02 22:25:40 UTC (rev 1054) @@ -29,7 +29,7 @@ public class BeanValidatorHandler extends DefaultObjectHandler { - public static final String BEAN_VALIDATOR_TAG = BeanValidator.class.getSimpleName(); + public static final String TAG = BeanValidator.class.getSimpleName(); public static final String BEAN_ATTRIBUTE = "bean"; public static final String BEAN_CLASS_ATTRIBUTE = "beanClass"; public static final String BEAN_INITIALIZER_ATTRIBUTE = "beanInitializer"; @@ -71,8 +71,8 @@ if (compiler.getOptions().isVerbose()) { log.info(tag); } - if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) { - compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName()); + if (!tag.getLocalName().equals(FieldValidatorHandler.TAG)) { + compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.TAG + " as children, but found : " + tag.getLocalName()); } else { compiler.compileFirstPass(tag); } @@ -146,6 +146,7 @@ public static class CompiledBeanValidator extends CompiledObject { protected Map<String, String> fields; + protected Map<String, String> excludeFields; protected String bean; protected String beanClass; protected String contextName; @@ -162,16 +163,25 @@ public CompiledBeanValidator(String id, ClassDescriptor objectClass, JAXXCompiler compiler) { super(id, objectClass, compiler); fields = new TreeMap<String, String>(); + excludeFields = new TreeMap<String, String>(); } public Map<String, String> getFields() { return fields; } + public Map<String, String> getExcludeFields() { + return excludeFields; + } + public void setFields(Map<String, String> fields) { this.fields = fields; } + public void setExcludeFields(Map<String, String> excludeFields) { + this.excludeFields = excludeFields; + } + @Override public void addProperty(String property, String value) { @@ -319,7 +329,7 @@ @Override public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException { // do nothing - compiler.reportError("can not add CompiledObject in the tag '" + BEAN_VALIDATOR_TAG + " (only field tags)"); + compiler.reportError("can not add CompiledObject in the tag '" + TAG + " (only field tags)"); } public boolean foundBean() { @@ -554,6 +564,10 @@ // already defined in field continue; } + if (excludeFields.containsKey(descriptionName)) { + // exclude field + continue; + } if (!compiler.checkReference(tag, descriptionName, getStrictMode(), null)) { // no editor component found continue; @@ -561,6 +575,14 @@ // ok add the field mapping registerField(descriptionName, descriptionName, compiler); } + + for (Entry<String, String> entry : excludeFields.entrySet()) { + String key = entry.getKey(); + if (fields.containsKey(key)) { + compiler.reportWarning("field '" + key + "' can not be used and excluded at same time ! (field is skipped) for validator " + this); + fields.remove(key); + } + } } public void registerField(String id, String component, JAXXCompiler compiler) { @@ -574,6 +596,17 @@ } } + public void registerExcludeField(String id, String component, JAXXCompiler compiler) { + if (excludeFields.containsKey(id)) { + compiler.reportError("duplicate field '" + id + "' for validator " + this); + } else { + if (compiler.getOptions().isVerbose()) { + log.info("add excludeField <" + id + ":" + component + ">"); + } + excludeFields.put(id, component); + } + } + protected boolean checkBeanProperty(JAXXCompiler compiler, String propertyName) { for (JAXXPropertyDescriptor beanProperty : getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) { Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/ExcludeFieldValidatorHandler.java (from rev 1003, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java) =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/ExcludeFieldValidatorHandler.java (rev 0) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/ExcludeFieldValidatorHandler.java 2008-12-02 22:25:40 UTC (rev 1054) @@ -0,0 +1,85 @@ +/* + * Copyright 2006 Ethan Nicholas. All rights reserved. + * Use is subject to license terms. + */ +package jaxx.tags.validator; + +import jaxx.CompilerException; +import jaxx.compiler.JAXXCompiler; +import jaxx.reflect.ClassDescriptorLoader; +import jaxx.runtime.validator.BeanValidator; +import jaxx.tags.TagHandler; +import jaxx.tags.validator.BeanValidatorHandler.CompiledBeanValidator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Element; + +import java.io.IOException; + +public class ExcludeFieldValidatorHandler implements TagHandler { + + public static final String TAG = "excludeField"; + public static final String NAME_ATTRIBUTE = "name"; + public static final String COMPONENT_ATTRIBUTE = "component"; + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ExcludeFieldValidatorHandler.class); + + public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + if (compiler.getOptions().isVerbose()) { + log.info(tag); + } + //todo check there is no child + } + + public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { + if (compiler.getOptions().isVerbose()) { + log.debug(tag); + } + + if (!ClassDescriptorLoader.getClassDescriptor(BeanValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) { + compiler.reportError(TAG + " tag may only appear within " + BeanValidatorHandler.TAG + " tag but was " + tag); + return; + } + + CompiledBeanValidator info = (CompiledBeanValidator) compiler.getOpenComponent(); + if (!info.getAutoField()) { + compiler.reportError(TAG + " tag can not be used without an 'autoField' validator : " + tag); + return; + } + String name = tag.getAttribute(NAME_ATTRIBUTE); + String component = tag.getAttribute(COMPONENT_ATTRIBUTE); + if (name == null || name.trim().isEmpty()) { + compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); + return; + } + name = name.trim(); + if (component == null || component.trim().isEmpty()) { + // try to use the name as component + if (!compiler.checkReference(tag, name, false, name)) { + compiler.reportError(TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found"); + return; + } + component = name; + } + component = component.trim(); + + // check component is not already used by this compiled object + if (info.getFields().containsValue(component)) { + compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " ["+component+"] already used in this validator"); + return; + } + if (info.getExcludeFields().containsValue(component)) { + compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " ["+component+"] already used in this validator"); + return; + } + // check component exist (again perharps, but let the error knows exactly which tag failed...) + if (compiler.checkReference(tag, component, true, COMPONENT_ATTRIBUTE)) { + // add a field + info.registerField(name, component, compiler); + } + + + } + +} \ No newline at end of file Property changes on: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/ExcludeFieldValidatorHandler.java ___________________________________________________________________ Name: svn:mergeinfo + Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java 2008-12-02 20:59:03 UTC (rev 1053) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java 2008-12-02 22:25:40 UTC (rev 1054) @@ -18,7 +18,7 @@ public class FieldValidatorHandler implements TagHandler { - public static final String FIELD_VALIDATOR_TAG = "field"; + public static final String TAG = "field"; public static final String NAME_ATTRIBUTE = "name"; public static final String COMPONENT_ATTRIBUTE = "component"; @@ -38,7 +38,7 @@ } if (!ClassDescriptorLoader.getClassDescriptor(BeanValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) { - compiler.reportError(FIELD_VALIDATOR_TAG + " tag may only appear within " + BeanValidatorHandler.BEAN_VALIDATOR_TAG + " tag but was " + tag); + compiler.reportError(TAG + " tag may only appear within " + BeanValidatorHandler.TAG + " tag but was " + tag); return; } @@ -47,14 +47,14 @@ String name = tag.getAttribute(NAME_ATTRIBUTE); String component = tag.getAttribute(COMPONENT_ATTRIBUTE); if (name == null || name.trim().isEmpty()) { - compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); + compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); return; } name = name.trim(); if (component == null || component.trim().isEmpty()) { // try to use the name as component if (!compiler.checkReference(tag, name, false, name)) { - compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found"); + compiler.reportError(TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found"); return; } component = name; @@ -63,7 +63,7 @@ // check component is not already used by this compiled object if (info.getFields().containsValue(component)) { - compiler.reportError(FIELD_VALIDATOR_TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " ["+component+"] already used in this validator"); + compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " ["+component+"] already used in this validator"); return; } // check component exist (again perharps, but let the error knows exactly which tag failed...)
participants (1)
-
tchemit@users.labs.libre-entreprise.org