xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
Date Mon, 12 Apr 2004 22:39:46 GMT
zieg        2004/04/12 15:39:46

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        ByNameTypeVisitor.java CharacterVisitor.java
                        MarshalResult.java NamedXmlTypeVisitor.java
                        SimpleContentTypeVisitor.java
                        SimpleTypeVisitor.java WrappedArrayTypeVisitor.java
                        XmlTypeVisitor.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections
                        StringList.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal/util
                        AttributeHolder.java
  Log:
  avoid excessive ArrayList and QName object creation
  
  Revision  Changes    Path
  1.23      +7 -57     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java
  
  Index: ByNameTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ByNameTypeVisitor.java	6 Apr 2004 00:53:08 -0000	1.22
  +++ ByNameTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.23
  @@ -16,14 +16,10 @@
   package org.apache.xmlbeans.impl.marshal;
   
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.impl.util.XsTypeConverter;
   import org.apache.xmlbeans.impl.marshal.util.ArrayUtils;
   
  -import javax.xml.namespace.QName;
  -import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  -import java.util.List;
   
   final class ByNameTypeVisitor
       extends NamedXmlTypeVisitor
  @@ -32,7 +28,6 @@
       private final int maxElementPropCount;
       private final int maxAttributePropCount;
       private int elemPropIdx = -1;
  -    private List attributes; //name, value, name, value...
       private Iterator currMultipleIterator;
       private Object currMultipleItem;
       private boolean haveMultipleItem;
  @@ -69,7 +64,8 @@
           do {
               boolean hit_end = advanceToNextItem();
               if (hit_end) return END;
  -        } while (!currentPropHasMore());
  +        }
  +        while (!currentPropHasMore());
   
           assert elemPropIdx >= 0;
   
  @@ -161,19 +157,10 @@
           return property;
       }
   
  -    protected int getAttributeCount()
  -        throws XmlException
  -    {
  -        final int sz = ((attributes.size()) / 2);
  -        return sz;
  -    }
  -
       protected void initAttributes()
           throws XmlException
       {
  -        attributes = new ArrayList();
           initAttributesInternal(this,
  -                               attributes,
                                  type,
                                  maxAttributePropCount,
                                  marshalResult);
  @@ -181,29 +168,17 @@
       }
   
       static void initAttributesInternal(NamedXmlTypeVisitor typeVisitor,
  -                                       List atts,
                                          AttributeRuntimeBindingType rtt,
                                          int maxAttributePropCount,
                                          MarshalResult marshalResult)
           throws XmlException
       {
  -        assert atts != null;
  -        atts.clear();
  -
  -
           final Object parent = typeVisitor.getParentObject();
           if (parent == null) {
  -            QName nil_qn = typeVisitor.fillPrefix(MarshalStreamUtils.XSI_NIL_QNAME);
  -            addAttribute(atts, nil_qn, XsTypeConverter.printBoolean(true));
  +            marshalResult.addXsiNilAttribute();
           } else {
               if (typeVisitor.needsXsiType()) {
  -                QName aname = typeVisitor.fillPrefix(MarshalStreamUtils.XSI_TYPE_QNAME);
  -                QName tn = typeVisitor.fillPrefix(rtt.getSchemaTypeName());
  -                String aval = XsTypeConverter.getQNameString(tn.getNamespaceURI(),
  -                                                             tn.getLocalPart(),
  -                                                             tn.getPrefix());
  -
  -                addAttribute(atts, aname, aval);
  +                marshalResult.addXsiTypeAttribute(rtt);
               }
   
               for (int i = 0, len = maxAttributePropCount; i < len; i++) {
  @@ -219,36 +194,11 @@
   
                   if (val == null) continue;
   
  -                addAttribute(atts, typeVisitor.fillPrefix(prop.getName()), val);
  +                //REVIEW: defer toString call until actually used?
  +                marshalResult.fillAndAddAttribute(prop.getName(),
  +                                                  val.toString());
               }
           }
  -
  -        assert (atts.size() % 2) == 0;
  -    }
  -
  -    static void addAttribute(List atts, QName name, CharSequence value) {
  -        atts.add(name);
  -        atts.add(value);
  -
  -        assert (atts.size() % 2) == 0;
  -    }
  -
  -
  -    protected String getAttributeValue(int idx)
  -    {
  -        CharSequence val = (CharSequence)attributes.get(1 + (idx * 2));
  -        return val.toString();
  -    }
  -
  -    protected QName getAttributeName(int idx)
  -    {
  -        QName an = (QName)attributes.get(idx * 2);
  -
  -        //make sure we have a valid prefix
  -        assert ((an.getPrefix().length() == 0) ==
  -            (an.getNamespaceURI().length() == 0));
  -
  -        return an;
       }
   
       protected CharSequence getCharData()
  
  
  
  1.13      +6 -7      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/CharacterVisitor.java
  
  Index: CharacterVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/CharacterVisitor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CharacterVisitor.java	19 Feb 2004 18:43:56 -0000	1.12
  +++ CharacterVisitor.java	12 Apr 2004 22:39:46 -0000	1.13
  @@ -67,20 +67,19 @@
           throw new AssertionError("no name on " + this);
       }
   
  -    protected int getAttributeCount()
  -        throws XmlException
  +    protected String getLocalPart()
       {
  -        return 0;
  +        throw new AssertionError("no name on " + this);
       }
   
  -    protected String getAttributeValue(int idx)
  +    protected String getNamespaceURI()
       {
  -        throw new AssertionError("no attributes on " + this);
  +        throw new AssertionError("no name on " + this);
       }
   
  -    protected QName getAttributeName(int idx)
  +    protected String getPrefix()
       {
  -        throw new AssertionError("no attributes on " + this);
  +        throw new AssertionError("no name on " + this);
       }
   
       protected CharSequence getCharData()
  
  
  
  1.25      +87 -19    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java
  
  Index: MarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MarshalResult.java	9 Apr 2004 09:20:24 -0000	1.24
  +++ MarshalResult.java	12 Apr 2004 22:39:46 -0000	1.25
  @@ -32,6 +32,8 @@
   import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
   import org.apache.xmlbeans.impl.common.XmlStreamUtils;
   import org.apache.xmlbeans.impl.common.XmlWhitespace;
  +import org.apache.xmlbeans.impl.marshal.util.AttributeHolder;
  +import org.apache.xmlbeans.impl.util.XsTypeConverter;
   
   import javax.xml.namespace.NamespaceContext;
   import javax.xml.namespace.QName;
  @@ -58,6 +60,7 @@
       private XmlTypeVisitor currVisitor;
       private int currentEventType = XMLStreamReader.START_ELEMENT;
       private boolean initedAttributes = false;
  +    private AttributeHolder attributeHolder;
       private int prefixCnt = 0;
   
       //used for some array types
  @@ -175,6 +178,9 @@
   
       String ensurePrefix(String uri)
       {
  +        assert uri != null;  //QName's should use "" for no namespace
  +        assert (uri.length() > 0);
  +
           String prefix = namespaceContext.getPrefix(uri);
           if (prefix == null) {
               prefix = bindNextPrefix(uri);
  @@ -192,7 +198,8 @@
           do {
               prefix = NSPREFIX + (++prefixCnt);
               testuri = namespaceContext.getNamespaceURI(prefix);
  -        } while (testuri != null);
  +        }
  +        while (testuri != null);
           assert prefix != null;
           namespaceContext.bindNamespace(prefix, uri);
           return prefix;
  @@ -306,37 +313,38 @@
       public int getAttributeCount()
       {
           initAttributes();
  -        try {
  -            return currVisitor.getAttributeCount();
  -        }
  -        catch (XmlException e) {
  -            //interface forces us into this...
  -            throw new XmlRuntimeException(e);
  -        }
  +        if (attributeHolder == null)
  +            return 0;
  +        else
  +            return attributeHolder.getAttributeCount();
       }
   
       public QName getAttributeName(int i)
       {
           initAttributes();
  -        return currVisitor.getAttributeName(i);
  +        assert attributeHolder != null;
  +        return attributeHolder.getAttributeName(i);
       }
   
       public String getAttributeNamespace(int i)
       {
           initAttributes();
  -        return getAttributeName(i).getNamespaceURI();
  +        assert attributeHolder != null;
  +        return attributeHolder.getAttributeNamespace(i);
       }
   
       public String getAttributeLocalName(int i)
       {
           initAttributes();
  -        return getAttributeName(i).getLocalPart();
  +        assert attributeHolder != null;
  +        return attributeHolder.getAttributeLocalName(i);
       }
   
       public String getAttributePrefix(int i)
       {
           initAttributes();
  -        return getAttributeName(i).getPrefix();
  +        assert attributeHolder != null;
  +        return attributeHolder.getAttributePrefix(i);
       }
   
       public String getAttributeType(int i)
  @@ -348,14 +356,16 @@
       public String getAttributeValue(int i)
       {
           initAttributes();
  -        return currVisitor.getAttributeValue(i);
  +        assert attributeHolder != null;
  +        return attributeHolder.getAttributeValue(i);
       }
   
       public boolean isAttributeSpecified(int i)
       {
           initAttributes();
   
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        assert attributeHolder != null;
  +        return attributeHolder.isAttributeSpecified(i);
       }
   
       public int getNamespaceCount()
  @@ -485,7 +495,7 @@
   
       public String getLocalName()
       {
  -        return getName().getLocalPart();
  +        return currVisitor.getLocalPart();
       }
   
       public boolean hasName()
  @@ -496,12 +506,12 @@
   
       public String getNamespaceURI()
       {
  -        return getName().getNamespaceURI();
  +        return currVisitor.getNamespaceURI();
       }
   
       public String getPrefix()
       {
  -        return getName().getPrefix();
  +        return currVisitor.getPrefix();
       }
   
       public String getVersion()
  @@ -538,6 +548,9 @@
       {
           if (!initedAttributes) {
               try {
  +                if (attributeHolder != null) {
  +                    attributeHolder.clear();
  +                }
                   currVisitor.initAttributes();
               }
               catch (XmlException e) {
  @@ -627,13 +640,68 @@
           return typeTable.getRuntimeTypeFactory();
       }
   
  -    QName createQName(String uri, String localpart, String prefix) {
  +    private QName createQName(String uri, String localpart, String prefix)
  +    {
           return new QName(uri, localpart, prefix);
       }
   
  -    QName createQName(String localpart) {
  +    private QName createQName(String localpart)
  +    {
           return new QName(localpart);
       }
  +
  +    void fillAndAddAttribute(QName qname_without_prefix,
  +                             String value)
  +    {
  +        final String uri = qname_without_prefix.getNamespaceURI();
  +        final String prefix;
  +        if (uri.length() == 0) {
  +            prefix = null;
  +        } else {
  +            prefix = ensurePrefix(uri);
  +        }
  +        addAttribute(uri, qname_without_prefix.getLocalPart(), prefix, value);
  +    }
  +
  +    private void addAttribute(String namespaceURI,
  +                      String localPart,
  +                      String prefix,
  +                      String value)
  +    {
  +        if (attributeHolder == null) {
  +            attributeHolder = new AttributeHolder();
  +        }
  +        attributeHolder.add(namespaceURI, localPart, prefix, value);
  +    }
  +
  +    void addXsiNilAttribute()
  +    {
  +        addAttribute(MarshalStreamUtils.XSI_NS,
  +                     MarshalStreamUtils.XSI_NIL_ATTR,
  +                     ensurePrefix(MarshalStreamUtils.XSI_NS),
  +                     NamedXmlTypeVisitor.TRUE_LEX);
  +    }
  +
  +    void addXsiTypeAttribute(RuntimeBindingType rtt)
  +    {
  +        final QName schema_type = rtt.getSchemaTypeName();
  +        final String type_uri = schema_type.getNamespaceURI();
  +
  +        //TODO: what about types from a schema with no targetNamespace??
  +        assert type_uri != null;
  +        assert type_uri.length() > 0;
  +
  +        final String aval =
  +            XsTypeConverter.getQNameString(type_uri,
  +                                           schema_type.getLocalPart(),
  +                                           ensurePrefix(type_uri));
  +
  +        addAttribute(MarshalStreamUtils.XSI_NS,
  +                     MarshalStreamUtils.XSI_TYPE_ATTR,
  +                     ensurePrefix(MarshalStreamUtils.XSI_NS),
  +                     aval);
  +    }
  +
   
       private static final class BindingTypeVisitor
           implements org.apache.xmlbeans.impl.binding.bts.BindingTypeVisitor
  
  
  
  1.10      +27 -4     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java
  
  Index: NamedXmlTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NamedXmlTypeVisitor.java	8 Apr 2004 19:03:44 -0000	1.9
  +++ NamedXmlTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.10
  @@ -25,9 +25,11 @@
   abstract class NamedXmlTypeVisitor
       extends XmlTypeVisitor
   {
  -    private final QName name;
  +    private final String prefix;
  +
       private final RuntimeBindingType actualRuntimeBindingType;
  -    protected static final String NIL_ATT_VAL =
  +
  +    protected static final String TRUE_LEX =
           XsTypeConverter.printBoolean(true).intern();
   
       NamedXmlTypeVisitor(Object parentObject,
  @@ -41,12 +43,33 @@
               property.getActualRuntimeType(parentObject, result);
   
           //TODO: optimize to avoid object creation
  -        name = fillPrefix(getBindingProperty().getName());
  +        final String uri = getBindingProperty().getName().getNamespaceURI();
  +        if (uri.length() > 0) {
  +            prefix = marshalResult.ensurePrefix(uri);
  +        } else {
  +            prefix = null;
  +        }
       }
   
       protected QName getName()
       {
  -        return name;
  +        final QName name = getBindingProperty().getName();
  +        return new QName(name.getNamespaceURI(), name.getLocalPart(), prefix);
  +    }
  +
  +    protected String getLocalPart()
  +    {
  +        return getBindingProperty().getName().getLocalPart();
  +    }
  +
  +    protected String getNamespaceURI()
  +    {
  +        return getBindingProperty().getName().getNamespaceURI();
  +    }
  +
  +    protected String getPrefix()
  +    {
  +        return prefix;
       }
   
       protected final RuntimeBindingType getActualRuntimeBindingType()
  
  
  
  1.2       +5 -29     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentTypeVisitor.java
  
  Index: SimpleContentTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentTypeVisitor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleContentTypeVisitor.java	9 Mar 2004 23:50:53 -0000	1.1
  +++ SimpleContentTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.2
  @@ -25,8 +25,6 @@
       extends SimpleContentVisitor
   {
       private final SimpleContentRuntimeBindingType type;
  -    private final int maxAttributePropCount;
  -    private List attributes; //name, value, name, value...
   
       public SimpleContentTypeVisitor(RuntimeBindingProperty property,
                                       Object obj,
  @@ -36,49 +34,27 @@
           super(property, obj, result);
   
           type = (SimpleContentRuntimeBindingType)getActualRuntimeBindingType();
  -        maxAttributePropCount =
  -            obj == null ? 0 : type.getAttributePropertyCount();
  -    }
  -
  -    protected int getAttributeCount()
  -        throws XmlException
  -    {
  -        return attributes.size() / 2;
       }
   
       protected void initAttributes()
           throws XmlException
       {
  -        attributes = new ArrayList();
           ByNameTypeVisitor.initAttributesInternal(this,
  -                                                 attributes,
                                                    type,
  -                                                 maxAttributePropCount,
  +                                                 getMaxAttributePropCount(),
                                                    marshalResult);
   
       }
   
   
  -    protected String getAttributeValue(int idx)
  -    {
  -        CharSequence val = (CharSequence)attributes.get(1 + (idx * 2));
  -        return val.toString();
  -    }
  -
  -    protected QName getAttributeName(int idx)
  +    protected CharSequence getCharData()
       {
  -        QName an = (QName)attributes.get(idx * 2);
  -
  -        //make sure we have a valid prefix
  -        assert ((an.getPrefix().length() == 0) ==
  -            (an.getNamespaceURI().length() == 0));
  -
  -        return an;
  +        throw new IllegalStateException("not text: " + this);
       }
   
  -    protected CharSequence getCharData()
  +    private int getMaxAttributePropCount()
       {
  -        throw new IllegalStateException("not text: " + this);
  +        return getParentObject() == null ? 0 : type.getAttributePropertyCount();
       }
   
   
  
  
  
  1.16      +2 -33     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java
  
  Index: SimpleTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SimpleTypeVisitor.java	6 Apr 2004 00:53:09 -0000	1.15
  +++ SimpleTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.16
  @@ -23,8 +23,6 @@
   final class SimpleTypeVisitor
       extends SimpleContentVisitor
   {
  -    private QName attributeName;
  -    private String xsiTypeAttVal;
   
       public SimpleTypeVisitor(RuntimeBindingProperty property,
                                Object obj,
  @@ -39,39 +37,10 @@
           throws XmlException
       {
           if (getParentObject() == null) {
  -            attributeName = fillPrefix(MarshalStreamUtils.XSI_NIL_QNAME);
  +            marshalResult.addXsiNilAttribute();
           } else if (needsXsiType()) {
  -            attributeName = fillPrefix(MarshalStreamUtils.XSI_TYPE_QNAME);
  -
  -            final QName schema_type_name =
  -                getActualRuntimeBindingType().getSchemaTypeName();
  -
  -            QName tn = fillPrefix(schema_type_name);
  -            xsiTypeAttVal = XsTypeConverter.getQNameString(tn.getNamespaceURI(),
  -                                                           tn.getLocalPart(),
  -                                                           tn.getPrefix());
  -        } else {
  -            attributeName = null;
  +            marshalResult.addXsiTypeAttribute(getActualRuntimeBindingType());
           }
  -    }
  -
  -    protected int getAttributeCount()
  -        throws XmlException
  -    {
  -        return attributeName == null ? 0 : 1;
  -    }
  -
  -    protected String getAttributeValue(int idx)
  -    {
  -        assert attributeName != null;
  -        
  -        return xsiTypeAttVal==null ? NIL_ATT_VAL : xsiTypeAttVal;
  -    }
  -
  -    protected QName getAttributeName(int idx)
  -    {
  -        assert attributeName != null;
  -        return attributeName;
       }
   
   }
  
  
  
  1.4       +4 -35     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java
  
  Index: WrappedArrayTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WrappedArrayTypeVisitor.java	9 Apr 2004 21:54:16 -0000	1.3
  +++ WrappedArrayTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.4
  @@ -67,8 +67,6 @@
       private final WrappedArrayRuntimeBindingType type;
       private final int arrayLength;
   
  -    private QName attributeName;
  -    private String xsiTypeAttVal;
       private int currIndex = -1;
   
       WrappedArrayTypeVisitor(RuntimeBindingProperty property,
  @@ -108,7 +106,8 @@
           do {
               currIndex++;
               if (currIndex == arrayLength) return END;
  -        } while (!currentItemHasValue());
  +        }
  +        while (!currentItemHasValue());
   
   
           assert currIndex >= 0;
  @@ -141,48 +140,18 @@
           return marshalResult.createVisitor(type.getElementProperty(), value);
       }
   
  -    protected int getAttributeCount()
  -        throws XmlException
  -    {
  -        return attributeName == null ? 0 : 1;
  -    }
  -
  -    protected String getAttributeValue(int idx)
  -    {
  -        assert attributeName != null;
  -
  -        return xsiTypeAttVal == null ? NIL_ATT_VAL : xsiTypeAttVal;
  -    }
  -
  -    protected QName getAttributeName(int idx)
  -    {
  -        assert attributeName != null;
  -        return attributeName;
  -    }
  -
       protected CharSequence getCharData()
       {
           throw new IllegalStateException("not text: " + this);
       }
   
  -    //TODO: refactor to avoid duplicate code in SimpleTypeVisitor
       protected void initAttributes()
           throws XmlException
       {
           if (getParentObject() == null) {
  -            attributeName = fillPrefix(MarshalStreamUtils.XSI_NIL_QNAME);
  +            marshalResult.addXsiNilAttribute();
           } else if (needsXsiType()) {
  -            attributeName = fillPrefix(MarshalStreamUtils.XSI_TYPE_QNAME);
  -
  -            final QName schema_type_name =
  -                getActualRuntimeBindingType().getSchemaTypeName();
  -
  -            QName tn = fillPrefix(schema_type_name);
  -            xsiTypeAttVal = XsTypeConverter.getQNameString(tn.getNamespaceURI(),
  -                                                           tn.getLocalPart(),
  -                                                           tn.getPrefix());
  -        } else {
  -            attributeName = null;
  +            marshalResult.addXsiTypeAttribute(getActualRuntimeBindingType());
           }
       }
   
  
  
  
  1.12      +4 -13     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java
  
  Index: XmlTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XmlTypeVisitor.java	8 Apr 2004 19:03:44 -0000	1.11
  +++ XmlTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.12
  @@ -64,8 +64,11 @@
       public abstract XmlTypeVisitor getCurrentChild()
           throws XmlException;
   
  -
       protected abstract QName getName();
  +    protected abstract String getLocalPart();
  +    protected abstract String getNamespaceURI();
  +    protected abstract String getPrefix();
  +    
   
       //guaranteed to be called before any getAttribute* or getNamespace* method
       protected void initAttributes()
  @@ -73,13 +76,6 @@
       {
       }
   
  -    protected abstract int getAttributeCount()
  -        throws XmlException;
  -
  -    protected abstract String getAttributeValue(int idx);
  -
  -    protected abstract QName getAttributeName(int idx);
  -
       protected abstract CharSequence getCharData();
   
       public String toString()
  @@ -87,11 +83,6 @@
           return this.getClass().getName() +
               " prop=" + bindingProperty.getName() +
               " type=" + bindingProperty.getRuntimeBindingType().getBindingType();
  -    }
  -
  -    protected QName fillPrefix(final QName pname)
  -    {
  -        return marshalResult.fillPrefix(pname);
       }
   
   
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/AttributeHolder.java
  
  Index: AttributeHolder.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/>.
  */
  
  package org.apache.xmlbeans.impl.marshal.util;
  
  import org.apache.xmlbeans.impl.marshal.util.collections.StringList;
  
  import javax.xml.namespace.QName;
  
  public final class AttributeHolder
  {
      private final StringList data;
  
      public AttributeHolder(int initial_capacity)
      {
          data = new StringList(4 * initial_capacity);
      }
  
      public AttributeHolder()
      {
          this(4);
      }
  
      public void clear()
      {
          data.clear();
  
          assert data.getSize() == 0;
      }
  
      public void add(String namespaceURI, String localPart, String prefix,
                      String value)
      {
          data.add(namespaceURI);
          data.add(localPart);
          data.add(prefix);
          data.add(value);
  
          assert (data.getSize() % 4) == 0;
      }
  
      public void add(QName name, String value)
      {
          add(name.getNamespaceURI(),
              name.getLocalPart(),
              name.getPrefix(),
              value);
      }
  
  
      public int getAttributeCount()
      {
          assert (data.getSize() % 4) == 0;
          return data.getSize() / 4;
      }
  
      public String getAttributeValue(int idx)
      {
          assert (data.getSize() % 4) == 0;
  
          return data.get(3 + idx * 4);
      }
  
      public QName getAttributeName(int idx)
      {
          //TODO: consider caching these values...
          return new QName(getAttributeNamespace(idx),
                           getAttributeLocalName(idx),
                           getAttributePrefix(idx));
      }
  
  
      public String getAttributeNamespace(int i)
      {
          assert (data.getSize() % 4) == 0;
  
          return data.get(i * 4);
      }
  
      public String getAttributeLocalName(int i)
      {
          assert (data.getSize() % 4) == 0;
  
          return data.get(1 + i * 4);
      }
  
      public String getAttributePrefix(int i)
      {
          assert (data.getSize() % 4) == 0;
  
          return data.get(2 + i * 4);
      }
  
      public boolean isAttributeSpecified(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
  
      public String getAttributeValue(String uri, String lname)
      {
          //TODO: do better than this basic and slow implementation
          for (int i = 0, len = getAttributeCount(); i < len; i++) {
  
              if (lname.equals(getAttributeLocalName(i))) {
                  if (uri == null || uri.equals(getAttributeNamespace(i)))
                      return getAttributeValue(i);
              }
          }
          return null;
      }
  
  }
  
  
  
  1.6       +7 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/StringList.java
  
  Index: StringList.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/StringList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StringList.java	6 Apr 2004 00:53:09 -0000	1.5
  +++ StringList.java	12 Apr 2004 22:39:46 -0000	1.6
  @@ -15,6 +15,8 @@
   
   package org.apache.xmlbeans.impl.marshal.util.collections;
   
  +import java.util.Arrays;
  +
   /**
    minimal, simplisitic typesafe version of ArrayList for Strings
    wraps String[]
  @@ -77,6 +79,11 @@
       public void append(Object o)
       {
           add((String)o);
  +    }
  +
  +    public void clear() {
  +        Arrays.fill(store, null);
  +        size = 0;
       }
   
       /**
  
  
  
  1.51      +9 -7      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.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- MarshalTests.java	9 Apr 2004 21:54:16 -0000	1.50
  +++ MarshalTests.java	12 Apr 2004 22:39:46 -0000	1.51
  @@ -330,7 +330,6 @@
               Object out = um.unmarshalType(reader, schemaType, javaType, options);
               Assert.assertEquals(our_obj, out);
   
  -
               if (!errors.isEmpty()) {
                   for (Iterator itr = errors.iterator(); itr.hasNext();) {
                       Object err = itr.next();
  @@ -577,8 +576,9 @@
           //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 = 1;
  -        final int depth = 3;
  +        final int trials = 3;
  +//        final int trials = 10000;
  +        final int depth = 7;
           final int boolean_array_size = 5;
   
           Random rnd = new Random();
  @@ -610,7 +610,7 @@
               curr = my_c;
           }
   
  -        //inform("top_obj = " + top_obj);
  +        inform("top_perf_obj = " + top_obj);
   
           BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
   
  @@ -625,11 +625,14 @@
           final LinkedList errors = new LinkedList();
           options.setErrorListener(errors);
   
  +
  +        final Marshaller ctx =
  +            bindingContext.createMarshaller();
  +        final Unmarshaller umctx = bindingContext.createUnmarshaller();
  +
           for (int i = 0; i < trials; i++) {
               errors.clear();
   
  -            Marshaller ctx =
  -                bindingContext.createMarshaller();
               Assert.assertNotNull(ctx);
   
   
  @@ -645,7 +648,6 @@
   //                return;
   //            }
   
  -            Unmarshaller umctx = bindingContext.createUnmarshaller();
               out_obj = umctx.unmarshalType(reader, schemaType, javaType, options);
           }
           final long after_millis = System.currentTimeMillis();
  
  
  

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


Mime
View raw message