commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin van den Bemt <mll...@mvdb.net>
Subject Re: [PATCH] Betwixt. setting namemapper for attributes.
Date Wed, 05 Jun 2002 16:20:23 GMT
If I am not mistaking the only change that is need then is to change the
current setNameMapper(..) to setElementNameMapper(..).
Since the attributeNameMapper is already a NameMapper type ;)
The suggestion was merely a mind spin, that it maybe better to use an
AttributeNameMapper type, so it is more clear. That mind spin came from
the fact that I thought that attributes were always read, not caring
about naming rules.. Since the setAttributeNameMapper is pretty clear, I
don't think we can leave it simple.
I am using the HyphenatedNameMapper for my elements
and the DecapitalizeNameMapper for my attributes ;)

My renewed patch will be sent tonight (seems like it is working, but
didn't get to parse the complete xml file yet).

BTW I am now manually testing the thing I have the deadline on, which
makes life a little bit less stressfull ;)

Mvgr,
Martin
 

On Wed, 2002-06-05 at 17:53, James Strachan wrote:
> How about if the XMLIntrospector had an 'elementNameMapper' and an
> 'attributeNameMapper' properties (both of type NameMapper) then you could
> use upper case element names and lower case attribute names, but still keep
> the same implementations of NameMapper?  i.e. then it allows you to
> configure each mechanism seperately. We should probably change the method
> name of NameMapper to something a little more suitable, like
> convertToXmlName()?
> 
> James
> ----- Original Message -----
> From: "Martin van den Bemt" <mllist@mvdb.net>
> To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> Sent: Wednesday, June 05, 2002 4:50 PM
> Subject: Re: [PATCH] Betwixt. setting namemapper for attributes.
> 
> 
> > Hmm.. hold back on the patch ;))..
> > Found another issue.. It is also using the attributenamemapper for
> > subelemenents.. Fixing that now..
> >
> > Mvgr,
> > Martin
> > On Wed, 2002-06-05 at 17:18, Martin van den Bemt wrote:
> > > Hi James,
> > >
> > > Finally found the problem. The nameMapper is also used for attributes..
> > > so if I have an xml file like
> > > <PHYSICAL_SCHEMA autocreate="yes"/>
> > >
> > > You end up with trouble ;).. Since autocreate will be mapped to the
> > > attribute AUTOCREATE, which doesn't exist.
> > >
> > > So I added an extra nameMapper setter (setAttributeNameMapper), which
> > > you can call if you want to use a different nameMapper for attributes.
> > >
> > > I have chosen not to make a specific attributenamemapper Interface /
> > > abstract class for simplicity and easier reuse of code..
> > >
> > > The default is to use the normal NameMapper, so no backward
> > > compatibility issues on this.
> > >
> > > If you don't mind, I will make my testcases a little bit later.
> > > (hopefully tonight, or else on sunday, since I am off sailing for a
> > > couple of days..)
> > > Hope you wil apply the patch however, ran all tests and it doesn't break
> > > backward compatibility.
> > >
> > > Hope it is usefull for you too ;)
> > >
> > > Mvgr,
> > > Martin
> > >
> > >
> > >
> > >
> > > ----
> > >
> >
> > > Index: XMLIntrospector.java
> > > ===================================================================
> > > RCS file:
> /home/cvspublic/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/
> betwixt/XMLIntrospector.java,v
> > > retrieving revision 1.28
> > > diff -u -r1.28 XMLIntrospector.java
> > > --- XMLIntrospector.java 3 Jun 2002 20:51:08 -0000 1.28
> > > +++ XMLIntrospector.java 5 Jun 2002 15:03:48 -0000
> > > @@ -93,6 +93,7 @@
> > >    * Later requests for the same class will return the cached value.</p>
> > >    *
> > >    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
> > > +  * @author <a href-"mailto:martin@mvdb.net">Martin van den Bemt</a>
> > >    * @version $Id: XMLIntrospector.java,v 1.28 2002/06/03 20:51:08 jon
> Exp $
> > >    */
> > >  public class XMLIntrospector {
> > > @@ -123,6 +124,12 @@
> > >      /** The strategy used to convert bean type names into element names
> */
> > >      private NameMapper nameMapper;
> > >
> > > +    /**
> > > +     * The strategy used to convert bean type names into attribute
> names
> > > +     * It will default to the normal nameMapper.
> > > +     */
> > > +    private NameMapper attributeNameMapper;
> > > +
> > >      /** Base constructor */
> > >      public XMLIntrospector() {
> > >      }
> > > @@ -329,13 +336,32 @@
> > >          }
> > >          return nameMapper;
> > >      }
> > > +    /**
> > > +     * @return the strategy used to convert bean type names into
> attribute
> > > +     * names. If no attributeNamemapper is known, it will default to
> the NameMapper
> > > +     */
> > > +    public NameMapper getAttributeNameMapper() {
> > > +        if (attributeNameMapper == null) {
> > > +            attributeNameMapper = getNameMapper();
> > > +        }
> > > +        return attributeNameMapper;
> > > +    }
> > >
> > >      /**
> > >       * Sets the strategy used to convert bean type names into element
> names
> > > +     * @param nameMapper
> > >       */
> > >      public void setNameMapper(NameMapper nameMapper) {
> > >          this.nameMapper = nameMapper;
> > >      }
> > > +
> > > +    /**
> > > +     * Sets the strategy used to convert bean type names into attribute
> names
> > > +     * @param nameMapper
> > > +     */
> > > +    public void setAttributeNameMapper(NameMapper nameMapper) {
> > > +        this.attributeNameMapper = nameMapper;
> > > +    }
> > >
> > >
> > >
> > > @@ -508,7 +534,7 @@
> > >              elements.add( nodeDescriptor );
> > >          }
> > >
> > > -        nodeDescriptor.setLocalName(
> getNameMapper().mapTypeToElementName( propertyDescriptor.getName() ) );
> > > +        nodeDescriptor.setLocalName(
> getAttributeNameMapper().mapTypeToElementName(
> propertyDescriptor.getName() ) );
> > >          nodeDescriptor.setPropertyName( propertyDescriptor.getName() );
> > >          nodeDescriptor.setPropertyType( type );
> > >
> > >
> > > ----
> > >
> >
> > > --
> > > To unsubscribe, e-mail:
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> <mailto:commons-dev-help@jakarta.apache.org>
> >
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
> 
> 



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


Mime
View raw message