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/strategy MixedContentEncodingStrategy.java
Date Fri, 27 Aug 2004 21:14:04 GMT
rdonkin     2004/08/27 14:14:04

  Modified:    betwixt/src/java/org/apache/commons/betwixt
                        XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/io
                        BeanReader.java
               betwixt/src/java/org/apache/commons/betwixt/strategy
                        MixedContentEncodingStrategy.java
  Log:
  Multi mapping document support. Contributed by Brian Pugh.
  
  Revision  Changes    Path
  1.34      +55 -0     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XMLIntrospector.java	24 Aug 2004 21:00:50 -0000	1.33
  +++ XMLIntrospector.java	27 Aug 2004 21:14:04 -0000	1.34
  @@ -29,10 +29,12 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Set;
   
   import org.apache.commons.beanutils.DynaBean;
   import org.apache.commons.beanutils.DynaClass;
   import org.apache.commons.beanutils.DynaProperty;
  +import org.apache.commons.betwixt.digester.MultiMappingBeanInfoDigester;
   import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
   import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   import org.apache.commons.betwixt.expression.EmptyExpression;
  @@ -85,6 +87,9 @@
       /** Digester used to parse the XML descriptor files */
       private XMLBeanInfoDigester digester;
   
  +    /** Digester used to parse the multi-mapping XML descriptor files */
  +    private MultiMappingBeanInfoDigester multiMappingdigester;
  +    
       /** Configuration to be used for introspection*/
       private IntrospectionConfiguration configuration;
       
  @@ -525,6 +530,56 @@
           XMLBeanInfo xmlBeanInfo = createXMLBeanInfo( beanInfo );
           populate( xmlBeanInfo, new JavaBeanType( beanInfo ) );
           return xmlBeanInfo;
  +    }
  +    
  +    
  +    /**
  +     * <p>Registers the class mappings specified in the multi-class document
  +     * given by the <code>InputSource</code>.
  +     * </p>
  +     * <p>
  +     * <strong>Note:</strong> that this method will override any existing mapping
  +     * for the speficied classes.
  +     * </p>
  +     * @param source <code>InputSource</code>, not null
  +     * @return <code>Class</code> array containing all mapped classes
  +     * @throws IntrospectionException
  +     * @throws SAXException
  +     * @throws IOException
  +     */
  +    public synchronized Class[] register(InputSource source) throws IntrospectionException,
IOException, SAXException {
  +        Map xmlBeanInfoByClass = loadMultiMapping(source);	
  +        Set keySet = xmlBeanInfoByClass.keySet();
  +        Class mappedClasses[] = new Class[keySet.size()];
  +        int i=0;
  +        for (Iterator it=keySet.iterator(); it.hasNext(); ) {
  +            Class clazz = (Class) it.next();
  +            mappedClasses[i++] = clazz;
  +            XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) xmlBeanInfoByClass.get(clazz);
  +            if (xmlBeanInfo != null) {
  +                getRegistry().put(clazz, xmlBeanInfo);
  +            }   
  +        }
  +        return mappedClasses;
  +    }
  +    
  +    /**
  +     * Loads the multi-mapping from the given <code>InputSource</code>.
  +     * @param mapping <code>InputSource</code>, not null
  +     * @return <code>Map</code> containing <code>XMLBeanInfo</code>'s
  +     * indexes by the <code>Class</code> they describe
  +     * @throws IOException
  +     * @throws SAXException
  +     */
  +    private synchronized Map loadMultiMapping(InputSource mapping) throws IOException,
SAXException {
  +        // synchronized method so this digester is only used by
  +        // one thread at once
  +        if (multiMappingdigester == null) {
  +            multiMappingdigester = new MultiMappingBeanInfoDigester();
  +            multiMappingdigester.setXMLIntrospector(this);
  +        }
  +        Map multiBeanInfoMap = (Map) multiMappingdigester.parse(mapping);
  +        return multiBeanInfoMap;
       }
       
       /**
  
  
  
  1.24      +30 -0     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java
  
  Index: BeanReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- BeanReader.java	24 Aug 2004 21:00:50 -0000	1.23
  +++ BeanReader.java	27 Aug 2004 21:14:04 -0000	1.24
  @@ -191,6 +191,36 @@
           }
       }
       
  +    /**
  +     * <p>Registers a class with a multi-mapping.
  +     * This mapping is specified by the multi-mapping document
  +     * contained in the given <code>InputSource</code>.
  +     * </p><p>
  +     * <strong>Note:</strong> the custom mappings will be registered with
  +     * the introspector. This must remain so for the reading to work correctly
  +     * It is recommended that use of the pre-registeration process provided
  +     * by {@link XMLIntrospector#register}  be considered as an alternative to this method.
  +     * </p>
  +     * @see {@link #registerBeanClass(Class)} since the general notes given there
  +     * apply equally to this 
  +     * @see {@link XMLIntrospector#register(InputSource) for more details on the multi-mapping
format
  +     * @param mapping <code>InputSource</code> giving the multi-mapping document
specifying 
  +     * the mapping
  +     * @throws IntrospectionException
  +     * @throws SAXException
  +     * @throws IOException
  +     */
  +    public void registerMultiMapping(InputSource mapping) throws IntrospectionException,
IOException, SAXException {
  +        Class[] mappedClasses = introspector.register(mapping);
  +        for (int i=0, size=mappedClasses.length; i<size; i++) 
  +        {
  +            Class beanClass = mappedClasses[i];
  +	        if ( ! registeredClasses.contains( beanClass ) ) {
  +	            register(beanClass, null);
  +	            
  +	        }
  +        }
  +    }
       
       /**
        * <p>Registers a class with a custom mapping.
  
  
  
  1.5       +1 -0      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/MixedContentEncodingStrategy.java
  
  Index: MixedContentEncodingStrategy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/MixedContentEncodingStrategy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MixedContentEncodingStrategy.java	4 Jul 2004 16:57:05 -0000	1.4
  +++ MixedContentEncodingStrategy.java	27 Aug 2004 21:14:04 -0000	1.5
  @@ -17,6 +17,7 @@
   package org.apache.commons.betwixt.strategy;
   
   import org.apache.commons.betwixt.ElementDescriptor;
  +import org.apache.commons.betwixt.io.BeanWriter;
   
   /**
    * <p>Encodes body content.
  
  
  

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