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/java/org/apache/commons/betwixt/io/read BeanBindAction.java MappingAction.java ReadContext.java
Date Thu, 15 Jan 2004 20:21:22 GMT
rdonkin     2004/01/15 12:21:22

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io/read Tag:
                        REFACTORING-BRANCH_2004-01-13 BeanBindAction.java
                        MappingAction.java ReadContext.java
  Log:
  Fixed bug in only failing unit test.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +7 -50     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/BeanBindAction.java
  
  Index: BeanBindAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/BeanBindAction.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- BeanBindAction.java	13 Jan 2004 21:57:54 -0000	1.1.2.1
  +++ BeanBindAction.java	15 Jan 2004 20:21:21 -0000	1.1.2.2
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-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
  @@ -353,7 +353,7 @@
                   // iterate through all attributes        
                   AttributeDescriptor[] attributeDescriptors =
                       typeDescriptor.getAttributeDescriptors();
  -                populateAttributes(attributeDescriptors, attributes, context);
  +                context.populateAttributes(attributeDescriptors, attributes);
   
                   if (log.isTraceEnabled()) {
                       log.trace("Created bean " + instance);
  @@ -374,49 +374,6 @@
           return action;
       }
   
  -    private void populateAttributes(
  -        AttributeDescriptor[] attributeDescriptors,
  -        Attributes attributes,
  -        ReadContext context) {
  -
  -        Log log = context.getLog();
  -        if (attributeDescriptors != null) {
  -            for (int i = 0, size = attributeDescriptors.length;
  -                i < size;
  -                i++) {
  -                AttributeDescriptor attributeDescriptor =
  -                    attributeDescriptors[i];
  -
  -                // The following isn't really the right way to find the attribute
  -                // but it's quite robust.
  -                // The idea is that you try both namespace and local name first
  -                // and if this returns null try the qName.
  -                String value =
  -                    attributes.getValue(
  -                        attributeDescriptor.getURI(),
  -                        attributeDescriptor.getLocalName());
  -
  -                if (value == null) {
  -                    value =
  -                        attributes.getValue(
  -                            attributeDescriptor.getQualifiedName());
  -                }
  -
  -                if (log.isTraceEnabled()) {
  -                    log.trace("Attr URL:" + attributeDescriptor.getURI());
  -                    log.trace(
  -                        "Attr LocalName:" + attributeDescriptor.getLocalName());
  -                    log.trace(value);
  -                }
  -
  -                Updater updater = attributeDescriptor.getUpdater();
  -                log.trace(updater);
  -                if (updater != null && value != null) {
  -                    updater.update(context, value);
  -                }
  -            }
  -        }
  -    }
   
       /** 
       * Factory method to create new bean instances 
  
  
  
  1.1.2.2   +93 -76    jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/MappingAction.java
  
  Index: MappingAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/Attic/MappingAction.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- MappingAction.java	13 Jan 2004 22:26:19 -0000	1.1.2.1
  +++ MappingAction.java	15 Jan 2004 20:21:21 -0000	1.1.2.2
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-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
  @@ -61,6 +61,8 @@
    */
   package org.apache.commons.betwixt.io.read;
   
  +import org.apache.commons.betwixt.AttributeDescriptor;
  +import org.apache.commons.betwixt.ElementDescriptor;
   import org.xml.sax.Attributes;
   
   /**
  @@ -71,74 +73,89 @@
    * @version $Revision$
    */
   public abstract class MappingAction {
  -	
  -	/**
  -	 * Executes mapping action on new element.
  -	 * @param namespace
  -	 * @param name
  -	 * @param attributes Attributes not null
  -	 * @param context Context not null
  -	 * @return the MappingAction to be used to map the sub-graph 
  -	 * under this element
  -	 * @throws Exception
  -	 */
  -	public abstract MappingAction begin(
  -								String namespace, 
  -								String name,
  -								Attributes attributes,
  -								ReadContext context) throws Exception;
  -
  -	/**
  -	 * Executes mapping action for element body text
  -	 * @param text
  -	 * @param context
  -	 * @throws Exception
  -	 */
  -	public abstract void body(
  -					String text, 
  -					ReadContext context) throws Exception;
  -					
  -	/**
  -	 * Executes mapping action one element ends
  -	 * @param context
  -	 * @throws Exception
  -	 */
  -	public abstract void end(ReadContext context) throws Exception;
  -
  -	public static final MappingAction EMPTY = new MappingAction.Base();
  -
  -	/**
  -	 * Basic action.
  -	 * 
  -	 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  -	 * @version $Revision$
  -	 */
  -	public static class Base extends MappingAction {
  -
  -		/* (non-Javadoc)
  -		 * @see org.apache.commons.betwixt.io.read.MappingAction#begin(java.lang.String, java.lang.String,
org.xml.sax.Attributes, org.apache.commons.betwixt.io.read.ReadContext, org.apache.commons.betwixt.XMLIntrospector)
  -		 */
  -		public MappingAction begin(String namespace, String name, Attributes attributes, ReadContext
context) throws Exception {
  -			return this;
  -		}
  -
  -		/* (non-Javadoc)
  -		 * @see org.apache.commons.betwixt.io.read.MappingAction#body(java.lang.String, org.apache.commons.betwixt.io.read.ReadContext,
org.apache.commons.betwixt.XMLIntrospector)
  -		 */
  -		public void body(String text, ReadContext context) throws Exception {
  -			// do nothing
  -		}
  -
  -		/* (non-Javadoc)
  -		 * @see org.apache.commons.betwixt.io.read.MappingAction#end(org.apache.commons.betwixt.io.read.ReadContext,
org.apache.commons.digester.Digester, org.apache.commons.betwixt.XMLIntrospector)
  -		 */
  -		public void end(ReadContext context) throws Exception {
  -			// do nothing
  -			// TODO: this is a temporary refactoring
  -			// it would be better to do this in the rule
  -			// need to move more logic into the context and out of the rule
  -			context.popElement();
  -		}
  -		
  -	}
  +
  +    /**
  +     * Executes mapping action on new element.
  +     * @param namespace
  +     * @param name
  +     * @param attributes Attributes not null
  +     * @param context Context not null
  +     * @return the MappingAction to be used to map the sub-graph 
  +     * under this element
  +     * @throws Exception
  +     */
  +    public abstract MappingAction begin(
  +        String namespace,
  +        String name,
  +        Attributes attributes,
  +        ReadContext context)
  +        throws Exception;
  +
  +    /**
  +     * Executes mapping action for element body text
  +     * @param text
  +     * @param context
  +     * @throws Exception
  +     */
  +    public abstract void body(String text, ReadContext context)
  +        throws Exception;
  +
  +    /**
  +     * Executes mapping action one element ends
  +     * @param context
  +     * @throws Exception
  +     */
  +    public abstract void end(ReadContext context) throws Exception;
  +
  +    public static final MappingAction EMPTY = new MappingAction.Base();
  +
  +    /**
  +     * Basic action.
  +     * 
  +     * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  +     * @version $Revision$
  +     */
  +    public static class Base extends MappingAction {
  +
  +        /* (non-Javadoc)
  +         * @see org.apache.commons.betwixt.io.read.MappingAction#begin(java.lang.String,
java.lang.String, org.xml.sax.Attributes, org.apache.commons.betwixt.io.read.ReadContext,
org.apache.commons.betwixt.XMLIntrospector)
  +         */
  +        public MappingAction begin(
  +            String namespace,
  +            String name,
  +            Attributes attributes,
  +            ReadContext context)
  +            throws Exception {
  +            // TODO: i'm not too sure about this part of the design
  +            // i'm not sure whether base should give base behaviour or if it should give
standard behaviour
  +            // i'm hoping that things will become clearer once the descriptor logic has
been cleared 
  +            ElementDescriptor descriptor = context.getCurrentDescriptor();
  +            if (descriptor != null) {
  +
  +                AttributeDescriptor[] attributeDescriptors =
  +                    descriptor.getAttributeDescriptors();
  +                context.populateAttributes(attributeDescriptors, attributes);
  +            }
  +            return this;
  +        }
  +
  +        /* (non-Javadoc)
  +         * @see org.apache.commons.betwixt.io.read.MappingAction#body(java.lang.String,
org.apache.commons.betwixt.io.read.ReadContext, org.apache.commons.betwixt.XMLIntrospector)
  +         */
  +        public void body(String text, ReadContext context) throws Exception {
  +            // do nothing
  +        }
  +
  +        /* (non-Javadoc)
  +         * @see org.apache.commons.betwixt.io.read.MappingAction#end(org.apache.commons.betwixt.io.read.ReadContext,
org.apache.commons.digester.Digester, org.apache.commons.betwixt.XMLIntrospector)
  +         */
  +        public void end(ReadContext context) throws Exception {
  +            // do nothing
  +            // TODO: this is a temporary refactoring
  +            // it would be better to do this in the rule
  +            // need to move more logic into the context and out of the rule
  +            context.popElement();
  +        }
  +
  +    }
   }
  
  
  
  1.4.2.2   +52 -5     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadContext.java
  
  Index: ReadContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/read/ReadContext.java,v
  retrieving revision 1.4.2.1
  retrieving revision 1.4.2.2
  diff -u -r1.4.2.1 -r1.4.2.2
  --- ReadContext.java	13 Jan 2004 21:49:46 -0000	1.4.2.1
  +++ ReadContext.java	15 Jan 2004 20:21:21 -0000	1.4.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
  @@ -65,14 +65,17 @@
   import java.util.Iterator;
   import java.util.NoSuchElementException;
   
  +import org.apache.commons.betwixt.AttributeDescriptor;
   import org.apache.commons.betwixt.BindingConfiguration;
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.XMLBeanInfo;
   import org.apache.commons.betwixt.XMLIntrospector;
   import org.apache.commons.betwixt.expression.Context;
  +import org.apache.commons.betwixt.expression.Updater;
   import org.apache.commons.collections.ArrayStack;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.xml.sax.Attributes;
   
   /**  
     * Extends <code>Context</code> to provide read specific functionality. 
  @@ -516,4 +519,48 @@
   		}
   		return computedDescriptor;
   	}
  +	
  +	public void populateAttributes(
  +		AttributeDescriptor[] attributeDescriptors,
  +		Attributes attributes) {
  +
  +		Log log = getLog();
  +		if (attributeDescriptors != null) {
  +			for (int i = 0, size = attributeDescriptors.length;
  +				i < size;
  +				i++) {
  +				AttributeDescriptor attributeDescriptor =
  +					attributeDescriptors[i];
  +
  +				// The following isn't really the right way to find the attribute
  +				// but it's quite robust.
  +				// The idea is that you try both namespace and local name first
  +				// and if this returns null try the qName.
  +				String value =
  +					attributes.getValue(
  +						attributeDescriptor.getURI(),
  +						attributeDescriptor.getLocalName());
  +
  +				if (value == null) {
  +					value =
  +						attributes.getValue(
  +							attributeDescriptor.getQualifiedName());
  +				}
  +
  +				if (log.isTraceEnabled()) {
  +					log.trace("Attr URL:" + attributeDescriptor.getURI());
  +					log.trace(
  +						"Attr LocalName:" + attributeDescriptor.getLocalName());
  +					log.trace(value);
  +				}
  +
  +				Updater updater = attributeDescriptor.getUpdater();
  +				log.trace(updater);
  +				if (updater != null && value != null) {
  +					updater.update(this, value);
  +				}
  +			}
  +		}
  +	}
  +
   }
  
  
  

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