commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Inger, Matthew" <In...@Synygy.com>
Subject RE: [betwixt] Inheritance version 2
Date Sun, 30 May 2004 04:48:06 GMT
I will try to come up with some unit tests following whatever
examples are in the betwixt package currently.  I'm still waiting
on my committer access (CLA still hasn't been recorded), otherwise
I'd make the commit myself when i've got the unit tests ready.

As far as the documentation, i'm assuming it's bundled with the
source code, correct?  If not, please let me know where i can
get it, and how to get the changes back to you.

The one thing also to note about this approach, is that by only
going up one superclass (rather than all the way up the chain),
it allows the superclass to control the
inheritance from further up the hierarchy.  I'm not sure if you'd consider
this an advantage or not.

I'll let you know when i'm ready with unit tests.
-----Original Message-----
From: robert burrell donkin
[mailto:robertburrelldonkin@blueyonder.co.uk]
Sent: Saturday, May 29, 2004 6:50 AM
To: Jakarta Commons Developers List
Subject: Re: [betwixt] Inheritance version 2


hi matthew

thanks for the patch.

i like the sound of this. as you'll probably be aware, i'll pretty busy  
at the moment and (unless some other committer step ups) i'm not sure  
when i'll get the change to create the unit tests and documentation  
that needs to go with this patch.

if you could create some unit tests for this extra functionality and a  
documentation patch for the web site, not only would i be very, very  
grateful but it'd massively increase the chances of this patch being  
applied sooner (rather than later). if you have any questions about the  
way we like unit tests done or about how to write content for the  
documentation,  don't hesitate to ask.

- robert

On 28 May 2004, at 23:41, Inger, Matthew wrote:

> Here's the diff which allows either approach:
>
> Index: InfoRule.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/ 
> betwixt/
> digester/InfoRule.java,v
> retrieving revision 1.8
> diff -u -r1.8 InfoRule.java
> --- InfoRule.java	28 Feb 2004 13:38:32 -0000	1.8
> +++ InfoRule.java	28 May 2004 22:41:51 -0000
> @@ -1,25 +1,31 @@
>  /*
>   * Copyright 2001-2004 The Apache Software Foundation.
> - *
> + *
>   * Licensed under the Apache License, Version 2.0 (the "License");
>   * you may not use this file except in compliance with the License.
>   * You may obtain a copy of the License at
> - *
> + *
>   *      http://www.apache.org/licenses/LICENSE-2.0
> - *
> + *
>   * Unless required by applicable law or agreed to in writing, software
>   * distributed under the License is distributed on an "AS IS" BASIS,
>   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
> implied.
>   * See the License for the specific language governing permissions and
>   * limitations under the License.
> - */
> + */
>  package org.apache.commons.betwixt.digester;
>
> +import org.apache.commons.betwixt.AttributeDescriptor;
> +import org.apache.commons.betwixt.ElementDescriptor;
>  import org.apache.commons.betwixt.XMLBeanInfo;
> +import org.apache.commons.betwixt.XMLIntrospector;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>  import org.xml.sax.Attributes;
>  import org.xml.sax.SAXException;
> +import java.beans.IntrospectionException;
> +import java.util.ArrayList;
> +import java.util.List;
>
>  /** <p><code>InfoRule</code> the digester Rule for parsing the info
> element.</p>
>    *
> @@ -32,14 +38,16 @@
>      private static final Log log = LogFactory.getLog( InfoRule.class  
> );
>      /** <code>XMLBeanInfo</code> being created */
>      private XMLBeanInfo xmlBeanInfo;
> -
> +    private boolean inherited = false;
> +    private boolean inheritedElement = false;
> +
>      /** Base constructor */
>      public InfoRule() {
>      }
> -
> +
>      // Rule interface
> -
> / 
> /---------------------------------------------------------------------- 
> ---
>
> -
> +
> / 
> /---------------------------------------------------------------------- 
> ---
> +
>      /**
>       * Process the beginning of this element.
>       *
> @@ -48,32 +56,66 @@
>       */
>      public void begin(Attributes attributes) throws SAXException {
>          Class beanClass = getBeanClass();
> -
> +
>          xmlBeanInfo = new XMLBeanInfo( beanClass );
> -
> +
>          String value = attributes.getValue( "primitiveTypes" );
>          if ( value != null ) {
>              if ( value.equalsIgnoreCase( "element" ) ) {
>                  getXMLInfoDigester().setAttributesForPrimitives(  
> false );
> -
> +
>              } else if ( value.equalsIgnoreCase( "attribute" ) ) {
>                  getXMLInfoDigester().setAttributesForPrimitives( true  
> );
> -
> +
>              } else {
>                  throw new SAXException(
>                      "Invalid value inside element <info> for attribute
> 'primitiveTypes'."
>                      + " Value should be 'element' or 'attribute'" );
>              }
>          }
> -
> -        getDigester().push(xmlBeanInfo);
> +
> +        String inherit = attributes.getValue( "inherit" );
> +        if (inherit != null && inherit.equalsIgnoreCase("true")) {
> +            inherited = true;
> +        }
> +
> +        String inheritElement = attributes.getValue( "inheritelement"  
> );
> +        if (inheritElement != null && inheritElement
> .equalsIgnoreCase("true")) {
> +            inherited = true;
> +            inheritedElement = true;
> +        }
> +
> +        getDigester().push(xmlBeanInfo);
>      }
>
>
>      /**
>       * Process the end of this element.
>       */
> -    public void end() {
> +    public void end() throws IntrospectionException {
> +        Class beanClass = getBeanClass();
>          Object top = getDigester().pop();
> +
> +        ElementDescriptor descriptor =  
> xmlBeanInfo.getElementDescriptor();
> +        if (inherited) {
> +            XMLIntrospector introspector = new XMLIntrospector();
> +            Class clazz = beanClass.getSuperclass();
> +            XMLBeanInfo info = introspector.introspect(clazz);
> +            ElementDescriptor ed = info.getElementDescriptor();
> +
> +            if (inheritedElement) {
> +                descriptor.addElementDescriptor(ed);
> +            }
> +            else {
> +                AttributeDescriptor att[] =  
> ed.getAttributeDescriptors();
> +                for (int i=0;i<att.length;i++) {
> +                    descriptor.addAttributeDescriptor(att[i]);
> +                }
> +                ElementDescriptor eld[] = ed.getElementDescriptors();
> +                for (int i=0;i<eld.length;i++) {
> +                    descriptor.addElementDescriptor(eld[i]);
> +                }
> +            }
> +        }
>      }
>  }
>
>
> -----Original Message-----
> From: Inger, Matthew [mailto:Inger@Synygy.com]
> Sent: Friday, May 28, 2004 6:28 PM
> To: 'Jakarta Commons Developers List'
> Subject: RE: [betwixt] Inheritance
>
>
> FYI:  The following patch will take care of the inheritance issue.  It  
> still
> behaves,
> by default, as it used to but there is now an "inherit" attribute  
> which can
> be
> specified on the <info> element which will cause the InfoRule to  
> introspect
> the
> immediate superclass of the current class being mapped, and take all  
> of it's
> superclasses' element and attribute descriptors.
>
> This will put all elements and attributes of the superclass directly  
> under
> the root element for the object.
>
> <child>
>    <parentProperty>1</parentProperty>
> </child>
>
> Or we could always just add the ElementDescriptor for the superclass,  
> so
> that
> we would use the following XML:
>
> <child>
>    <parent>
>      <parentProperty>1</parentProperty>
>    </parent>
> </child>
>
> The patch below deals with the first scenario, but i'm willing to keep
> working
> on it to allow inheritance to be done in either fashion, maybe  
> something
> like
>
> <info inheritinline="true">...</info>
>
> OR
>
> <info inheritelement="true">...</info>
>
> Thoughts?
>
>
> Index: InfoRule.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/ 
> betwixt/
> digester/InfoRule.java,v
> retrieving revision 1.8
> diff -u -r1.8 InfoRule.java
> --- InfoRule.java	28 Feb 2004 13:38:32 -0000	1.8
> +++ InfoRule.java	28 May 2004 22:22:59 -0000
> @@ -1,25 +1,31 @@
>  /*
>   * Copyright 2001-2004 The Apache Software Foundation.
> - *
> + *
>   * Licensed under the Apache License, Version 2.0 (the "License");
>   * you may not use this file except in compliance with the License.
>   * You may obtain a copy of the License at
> - *
> + *
>   *      http://www.apache.org/licenses/LICENSE-2.0
> - *
> + *
>   * Unless required by applicable law or agreed to in writing, software
>   * distributed under the License is distributed on an "AS IS" BASIS,
>   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
> implied.
>   * See the License for the specific language governing permissions and
>   * limitations under the License.
> - */
> + */
>  package org.apache.commons.betwixt.digester;
>
> +import org.apache.commons.betwixt.AttributeDescriptor;
> +import org.apache.commons.betwixt.ElementDescriptor;
>  import org.apache.commons.betwixt.XMLBeanInfo;
> +import org.apache.commons.betwixt.XMLIntrospector;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>  import org.xml.sax.Attributes;
>  import org.xml.sax.SAXException;
> +import java.beans.IntrospectionException;
> +import java.util.ArrayList;
> +import java.util.List;
>
>  /** <p><code>InfoRule</code> the digester Rule for parsing the info
> element.</p>
>    *
> @@ -32,14 +38,15 @@
>      private static final Log log = LogFactory.getLog( InfoRule.class  
> );
>      /** <code>XMLBeanInfo</code> being created */
>      private XMLBeanInfo xmlBeanInfo;
> -
> +    private boolean inherited = false;
> +
>      /** Base constructor */
>      public InfoRule() {
>      }
> -
> +
>      // Rule interface
> -
> / 
> /---------------------------------------------------------------------- 
> ---
>
> -
> +
> / 
> /---------------------------------------------------------------------- 
> ---
> +
>      /**
>       * Process the beginning of this element.
>       *
> @@ -48,32 +55,56 @@
>       */
>      public void begin(Attributes attributes) throws SAXException {
>          Class beanClass = getBeanClass();
> -
> +
>          xmlBeanInfo = new XMLBeanInfo( beanClass );
> -
> +
>          String value = attributes.getValue( "primitiveTypes" );
>          if ( value != null ) {
>              if ( value.equalsIgnoreCase( "element" ) ) {
>                  getXMLInfoDigester().setAttributesForPrimitives(  
> false );
> -
> +
>              } else if ( value.equalsIgnoreCase( "attribute" ) ) {
>                  getXMLInfoDigester().setAttributesForPrimitives( true  
> );
> -
> +
>              } else {
>                  throw new SAXException(
>                      "Invalid value inside element <info> for attribute
> 'primitiveTypes'."
>                      + " Value should be 'element' or 'attribute'" );
>              }
>          }
> -
> -        getDigester().push(xmlBeanInfo);
> +
> +        String inherit = attributes.getValue( "inherit" );
> +        if (inherit != null && inherit.equalsIgnoreCase("true")) {
> +            inherited = true;
> +        }
> +
> +        getDigester().push(xmlBeanInfo);
>      }
>
>
>      /**
>       * Process the end of this element.
>       */
> -    public void end() {
> +    public void end() throws IntrospectionException {
> +        Class beanClass = getBeanClass();
>          Object top = getDigester().pop();
> +
> +        ElementDescriptor descriptor =  
> xmlBeanInfo.getElementDescriptor();
> +        if (inherited) {
> +           XMLIntrospector introspector = new XMLIntrospector();
> +           Class clazz = beanClass.getSuperclass();
> +           XMLBeanInfo info = introspector.introspect(clazz);
> +           ElementDescriptor ed = info.getElementDescriptor();
> +           AttributeDescriptor att[] = ed.getAttributeDescriptors();
> +           for (int i=0;i<att.length;i++) {
> +               descriptor.addAttributeDescriptor(att[i]);
> +           }
> +           ElementDescriptor eld[] = ed.getElementDescriptors();
> +           for (int i=0;i<eld.length;i++) {
> +               descriptor.addElementDescriptor(eld[i]);
> +           }
> +        }
> +
> +
>      }
>  }
>
>
>
> -----Original Message-----
> From: Inger, Matthew [mailto:Inger@Synygy.com]
> Sent: Friday, May 28, 2004 4:06 PM
> To: 'Jakarta Commons Developers List'
> Subject: [betwixt] Inheritance
>
>
> It's possible i'm just missing something, but i've
> been unsucessful in trying to achieve mapping inheritance
> in betwixt.
>
> I have an abstract base class, which has some properties which are
> mapped.  There is then a subclass with it's own additional properties
> for mapping.
>
> I cannnot seem to get betwixt to output the properties from the
> superclass unless i specifically refer to each of those properties
> in the mapping for the subclass.
>
> Shouldn't mappings inherit (at least optionally) from the mapping
> for their superclass?
>
> If anyone has any hints, please let me know.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>


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

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


Mime
View raw message