Versioning of XML Output ------------------------ Key: BETWIXT-50 URL: http://issues.apache.org/jira/browse/BETWIXT-50 Project: Commons Betwixt Type: Improvement
Reporter: Holger Haag Referring to the thread "Versioning of XML Output" (http://mail-archives.apache.org/mod_mbox/jakarta-commons-user/200605.mbox/[EMAIL PROTECTED]) on the jakarta-commons-user mailing list, I'll provide here a SVN patch for the described problem. - Two new strategies: Attribute and Element suppression. Chose interfaces instead of abstract class so that one class (see test cases) can implement both. - After an element/attribute descriptor has been build completely (including the options), the suppression strategies are evaluated. If the element/attribute shall be suppressed, it is removed from the introspection results. - Important: use <addDefaults add-properties="false" /> ! Otherwise the effects of element/attribute suppression will be ... none. - Test cases for illustration === Code snippets + explanation == : * Added new Interfaces org.apache.commons.betwixt.strategy.AttributeSuppressionStrategy public boolean suppress(AttributeDescriptor descr); org.apache.commons.betwixt.strategy.ElementSuppressionStrategy public boolean suppress(ElementDescriptor descr); * Added setter/getter methods for such strategies in org.apache.commons.betwixt.IntrospectionConfiguration * org.apache.commons.betwixt.digester.ElementRule: Remove element descriptor if suppressed: ElementDescriptor descriptor = (ElementDescriptor)digester.pop(); final Object peek = digester.peek(); if(peek instanceof ElementDescriptor) { ElementDescriptor parent = (ElementDescriptor)digester.peek(); // check for element suppression if( getXMLIntrospector().getConfiguration().getElementSuppressionStrategy().suppress(descriptor)) { parent.removeElementDescriptor(descriptor); } } * org.apache.commons.betwixt.digester.AttributeRule: Remove attribute descrptor if suppressed: AttributeDescriptor descriptor = (AttributeDescriptor)digester.pop(); ElementDescriptor parent = (ElementDescriptor)digester.peek(); // check for attribute suppression if( getXMLIntrospector().getConfiguration().getAttributeSuppressionStrategy().suppress(descriptor)) { parent.removeAttributeDescriptor(descriptor); } * ElementDescriptor: new methods: public void removeAttributeDescriptor(AttributeDescriptor descriptor) { getAttributeList().remove(descriptor); } public void removeElementDescriptor(ElementDescriptor descriptor) { getElementList().remove(descriptor); getContentList().remove(descriptor); } public AttributeDescriptor getAttributeDescriptor(final String name) { for (int i = 0, size = attributeDescriptors.length; i < size; i++) { AttributeDescriptor descr = attributeDescriptors[i]; if (descr.getQualifiedName().equals(name)) { return descr; } } return null; } * Test cases: package org.apache.commons.betwixt.versioning VersioningStrategy implements both an element and versioning strategy VersioningTest well.. .test the versioning. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]