commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt Father.java
Date Sun, 01 Feb 2004 22:55:48 GMT
rdonkin     2004/02/01 14:55:48

  Modified:    betwixt/src/java/org/apache/commons/betwixt Tag:
                        REFACTORING-BRANCH_2004-01-13
                        IntrospectionConfiguration.java
               betwixt/src/java/org/apache/commons/betwixt/digester Tag:
                        REFACTORING-BRANCH_2004-01-13 AttributeRule.java
                        ElementRule.java
               betwixt/src/java/org/apache/commons/betwixt/io Tag:
                        REFACTORING-BRANCH_2004-01-13
                        AbstractBeanWriter.java BeanWriter.java
               betwixt/src/java/org/apache/commons/betwixt/schema Tag:
                        REFACTORING-BRANCH_2004-01-13 Schema.java
               betwixt/src/test/org/apache/commons/betwixt/dotbetwixt Tag:
                        REFACTORING-BRANCH_2004-01-13 Father.java
  Log:
  Improvements to namespace support.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +25 -5     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/Attic/IntrospectionConfiguration.java
  
  Index: IntrospectionConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/Attic/IntrospectionConfiguration.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- IntrospectionConfiguration.java	18 Jan 2004 23:01:52 -0000	1.1.2.2
  +++ IntrospectionConfiguration.java	1 Feb 2004 22:55:47 -0000	1.1.2.3
  @@ -65,6 +65,7 @@
   import org.apache.commons.betwixt.strategy.DefaultNameMapper;
   import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
   import org.apache.commons.betwixt.strategy.NameMapper;
  +import org.apache.commons.betwixt.strategy.NamespacePrefixMapper;
   import org.apache.commons.betwixt.strategy.PluralStemmer;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -117,7 +118,8 @@
        */
       private NameMapper attributeNameMapper;
   
  -
  +    /** Prefix naming strategy */
  +    private NamespacePrefixMapper prefixMapper = new NamespacePrefixMapper();
   
   
       /**
  @@ -303,4 +305,22 @@
           introspectionLog = log;
       }
   
  +    
  +    /**
  +     * Gets the <code>NamespacePrefixMapper</code> used to convert namespace
URIs 
  +     * into prefixes.
  +     * @return NamespacePrefixMapper, not null
  +     */
  +    public NamespacePrefixMapper getPrefixMapper() {
  +        return prefixMapper;
  +    }
  +
  +    /**
  +     * Sets the <code>NamespacePrefixMapper</code> used to convert namespave
URIs
  +     * into prefixes.
  +     * @param mapper NamespacePrefixMapper, not null
  +     */
  +    public void setPrefixMapper(NamespacePrefixMapper mapper) {
  +        prefixMapper = mapper;
  +    }
   }
  
  
  
  No                   revision
  No                   revision
  1.8.2.4   +10 -6     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
  
  Index: AttributeRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java,v
  retrieving revision 1.8.2.3
  retrieving revision 1.8.2.4
  diff -u -r1.8.2.3 -r1.8.2.4
  --- AttributeRule.java	18 Jan 2004 22:25:22 -0000	1.8.2.3
  +++ AttributeRule.java	1 Feb 2004 22:55:47 -0000	1.8.2.4
  @@ -117,12 +117,16 @@
               throw new SAXException("'" + nameAttributeValue + "' would not be a well formed
xml attribute name.");
           }
           
  -        descriptor.setQualifiedName( nameAttributeValue );
  +        String qName = nameAttributeValue;
           descriptor.setLocalName( nameAttributeValue );
           String uri = attributes.getValue( "uri" );
           if ( uri != null ) {
  -            descriptor.setURI( uri );        
  +            descriptor.setURI( uri );  
  +            String prefix = getXMLIntrospector().getConfiguration().getPrefixMapper().getPrefix(uri);
  +            qName = prefix + ":" + nameAttributeValue; 
           }
  +        descriptor.setQualifiedName( qName );
  +        
           String propertyName = attributes.getValue( "property" );
           descriptor.setPropertyName( propertyName );
           descriptor.setPropertyType( loadClass( attributes.getValue( "type" ) ) );
  
  
  
  1.13.2.5  +9 -6      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java
  
  Index: ElementRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v
  retrieving revision 1.13.2.4
  retrieving revision 1.13.2.5
  diff -u -r1.13.2.4 -r1.13.2.5
  --- ElementRule.java	18 Jan 2004 22:25:22 -0000	1.13.2.4
  +++ ElementRule.java	1 Feb 2004 22:55:47 -0000	1.13.2.5
  @@ -125,12 +125,15 @@
           }
           
           ElementDescriptor descriptor = new ElementDescriptor();
  -        descriptor.setQualifiedName( nameAttributeValue );
           descriptor.setLocalName( nameAttributeValue );
           String uri = attributes.getValue( "uri" );
  +        String qName = nameAttributeValue;
           if ( uri != null ) {
  -            descriptor.setURI( uri );        
  +            descriptor.setURI( uri );  
  +            String prefix = getXMLIntrospector().getConfiguration().getPrefixMapper().getPrefix(uri);
  +            qName = prefix + ":" + nameAttributeValue;
           }
  +        descriptor.setQualifiedName( qName );
           
           String propertyName = attributes.getValue( "property" );
           descriptor.setPropertyName( propertyName );
  
  
  
  No                   revision
  No                   revision
  1.22.2.5  +51 -13    jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java
  
  Index: AbstractBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java,v
  retrieving revision 1.22.2.4
  retrieving revision 1.22.2.5
  diff -u -r1.22.2.4 -r1.22.2.5
  --- AbstractBeanWriter.java	26 Jan 2004 22:20:01 -0000	1.22.2.4
  +++ AbstractBeanWriter.java	1 Feb 2004 22:55:47 -0000	1.22.2.5
  @@ -62,6 +62,8 @@
   
   import java.beans.IntrospectionException;
   import java.io.IOException;
  +import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   
  @@ -115,6 +117,8 @@
       private boolean writeEmptyElements = true;
       /** Dynamic binding configuration settings */
       private BindingConfiguration bindingConfiguration = new BindingConfiguration();
  +    /** Collection of namespaces which have already been declared */
  +    private Collection namespacesDeclared = new ArrayList();
       
       /**
        * Marks the start of the bean writing.
  @@ -354,6 +358,8 @@
           this.idGenerator = idGenerator;
       }
       
  +    
  +    
       /**
        * Gets the dynamic configuration setting to be used for bean reading.
        * @return the BindingConfiguration settings, not null
  @@ -558,11 +564,13 @@
                   log.trace( "Element " + elementDescriptor + " is empty." );
               }
           
  +            Attributes attributes = addNamespaceDeclarations(new ElementAttributes( elementDescriptor,
context ));
  +            
               startElement( 
                               namespaceUri, 
                               localName, 
                               qualifiedName,
  -                            new ElementAttributes( elementDescriptor, context ));
  +                            attributes);
              
               writeElementContent( elementDescriptor, context ) ;
               
  @@ -571,6 +579,33 @@
           }
       }
       
  +    /**
  +     * Adds namespace declarations (if any are needed) to the given attributes.
  +     * @param attributes Attributes, not null
  +     * @return Attributes, not null
  +     */
  +    private Attributes addNamespaceDeclarations(Attributes attributes) {
  +        Attributes result = attributes;
  +        AttributesImpl withDeclarations = null; 
  +        for (int i=0, size=attributes.getLength(); i<size ; i++) {
  +            String uri = attributes.getURI(i);
  +            if (uri != null && !"".equals(uri) && !namespacesDeclared.contains(uri))
{
  +                if (withDeclarations == null) {
  +                    withDeclarations = new AttributesImpl(attributes);
  +                }
  +                withDeclarations.addAttribute("", "", "xmlns:" 
  +                    + getXMLIntrospector().getConfiguration().getPrefixMapper().getPrefix(uri),
"NOTATION", uri);
  +                namespacesDeclared.add(uri);
  +            }
  +        }
  +        
  +        if (withDeclarations != null) {
  +            result = withDeclarations;
  +        }
  +        return result;
  +    }
  +    
  +    
       /** 
        * Writes the given element adding an ID attribute 
        *
  @@ -599,16 +634,16 @@
                                       IntrospectionException {
                      
           if ( !ignoreElement( elementDescriptor, context ) ) {
  -        
  +            Attributes attributes = new IDElementAttributes( 
  +                        elementDescriptor, 
  +                        context, 
  +                        idAttribute, 
  +                        idValue );
               startElement( 
                           namespaceUri, 
                           localName, 
                           qualifiedName,
  -                        new IDElementAttributes( 
  -                                                elementDescriptor, 
  -                                                context, 
  -                                                idAttribute, 
  -                                                idValue ));
  +                        addNamespaceDeclarations(attributes));
       
               writeElementContent( elementDescriptor, context ) ;
               endElement( namespaceUri, localName, qualifiedName );
  @@ -679,7 +714,7 @@
                                   idrefAttributeName,
                                   "IDREF",
                                   idrefAttributeValue);
  -        startElement( uri, localName, qualifiedName, attributes);        
  +        startElement( uri, localName, qualifiedName, addNamespaceDeclarations(attributes));
       
           endElement( uri, localName, qualifiedName );
       }
       
  @@ -891,6 +926,7 @@
           return true;
       }
       
  +    
       /**
        * Attributes backed by attribute descriptors.
        * ID/IDREFs not set.
  @@ -1596,4 +1632,6 @@
       private Context makeContext(Object bean) {
           return new Context( bean, log, bindingConfiguration );
       }
  +
  +
   }
  
  
  
  1.20.2.2  +5 -5      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java
  
  Index: BeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java,v
  retrieving revision 1.20.2.1
  retrieving revision 1.20.2.2
  diff -u -r1.20.2.1 -r1.20.2.2
  --- BeanWriter.java	13 Jan 2004 21:49:46 -0000	1.20.2.1
  +++ BeanWriter.java	1 Feb 2004 22:55:47 -0000	1.20.2.2
  @@ -7,7 +7,7 @@
    * 
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  
  
  
  No                   revision
  No                   revision
  1.1.2.3   +4 -5      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Schema.java
  
  Index: Schema.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Schema.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Schema.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  +++ Schema.java	1 Feb 2004 22:55:48 -0000	1.1.2.3
  @@ -62,7 +62,6 @@
   package org.apache.commons.betwixt.schema;
   
   import java.util.ArrayList;
  -import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
   
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +4 -4      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/Attic/Father.java
  
  Index: Father.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/Attic/Father.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Father.java	20 Jan 2004 23:00:29 -0000	1.1.2.1
  +++ Father.java	1 Feb 2004 22:55:48 -0000	1.1.2.2
  @@ -61,8 +61,8 @@
   
   package org.apache.commons.betwixt.dotbetwixt;
   
  -import java.util.List;
   import java.util.ArrayList;
  +import java.util.List;
   
   /**
    * @author Brian Pugh
  
  
  

---------------------------------------------------------------------
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