[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-cvs
Subject:    cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
From:       zieg () apache ! org
Date:       2004-01-26 3:34:37
Message-ID: 20040126033437.3403.qmail () minotaur ! apache ! org
[Download RAW message or body]

zieg        2004/01/25 19:34:37

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BindingContextFactoryImpl.java
                        BindingContextImpl.java
                        ByNameRuntimeBindingType.java
                        ByNameUnmarshaller.java ClassLoadingUtils.java
                        EmptyNamespaceContext.java MarshalStreamUtils.java
                        MarshallerImpl.java RuntimeBindingTypeTable.java
                        RuntimeTypeFactory.java ScopedNamespaceContext.java
                        TypeUnmarshaller.java UnmarshalResult.java
                        UnmarshallerImpl.java
               v2/src/xmlpublic/org/apache/xmlbeans BindingContext.java
               v2/test/cases/marshal example_config.xml
               v2/test/cases/marshal/com/mytest YourClass.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/common/org/apache/xmlbeans/impl/common
                        ConcurrentReaderHashMap.java
  Log:
  significant refactoring of marshalling code:
  - load runtime type info only on demand -- no more preloading
  - better sharing of runtime type info -- only one instance per BindingContext
  - improved concurrency (needed by above changes).
  - added multi-threaded test to MarshalTests
  
  Revision  Changes    Path
  1.1                  \
xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/ConcurrentReaderHashMap.java
  
  Index: ConcurrentReaderHashMap.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  
  /*
    File: ConcurrentReaderHashMap
  
    Written by Doug Lea. Adapted and released, under explicit
    permission, from JDK1.2 HashMap.java and Hashtable.java which
    carries the following copyright:
  
       * Copyright 1997 by Sun Microsystems, Inc.,
       * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
       * All rights reserved.
       *
       * This software is the confidential and proprietary information
       * of Sun Microsystems, Inc. ("Confidential Information").  You
       * shall not disclose such Confidential Information and shall use
       * it only in accordance with the terms of the license agreement
       * you entered into with Sun.
  
    History:
    Date       Who                What
    28oct1999  dl               Created
    14dec1999  dl               jmm snapshot
    19apr2000  dl               use barrierLock
    12jan2001  dl               public release
    17nov2001  dl               Minor tunings
    20may2002  dl               BarrierLock can now be serialized.
    09dec2002  dl               Fix interference checks.
  */
  
  //package EDU.oswego.cs.dl.util.concurrent;
  package org.apache.xmlbeans.impl.common;
  
  import java.io.IOException;
  import java.io.Serializable;
  import java.util.AbstractCollection;
  import java.util.AbstractMap;
  import java.util.AbstractSet;
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.NoSuchElementException;
  import java.util.Set;
  
  
  /**
   * A version of Hashtable that supports mostly-concurrent reading, but
   * exclusive writing.  Because reads are not limited to periods
   * without writes, a concurrent reader policy is weaker than a classic
   * reader/writer policy, but is generally faster and allows more
   * concurrency. This class is a good choice especially for tables that
   * are mainly created by one thread during the start-up phase of a
   * program, and from then on, are mainly read (with perhaps occasional
   * additions or removals) in many threads.  If you also need concurrency
   * among writes, consider instead using ConcurrentHashMap.
   * <p>
   *
   * Successful retrievals using get(key) and containsKey(key) usually
   * run without locking. Unsuccessful ones (i.e., when the key is not
   * present) do involve brief synchronization (locking).  Also, the
   * size and isEmpty methods are always synchronized.
   *
   * <p> Because retrieval operations can ordinarily overlap with
   * writing operations (i.e., put, remove, and their derivatives),
   * retrievals can only be guaranteed to return the results of the most
   * recently <em>completed</em> operations holding upon their
   * onset. Retrieval operations may or may not return results
   * reflecting in-progress writing operations.  However, the retrieval
   * operations do always return consistent results -- either those
   * holding before any single modification or after it, but never a
   * nonsense result.  For aggregate operations such as putAll and
   * clear, concurrent reads may reflect insertion or removal of only
   * some entries. In those rare contexts in which you use a hash table
   * to synchronize operations across threads (for example, to prevent
   * reads until after clears), you should either encase operations
   * in synchronized blocks, or instead use java.util.Hashtable.
   *
   * <p>
   *
   * This class also supports optional guaranteed
   * exclusive reads, simply by surrounding a call within a synchronized
   * block, as in <br> 
   * <code>ConcurrentReaderHashMap t; ... Object v; <br>
   * synchronized(t) { v = t.get(k); } </code> <br>
   *
   * But this is not usually necessary in practice. For
   * example, it is generally inefficient to write:
   *
   * <pre>
   *   ConcurrentReaderHashMap t; ...            // Inefficient version
   *   Object key; ...
   *   Object value; ...
   *   synchronized(t) { 
   *     if (!t.containsKey(key))
   *       t.put(key, value);
   *       // other code if not previously present
   *     }
   *     else {
   *       // other code if it was previously present
   *     }
   *   }
   *</pre>
   * Instead, if the values are intended to be the same in each case, just take \
                advantage of the fact that put returns
   * null if the key was not previously present:
   * <pre>
   *   ConcurrentReaderHashMap t; ...                // Use this instead
   *   Object key; ...
   *   Object value; ...
   *   Object oldValue = t.put(key, value);
   *   if (oldValue == null) {
   *     // other code if not previously present
   *   }
   *   else {
   *     // other code if it was previously present
   *   }
   *</pre>
   * <p>
   *
   * Iterators and Enumerations (i.e., those returned by
   * keySet().iterator(), entrySet().iterator(), values().iterator(),
   * keys(), and elements()) return elements reflecting the state of the
   * hash table at some point at or since the creation of the
   * iterator/enumeration.  They will return at most one instance of
   * each element (via next()/nextElement()), but might or might not
   * reflect puts and removes that have been processed since they were
   * created.  They do <em>not</em> throw ConcurrentModificationException.
   * However, these iterators are designed to be used by only one
   * thread at a time. Sharing an iterator across multiple threads may
   * lead to unpredictable results if the table is being concurrently
   * modified.  Again, you can ensure interference-free iteration by
   * enclosing the iteration in a synchronized block.  <p>
   *
   * This class may be used as a direct replacement for any use of
   * java.util.Hashtable that does not depend on readers being blocked
   * during updates. Like Hashtable but unlike java.util.HashMap,
   * this class does NOT allow <tt>null</tt> to be used as a key or
   * value.  This class is also typically faster than ConcurrentHashMap
   * when there is usually only one thread updating the table, but 
   * possibly many retrieving values from it.
   * <p>
   *
   * Implementation note: A slightly faster implementation of
   * this class will be possible once planned Java Memory Model
   * revisions are in place.
   *
   * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> \
Introduction to this package. </a>]  
   **/
  
  
  public class ConcurrentReaderHashMap 
    extends AbstractMap 
    implements Map, Cloneable, Serializable {
  
  
    /*
      The basic strategy is an optimistic-style scheme based on
      the guarantee that the hash table and its lists are always
      kept in a consistent enough state to be read without locking:
  
      * Read operations first proceed without locking, by traversing the
         apparently correct list of the apparently correct bin. If an
         entry is found, but not invalidated (value field null), it is
         returned. If not found, operations must recheck (after a memory
         barrier) to make sure they are using both the right list and
         the right table (which can change under resizes). If
         invalidated, reads must acquire main update lock to wait out
         the update, and then re-traverse.
  
      * All list additions are at the front of each bin, making it easy
         to check changes, and also fast to traverse.  Entry next
         pointers are never assigned. Remove() builds new nodes when
         necessary to preserve this.
  
      * Remove() (also clear()) invalidates removed nodes to alert read
         operations that they must wait out the full modifications.
   
    */
  
    /** A Serializable class for barrier lock **/
    protected static class BarrierLock implements java.io.Serializable { }
  
    /**
     * Lock used only for its memory effects.
     **/
    protected final BarrierLock barrierLock = new BarrierLock();
  
    /**
     * field written to only to guarantee lock ordering.
     **/
  
    protected transient Object lastWrite;
  
    /**
     * Force a memory synchronization that will cause
     * all readers to see table. Call only when already
     * holding main synch lock.
     **/
    protected final void recordModification(Object x) { 
      synchronized(barrierLock) {
        lastWrite = x;
      }
    }
  
    /**
     * Get ref to table; the reference and the cells it
     * accesses will be at least as fresh as from last
     * use of barrierLock
     **/
    protected final Entry[] getTableForReading() { 
      synchronized(barrierLock) {
        return table; 
      }
    }
  
  
    /**
     * The default initial number of table slots for this table (32).
     * Used when not otherwise specified in constructor.
     **/
    public static int DEFAULT_INITIAL_CAPACITY = 32; 
  
  
    /**
     * The minimum capacity, used if a lower value is implicitly specified
     * by either of the constructors with arguments.  
     * MUST be a power of two.
     */
    private static final int MINIMUM_CAPACITY = 4;
    
    /**
     * The maximum capacity, used if a higher value is implicitly specified
     * by either of the constructors with arguments.
     * MUST be a power of two <= 1<<30.
     */
    private static final int MAXIMUM_CAPACITY = 1 << 30;
    
    /**
     * The default load factor for this table (1.0).
     * Used when not otherwise specified in constructor.
     **/
  
    public static final float DEFAULT_LOAD_FACTOR = 0.75f; 
  
  
    /**
     * The hash table data.
     */
    protected transient Entry[] table;
  
    /**
     * The total number of mappings in the hash table.
     */
    protected transient int count;
  
    /**
     * The table is rehashed when its size exceeds this threshold.  (The
     * value of this field is always (int)(capacity * loadFactor).)
     *
     * @serial
     */
    protected int threshold;
  
    /**
     * The load factor for the hash table.
     *
     * @serial
     */
    protected float loadFactor;
  
    /**
     * Returns the appropriate capacity (power of two) for the specified 
     * initial capacity argument.
     */
    private int p2capacity(int initialCapacity) {
      int cap = initialCapacity;
      
      // Compute the appropriate capacity
      int result;
      if (cap > MAXIMUM_CAPACITY || cap < 0) {
        result = MAXIMUM_CAPACITY;
      } else {
        result = MINIMUM_CAPACITY;
        while (result < cap)
          result <<= 1;
      }
      return result;
    }
  
    /**
     * Return hash code for Object x. Since we are using power-of-two
     * tables, it is worth the effort to improve hashcode via
     * the same multiplicative scheme as used in IdentityHashMap.
     */
    private static int hash(Object x) {
      int h = x.hashCode();
      // Multiply by 127 (quickly, via shifts), and mix in some high
      // bits to help guard against bunching of codes that are
      // consecutive or equally spaced.
      return ((h << 7) - h + (h >>> 9) + (h >>> 17));
    }
  
    /** 
     * Check for equality of non-null references x and y. 
     **/
    protected boolean eq(Object x, Object y) {
      return x == y || x.equals(y);
    }
  
    /**
     * Constructs a new, empty map with the specified initial 
     * capacity and the specified load factor. 
     *
     * @param initialCapacity the initial capacity
     *  The actual initial capacity is rounded to the nearest power of two.
     * @param loadFactor  the load factor of the ConcurrentReaderHashMap
     * @throws IllegalArgumentException  if the initial maximum number 
     *               of elements is less
     *               than zero, or if the load factor is nonpositive.
     */
  
    public ConcurrentReaderHashMap(int initialCapacity, float loadFactor) {
      if (loadFactor <= 0)
        throw new IllegalArgumentException("Illegal Load factor: "+
                                           loadFactor);
      this.loadFactor = loadFactor;
  
      int cap = p2capacity(initialCapacity);
  
      table = new Entry[cap];
      threshold = (int)(cap * loadFactor);
    }
  
    /**
     * Constructs a new, empty map with the specified initial 
     * capacity and default load factor.
     *
     * @param   initialCapacity   the initial capacity of the 
     *                            ConcurrentReaderHashMap.
     * @throws    IllegalArgumentException if the initial maximum number 
     *              of elements is less
     *              than zero.
     */
  
    public ConcurrentReaderHashMap(int initialCapacity) {
      this(initialCapacity, DEFAULT_LOAD_FACTOR);
    }
  
    /**
     * Constructs a new, empty map with a default initial capacity
     * and load factor.
     */
  
    public ConcurrentReaderHashMap() {
      this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
    }
  
    /**
     * Constructs a new map with the same mappings as the given map.  The
     * map is created with a capacity of twice the number of mappings in
     * the given map or 16 (whichever is greater), and a default load factor.
     */
  
    public ConcurrentReaderHashMap(Map t) {
          this(Math.max((int) (t.size() / DEFAULT_LOAD_FACTOR) + 1, 16),
               DEFAULT_LOAD_FACTOR);
      putAll(t);
    }
  
    /**
     * Returns the number of key-value mappings in this map.
     *
     * @return the number of key-value mappings in this map.
     */
  
    public synchronized int size() {
      return count;
    }
  
    /**
     * Returns <tt>true</tt> if this map contains no key-value mappings.
     *
     * @return <tt>true</tt> if this map contains no key-value mappings.
     */
  
    public synchronized boolean isEmpty() {
      return count == 0;
    }
    
  
  
    /**
     * Returns the value to which the specified key is mapped in this table.
     *
     * @param   key   a key in the table.
     * @return  the value to which the key is mapped in this table;
     *          <code>null</code> if the key is not mapped to any value in
     *          this table.
     * @exception  NullPointerException  if the key is
     *               <code>null</code>.
     * @see     #put(Object, Object)
     */
    
  
    public Object get(Object key) {
  
      // throw null pointer exception if key null
      int hash = hash(key);
  
      /* 
         Start off at the apparently correct bin.  If entry is found, we
         need to check after a barrier anyway.  If not found, we need a
         barrier to check if we are actually in right bin. So either
         way, we encounter only one barrier unless we need to retry.
         And we only need to fully synchronize if there have been
         concurrent modifications.
      */
  
      Entry[] tab = table;
      int index = hash & (tab.length - 1);
      Entry first = tab[index];
      Entry e = first;
  
      for (;;) {
        if (e == null) {
  
          // If key apparently not there, check to
          // make sure this was a valid read
  
          Entry[] reread = getTableForReading();
          if (tab == reread && first == tab[index])
            return null;
          else {
            // Wrong list -- must restart traversal at new first
            tab = reread;
            e = first = tab[index = hash & (tab.length-1)];
          }
  
        }
  
        else if (e.hash == hash && eq(key, e.key)) {
          Object value = e.value;
          if (value != null) 
            return value;
  
          // Entry was invalidated during deletion. But it could
          // have been re-inserted, so we must retraverse.
          // To avoid useless contention, get lock to wait out modifications
          // before retraversing.
  
          synchronized(this) {
            tab = table;
          }
          e = first = tab[index = hash & (tab.length-1)];
  
        }
        else
          e = e.next;
      }
    }
  
  
    /**
     * Tests if the specified object is a key in this table.
     * 
     * @param   key   possible key.
     * @return  <code>true</code> if and only if the specified object 
     *          is a key in this table, as determined by the 
     *          <tt>equals</tt> method; <code>false</code> otherwise.
     * @exception  NullPointerException  if the key is
     *               <code>null</code>.
     * @see     #contains(Object)
     */
  
  
    public boolean containsKey(Object key) {
      return get(key) != null;
    }
  
    /**
     * Maps the specified <code>key</code> to the specified 
     * <code>value</code> in this table. Neither the key nor the 
     * value can be <code>null</code>. <p>
     *
     * The value can be retrieved by calling the <code>get</code> method 
     * with a key that is equal to the original key. 
     *
     * @param      key     the table key.
     * @param      value   the value.
     * @return     the previous value of the specified key in this table,
     *             or <code>null</code> if it did not have one.
     * @exception  NullPointerException  if the key or value is
     *               <code>null</code>.
     * @see     Object#equals(Object)
     * @see     #get(Object)
     */
  
    public Object put(Object key, Object value) {
      if (value == null) 
        throw new NullPointerException();
      
      int hash = hash(key);
      Entry[] tab = table;
      int index = hash & (tab.length-1);
      Entry first = tab[index];
      Entry e;
  
      for (e = first; e != null; e = e.next)
        if (e.hash == hash && eq(key, e.key))
          break;
  
      synchronized(this) {
        if (tab == table) {
          if (e == null) {
            //  make sure we are adding to correct list
            if (first == tab[index]) {
              //  Add to front of list
              Entry newEntry = new Entry(hash, key, value, first);
              tab[index] = newEntry;
              if (++count >= threshold) rehash();
              else recordModification(newEntry);
              return null;
            }
          }
          else {
            Object oldValue = e.value; 
            if (first == tab[index] && oldValue != null) {
              e.value = value;
              return oldValue;
            }
          }
        }
        
        // retry if wrong list or lost race against concurrent remove
        return sput(key, value, hash);
      }
    }
  
  
    /**
     * Continuation of put(), called only when synch lock is
     * held and interference has been detected.
     **/
    protected Object sput(Object key, Object value, int hash) { 
  
      Entry[] tab = table;
      int index = hash & (tab.length-1);
      Entry first = tab[index];
      Entry e = first;
  
      for (;;) {
        if (e == null) {
          Entry newEntry = new Entry(hash, key, value, first);
          tab[index] = newEntry;
          if (++count >= threshold) rehash();
          else recordModification(newEntry);
          return null;
        }
        else if (e.hash == hash && eq(key, e.key)) {
          Object oldValue = e.value; 
          e.value = value;
          return oldValue;
        }
        else
          e = e.next;
      }
    }
  
  
    /**
     * Rehashes the contents of this map into a new table
     * with a larger capacity. This method is called automatically when the
     * number of keys in this map exceeds its capacity and load factor.
     */
    protected void rehash() { 
      Entry[] oldTable = table;
      int oldCapacity = oldTable.length;
      if (oldCapacity >= MAXIMUM_CAPACITY) {
        threshold = Integer.MAX_VALUE; // avoid retriggering
        return;
      }
  
      int newCapacity = oldCapacity << 1;
      int mask = newCapacity - 1;
      threshold = (int)(newCapacity * loadFactor);
  
      Entry[] newTable = new Entry[newCapacity];
      /*
       * Reclassify nodes in each list to new Map.  Because we are
       * using power-of-two expansion, the elements from each bin
       * must either stay at same index, or move to
       * oldCapacity+index. We also eliminate unnecessary node
       * creation by catching cases where old nodes can be reused
       * because their next fields won't change. Statistically, at
       * the default threshhold, only about one-sixth of them need
       * cloning. (The nodes they replace will be garbage
       * collectable as soon as they are no longer referenced by any
       * reader thread that may be in the midst of traversing table
       * right now.)
       */
      
      for (int i = 0; i < oldCapacity ; i++) {
        // We need to guarantee that any existing reads of old Map can
        //  proceed. So we cannot yet null out each bin.  
        Entry e = oldTable[i];
        
        if (e != null) {
          int idx = e.hash & mask;
          Entry next = e.next;
          
          //  Single node on list
          if (next == null) 
            newTable[idx] = e;
          
          else {    
            // Reuse trailing consecutive sequence of all same bit
            Entry lastRun = e;
            int lastIdx = idx;
            for (Entry last = next; last != null; last = last.next) {
              int k = last.hash & mask;
              if (k != lastIdx) {
                lastIdx = k;
                lastRun = last;
              }
            }
            newTable[lastIdx] = lastRun;
            
            // Clone all remaining nodes
            for (Entry p = e; p != lastRun; p = p.next) {
              int k = p.hash & mask;
              newTable[k] = new Entry(p.hash, p.key, 
                                      p.value, newTable[k]);
            }
          }
        }
      }
  
      table = newTable;
      recordModification(newTable);
    }
  
    /**
     * Removes the key (and its corresponding value) from this 
     * table. This method does nothing if the key is not in the table.
     *
     * @param   key   the key that needs to be removed.
     * @return  the value to which the key had been mapped in this table,
     *          or <code>null</code> if the key did not have a mapping.
     * @exception  NullPointerException  if the key is
     *               <code>null</code>.
     */
  
    public Object remove(Object key) {
      /*
        Find the entry, then 
          1. Set value field to null, to force get() to retry
          2. Rebuild the list without this entry.
             All entries following removed node can stay in list, but
             all preceeding ones need to be cloned.  Traversals rely
             on this strategy to ensure that elements will not be
            repeated during iteration.
      */
            
  
      int hash = hash(key);
      Entry[] tab = table;
      int index = hash & (tab.length-1);
      Entry first = tab[index];
      Entry e = first;
        
      for (e = first; e != null; e = e.next) 
        if (e.hash == hash && eq(key, e.key)) 
          break;
  
  
      synchronized(this) {
        if (tab == table) {
          if (e == null) {
            if (first == tab[index])
              return null;
          }
          else {
            Object oldValue = e.value;
            if (first == tab[index] && oldValue != null) {
              e.value = null;
              count--;
              
              Entry head = e.next;
              for (Entry p = first; p != e; p = p.next) 
                head = new Entry(p.hash, p.key, p.value, head);
              
              tab[index] = head;
              recordModification(head);
              return oldValue;
            }
          }
        }
      
        // Wrong list or interference
        return sremove(key, hash);
      }
    }
  
    /**
     * Continuation of remove(), called only when synch lock is
     * held and interference has been detected.
     **/
  
    protected Object sremove(Object key, int hash) {
      Entry[] tab = table;
      int index = hash & (tab.length-1);
      Entry first = tab[index];
        
      for (Entry e = first; e != null; e = e.next) {
        if (e.hash == hash && eq(key, e.key)) {
          Object oldValue = e.value;
          e.value = null;
          count--;
          Entry head = e.next;
          for (Entry p = first; p != e; p = p.next) 
            head = new Entry(p.hash, p.key, p.value, head);
          
          tab[index] = head;
          recordModification(head);
          return oldValue;
        }
      }
      return null;
    }
  
  
    /**
     * Returns <tt>true</tt> if this map maps one or more keys to the
     * specified value. Note: This method requires a full internal
     * traversal of the hash table, and so is much slower than
     * method <tt>containsKey</tt>.
     *
     * @param value value whose presence in this map is to be tested.
     * @return <tt>true</tt> if this map maps one or more keys to the
     * specified value.  
     * @exception  NullPointerException  if the value is <code>null</code>.
     */
  
    public boolean containsValue(Object value) {
      if (value == null) throw new NullPointerException();
  
      Entry tab[] = getTableForReading();
      
      for (int i = 0 ; i < tab.length; ++i) {
        for (Entry e = tab[i] ; e != null ; e = e.next) 
          if (value.equals(e.value))
            return true;
      }
  
      return false;
    }
  
    /**
     * Tests if some key maps into the specified value in this table.
     * This operation is more expensive than the <code>containsKey</code>
     * method.<p>
     *
     * Note that this method is identical in functionality to containsValue,
     * (which is part of the Map interface in the collections framework).
     * 
     * @param      value   a value to search for.
     * @return     <code>true</code> if and only if some key maps to the
     *             <code>value</code> argument in this table as 
     *             determined by the <tt>equals</tt> method;
     *             <code>false</code> otherwise.
     * @exception  NullPointerException  if the value is <code>null</code>.
     * @see        #containsKey(Object)
     * @see        #containsValue(Object)
     * @see	   Map
     */
  
    public boolean contains(Object value) {
      return containsValue(value);
    }
  
  
    /**
     * Copies all of the mappings from the specified map to this one.
     * 
     * These mappings replace any mappings that this map had for any of the
     * keys currently in the specified Map.
     *
     * @param t Mappings to be stored in this map.
     */
  
    public synchronized void putAll(Map t) {
      int n = t.size();
      if (n == 0)
        return;
  
      // Expand enough to hold at least n elements without resizing.
      // We can only resize table by factor of two at a time.
      // It is faster to rehash with fewer elements, so do it now.
      while (n >= threshold)
        rehash();
  
      for (Iterator it = t.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        put(key, value);
      }
    }
  
  
    /**
     * Removes all mappings from this map.
     */
    public synchronized void clear() {
      Entry tab[] = table;
      for (int i = 0; i < tab.length ; ++i) { 
  
        // must invalidate all to force concurrent get's to wait and then retry
        for (Entry e = tab[i]; e != null; e = e.next) 
          e.value = null; 
  
        tab[i] = null;
      }
      count = 0;
      recordModification(tab);
    }
  
    /**
     * Returns a shallow copy of this 
     * <tt>ConcurrentReaderHashMap</tt> instance: the keys and
     * values themselves are not cloned.
     *
     * @return a shallow copy of this map.
     */
  
    public synchronized Object clone() {
      try { 
        ConcurrentReaderHashMap t = (ConcurrentReaderHashMap)super.clone();
  
        t.keySet = null;
        t.entrySet = null;
        t.values = null;
  
        Entry[] tab = table;
        t.table = new Entry[tab.length];
        Entry[] ttab = t.table;
  
        for (int i = 0; i < tab.length; ++i) {
          Entry first = null;
          for (Entry e = tab[i]; e != null; e = e.next) 
            first = new Entry(e.hash, e.key, e.value, first);
          ttab[i] = first;
        }
  
        return t;
      } 
      catch (CloneNotSupportedException e) { 
        // this shouldn't happen, since we are Cloneable
        throw new InternalError();
      }
    }
  
    // Views
  
    protected transient Set keySet = null;
    protected transient Set entrySet = null;
    protected transient Collection values = null;
  
    /**
     * Returns a set view of the keys contained in this map.  The set is
     * backed by the map, so changes to the map are reflected in the set, and
     * vice-versa.  The set supports element removal, which removes the
     * corresponding mapping from this map, via the <tt>Iterator.remove</tt>,
     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt>, and
     * <tt>clear</tt> operations.  It does not support the <tt>add</tt> or
     * <tt>addAll</tt> operations.
     *
     * @return a set view of the keys contained in this map.
     */
    
    public Set keySet() {
      Set ks = keySet;
      return (ks != null)? ks : (keySet = new KeySet());
    }
    
    private class KeySet extends AbstractSet {
      public Iterator iterator() {
        return new KeyIterator();
      }
      public int size() {
        return ConcurrentReaderHashMap.this.size();
      }
      public boolean contains(Object o) {
        return ConcurrentReaderHashMap.this.containsKey(o);
      }
      public boolean remove(Object o) {
        return ConcurrentReaderHashMap.this.remove(o) != null;
      }
      public void clear() {
        ConcurrentReaderHashMap.this.clear();
      }
    }
  
    /**
     * Returns a collection view of the values contained in this map.  The
     * collection is backed by the map, so changes to the map are reflected in
     * the collection, and vice-versa.  The collection supports element
     * removal, which removes the corresponding mapping from this map, via the
     * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
     * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
     *
     * @return a collection view of the values contained in this map.
     */
    
    public Collection values() {
      Collection vs = values;
      return (vs != null)? vs : (values = new Values());
    }
    
    private class Values extends AbstractCollection {
      public Iterator iterator() {
        return new ValueIterator();
      }
      public int size() {
        return ConcurrentReaderHashMap.this.size();
      }
      public boolean contains(Object o) {
        return ConcurrentReaderHashMap.this.containsValue(o);
      }
      public void clear() {
        ConcurrentReaderHashMap.this.clear();
      }
    }
  
    /**
     * Returns a collection view of the mappings contained in this map.  Each
     * element in the returned collection is a <tt>Map.Entry</tt>.  The
     * collection is backed by the map, so changes to the map are reflected in
     * the collection, and vice-versa.  The collection supports element
     * removal, which removes the corresponding mapping from the map, via the
     * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
     * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
     *
     * @return a collection view of the mappings contained in this map.
     */
    
    public Set entrySet() {
      Set es = entrySet;
      return (es != null) ? es : (entrySet = new EntrySet());
    }
  
    private class EntrySet extends AbstractSet {
      public Iterator iterator() {
        return new HashIterator();
      }
      public boolean contains(Object o) {
        if (!(o instanceof Map.Entry))
          return false;
        Map.Entry entry = (Map.Entry)o;
        Object v = ConcurrentReaderHashMap.this.get(entry.getKey());
        return v != null && v.equals(entry.getValue());
      }
      public boolean remove(Object o) {
        if (!(o instanceof Map.Entry))
          return false;
        return ConcurrentReaderHashMap.this.findAndRemoveEntry((Map.Entry)o);
      }
      public int size() {
        return ConcurrentReaderHashMap.this.size();
      }
      public void clear() {
        ConcurrentReaderHashMap.this.clear();
      }
    }
  
    /**
     * Helper method for entrySet.remove
     **/
    protected synchronized boolean findAndRemoveEntry(Map.Entry entry) {
      Object key = entry.getKey();
      Object v = get(key);
      if (v != null && v.equals(entry.getValue())) {
        remove(key);
        return true;
      }
      else
        return false;
    }
  
    /**
     * Returns an enumeration of the keys in this table.
     *
     * @return  an enumeration of the keys in this table.
     * @see     Enumeration
     * @see     #elements()
     * @see	#keySet()
     * @see	Map
     */
    public Enumeration keys() {
      return new KeyIterator();
    }
  
    /**
     * Returns an enumeration of the values in this table.
     * Use the Enumeration methods on the returned object to fetch the elements
     * sequentially.
     *
     * @return  an enumeration of the values in this table.
     * @see     java.util.Enumeration
     * @see     #keys()
     * @see	#values()
     * @see	Map
     */
    
    public Enumeration elements() {
      return new ValueIterator();
    }
  
  
    /**
     * ConcurrentReaderHashMap collision list entry.
     */
  
    protected static class Entry implements Map.Entry {
  
      /* 
         The use of volatile for value field ensures that
         we can detect status changes without synchronization.
         The other fields are never changed, and are
         marked as final. 
      */
  
      protected final int hash;
      protected final Object key;
      protected final Entry next;
      protected volatile Object value;
  
      Entry(int hash, Object key, Object value, Entry next) {
        this.hash = hash;
        this.key = key;
        this.next = next;
        this.value = value;
      }
  
      // Map.Entry Ops 
  
      public Object getKey() {
        return key;
      }
  
      /**
       * Get the value.  Note: In an entrySet or entrySet.iterator,
       * unless the set or iterator is used under synchronization of the
       * table as a whole (or you can otherwise guarantee lack of
       * concurrent modification), <tt>getValue</tt> <em>might</em>
       * return null, reflecting the fact that the entry has been
       * concurrently removed. However, there are no assurances that
       * concurrent removals will be reflected using this method.
       * 
       * @return     the current value, or null if the entry has been 
       * detectably removed.
       **/
      public Object getValue() {
        return value; 
      }
  
      /**
       * Set the value of this entry.  Note: In an entrySet or
       * entrySet.iterator), unless the set or iterator is used under
       * synchronization of the table as a whole (or you can otherwise
       * guarantee lack of concurrent modification), <tt>setValue</tt>
       * is not strictly guaranteed to actually replace the value field
       * obtained via the <tt>get</tt> operation of the underlying hash
       * table in multithreaded applications.  If iterator-wide
       * synchronization is not used, and any other concurrent
       * <tt>put</tt> or <tt>remove</tt> operations occur, sometimes
       * even to <em>other</em> entries, then this change is not
       * guaranteed to be reflected in the hash table. (It might, or it
       * might not. There are no assurances either way.)
       *
       * @param      value   the new value.
       * @return     the previous value, or null if entry has been detectably
       * removed.
       * @exception  NullPointerException  if the value is <code>null</code>.
       * 
       **/
  
      public Object setValue(Object value) {
        if (value == null)
          throw new NullPointerException();
        Object oldValue = this.value;
        this.value = value;
        return oldValue;
      }
  
      public boolean equals(Object o) {
        if (!(o instanceof Map.Entry))
          return false;
        Map.Entry e = (Map.Entry)o;
        return (key.equals(e.getKey()) && value.equals(e.getValue()));
      }
      
      public int hashCode() {
        return  key.hashCode() ^ value.hashCode();
      }
      
      public String toString() {
        return key + "=" + value;
      }
  
    }
  
    protected class HashIterator implements Iterator, Enumeration {
      protected final Entry[] tab;           // snapshot of table
      protected int index;                   // current slot 
      protected Entry entry = null;          // current node of slot
      protected Object currentKey;           // key for current node
      protected Object currentValue;         // value for current node
      protected Entry lastReturned = null;   // last node returned by next
  
      protected HashIterator() {
        tab = ConcurrentReaderHashMap.this.getTableForReading();
        index = tab.length - 1;
      }
  
      public boolean hasMoreElements() { return hasNext(); }
      public Object nextElement() { return next(); }
  
  
      public boolean hasNext() {
  
        /*
          currentkey and currentValue are set here to ensure that next()
          returns normally if hasNext() returns true. This avoids
          surprises especially when final element is removed during
          traversal -- instead, we just ignore the removal during
          current traversal.  
        */
  
        for (;;) {
          if (entry != null) {
            Object v = entry.value;
            if (v != null) {
              currentKey = entry.key;
              currentValue = v;
              return true;
            }
            else
              entry = entry.next;
          }
  
          while (entry == null && index >= 0)
            entry = tab[index--];
  
          if (entry == null) {
            currentKey = currentValue = null;
            return false;
          }
        }
      }
  
      protected Object returnValueOfNext() { return entry; }
  
      public Object next() {
        if (currentKey == null && !hasNext())
          throw new NoSuchElementException();
  
        Object result = returnValueOfNext();
        lastReturned = entry;
        currentKey = currentValue = null;
        entry = entry.next;
        return result;
      }
  
      public void remove() {
        if (lastReturned == null)
          throw new IllegalStateException();
        ConcurrentReaderHashMap.this.remove(lastReturned.key);
        lastReturned = null;
      }
  
    }
  
  
    protected class KeyIterator extends HashIterator {
      protected Object returnValueOfNext() { return currentKey; }
    }
    
    protected class ValueIterator extends HashIterator {
      protected Object returnValueOfNext() { return currentValue; }
    }
    
  
  
    /**
     * Save the state of the <tt>ConcurrentReaderHashMap</tt> 
     * instance to a stream (i.e.,
     * serialize it).
     *
     * @serialData The <i>capacity</i> of the 
     * ConcurrentReaderHashMap (the length of the
     * bucket array) is emitted (int), followed  by the
     * <i>size</i> of the ConcurrentReaderHashMap (the number of key-value
     * mappings), followed by the key (Object) and value (Object)
     * for each key-value mapping represented by the ConcurrentReaderHashMap
     * The key-value mappings are emitted in no particular order.
     */
  
    private synchronized void writeObject(java.io.ObjectOutputStream s)
      throws IOException  {
      // Write out the threshold, loadfactor, and any hidden stuff
      s.defaultWriteObject();
      
      // Write out number of buckets
      s.writeInt(table.length);
      
      // Write out size (number of Mappings)
      s.writeInt(count);
      
      // Write out keys and values (alternating)
      for (int index = table.length-1; index >= 0; index--) {
        Entry entry = table[index];
        
        while (entry != null) {
          s.writeObject(entry.key);
          s.writeObject(entry.value);
          entry = entry.next;
        }
      }
    }
  
    /**
     * Reconstitute the <tt>ConcurrentReaderHashMap</tt> 
     * instance from a stream (i.e.,
     * deserialize it).
     */
    private synchronized void readObject(java.io.ObjectInputStream s)
      throws IOException, ClassNotFoundException  {
      // Read in the threshold, loadfactor, and any hidden stuff
      s.defaultReadObject();
  
      // Read in number of buckets and allocate the bucket array;
      int numBuckets = s.readInt();
      table = new Entry[numBuckets];
      
      // Read in size (number of Mappings)
      int size = s.readInt();
      
      // Read the keys and values, and put the mappings in the table
      for (int i=0; i<size; i++) {
        Object key = s.readObject();
        Object value = s.readObject();
        put(key, value);
      }
    }
    
    /** 
     * Return the number of slots in this table 
     **/
  
    public synchronized int capacity() {
      return table.length;
    }
  
    /** 
     * Return the load factor 
     **/
    public float loadFactor() {
      return loadFactor;
    }
  }
  
  
  
  1.12      +75 -190   \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java
  
  Index: BindingContextFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BindingContextFactoryImpl.java	22 Jan 2004 01:23:54 -0000	1.11
  +++ BindingContextFactoryImpl.java	26 Jan 2004 03:34:36 -0000	1.12
  @@ -60,213 +60,98 @@
   import org.apache.xmlbeans.BindingContext;
   import org.apache.xmlbeans.BindingContextFactory;
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.XmlRuntimeException;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.impl.binding.bts.BindingType;
  -import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
   import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
  -import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
  -import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
   import org.apache.xmlbeans.impl.binding.bts.CompositeBindingLoader;
  -import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
  -import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
   import org.apache.xmlbeans.impl.binding.tylar.DefaultTylarLoader;
   import org.apache.xmlbeans.impl.binding.tylar.Tylar;
   import org.apache.xmlbeans.impl.binding.tylar.TylarLoader;
  -import org.apache.xmlbeans.impl.binding.tylar.CompositeTylar;
  -import org.apache.xmlbeans.impl.common.XmlWhitespace;
   
   import java.io.File;
   import java.io.IOException;
  -import java.io.InputStream;
   import java.net.URI;
  -import java.util.Iterator;
   import java.util.jar.JarInputStream;
   
   /**
    * creates BindingContext objects from various inputs.
    */
  -public final class BindingContextFactoryImpl extends BindingContextFactory {
  +public final class BindingContextFactoryImpl extends BindingContextFactory
  +{
   
  -  public BindingContext createBindingContext(URI tylarUri)
  -          throws IOException, XmlException {
  -    return createBindingContext(new URI[]{tylarUri});
  -  }
  -
  -  public BindingContext createBindingContext(URI[] tylarUris)
  -          throws IOException, XmlException {
  -    if (tylarUris == null) throw new IllegalArgumentException("null uris");
  -    //FIXME loader class needs to be pluggable
  -    TylarLoader loader = DefaultTylarLoader.getInstance();
  -    if (loader == null) throw new IllegalStateException("null loader");
  -    return createBindingContext(loader.load(tylarUris));
  -  }
  -
  -  public BindingContext createBindingContext(JarInputStream jar)
  -          throws IOException, XmlException {
  -    if (jar == null) throw new IllegalArgumentException("null InputStream");
  -    //FIXME loader class needs to be pluggable
  -    TylarLoader loader = DefaultTylarLoader.getInstance();
  -    if (loader == null) throw new IllegalStateException("null TylarLoader");
  -    return createBindingContext(loader.load(jar));
  -  }
  -
  -  // REVIEW It's unfortunate that we can't expose this method to the public
  -  // at the moment.  It's easy to imagine cases where one has already built
  -  // up the tylar and doesn't want to pay the cost of re-parsing it.
  -  // Of course, exposing it means we expose Tylar to the public as well,
  -  // and this should be done with caution.
  -  public BindingContext createBindingContext(Tylar tylar) {
  -    // get the binding files
  -    BindingFile[] bfs = tylar.getBindingFiles();
  -    // also build the loader chain - this is the binding files plus
  -    // the builtin loader
  -    BindingLoader loader = tylar.getBindingLoader();
  -    // finally, glue it all together
  -    RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bfs, loader);
  -    return new BindingContextImpl(loader, tbl);
  -  }
  -
  -  public BindingContext createBindingContext() {
  -    BindingFile empty = new BindingFile();
  -    return createBindingContext(empty);
  -  }
  -
  -  // ========================================================================
  -  // Private methods
  -
  -  private static BindingContextImpl createBindingContext(BindingFile bf) {
  -    BindingLoader bindingLoader = buildBindingLoader(bf);
  -    RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bf, bindingLoader);
  -
  -    return new BindingContextImpl(bindingLoader, tbl);
  -  }
  -
  -  private static BindingLoader buildBindingLoader(BindingFile bf) {
  -    BindingLoader builtins = BuiltinBindingLoader.getInstance();
  -    return CompositeBindingLoader.forPath(new BindingLoader[]{builtins, bf});
  -  }
  -
  -  private static RuntimeBindingTypeTable buildUnmarshallingTypeTable(BindingFile \
                bf,
  -                                                                     BindingLoader \
                loader) {
  -    RuntimeBindingTypeTable tbl = \
                RuntimeBindingTypeTable.createRuntimeBindingTypeTable();
  -    populateTable(bf, loader, tbl);
  -    return tbl;
  -  }
  -
  -  private static RuntimeBindingTypeTable buildUnmarshallingTypeTable(BindingFile[] \
                bfs,
  -                                                                     BindingLoader \
                loader) {
  -    RuntimeBindingTypeTable tbl = \
                RuntimeBindingTypeTable.createRuntimeBindingTypeTable();
  -    for (int i = 0; i < bfs.length; i++) populateTable(bfs[i], loader, tbl);
  -    return tbl;
  -  }
  -
  -  private static RuntimeBindingTypeTable populateTable(BindingFile bf,
  -                                                       BindingLoader loader,
  -                                                       RuntimeBindingTypeTable \
                tbl) {
  -    //TODO scott This may need some more thought; may want to iterate
  -    //through typenames instead of types and resolve them with the loader.
  -    //The loader currently isn't really being used here.
  -    for (Iterator itr = bf.bindingTypes().iterator(); itr.hasNext();) {
  -      BindingType type = (BindingType) itr.next();
  -      if (type instanceof SimpleDocumentBinding) continue;
  -      TypeUnmarshaller um = createTypeUnmarshaller(type, loader, tbl);
  -      tbl.putTypeUnmarshaller(type, um);
  -    }
  -    tbl.initUnmarshallers(loader);
  -    return tbl;
  -  }
  -
  -  private static TypeUnmarshaller createTypeUnmarshaller(BindingType type,
  -                                                         BindingLoader loader,
  -                                                         RuntimeBindingTypeTable \
                table) {
  -    //TODO: cleanup this nasty instanceof stuff (Visitor?)
  -
  -    if (type instanceof SimpleBindingType) {
  -      //note this could return a static for builtin types
  -      return createSimpleTypeUnmarshaller((SimpleBindingType) type, loader, \
                table);
  -    } else if (type instanceof ByNameBean) {
  -      return new ByNameUnmarshaller((ByNameBean) type);
  -    }
  -
  -    throw new AssertionError("UNIMPLEMENTED TYPE: " + type);
  -  }
  -
  -  private static TypeUnmarshaller createSimpleTypeUnmarshaller(SimpleBindingType \
                stype,
  -                                                               BindingLoader \
                loader,
  -                                                               \
                RuntimeBindingTypeTable table) {
  -    TypeUnmarshaller um = table.getTypeUnmarshaller(stype);
  -    if (um != null) return um;
  -
  -
  -    int curr_ws = XmlWhitespace.WS_UNSPECIFIED;
  -    SimpleBindingType curr = stype;
  -    BuiltinBindingType resolved = null;
  -
  -    while (true) {
  -      //we want to keep the first whitespace setting as we walk up
  -      if (curr_ws == XmlWhitespace.WS_UNSPECIFIED) {
  -        curr_ws = curr.getWhitespace();
  -      }
  -
  -      BindingTypeName asif_name = curr.getAsIfBindingTypeName();
  -      if (asif_name != null) {
  -        BindingType asif_new = loader.getBindingType(asif_name);
  -        if (asif_new instanceof BuiltinBindingType) {
  -          resolved = (BuiltinBindingType) asif_new;
  -          break;
  -        } else if (asif_new instanceof SimpleBindingType) {
  -          curr = (SimpleBindingType) asif_new;
  -        } else {
  -          String msg = "invalid as-xml type: " + asif_name +
  -                  " on type: " + curr.getName();
  -          throw new XmlRuntimeException(msg);
  -        }
  -      } else {
  -        throw new XmlRuntimeException("missing as-xml type on " +
  -                curr.getName());
  -      }
  -    }
  -    assert resolved != null;
  -
  -
  -    //special processing for whitespace facets.
  -    //TODO: assert that our type is derived from xsd:string
  -    switch (curr_ws) {
  -      case XmlWhitespace.WS_UNSPECIFIED:
  -        break;
  -      case XmlWhitespace.WS_PRESERVE:
  -        return PreserveStringTypeConverter.getInstance();
  -      case XmlWhitespace.WS_REPLACE:
  -        return ReplaceStringTypeConverter.getInstance();
  -      case XmlWhitespace.WS_COLLAPSE:
  -        return CollapseStringTypeConverter.getInstance();
  -      default:
  -        throw new AssertionError("invalid whitespace: " + curr_ws);
  -    }
  -
  -
  -    um = table.getTypeUnmarshaller(resolved);
  -    if (um != null) return um;
  -
  -    String msg = "unable to get simple type unmarshaller for " + stype +
  -            " resolved to " + resolved;
  -    throw new AssertionError(msg);
  -  }
  -
  -  /**
  -   * @deprecated We no longer support naked config files.  This is currently
  -   * only used by MarshalTests
  -   */
  -  public BindingContext createBindingContextFromConfig(File bindingConfig)
  -      throws IOException, XmlException
  -  {
  -      BindingConfigDocument doc =
  -          BindingConfigDocument.Factory.parse(bindingConfig);
  -      BindingFile bf = BindingFile.forDoc(doc);
  -      return createBindingContext(bf);
  -  }
  +    public BindingContext createBindingContext(URI tylarUri)
  +        throws IOException, XmlException
  +    {
  +        return createBindingContext(new URI[]{tylarUri});
  +    }
  +
  +    public BindingContext createBindingContext(URI[] tylarUris)
  +        throws IOException, XmlException
  +    {
  +        if (tylarUris == null) throw new IllegalArgumentException("null uris");
  +        //FIXME loader class needs to be pluggable
  +        TylarLoader loader = DefaultTylarLoader.getInstance();
  +        if (loader == null) throw new IllegalStateException("null loader");
  +        return createBindingContext(loader.load(tylarUris));
  +    }
  +
  +    public BindingContext createBindingContext(JarInputStream jar)
  +        throws IOException, XmlException
  +    {
  +        if (jar == null) throw new IllegalArgumentException("null InputStream");
  +        //FIXME loader class needs to be pluggable
  +        TylarLoader loader = DefaultTylarLoader.getInstance();
  +        if (loader == null) throw new IllegalStateException("null TylarLoader");
  +        return createBindingContext(loader.load(jar));
  +    }
  +
  +    // REVIEW It's unfortunate that we can't expose this method to the public
  +    // at the moment.  It's easy to imagine cases where one has already built
  +    // up the tylar and doesn't want to pay the cost of re-parsing it.
  +    // Of course, exposing it means we expose Tylar to the public as well,
  +    // and this should be done with caution.
  +    public BindingContext createBindingContext(Tylar tylar)
  +    {
  +        // build the loader chain - this is the binding files plus
  +        // the builtin loader
  +        BindingLoader loader = tylar.getBindingLoader();
  +        // finally, glue it all together
  +        return new BindingContextImpl(loader);
  +    }
  +
  +    public BindingContext createBindingContext()
  +    {
  +        BindingFile empty = new BindingFile();
  +        return createBindingContext(empty);
  +    }
  +
  +    // ========================================================================
  +    // Private methods
  +
  +    private static BindingContextImpl createBindingContext(BindingFile bf)
  +    {
  +        BindingLoader bindingLoader = buildBindingLoader(bf);
  +        return new BindingContextImpl(bindingLoader);
  +    }
  +
  +    private static BindingLoader buildBindingLoader(BindingFile bf)
  +    {
  +        BindingLoader builtins = BuiltinBindingLoader.getInstance();
  +        return CompositeBindingLoader.forPath(new BindingLoader[]{builtins, bf});
  +    }
  +
  +    /**
  +     * @deprecated We no longer support naked config files.  This is currently
  +     * only used by MarshalTests
  +     */
  +    public BindingContext createBindingContextFromConfig(File bindingConfig)
  +        throws IOException, XmlException
  +    {
  +        BindingConfigDocument doc =
  +            BindingConfigDocument.Factory.parse(bindingConfig);
  +        BindingFile bf = BindingFile.forDoc(doc);
  +        return createBindingContext(bf);
  +    }
   
   
   }
  
  
  
  1.9       +8 -14     \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextImpl.java  \
  Index: BindingContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BindingContextImpl.java	22 Jan 2004 21:43:46 -0000	1.8
  +++ BindingContextImpl.java	26 Jan 2004 03:34:36 -0000	1.9
  @@ -69,17 +69,20 @@
    * Main entry point into marshalling framework.
    * Use the BindingContextFactory to create one
    */
  -public final class BindingContextImpl implements BindingContext
  +final class BindingContextImpl implements BindingContext
   {
       private final BindingLoader bindingLoader;
  +    private final RuntimeTypeFactory runtimeTypeFactory;
       private final RuntimeBindingTypeTable typeTable;
   
  +
       /* package protected -- use the factory */
  -    BindingContextImpl(BindingLoader bindingLoader,
  -                       RuntimeBindingTypeTable typeTable)
  +    BindingContextImpl(BindingLoader bindingLoader)
       {
           this.bindingLoader = bindingLoader;
  -        this.typeTable = typeTable;
  +        runtimeTypeFactory = new RuntimeTypeFactory();
  +        this.typeTable =
  +            RuntimeBindingTypeTable.createTable(runtimeTypeFactory);
       }
   
   
  @@ -102,7 +105,7 @@
       public Marshaller createMarshaller()
           throws XmlException
       {
  -        return new MarshallerImpl(bindingLoader, typeTable);
  +        return new MarshallerImpl(bindingLoader, typeTable, runtimeTypeFactory);
       }
   
   
  @@ -114,15 +117,6 @@
           }
   
           return createMarshaller();
  -    }
  -
  -
  -    /**
  -     * @deprecated do not use this
  -     */
  -    public BindingLoader getBindingLoader()
  -    {
  -        return bindingLoader;
       }
   
       static Collection extractErrorHandler(XmlOptions options)
  
  
  
  1.21      +14 -25    \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java
  
  Index: ByNameRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ByNameRuntimeBindingType.java	22 Jan 2004 21:43:46 -0000	1.20
  +++ ByNameRuntimeBindingType.java	26 Jan 2004 03:34:36 -0000	1.21
  @@ -89,6 +89,7 @@
       private final boolean isSubType;
   
   
  +    //DO NOT CALL THIS CONSTRUCTOR, use the RuntimeTypeFactory
       ByNameRuntimeBindingType(ByNameBean btype)
       {
           byNameBean = btype;
  @@ -333,20 +334,20 @@
           }
   
           private TypeUnmarshaller lookupUnmarshaller(BindingProperty prop,
  -                                                    RuntimeBindingTypeTable \
                typeTable,
  -                                                    BindingLoader bindingLoader)
  +                                                    RuntimeBindingTypeTable table,
  +                                                    BindingLoader loader)
           {
               assert prop != null;
               final BindingTypeName type_name = prop.getTypeName();
               assert type_name != null;
  -            final BindingType binding_type =
  -                bindingLoader.getBindingType(type_name);
  +            final BindingType binding_type = loader.getBindingType(type_name);
               if (binding_type == null) {
                   throw new XmlRuntimeException("failed to load type: " +
                                                 type_name);
               }
   
  -            TypeUnmarshaller um = typeTable.getTypeUnmarshaller(binding_type);
  +            TypeUnmarshaller um =
  +                table.getOrCreateTypeUnmarshaller(binding_type, loader);
               if (um == null) {
                   throw new AssertionError("failed to get unmarshaller for " +
                                            type_name);
  @@ -414,7 +415,7 @@
           {
               //means xsi:nil was true but we're a primtive.
               //schema should have nillable="false" so this
  -            //is a validation problems
  +            //is a validation problem
               if (prop_obj == null && javaPrimitive)
                   return;
   
  @@ -459,29 +460,17 @@
               }
           }
   
  -        //non simple type props can throw some runtime exception.
           public CharSequence getLexical(Object value, MarshalResult result)
           {
  +            assert value != null :
  +                "null value for " + bindingProperty + " class=" + beanClass;
   
  -            //TODO: after marshalling table is refactored
  -            //turn these into assertions   zieg Dec 19 2003.
  +            assert  result != null :
  +                "null value for " + bindingProperty + " class=" + beanClass;
   
  -            if (value == null) {
  -                throw new AssertionError("null value for " + bindingProperty +
  -                                         " class=" + beanClass);
  -            }
  -
  -            if (result == null) {
  -                throw new AssertionError("null value for " + bindingProperty +
  -                                         " class=" + beanClass);
  -            }
  -
  -            if (marshaller == null) {
  -                String msg = "null marshaller for prop=" + bindingProperty +
  -                    " class=" + beanClass + " propType=" +
  -                    bindingProperty.getTypeName();
  -                throw new AssertionError(msg);
  -            }
  +            assert marshaller != null :
  +                "null marshaller for prop=" + bindingProperty + " class=" +
  +                beanClass + " propType=" + bindingProperty.getTypeName();
   
               return marshaller.print(value, result);
           }
  
  
  
  1.11      +3 -4      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameUnmarshaller.java  \
  Index: ByNameUnmarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameUnmarshaller.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ByNameUnmarshaller.java	22 Jan 2004 21:43:47 -0000	1.10
  +++ ByNameUnmarshaller.java	26 Jan 2004 03:34:36 -0000	1.11
  @@ -57,16 +57,15 @@
   package org.apache.xmlbeans.impl.marshal;
   
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
   import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
   
   final class ByNameUnmarshaller implements TypeUnmarshaller
   {
       private final ByNameRuntimeBindingType type;
   
  -    public ByNameUnmarshaller(ByNameBean type)
  +    public ByNameUnmarshaller(ByNameRuntimeBindingType type)
       {
  -        this.type = new ByNameRuntimeBindingType(type);
  +        this.type = type;
       }
   
       public Object unmarshal(UnmarshalResult context)
  @@ -184,7 +183,7 @@
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader)
       {
  -        type.initialize(typeTable, bindingLoader);
  +        //type.initialize(typeTable, bindingLoader);
       }
   
   
  
  
  
  1.2       +2 -2      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ClassLoadingUtils.java  
  Index: ClassLoadingUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ClassLoadingUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassLoadingUtils.java	23 Oct 2003 23:49:03 -0000	1.1
  +++ ClassLoadingUtils.java	26 Jan 2004 03:34:36 -0000	1.2
  @@ -143,8 +143,8 @@
       //TODO: make sure we don't have a another version of this method somewhere
       //compname holds return value
       //return int is number of dimensions of array
  -    public static int getArrayComponentNameFromDecl(StringBuffer compname,
  -                                                    String aname)
  +    private static int getArrayComponentNameFromDecl(StringBuffer compname,
  +                                                     String aname)
       {
           compname.setLength(0);
   
  
  
  
  1.2       +4 -2      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/EmptyNamespaceContext.java
  
  Index: EmptyNamespaceContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/EmptyNamespaceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EmptyNamespaceContext.java	13 Dec 2003 00:01:58 -0000	1.1
  +++ EmptyNamespaceContext.java	26 Jan 2004 03:34:36 -0000	1.2
  @@ -56,10 +56,12 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  +import org.apache.xmlbeans.impl.marshal.util.collections.EmptyIterator;
  +
   import javax.xml.namespace.NamespaceContext;
   import java.util.Iterator;
   
  -public final class EmptyNamespaceContext
  +final class EmptyNamespaceContext
       implements NamespaceContext
   {
       private static final NamespaceContext INSTANCE =
  @@ -86,7 +88,7 @@
   
       public Iterator getPrefixes(String s)
       {
  -        return null;
  +        return EmptyIterator.getInstance();
       }
   
   }
  
  
  
  1.11      +3 -3      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java  \
  Index: MarshalStreamUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MarshalStreamUtils.java	15 Dec 2003 05:03:30 -0000	1.10
  +++ MarshalStreamUtils.java	26 Jan 2004 03:34:36 -0000	1.11
  @@ -236,9 +236,9 @@
       }
   
   
  -    public static boolean isXsiNilTrue(XMLStreamReader reader,
  -                                       int att_idx,
  -                                       Collection errors)
  +    private static boolean isXsiNilTrue(XMLStreamReader reader,
  +                                        int att_idx,
  +                                        Collection errors)
       {
           final String lname = reader.getAttributeLocalName(att_idx);
           if (!XSI_NIL_ATTR.equals(lname))
  
  
  
  1.14      +5 -6      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshallerImpl.java  
  Index: MarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshallerImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MarshallerImpl.java	22 Jan 2004 21:43:47 -0000	1.13
  +++ MarshallerImpl.java	26 Jan 2004 03:34:36 -0000	1.14
  @@ -83,10 +83,7 @@
       //per binding context constants
       private final BindingLoader loader;
       private final RuntimeBindingTypeTable typeTable;
  -
  -    //TODO: this needs to be moved into the binding context
  -    private final RuntimeTypeFactory runtimeTypeFactory =
  -        new RuntimeTypeFactory();
  +    private final RuntimeTypeFactory runtimeTypeFactory;
   
       //REVIEW: can this be static?
       private final XMLOutputFactory xmlOutputFactory =
  @@ -94,11 +91,13 @@
   
       private static final String XML_VERSION = "1.0";
   
  -    MarshallerImpl(BindingLoader loader,
  -                   RuntimeBindingTypeTable typeTable)
  +    public MarshallerImpl(BindingLoader loader,
  +                          RuntimeBindingTypeTable typeTable,
  +                          RuntimeTypeFactory runtimeTypeFactory)
       {
           this.loader = loader;
           this.typeTable = typeTable;
  +        this.runtimeTypeFactory = runtimeTypeFactory;
       }
   
       public XMLStreamReader marshal(Object obj,
  
  
  
  1.10      +154 -77   \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java
  
  Index: RuntimeBindingTypeTable.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- RuntimeBindingTypeTable.java	13 Dec 2003 00:01:58 -0000	1.9
  +++ RuntimeBindingTypeTable.java	26 Jan 2004 03:34:36 -0000	1.10
  @@ -56,111 +56,149 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  +import org.apache.xmlbeans.XmlRuntimeException;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingType;
   import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
   import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
  +import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
  +import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
   import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
  +import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
   import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
  +import org.apache.xmlbeans.impl.common.ConcurrentReaderHashMap;
  +import org.apache.xmlbeans.impl.common.XmlWhitespace;
   
   import javax.xml.namespace.QName;
  -import java.util.HashMap;
  -import java.util.Iterator;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
  +import java.util.Calendar;
   import java.util.Map;
  -import java.util.Set;
   
   /**
    * Table of TypeMarshaller and TypeUnmarshaller objects keyed by BindingType
    */
   final class RuntimeBindingTypeTable
   {
  -    //key is BindingType, value is TTEntry
  -    private final Map typeMap = new HashMap();
  +    private final Map unmarshallerMap;
  +    private final Map marshallerMap;
  +    private final RuntimeTypeFactory runtimeTypeFactory;
   
       private static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
   
  -    private static final Map BUILTIN_TYPE_MAP = createBuiltinTypeMap();
  +    private static final ConcurrentReaderHashMap BUILTIN_MARSHALLER_MAP;
  +    private static final ConcurrentReaderHashMap BUILTIN_UNMARSHALLER_MAP;
   
  +    static
  +    {
  +        final RuntimeBindingTypeTable tbl =
  +            new RuntimeBindingTypeTable(null);
  +        tbl.addBuiltins();
  +        BUILTIN_UNMARSHALLER_MAP = (ConcurrentReaderHashMap)tbl.unmarshallerMap;
  +        BUILTIN_MARSHALLER_MAP = (ConcurrentReaderHashMap)tbl.marshallerMap;
  +    }
   
  -    public static RuntimeBindingTypeTable createRuntimeBindingTypeTable()
  +    static RuntimeBindingTypeTable createTable(RuntimeTypeFactory factory)
       {
  -        //this pseudo-clone is to ensure that we only have one instance of
  -        //all builtin (un)marshallers per JVM,
  -        //without having to make each builtin a singleton.
  -
  -        final RuntimeBindingTypeTable tbl = new RuntimeBindingTypeTable();
  -        final Map tbl_map = tbl.typeMap;
  -        final Set entries = BUILTIN_TYPE_MAP.entrySet();
  -        for (Iterator itr = entries.iterator(); itr.hasNext();) {
  -            Map.Entry entry = (Map.Entry)itr.next();
  -            final TTEntry value = (TTEntry)entry.getValue();
  -            tbl_map.put(entry.getKey(), value.shallowCopy());
  -        }
  +        final RuntimeBindingTypeTable tbl =
  +            new RuntimeBindingTypeTable((Map)BUILTIN_UNMARSHALLER_MAP.clone(),
  +                                        (Map)BUILTIN_MARSHALLER_MAP.clone(),
  +                                        factory);
           return tbl;
       }
   
   
  -    private static Map createBuiltinTypeMap()
  -    {
  -        RuntimeBindingTypeTable builtins = new RuntimeBindingTypeTable();
  -        builtins.addBuiltins();
  -        return builtins.typeMap;
  +    private RuntimeBindingTypeTable(Map unmarshallerMap,
  +                                    Map marshallerMap,
  +                                    RuntimeTypeFactory runtimeTypeFactory)
  +    {
  +        this.unmarshallerMap = unmarshallerMap;
  +        this.marshallerMap = marshallerMap;
  +        this.runtimeTypeFactory = runtimeTypeFactory;
  +    }
  +
  +    private RuntimeBindingTypeTable(RuntimeTypeFactory runtimeTypeFactory)
  +    {
  +        this(new ConcurrentReaderHashMap(),
  +             new ConcurrentReaderHashMap(),
  +             runtimeTypeFactory);
  +    }
  +
  +    private TypeUnmarshaller createTypeUnmarshaller(BindingType type,
  +                                                    BindingLoader loader)
  +    {
  +        TypeUnmarshaller type_um;
  +        //TODO: cleanup this nasty instanceof stuff (Visitor?)
  +
  +        if (type instanceof SimpleBindingType) {
  +            //note this could return a static for builtin types
  +            type_um = createSimpleTypeUnmarshaller((SimpleBindingType)type,
  +                                                   loader, this);
  +        } else if (type instanceof ByNameBean) {
  +            //NOTE that in the case of cyclical types, it is possible
  +            //to have "dangling" TypeUnmarshal objects that are not in the map.
  +            //But this is of no concern as they are immutable and will share
  +            //the same RuntimeBindingType object
  +            ByNameRuntimeBindingType runtimeType =
  +                (ByNameRuntimeBindingType)runtimeTypeFactory.createRuntimeType(type, \
this, loader);  +            type_um = new ByNameUnmarshaller(runtimeType);
  +        } else {
  +            throw new AssertionError("UNIMPLEMENTED TYPE: " + type);
  +        }
  +        putTypeUnmarshaller(type, type_um);
  +        type_um.initialize(this, loader);
  +        return type_um;
       }
   
  -    private RuntimeBindingTypeTable()
  -    {
  -    }
   
  -    TypeUnmarshaller getTypeUnmarshaller(BindingType key)
  +    TypeUnmarshaller getOrCreateTypeUnmarshaller(BindingType type,
  +                                                 BindingLoader loader)
       {
  -        TTEntry e = (TTEntry)typeMap.get(key);
  -        if (e == null) return null;
  -        return e.typeUnmarshaller;
  +        TypeUnmarshaller um = (TypeUnmarshaller)unmarshallerMap.get(type);
  +        if (um == null) {
  +            um = createTypeUnmarshaller(type, loader);
  +        }
  +        return um;
       }
   
  -    TypeMarshaller getTypeMarshaller(BindingType key)
  +
  +    TypeUnmarshaller getTypeUnmarshaller(BindingType type)
       {
  -        TTEntry e = (TTEntry)typeMap.get(key);
  -        if (e == null) return null;
  -        return e.typeMarshaller;
  +        return (TypeUnmarshaller)unmarshallerMap.get(type);
       }
   
  -    void putTypeUnmarshaller(BindingType key, TypeUnmarshaller um)
  +    TypeMarshaller getTypeMarshaller(BindingType type)
       {
  -        TTEntry e = (TTEntry)typeMap.get(key);
  -        if (e == null) {
  -            e = new TTEntry();
  -            typeMap.put(key, e);
  -        }
  -        e.typeUnmarshaller = um;
  +        return (TypeMarshaller)marshallerMap.get(type);
       }
   
  -    void putTypeMarshaller(BindingType key, TypeMarshaller m)
  +    private void putTypeUnmarshaller(BindingType type, TypeUnmarshaller um)
       {
  -        TTEntry e = (TTEntry)typeMap.get(key);
  -        if (e == null) {
  -            e = new TTEntry();
  -            typeMap.put(key, e);
  -        }
  -        e.typeMarshaller = m;
  +        assert type != null;
  +        assert um != null;
  +
  +        unmarshallerMap.put(type, um);
       }
   
  -    public void initUnmarshallers(BindingLoader loader)
  +    private void putTypeMarshaller(BindingType type, TypeMarshaller m)
       {
  -        for (Iterator iterator = typeMap.values().iterator(); iterator.hasNext();) \
                {
  -            TTEntry entry = (TTEntry)iterator.next();
  -            entry.typeUnmarshaller.initialize(this, loader);
  -        }
  +        assert type != null;
  +        assert m != null;
  +
  +        marshallerMap.put(type, m);
       }
   
  -    protected void addXsdBuiltin(String xsdType, Class javaClass, TypeConverter \
converter)  +    private void addXsdBuiltin(String xsdType,
  +                               Class javaClass,
  +                               TypeConverter converter)
       {
           final BindingLoader bindingLoader = BuiltinBindingLoader.getInstance();
   
           QName xml_type = new QName(XSD_NS, xsdType);
           JavaTypeName jName = JavaTypeName.forString(javaClass.getName());
           XmlTypeName xName = XmlTypeName.forTypeNamed(xml_type);
  -        BindingType btype = \
bindingLoader.getBindingType(BindingTypeName.forPair(jName, xName));  +        \
BindingType btype =  +            \
bindingLoader.getBindingType(BindingTypeName.forPair(jName, xName));  if (btype == \
                null) {
               throw new AssertionError("failed to find builtin for java:" + jName +
                                        " - xsd:" + xName);
  @@ -184,7 +222,7 @@
           addXsdBuiltin("double", Double.class, double_conv);
   
           final IntegerTypeConverter integer_conv = new IntegerTypeConverter();
  -        final Class bigint = java.math.BigInteger.class;
  +        final Class bigint = BigInteger.class;
           addXsdBuiltin("integer", bigint, integer_conv);
           addXsdBuiltin("nonPositiveInteger", bigint, integer_conv);
           addXsdBuiltin("negativeInteger", bigint, integer_conv);
  @@ -192,7 +230,7 @@
           addXsdBuiltin("positiveInteger", bigint, integer_conv);
           addXsdBuiltin("unsignedLong", bigint, integer_conv);
   
  -        addXsdBuiltin("decimal", java.math.BigDecimal.class,
  +        addXsdBuiltin("decimal", BigDecimal.class,
                         new DecimalTypeConverter());
   
           final LongTypeConverter long_conv = new LongTypeConverter();
  @@ -239,36 +277,75 @@
                         new AnyUriToStringTypeConverter());
   
           addXsdBuiltin("dateTime",
  -                      java.util.Calendar.class,
  +                      Calendar.class,
                         new DateTimeTypeConverter());
   
           addXsdBuiltin("QName",
  -                      javax.xml.namespace.QName.class,
  +                      QName.class,
                         new QNameTypeConverter());
       }
   
  +    private static TypeUnmarshaller createSimpleTypeUnmarshaller(SimpleBindingType \
stype,  +                                                                 \
BindingLoader loader,  +                                                              \
RuntimeBindingTypeTable table)  +    {
  +        TypeUnmarshaller um = table.getTypeUnmarshaller(stype);
  +        if (um != null) return um;
  +
  +
  +        int curr_ws = XmlWhitespace.WS_UNSPECIFIED;
  +        SimpleBindingType curr = stype;
  +        BuiltinBindingType resolved;
  +
  +        while (true) {
  +            //we want to keep the first whitespace setting as we walk up
  +            if (curr_ws == XmlWhitespace.WS_UNSPECIFIED) {
  +                curr_ws = curr.getWhitespace();
  +            }
  +
  +            BindingTypeName asif_name = curr.getAsIfBindingTypeName();
  +            if (asif_name != null) {
  +                BindingType asif_new = loader.getBindingType(asif_name);
  +                if (asif_new instanceof BuiltinBindingType) {
  +                    resolved = (BuiltinBindingType)asif_new;
  +                    break;
  +                } else if (asif_new instanceof SimpleBindingType) {
  +                    curr = (SimpleBindingType)asif_new;
  +                } else {
  +                    String msg = "invalid as-xml type: " + asif_name +
  +                        " on type: " + curr.getName();
  +                    throw new XmlRuntimeException(msg);
  +                }
  +            } else {
  +                throw new XmlRuntimeException("missing as-xml type on " +
  +                                              curr.getName());
  +            }
  +        }
  +        assert resolved != null;
   
  -    private static class TTEntry
  -    {
  -        TypeMarshaller typeMarshaller;
  -        TypeUnmarshaller typeUnmarshaller;
   
  -        TTEntry()
  -        {
  +        //special processing for whitespace facets.
  +        //TODO: assert that our type is derived from xsd:string
  +        switch (curr_ws) {
  +            case XmlWhitespace.WS_UNSPECIFIED:
  +                break;
  +            case XmlWhitespace.WS_PRESERVE:
  +                return PreserveStringTypeConverter.getInstance();
  +            case XmlWhitespace.WS_REPLACE:
  +                return ReplaceStringTypeConverter.getInstance();
  +            case XmlWhitespace.WS_COLLAPSE:
  +                return CollapseStringTypeConverter.getInstance();
  +            default:
  +                throw new AssertionError("invalid whitespace: " + curr_ws);
           }
   
  -        TTEntry(TypeMarshaller typeMarshaller,
  -                TypeUnmarshaller typeUnmarshaller)
  -        {
  -            this.typeMarshaller = typeMarshaller;
  -            this.typeUnmarshaller = typeUnmarshaller;
  -        }
   
  -        TTEntry shallowCopy()
  -        {
  -            return new TTEntry(typeMarshaller, typeUnmarshaller);
  -        }
  -    }
  +        um = table.getTypeUnmarshaller(resolved);
  +        if (um != null) return um;
   
  +        String msg = "unable to get simple type unmarshaller for " + stype +
  +            " resolved to " + resolved;
  +        throw new AssertionError(msg);
  +    }
   
   }
  
  
  
  1.6       +28 -10    \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java  \
  Index: RuntimeTypeFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RuntimeTypeFactory.java	22 Jan 2004 21:43:47 -0000	1.5
  +++ RuntimeTypeFactory.java	26 Jan 2004 03:34:36 -0000	1.6
  @@ -59,6 +59,7 @@
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingType;
   import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  +import org.apache.xmlbeans.impl.common.ConcurrentReaderHashMap;
   
   import java.util.HashMap;
   import java.util.Map;
  @@ -69,18 +70,35 @@
   
   final class RuntimeTypeFactory
   {
  -    private final Map typeMap = new HashMap();
  +    //concurrent hashMap allows us to do hash lookups outside of any sync blocks,
  +    //and successful lookups  involve no locking, which should be
  +    //99% of the cases in any sort of long running process
  +    private final Map initedTypeMap = new ConcurrentReaderHashMap();
   
  -    //TODO: use a hash map that is sync only on write!!
  -    public synchronized RuntimeBindingType createRuntimeType(BindingType type,
  -                                                             \
                RuntimeBindingTypeTable type_table,
  -                                                             BindingLoader \
binding_loader)  +
  +    private final Map tempTypeMap = new HashMap();
  +
  +    RuntimeTypeFactory()
       {
  -        RuntimeBindingType rtype = (RuntimeBindingType)typeMap.get(type);
  -        if (rtype == null) {
  -            rtype = allocateType(type);
  -            typeMap.put(type, rtype);
  -            rtype.initialize(type_table, binding_loader);
  +    }
  +
  +    public RuntimeBindingType createRuntimeType(BindingType type,
  +                                                RuntimeBindingTypeTable \
type_table,  +                                                BindingLoader \
binding_loader)  +    {
  +        RuntimeBindingType rtype = (RuntimeBindingType)initedTypeMap.get(type);
  +        if (rtype != null) return rtype;
  +
  +        //safe but slow creation of new type.
  +        synchronized (this) {
  +            rtype = (RuntimeBindingType)tempTypeMap.get(type);
  +            if (rtype == null) {
  +                rtype = allocateType(type);
  +                tempTypeMap.put(type, rtype);
  +                rtype.initialize(type_table, binding_loader);
  +                initedTypeMap.put(type, rtype);
  +                tempTypeMap.remove(type); // save some memory.
  +            }
           }
           assert rtype != null;
           return rtype;
  
  
  
  1.3       +3 -3      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ScopedNamespaceContext.java
  
  Index: ScopedNamespaceContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ScopedNamespaceContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ScopedNamespaceContext.java	9 Jan 2004 02:18:57 -0000	1.2
  +++ ScopedNamespaceContext.java	26 Jan 2004 03:34:36 -0000	1.3
  @@ -271,7 +271,7 @@
               return prefix;
           }
   
  -        protected final LLNamespaceContext getPredecessor()
  +        final LLNamespaceContext getPredecessor()
           {
               return predecessor;
           }
  @@ -298,8 +298,8 @@
               return result.iterator();
           }
   
  -        protected static final Set getPrefixSet(String namespace,
  -                                                LLNamespaceContext context)
  +        static final Set getPrefixSet(String namespace,
  +                                      LLNamespaceContext context)
           {
               final Stack reversed = new Stack();
               LLNamespaceContext current = context;
  
  
  
  1.7       +2 -0      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeUnmarshaller.java  
  Index: TypeUnmarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeUnmarshaller.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TypeUnmarshaller.java	22 Jan 2004 21:43:47 -0000	1.6
  +++ TypeUnmarshaller.java	26 Jan 2004 03:34:36 -0000	1.7
  @@ -61,6 +61,8 @@
   /**
    * A TypeUnmarshaller knows how to unmarshal an xml
    * instance of a given BindingType
  + *
  + * All TypeUnmarshaller objects should be immutable.
    */
   interface TypeUnmarshaller
   {
  
  
  
  1.2       +2 -10     \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java  
  Index: UnmarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnmarshalResult.java	22 Jan 2004 21:43:47 -0000	1.1
  +++ UnmarshalResult.java	26 Jan 2004 03:34:36 -0000	1.2
  @@ -191,22 +191,14 @@
   
   
       private Object unmarshalBindingType(BindingType bindingType)
  -        throws XmlException
       {
  -        final TypeUnmarshaller um =
  -            typeTable.getTypeUnmarshaller(bindingType);
  -
  -        if (um == null) {
  -            throw new XmlException("failed to lookup unmarshaller for " + \
                bindingType);
  -        }
  -
  -        assert (baseReader != null);
  +        TypeUnmarshaller um =
  +            typeTable.getOrCreateTypeUnmarshaller(bindingType, bindingLoader);
   
           this.updateAttributeState();
   
           return um.unmarshal(this);
       }
  -
   
       Object unmarshalType(XMLStreamReader reader,
                            QName schemaType,
  
  
  
  1.16      +1 -1      \
xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java  
  Index: UnmarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- UnmarshallerImpl.java	22 Jan 2004 21:43:47 -0000	1.15
  +++ UnmarshallerImpl.java	26 Jan 2004 03:34:36 -0000	1.16
  @@ -67,7 +67,7 @@
   import javax.xml.stream.XMLStreamReader;
   import java.io.InputStream;
   
  -public class UnmarshallerImpl implements Unmarshaller
  +class UnmarshallerImpl implements Unmarshaller
   {
       private final BindingLoader bindingLoader;
       private final RuntimeBindingTypeTable typeTable;
  
  
  
  1.5       +2 -1      \
xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContext.java  
  Index: BindingContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BindingContext.java	22 Jan 2004 21:43:48 -0000	1.4
  +++ BindingContext.java	26 Jan 2004 03:34:37 -0000	1.5
  @@ -67,7 +67,6 @@
   public interface BindingContext
   {
       /**
  -     * @deprecated options are ignored and must be passed to Unmarshaller methods
        *
        * @return Unmarshaller object
        * @throws XmlException
  @@ -76,6 +75,8 @@
           throws XmlException;
   
       /**
  +     * @deprecated options are ignored and must be passed to Unmarshaller methods
  +
        * Create an Unmarshaller object capable of unmarshalling types
        * known by this context
        *
  
  
  
  1.18      +15 -0     xml-xmlbeans/v2/test/cases/marshal/example_config.xml
  
  Index: example_config.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/example_config.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- example_config.xml	15 Jan 2004 00:49:59 -0000	1.17
  +++ example_config.xml	26 Jan 2004 03:34:37 -0000	1.18
  @@ -10,6 +10,21 @@
           <bin:binding-type xsi:type="bin:by-name-bean" \
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
               <bin:javatype>com.mytest.YourClass</bin:javatype>
  +
  +
  +            <bin:qname-property>
  +                <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
  +                <bin:javatype>com.mytest.YourClass</bin:javatype>
  +                <bin:getter>
  +                    <bin:method-name>getMyBoss</bin:method-name>
  +                </bin:getter>
  +                <bin:setter>
  +                    <bin:method-name>setMyBoss</bin:method-name>
  +                    <bin:param-type>com.mytest.YourClass</bin:param-type>
  +                </bin:setter>
  +                <bin:qname>java:MyBoss</bin:qname>
  +            </bin:qname-property>
  +
               <bin:qname-property>
                   <bin:xmlcomponent>t=float@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  <bin:javatype>float</bin:javatype>
  
  
  
  1.9       +12 -0     xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java
  
  Index: YourClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- YourClass.java	15 Jan 2004 00:49:59 -0000	1.8
  +++ YourClass.java	26 Jan 2004 03:34:37 -0000	1.9
  @@ -66,6 +66,8 @@
   
   public class YourClass
   {
  +    private YourClass myBoss = null;
  +
       private MyClass myClass;
       private MySubClass mySubClass = new MySubClass();
   
  @@ -115,6 +117,16 @@
       public void setMyFloat(float myFloat)
       {
           this.myFloat = myFloat;
  +    }
  +
  +    public YourClass getMyBoss()
  +    {
  +        return myBoss;
  +    }
  +
  +    public void setMyBoss(YourClass myBoss)
  +    {
  +        this.myBoss = myBoss;
       }
   
       public MyClass getMyClass()
  
  
  
  1.30      +177 -18   xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java
  
  Index: MarshalTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- MarshalTests.java	24 Jan 2004 23:58:52 -0000	1.29
  +++ MarshalTests.java	26 Jan 2004 03:34:37 -0000	1.30
  @@ -171,9 +171,9 @@
           options.setErrorListener(errors);
   
           Unmarshaller umctx =
  -            bindingContext.createUnmarshaller(options);
  +            bindingContext.createUnmarshaller();
   
  -        Object obj = umctx.unmarshal(xrdr);
  +        Object obj = umctx.unmarshal(xrdr, options);
   
   
           //special case date/time tests.
  @@ -354,8 +354,8 @@
           StringReader sr = new StringReader(sw.getBuffer().toString());
           XMLStreamReader rdr =
               XMLInputFactory.newInstance().createXMLStreamReader(sr);
  -        Unmarshaller umctx = bindingContext.createUnmarshaller((new \
                XmlOptions()));
  -        Object out_obj = umctx.unmarshal(rdr);
  +        Unmarshaller umctx = bindingContext.createUnmarshaller();
  +        Object out_obj = umctx.unmarshal(rdr, options);
           Assert.assertEquals(mc, out_obj);
           Assert.assertTrue(errors.isEmpty());
       }
  @@ -395,9 +395,9 @@
           inform("16Doc=" + new String(buf, encoding));
   
           //now unmarshall from String and compare objects...
  -        Unmarshaller umctx = bindingContext.createUnmarshaller((new \
XmlOptions()));  +        Unmarshaller umctx = bindingContext.createUnmarshaller();
           final ByteArrayInputStream bais = new ByteArrayInputStream(buf);
  -        Object out_obj = umctx.unmarshal(bais);
  +        Object out_obj = umctx.unmarshal(bais, options);
           Assert.assertEquals(mc, out_obj);
           Assert.assertTrue(errors.isEmpty());
       }
  @@ -468,8 +468,8 @@
   //                return;
   //            }
   
  -            Unmarshaller umctx = bindingContext.createUnmarshaller(options);
  -            out_obj = umctx.unmarshalType(reader, schemaType, javaType);
  +            Unmarshaller umctx = bindingContext.createUnmarshaller();
  +            out_obj = umctx.unmarshalType(reader, schemaType, javaType, options);
           }
           final long after_millis = System.currentTimeMillis();
           final long diff = (after_millis - before_millis);
  @@ -480,6 +480,165 @@
           inform("milliseconds PER trial: " + (diff / (double)trials));
       }
   
  +
  +    public void testThreadedRoundtripPerf()
  +        throws Exception
  +    {
  +        //crank up these numbers to see real perf testing
  +        //the test still has some value aside from perf
  +        //in that it can test large stack depths.
  +        final int trials = 20;
  +        final int depth = 3;
  +        final int thread_cnt = 5;
  +        final int boolean_array_size = 3;
  +
  +        Random rnd = new Random();
  +
  +        com.mytest.MyClass top_obj = new com.mytest.MyClass();
  +
  +        com.mytest.MyClass curr = top_obj;
  +
  +        boolean[] bools = createRandomBooleanArray(rnd, boolean_array_size);
  +
  +        for (int i = 0; i < depth; i++) {
  +            com.mytest.YourClass myelt = new com.mytest.YourClass();
  +            myelt.setAttrib(rnd.nextFloat());
  +            myelt.setMyFloat(rnd.nextFloat());
  +            myelt.setBooleanArray(bools);
  +            final com.mytest.MyClass my_c = new com.mytest.MyClass();
  +            myelt.setMyClass(my_c);
  +            curr.setMyelt(myelt);
  +            curr.setMyatt("STR" + rnd.nextInt());
  +            curr = my_c;
  +        }
  +
  +        //inform("top_obj = " + top_obj);
  +
  +        BindingContext bindingContext = \
getBindingContext(getBindingConfigDocument());  +
  +        final String javaType = "com.mytest.MyClass";
  +        final QName schemaType = new QName("java:com.mytest", "MyClass");
  +        final QName elem_name = new QName("java:com.mytest", "load");
  +        final String class_name = top_obj.getClass().getName();
  +
  +        final Marshaller msh = bindingContext.createMarshaller();
  +        Assert.assertNotNull(msh);
  +        final Unmarshaller umsh = bindingContext.createUnmarshaller();
  +        Assert.assertNotNull(umsh);
  +
  +        Object out_obj = null;
  +        final XmlOptions options = new XmlOptions();
  +        final LinkedList errors = new LinkedList();
  +        options.setErrorListener(errors);
  +
  +        final long before_millis = System.currentTimeMillis();
  +
  +        RoundTripRunner[] runners = new RoundTripRunner[thread_cnt];
  +        for(int i = 0 ; i < thread_cnt ; i++) {
  +            runners[i] = new RoundTripRunner(top_obj, msh, umsh, elem_name,
  +                                             schemaType, class_name, javaType, \
options, trials);  +        }
  +
  +        inform("starting " + thread_cnt + " threads...");
  +
  +        for(int i = 0 ; i < thread_cnt ; i++) {
  +            runners[i].start();
  +        }
  +
  +        inform("joining " + thread_cnt + " threads...");
  +
  +        for(int i = 0 ; i < thread_cnt ; i++) {
  +            runners[i].join();
  +        }
  +
  +        inform("joined " + thread_cnt + " threads.");
  +
  +
  +
  +        final long after_millis = System.currentTimeMillis();
  +        final long diff = (after_millis - before_millis);
  +//        inform(" perf_out_obj = " + top_obj);
  +        Assert.assertTrue(errors.isEmpty());
  +        //Assert.assertEquals(top_obj, out_obj);
  +        inform("milliseconds: " + diff + " trials: " + trials +
  +               " threads=" + thread_cnt);
  +        inform("milliseconds PER trial: " + (diff / (double)trials));
  +        inform("milliseconds PER roundtrip: " + (diff / \
((double)trials*thread_cnt)));  +    }
  +
  +    private static Object doRoundTrip(MyClass top_obj,
  +                                      final Marshaller msh,
  +                                      final Unmarshaller umsh,
  +                                      final QName elem_name,
  +                                      final QName schemaType,
  +                                      final String class_name,
  +                                      final String javaType,
  +                                      final XmlOptions options)
  +        throws XmlException
  +    {
  +        Object out_obj;
  +        final XMLStreamReader reader =
  +            msh.marshalType(top_obj, elem_name,
  +                            schemaType,
  +                            class_name, options);
  +
  +        out_obj = umsh.unmarshalType(reader, schemaType, javaType);
  +        return out_obj;
  +    }
  +
  +    private static class RoundTripRunner extends Thread
  +    {
  +        private final MyClass top_obj;
  +        private final Marshaller msh;
  +        private final Unmarshaller umsh;
  +        private final QName elem_name;
  +        private final QName schemaType;
  +        private final String class_name;
  +        private final String javaType;
  +        private final XmlOptions options;
  +        private final int trials;
  +
  +
  +        public RoundTripRunner(MyClass top_obj,
  +                               Marshaller msh,
  +                               Unmarshaller umsh,
  +                               QName elem_name,
  +                               QName schemaType,
  +                               String class_name,
  +                               String javaType,
  +                               XmlOptions options,
  +                               int trials)
  +        {
  +            this.top_obj = top_obj;
  +            this.msh = msh;
  +            this.umsh = umsh;
  +            this.elem_name = elem_name;
  +            this.schemaType = schemaType;
  +            this.class_name = class_name;
  +            this.javaType = javaType;
  +            this.options = options;
  +            this.trials = trials;
  +        }
  +
  +        public void run()
  +        {
  +            final int t = trials;
  +            try {
  +                Object out_obj = null;
  +                for (int i = 0; i < t; i++) {
  +                    out_obj = doRoundTrip(top_obj, msh,
  +                                                 umsh, elem_name,
  +                                                 schemaType, class_name,
  +                                                 javaType, options);
  +                }
  +                Assert.assertEquals(top_obj, out_obj);
  +            }
  +            catch (XmlException xe) {
  +                throw new AssertionError(xe);
  +            }
  +        }
  +    }
  +
       private boolean[] createRandomBooleanArray(Random rnd, int size)
       {
           boolean[] a = new boolean[size];
  @@ -536,8 +695,8 @@
                               class_name, options);
   
           Unmarshaller umctx =
  -            bindingContext.createUnmarshaller(options);
  -        out_obj = umctx.unmarshalType(reader, schemaType, javaType);
  +            bindingContext.createUnmarshaller();
  +        out_obj = umctx.unmarshalType(reader, schemaType, javaType, options);
           inform(" out_obj = " + top_obj);
           Assert.assertEquals(top_obj, out_obj);
           Assert.assertTrue(errors.isEmpty());
  @@ -594,8 +753,8 @@
           options.setErrorListener(errors);
   
           Unmarshaller um_ctx =
  -            bindingContext.createUnmarshaller(options);
  -        Object obj = um_ctx.unmarshal(xrdr);
  +            bindingContext.createUnmarshaller();
  +        Object obj = um_ctx.unmarshal(xrdr, options);
   
           inform("doc2-obj = " + obj);
   
  @@ -620,8 +779,8 @@
           options.setErrorListener(errors);
   
           Unmarshaller um_ctx =
  -            bindingContext.createUnmarshaller(options);
  -        Object obj = um_ctx.unmarshal(new FileInputStream(doc));
  +            bindingContext.createUnmarshaller();
  +        Object obj = um_ctx.unmarshal(new FileInputStream(doc), options);
   
           inform("doc2-obj = " + obj);
   
  @@ -651,14 +810,14 @@
           final XmlOptions xmlOptions = new XmlOptions();
           Collection errors = new LinkedList();
           xmlOptions.setErrorListener(errors);
  -        Unmarshaller ctx = bindingContext.createUnmarshaller(xmlOptions);
  +        Unmarshaller ctx = bindingContext.createUnmarshaller();
   
           //this is not very safe but it should work...
           while (!xrdr.isStartElement()) {
               xrdr.next();
           }
   
  -        Object obj = ctx.unmarshalType(xrdr, schemaType, javaType);
  +        Object obj = ctx.unmarshalType(xrdr, schemaType, javaType, xmlOptions);
           for (Iterator itr = errors.iterator(); itr.hasNext();) {
               inform("ERROR: " + itr.next());
           }
  @@ -698,9 +857,9 @@
               XMLStreamReader xrdr =
                   xmlInputFactory.createXMLStreamReader(cr);
               Unmarshaller umctx =
  -                bindingContext.createUnmarshaller(xmlOptions);
  +                bindingContext.createUnmarshaller();
   
  -            Object obj = umctx.unmarshal(xrdr);
  +            Object obj = umctx.unmarshal(xrdr, xmlOptions);
   
               if ((i % 1000) == 0) {
                   String s = obj.toString().substring(0, 70);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic