commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Holger Haag" <j...@herr-der-mails.de>
Subject Re: [betwixt] Versioning of XML Output
Date Mon, 22 May 2006 12:31:59 GMT
Hi,

I hope this goes to the correct mailing list; if not pls. let me know:

I've been working on this issue and attached a SVN patch (see below). Here
is a quick overview:

- 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

I hope I've got everything properly according to the apache guidelines. Just
let me know if somethings wrong.

Eagerly waiting ;-)

Holger


=== 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.
  
   
== SVN Patch ==   

Index:
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java
===================================================================
---
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java	(revision
408590)
+++
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/ElementRule.java	(working
copy)
@@ -20,6 +20,7 @@
 import java.lang.reflect.Modifier;
 import java.util.Map;
 
+import org.apache.commons.betwixt.AttributeDescriptor;
 import org.apache.commons.betwixt.ElementDescriptor;
 import org.apache.commons.betwixt.XMLBeanInfo;
 import org.apache.commons.betwixt.XMLUtils;
@@ -193,7 +194,18 @@
      * Process the end of this element.
      */
     public void end(String name, String namespace) {
-        Object top = digester.pop();
+        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);
+            }
+        }
     }
 
     // Implementation methods
Index:
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
===================================================================
---
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
(revision
408590)
+++
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
(working
copy)
@@ -112,7 +112,13 @@
      * Process the end of this element.
      */
     public void end(String name, String namespace) {
-        Object top = digester.pop();
+        AttributeDescriptor descriptor =
(AttributeDescriptor)digester.pop();
+        ElementDescriptor parent = (ElementDescriptor)digester.peek();
+
+        // check for attribute suppression
+        if(
getXMLIntrospector().getConfiguration().getAttributeSuppressionStrategy().suppress(descriptor))
{
+            parent.removeAttributeDescriptor(descriptor);
+        }
     }
 
     
Index:
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
===================================================================
---
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
(revision
408590)
+++
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
(working
copy)
@@ -16,10 +16,12 @@
 
 package org.apache.commons.betwixt;
 
+import org.apache.commons.betwixt.strategy.AttributeSuppressionStrategy;
 import org.apache.commons.betwixt.strategy.ClassNormalizer;
 import org.apache.commons.betwixt.strategy.CollectiveTypeStrategy;
 import org.apache.commons.betwixt.strategy.DefaultNameMapper;
 import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
+import org.apache.commons.betwixt.strategy.ElementSuppressionStrategy;
 import org.apache.commons.betwixt.strategy.MappingDerivationStrategy;
 import org.apache.commons.betwixt.strategy.NameMapper;
 import org.apache.commons.betwixt.strategy.NamespacePrefixMapper;
@@ -90,6 +92,12 @@
     private TypeBindingStrategy typeBindingStrategy =
TypeBindingStrategy.DEFAULT;
     /** Strategy used for determining which types are collective */
     private CollectiveTypeStrategy collectiveTypeStrategy =
CollectiveTypeStrategy.DEFAULT;
+
+    /** Strategy for suppressing attributes */
+    private AttributeSuppressionStrategy attributeSuppressionStrategy =
AttributeSuppressionStrategy.DEFAULT;   
+    /** Strategy for suppressing elements */
+    private ElementSuppressionStrategy elementSuppressionStrategy =
ElementSuppressionStrategy.DEFAULT;
+
     
     /** 
      * Strategy used to determine whether the bind or introspection time
type is to be used to  
@@ -433,4 +441,51 @@
     public boolean isLoopType(Class type) {
         return getCollectiveTypeStrategy().isCollective(type);
     }
+
+
+    /**
+     * Returns the <code>AttributeSuppressionStrategy</code>. 
+     * This is used to suppress attributes, e.g. for versioning.
+     * 
+     * @since 0.8
+     * @return the strategy
+     */
+    public AttributeSuppressionStrategy getAttributeSuppressionStrategy() {
+        return attributeSuppressionStrategy;
+    }
+
+    /**
+     * Sets the <code>AttributeSuppressionStrategy</code>. 
+     * This is used to suppress attributes, e.g. for versioning.
+     * 
+     * @since 0.8
+     * @param the strategy 
+     */
+    public void setAttributeSuppressionStrategy(
+            AttributeSuppressionStrategy attributeSuppressionStrategy) {
+        this.attributeSuppressionStrategy = attributeSuppressionStrategy;
+    }
+
+    /**
+     * Returns the <code>ElementSuppressionStrategy</code>. 
+     * This is used to suppress elements, e.g. for versioning.
+     * 
+     * @since 0.8
+     * @return the strategy
+     */
+    public ElementSuppressionStrategy getElementSuppressionStrategy() {
+        return elementSuppressionStrategy;
+    }
+
+    /**
+     * Sets the <code>ElementSuppressionStrategy</code>. 
+     * This is used to suppress elements, e.g. for versioning.
+     * 
+     * @since 0.8
+     * @param the strategy 
+     */
+    public void setElementSuppressionStrategy(
+            ElementSuppressionStrategy elementSuppressionStrategy) {
+        this.elementSuppressionStrategy = elementSuppressionStrategy;
+    }
 }
Index:
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/ElementDescriptor.java
===================================================================
---
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/ElementDescriptor.java	(revision
408590)
+++
C:/workspace/betwixt-trunk/src/java/org/apache/commons/betwixt/ElementDescriptor.java	(working
copy)
@@ -230,7 +230,17 @@
         attributeDescriptors = null;
     }
     
-    
+
+    /**
+     * Removes an attribute descriptor from this element descriptor. 
+     * @param descriptor the <code>AttributeDescriptor</code> that will be
removed.
+     * 
+     * @param descriptor
+     */
+    public void removeAttributeDescriptor(AttributeDescriptor descriptor) {
+        getAttributeList().remove(descriptor);
+    }
+
     /** 
      * Returns the attribute descriptors for this element 
      *
@@ -252,6 +262,23 @@
         return attributeDescriptors;
     }
     
+    /**
+     * Returns an attribute descriptor with a given name or null.
+     *  
+     * @param name to search for; will be checked against the attributes'
qualified name.
+     * @return
+     */
+    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;
+    }
+
     /** 
      * Sets the <code>AttributesDescriptors</code> for this element.
      * This sets descriptors for the attributes of the element describe by
the 
@@ -278,6 +305,17 @@
         elementDescriptors = null;
         addContentDescriptor( descriptor );
     }
+
+    /**
+     * Removes an element descriptor from this element descriptor. 
+     * @param descriptor the <code>ElementDescriptor</code> that will be
removed.
+     * 
+     * @param descriptor
+     */
+    public void removeElementDescriptor(ElementDescriptor descriptor) {
+        getElementList().remove(descriptor);
+        getContentList().remove(descriptor);
+    }
     
     /** 
      * Returns descriptors for the child elements of the element this
describes.

-- 
GMX Produkte empfehlen und ganz einfach Geld verdienen!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message