xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Ziegler <z...@bea.com>
Subject Re: cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
Date Mon, 10 Nov 2003 15:56:12 GMT
That file is in cvs, so I don't think I missed that one.  What is the  
exact error message?

I've done a clean build on two different machines so I'm hoping I got  
everything.

--Scott

On Friday, November 7, 2003, at 10:03  AM, David Bau wrote:

> Scott, did you miss a file?
>
> This morning after syncing I was getting a problem with a class not  
> found on
> com.mytest.MyClass from MarshalTests.java.
>
> David
> ----- Original Message -----
> From: <zieg@apache.org>
> To: <xml-xmlbeans-cvs@apache.org>
> Sent: Wednesday, November 05, 2003 9:42 PM
> Subject: [xmlbeans-cvs] cvs commit:  
> xml-xmlbeans/v2/test/src/drt/drtcases
> MarshalTests.java
>
>
>> zieg        2003/11/05 18:42:02
>>
>>   Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
>>                         ByNameRuntimeBindingType.java
>>                         ByNameTypeVisitor.java CharacterVisitor.java
>>                         MarshalContext.java MarshalResult.java
>>                         MarshallerImpl.java  
>> RuntimeBindingProperty.java
>>                         RuntimeGlobalProperty.java  
>> RuntimeTypeFactory.java
>>                         SimpleTypeVisitor.java XmlTypeVisitor.java
>>                v2/test/src/drt/drtcases MarshalTests.java
>>   Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
>>                         NamedXmlTypeVisitor.java
>>   Log:
>>   improvements and bug fixes for marshalling
>>   attributes not working yet
>>
>>   review: coming soon
>>
>>   Revision  Changes    Path
>>   1.4       +62 -7
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> ByNameRuntimeBi
> ndingType.java
>>
>>   Index: ByNameRuntimeBindingType.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/ByNam
> eRuntimeBindingType.java,v
>>   retrieving revision 1.3
>>   retrieving revision 1.4
>>   diff -u -r1.3 -r1.4
>>   --- ByNameRuntimeBindingType.java 31 Oct 2003 22:23:25 -0000 1.3
>>   +++ ByNameRuntimeBindingType.java 6 Nov 2003 02:42:01 -0000 1.4
>>   @@ -93,7 +93,7 @@
>>
>>        //prepare internal data structures for use
>>        public void initialize(RuntimeBindingTypeTable typeTable,
>>   -                    BindingLoader loader)
>>   +                           BindingLoader loader)
>>        {
>>            int idx = 0;
>>            for (Iterator itr = byNameBean.getProperties().iterator();
> itr.hasNext();) {
>>   @@ -127,6 +127,11 @@
>>            return byNameBean;
>>        }
>>
>>   +    RuntimeBindingProperty getProperty(int index)
>>   +    {
>>   +        return properties[index];
>>   +    }
>>   +
>>        //TODO: optimize this linear scan
>>        RuntimeBindingProperty getMatchingElementProperty(String uri,
>>                                                          String  
>> localname)
>>   @@ -161,6 +166,11 @@
>>            return null;
>>        }
>>
>>   +    public int getPropertyCount()
>>   +    {
>>   +        return properties.length;
>>   +    }
>>   +
>>
>>        private static final class Property implements
> RuntimeBindingProperty
>>        {
>>   @@ -168,8 +178,11 @@
>>            private final BindingType bindingType;
>>            private final TypeUnmarshaller unmarshaller;
>>            private final Class propertyClass;
>>   +        private final Method getMethod;
>>            private final Method setMethod;
>>            private final boolean javaPrimitive;
>>   +        private static final Object[] EMPTY_OBJECT_ARRAY = new
> Object[]{};
>>   +        private static final Class[] EMPTY_CLASS_ARRAY = new  
>> Class[]{};
>>
>>            Property(Class beanClass,
>>                     QNameProperty prop,
>>   @@ -187,6 +200,7 @@
>>                    throw (RuntimeException)(new
> RuntimeException(msg).initCause(e));
>>                }
>>
>>   +            getMethod = getGetterMethod(prop, beanClass);
>>                setMethod = getSetterMethod(prop, beanClass,
> propertyClass);
>>                javaPrimitive = propertyClass.isPrimitive();
>>            }
>>   @@ -222,9 +236,8 @@
>>
>>                if (xsi_type == null)
>>                    return unmarshaller;
>>   -            else
>>   -                if (xsi_type == UnmarshalContext.XSI_NIL_MARKER)
>>   -                    return NullUnmarshaller.getInstance();
>>   +            else if (xsi_type == UnmarshalContext.XSI_NIL_MARKER)
>>   +                return NullUnmarshaller.getInstance();
>>
>>                return context.getTypeUnmarshaller(xsi_type);
>>            }
>>   @@ -254,14 +267,37 @@
>>            //non simple type props can throw some runtime exception.
>>            public CharSequence getLexical(Object parent,  
>> MarshalContext
> context)
>>            {
>>   -            return "FIXME this="+this;
>>   +            //TODO: FIXME: this is not correct!
>>   +
>>   +            if (parent instanceof CharSequence) {
>>   +                return (CharSequence)parent;
>>   +            } else {
>>   +                return String.valueOf(parent);
>>   +            }
>>            }
>>
>>   -        private static Method getSetterMethod(QNameProperty
> bindingProperty1,
>>   +        public Object getValue(Object parentObject, MarshalContext
> context)
>>   +        {
>>   +            assert parentObject != null;
>>   +            try {
>>   +                return getMethod.invoke(parentObject,
> EMPTY_OBJECT_ARRAY);
>>   +            }
>>   +            catch (SecurityException e) {
>>   +                throw new XmlRuntimeException(e);
>>   +            }
>>   +            catch (IllegalAccessException e) {
>>   +                throw new XmlRuntimeException(e);
>>   +            }
>>   +            catch (InvocationTargetException e) {
>>   +                throw new XmlRuntimeException(e);
>>   +            }
>>   +        }
>>   +
>>   +        private static Method getSetterMethod(QNameProperty
> binding_prop,
>>                                                  Class beanClass,
>>                                                  Class propClass)
>>            {
>>   -            String setter = bindingProperty1.getSetterName();
>>   +            String setter = binding_prop.getSetterName();
>>                try {
>>                    final Method set_method =
>>                        beanClass.getMethod(setter, new
> Class[]{propClass});
>>   @@ -274,6 +310,25 @@
>>                    throw new XmlRuntimeException(e);
>>                }
>>            }
>>   +
>>   +
>>   +        private static Method getGetterMethod(QNameProperty
> binding_prop,
>>   +                                              Class beanClass)
>>   +        {
>>   +            String getter = binding_prop.getGetterName();
>>   +            try {
>>   +                final Method get_method =
>>   +                    beanClass.getMethod(getter, EMPTY_CLASS_ARRAY);
>>   +                return get_method;
>>   +            }
>>   +            catch (NoSuchMethodException e) {
>>   +                throw new XmlRuntimeException(e);
>>   +            }
>>   +            catch (SecurityException e) {
>>   +                throw new XmlRuntimeException(e);
>>   +            }
>>   +        }
>>   +
>>
>>            boolean isAttribute()
>>            {
>>
>>
>>
>>   1.3       +32 -21
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> ByNameTypeVisit
> or.java
>>
>>   Index: ByNameTypeVisitor.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/ByNam
> eTypeVisitor.java,v
>>   retrieving revision 1.2
>>   retrieving revision 1.3
>>   diff -u -r1.2 -r1.3
>>   --- ByNameTypeVisitor.java 2 Nov 2003 20:21:47 -0000 1.2
>>   +++ ByNameTypeVisitor.java 6 Nov 2003 02:42:01 -0000 1.3
>>   @@ -56,47 +56,57 @@
>>
>>    package org.apache.xmlbeans.impl.marshal;
>>
>>   +import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
>>   +
>>    import javax.xml.namespace.QName;
>>
>>   -class ByNameTypeVisitor extends XmlTypeVisitor
>>   +class ByNameTypeVisitor extends NamedXmlTypeVisitor
>>    {
>>   +    private final ByNameRuntimeBindingType type;
>>   +    private final int propCount;
>>   +    private int propIdx = -1;
>>
>>   -    public ByNameTypeVisitor(RuntimeBindingProperty property,  
>> Object
> obj,
>>   -                             MarshalContext context)
>>   +    ByNameTypeVisitor(RuntimeBindingProperty property, Object obj,
>>   +                      MarshalContext context)
>>        {
>>   -        super(obj);
>>   -    }
>>   +        super(obj, property, context);
>>   +        final ByNameBean bean_type =  
>> (ByNameBean)property.getType();
>>   +        //TODO: avoid new
>>   +        type = new ByNameRuntimeBindingType(bean_type);
>>   +        type.initialize(context.getTypeTable(),  
>> context.getLoader());
>>
>>   -    // needs to update _currProp AND _currPropObj
>>   -    protected void advance()
>>   -    {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        //TODO: FIXME: proper null handling
>>   +        propCount = obj == null ? 0 : type.getPropertyCount();
>>        }
>>
>>   -    protected boolean hasMoreChildren()
>>   +    protected int getState()
>>        {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   -    }
>>   +        if (propIdx < 0) return START;
>>
>>   -    //return  
>> XmlTypeVisitorFactory.createXmlTypeVisitor(_currProp.get,
> _currPropObj);
>>   -    protected XmlTypeVisitor getCurrChild()
>>   -    {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        if (propIdx >= propCount) return END;
>>   +
>>   +        return CONTENT;
>>        }
>>
>>   -    protected QName getName()
>>   +    protected int advance()
>>        {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        assert propIdx < propCount; //ensure we don't go past the  
>> end
>>   +        ++propIdx;
>>   +        return getState();
>>        }
>>
>>   -    protected boolean isCharacters()
>>   +    public XmlTypeVisitor getCurrentChild()
>>        {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        final RuntimeBindingProperty property =
> type.getProperty(propIdx);
>>   +        assert property != null;
>>   +        Object prop_obj = property.getValue(parentObject,
> marshalContext);
>>   +        return MarshalResult.createVisitor(property, prop_obj,
> marshalContext);
>>        }
>>
>>        protected int getAttributeCount()
>>        {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        //TODO: FIXME use real values
>>   +        return 0;
>>        }
>>
>>        protected String getAttributeValue(int idx)
>>   @@ -113,5 +123,6 @@
>>        {
>>            throw new IllegalStateException("not text");
>>        }
>>   +
>>
>>    }
>>
>>
>>
>>   1.2       +14 -21
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> CharacterVisito
> r.java
>>
>>   Index: CharacterVisitor.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Chara
> cterVisitor.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- CharacterVisitor.java 31 Oct 2003 22:23:25 -0000 1.1
>>   +++ CharacterVisitor.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -62,17 +62,13 @@
>>    final class CharacterVisitor
>>        extends XmlTypeVisitor
>>    {
>>   -    private final RuntimeBindingProperty property;
>>   -    private final MarshalContext context;
>>
>>   -    public CharacterVisitor(RuntimeBindingProperty property,
>>   +
>>   +    CharacterVisitor(RuntimeBindingProperty property,
>>                                Object parentObject,
>>                                MarshalContext context)
>>        {
>>   -        super(parentObject);
>>   -        assert property != null;
>>   -        this.property = property;
>>   -        this.context = context;
>>   +        super(parentObject, property, context);
>>        }
>>
>>        private static CharSequence getCharData(RuntimeBindingProperty
> property,
>>   @@ -82,28 +78,25 @@
>>            return property.getLexical(parentObject, context);
>>        }
>>
>>   -    protected void advance()
>>   -    {
>>   -    }
>>
>>   -    protected boolean hasMoreChildren()
>>   +    protected int getState()
>>        {
>>   -        return false;
>>   +        return CHARS;
>>        }
>>
>>   -    protected XmlTypeVisitor getCurrChild()
>>   +    protected int advance()
>>        {
>>   -        throw new NoSuchElementException("no children");
>>   +        return CHARS;
>>        }
>>
>>   -    protected QName getName()
>>   +    public XmlTypeVisitor getCurrentChild()
>>        {
>>   -        throw new IllegalStateException();
>>   +        throw new AssertionError("no children");
>>        }
>>
>>   -    protected boolean isCharacters()
>>   +    protected QName getName()
>>        {
>>   -        return true;
>>   +        throw new AssertionError("no name on " + this);
>>        }
>>
>>        protected int getAttributeCount()
>>   @@ -113,17 +106,17 @@
>>
>>        protected String getAttributeValue(int idx)
>>        {
>>   -        throw new IllegalStateException();
>>   +        throw new AssertionError("no attributes on " + this);
>>        }
>>
>>        protected QName getAttributeName(int idx)
>>        {
>>   -        throw new IllegalStateException();
>>   +        throw new AssertionError("no attributes on " + this);
>>        }
>>
>>        protected CharSequence getCharData()
>>        {
>>   -        return getCharData(property, parentObject, context);
>>   +        return getCharData(bindingProperty, parentObject,
> marshalContext);
>>        }
>>
>>    }
>>
>>
>>
>>   1.2       +2 -0
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> MarshalContext.
> java
>>
>>   Index: MarshalContext.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Marsh
> alContext.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- MarshalContext.java 31 Oct 2003 22:23:25 -0000 1.1
>>   +++ MarshalContext.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -80,6 +80,8 @@
>>            this.loader = loader;
>>            this.typeTable = typeTable;
>>            this.errors = errors;
>>   +
>>   +        namespaceContext.openScope(); //TODO: verify this
>>        }
>>
>>        Collection getErrorCollection()
>>
>>
>>
>>   1.3       +84 -24
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> MarshalResult.j
> ava
>>
>>   Index: MarshalResult.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Marsh
> alResult.java,v
>>   retrieving revision 1.2
>>   retrieving revision 1.3
>>   diff -u -r1.2 -r1.3
>>   --- MarshalResult.java 2 Nov 2003 20:21:47 -0000 1.2
>>   +++ MarshalResult.java 6 Nov 2003 02:42:01 -0000 1.3
>>   @@ -72,17 +72,14 @@
>>    {
>>        private XmlTypeVisitor currVisitor;
>>        private final Stack visitorStack = new Stack();
>>   -    private final QName topElement;
>>        private final MarshalContext context;
>>        private int currentEventType = XMLStreamReader.START_ELEMENT;
>>
>>        MarshalResult(RuntimeBindingProperty property, Object obj,
>>   -                  QName elementName, MarshalContext context)
>>   +                  MarshalContext context)
>>        {
>>            currVisitor = createVisitor(property, obj, context);
>>   -        topElement = elementName;
>>            this.context = context;
>>   -        pushVisitor(currVisitor);
>>        }
>>
>>        protected static XmlTypeVisitor
> createVisitor(RuntimeBindingProperty property,
>>   @@ -111,26 +108,81 @@
>>
>>        public int next() throws XMLStreamException
>>        {
>>   -        final int retval;
>>   +        int retval = -1;
>>
>>   -
>>   -        if (currVisitor.hasMoreChildren()) {
>>   -            XmlTypeVisitor nextVisitor =  
>> currVisitor.getCurrChild();
>>   -            currVisitor.advance();
>>   -            pushVisitor(currVisitor);
>>   -            currVisitor = nextVisitor;
>>   -            if (nextVisitor.isCharacters()) {
>>   -                retval = XMLStreamReader.CHARACTERS;
>>   -            } else {
>>   -                retval = XMLStreamReader.START_ELEMENT;
>>   -            }
>>   -        } else {
>>   -            currVisitor = popVisitor();
>>   -            if (currVisitor.isCharacters())
>>   -                return next(); //chars have no matching end tags
>>   -            retval = XMLStreamReader.END_ELEMENT;
>>   +        final int curr_state = currVisitor.getState();
>>   +        switch (curr_state) {
>>   +            case XmlTypeVisitor.START:
>>   +                {
>>   +                    final int next_state = currVisitor.advance();
>>   +                    switch (next_state) {
>>   +                        case XmlTypeVisitor.CONTENT:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = START_ELEMENT;
>>   +                            break;
>>   +                        case XmlTypeVisitor.CHARS:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = CHARACTERS;
>>   +                            break;
>>   +                        case XmlTypeVisitor.END:
>>   +                            retval = END_ELEMENT;
>>   +                            break;
>>   +                        default:
>>   +                            throw new AssertionError("bad state: "  
>> +
> curr_state);
>>   +                    }
>>   +                }
>>   +                break;
>>   +            case XmlTypeVisitor.CHARS:
>>   +                {
>>   +                    currVisitor = popVisitor();
>>   +                    final int next_state = currVisitor.advance();
>>   +                    switch (next_state) {
>>   +                        case XmlTypeVisitor.CONTENT:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = START_ELEMENT;
>>   +                            break;
>>   +                        case XmlTypeVisitor.CHARS:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = CHARACTERS;
>>   +                        case XmlTypeVisitor.END:
>>   +                            retval = END_ELEMENT;
>>   +                            break;
>>   +                        default:
>>   +                            throw new AssertionError("bad state: "  
>> +
> curr_state);
>>   +                    }
>>   +                }
>>   +                break;
>>   +            case XmlTypeVisitor.END:
>>   +                {
>>   +                    currVisitor = popVisitor();
>>   +                    final int next_state = currVisitor.advance();
>>   +                    switch (next_state) {
>>   +                        case XmlTypeVisitor.CONTENT:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = START_ELEMENT;
>>   +                            break;
>>   +                        case XmlTypeVisitor.CHARS:
>>   +                            pushVisitor(currVisitor);
>>   +                            currVisitor =
> currVisitor.getCurrentChild();
>>   +                            retval = CHARACTERS;
>>   +                        case XmlTypeVisitor.END:
>>   +                            retval = END_ELEMENT;
>>   +                            break;
>>   +                         default:
>>   +                            throw new AssertionError("bad state: "  
>> +
> curr_state);
>>   +                    }
>>   +                }
>>   +                break;
>>   +            default:
>>   +                throw new AssertionError("unknown state: " +
> curr_state);
>>            }
>>
>>   +        assert retval != -1;
>>            currentEventType = retval;
>>            return retval;
>>        }
>>   @@ -144,7 +196,8 @@
>>        private XmlTypeVisitor popVisitor()
>>        {
>>            context.getNamespaceContext().closeScope();
>>   -        return (XmlTypeVisitor)visitorStack.pop();
>>   +        final XmlTypeVisitor tv =  
>> (XmlTypeVisitor)visitorStack.pop();
>>   +        return tv;
>>        }
>>
>>        public void require(int i, String s, String s1)
>>   @@ -165,12 +218,19 @@
>>
>>        public boolean hasNext() throws XMLStreamException
>>        {
>>   -        return !visitorStack.isEmpty();
>>   +
>>   +//        return !visitorStack.isEmpty();
>>   +
>>   +        if (visitorStack.isEmpty()) {
>>   +            return (currVisitor.getState() != XmlTypeVisitor.END);
>>   +        } else {
>>   +            return true;
>>   +        }
>>        }
>>
>>        public void close() throws XMLStreamException
>>        {
>>   -        throw new UnsupportedOperationException("UNIMPLEMENTED");
>>   +        //TODO: consider freeing memory
>>        }
>>
>>        public String getNamespaceURI(String s)
>>
>>
>>
>>   1.2       +2 -2
> 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/Marsh
> allerImpl.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- MarshallerImpl.java 31 Oct 2003 22:23:26 -0000 1.1
>>   +++ MarshallerImpl.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -112,7 +112,7 @@
>>            MarshalContext ctx = new MarshalContext(nscontext,
> bindingLoader,
>>                                                    typeTable, errors);
>>
>>   -        return new MarshalResult(prop, obj, elem_qn, ctx);
>>   +        return new MarshalResult(prop, obj, ctx);
>>        }
>>
>>        public XMLStreamReader marshallType(Object obj,
>>   @@ -126,7 +126,7 @@
>>            //TODO: REVIEW: should we move this method to the context?
>>            BindingType type = determineBindingType(obj, schemaType,
> javaType);
>>            RuntimeGlobalProperty prop = new  
>> RuntimeGlobalProperty(type,
> elementName);
>>   -        return new MarshalResult(prop, obj, elementName, context);
>>   +        return new MarshalResult(prop, obj, context);
>>        }
>>
>>        private BindingType determineBindingType(Object obj,
>>
>>
>>
>>   1.4       +2 -0
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> RuntimeBindingP
> roperty.java
>>
>>   Index: RuntimeBindingProperty.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Runti
> meBindingProperty.java,v
>>   retrieving revision 1.3
>>   retrieving revision 1.4
>>   diff -u -r1.3 -r1.4
>>   --- RuntimeBindingProperty.java 31 Oct 2003 22:23:26 -0000 1.3
>>   +++ RuntimeBindingProperty.java 6 Nov 2003 02:42:01 -0000 1.4
>>   @@ -74,4 +74,6 @@
>>        //non simple type props can throw some runtime exception.
>>        CharSequence getLexical(Object parent, MarshalContext context);
>>
>>   +    Object getValue(Object parentObject, MarshalContext context);
>>   +
>>    }
>>
>>
>>
>>   1.2       +5 -0
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> RuntimeGlobalPr
> operty.java
>>
>>   Index: RuntimeGlobalProperty.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Runti
> meGlobalProperty.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- RuntimeGlobalProperty.java 31 Oct 2003 22:23:26 -0000 1.1
>>   +++ RuntimeGlobalProperty.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -108,4 +108,9 @@
>>            final CharSequence retval = tm.print(parent, context);
>>            return retval;
>>        }
>>   +
>>   +    public Object getValue(Object parent_obj, MarshalContext  
>> context)
>>   +    {
>>   +        throw new AssertionError("UNIMP: " + this);
>>   +    }
>>    }
>>
>>
>>
>>   1.2       +2 -0
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> RuntimeTypeFact
> ory.java
>>
>>   Index: RuntimeTypeFactory.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Runti
> meTypeFactory.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- RuntimeTypeFactory.java 31 Oct 2003 22:23:26 -0000 1.1
>>   +++ RuntimeTypeFactory.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -63,6 +63,8 @@
>>    {
>>        public static RuntimeBindingType createRuntimeType(BindingType
> type)
>>        {
>>   +        //TODO: consider syncronized cache of these objects
>>   +
>>            //TODO: fix instanceof nastiness
>>            if (type instanceof ByNameBean) {
>>                return new ByNameRuntimeBindingType((ByNameBean)type);
>>
>>
>>
>>   1.3       +22 -40
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> SimpleTypeVisit
> or.java
>>
>>   Index: SimpleTypeVisitor.java
>>   ===================================================================
>>   RCS file:
> /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/ 
> marshal/Simpl
> eTypeVisitor.java,v
>>   retrieving revision 1.2
>>   retrieving revision 1.3
>>   diff -u -r1.2 -r1.3
>>   --- SimpleTypeVisitor.java 2 Nov 2003 20:21:47 -0000 1.2
>>   +++ SimpleTypeVisitor.java 6 Nov 2003 02:42:01 -0000 1.3
>>   @@ -58,60 +58,42 @@
>>
>>    import javax.xml.namespace.QName;
>>
>>   -final class SimpleTypeVisitor extends XmlTypeVisitor
>>   +final class SimpleTypeVisitor extends NamedXmlTypeVisitor
>>    {
>>   -    private final RuntimeBindingProperty property;
>>   -    private final MarshalContext context;
>>   -
>>   -    private boolean beforeChild = true;
>>   -    private String prefix;
>>   +    private int state = START;
>>
>>        public SimpleTypeVisitor(RuntimeBindingProperty property,  
>> Object
> obj,
>>                                 MarshalContext context)
>>        {
>>   -        super(obj);
>>   -        this.property = property;
>>   -        this.context = context;
>>   -    }
>>   -
>>   -    protected void advance()
>>   -    {
>>   -        beforeChild = false;
>>   +        super(obj, property, context);
>>        }
>>
>>   -    protected boolean hasMoreChildren()
>>   +    protected int getState()
>>        {
>>   -        return beforeChild;
>>   +        return state;
>>        }
>>
>>   -    protected XmlTypeVisitor getCurrChild()
>>   +    protected int advance()
>>        {
>>   -        return new CharacterVisitor(property, parentObject,  
>> context);
>>   -    }
>>   -
>>   -    protected QName getName()
>>   -    {
>>   -        //TODO: optimize this method (and related)
>>   -        final QName pname = property.getName();
>>   -        final String uri = pname.getNamespaceURI();
>>   -
>>   -        assert uri != null;  //QName's should use "" for no  
>> namespace
>>   -
>>   -        if (uri.length() == 0) {
>>   -            return new QName(pname.getLocalPart());
>>   -        } else {
>>   -
>>   -            if (prefix == null) {
>>   -                prefix = context.ensurePrefix(uri);
>>   -            }
>>   -
>>   -            return new QName(uri, pname.getLocalPart(), prefix);
>>   +        final int newstate;
>>   +        switch (state) {
>>   +            case START:
>>   +                newstate = CHARS;
>>   +                break;
>>   +            case CHARS:
>>   +                newstate = END;
>>   +                break;
>>   +            default:
>>   +                throw new AssertionError("invalid state: " +  
>> state);
>>            }
>>   +        state = newstate;
>>   +        return newstate;
>>        }
>>
>>   -    protected boolean isCharacters()
>>   +    public XmlTypeVisitor getCurrentChild()
>>        {
>>   -        return false;
>>   +        assert state == CHARS;
>>   +        return new CharacterVisitor(bindingProperty, parentObject,
> marshalContext);
>>        }
>>
>>        protected int getAttributeCount()
>>   @@ -132,7 +114,7 @@
>>
>>        protected CharSequence getCharData()
>>        {
>>   -        throw new IllegalStateException("not text");
>>   +        throw new AssertionError("not text");
>>        }
>>
>>    }
>>
>>
>>
>>   1.2       +29 -12
> 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/XmlTy
> peVisitor.java,v
>>   retrieving revision 1.1
>>   retrieving revision 1.2
>>   diff -u -r1.1 -r1.2
>>   --- XmlTypeVisitor.java 31 Oct 2003 22:23:26 -0000 1.1
>>   +++ XmlTypeVisitor.java 6 Nov 2003 02:42:01 -0000 1.2
>>   @@ -62,28 +62,37 @@
>>    abstract class XmlTypeVisitor
>>    {
>>        protected final Object parentObject;
>>   +    protected final RuntimeBindingProperty bindingProperty;
>>   +    protected final MarshalContext marshalContext;
>>
>>   -    protected XmlTypeVisitor(Object parent)
>>   +    XmlTypeVisitor(Object parentObject,
>>   +                   RuntimeBindingProperty property,
>>   +                   MarshalContext context)
>>        {
>>   -        parentObject = parent;
>>   +        this.parentObject = parentObject;
>>   +        this.bindingProperty = property;
>>   +        this.marshalContext = context;
>>        }
>>
>>   -    static final int CHARACTERS = XMLStreamReader.CHARACTERS;
>>   -    static final int START_ELEMENT = XMLStreamReader.START_ELEMENT;
>>   -    static final int END_ELEMENT = XMLStreamReader.END_ELEMENT;
>>
>>   -    // needs to update _currProp AND _currPropObj
>>   -    protected abstract void advance();
>>   +    static final int START = 1;
>>   +    static final int CONTENT = 2;
>>   +    static final int CHARS = 3;
>>   +    static final int END = 4;
>>   +
>>   +    protected abstract int getState();
>>   +
>>   +    /**
>>   +     *
>>   +     * @return  next state
>>   +     */
>>   +    protected abstract int advance();
>>
>>   -    protected abstract boolean hasMoreChildren();
>>   +    public abstract XmlTypeVisitor getCurrentChild();
>>
>>   -    //return  
>> XmlTypeVisitorFactory.createXmlTypeVisitor(_currProp.get,
> _currPropObj);
>>   -    protected abstract XmlTypeVisitor getCurrChild();
>>
>>        protected abstract QName getName();
>>
>>   -    protected abstract boolean isCharacters();
>>   -
>>        protected abstract int getAttributeCount();
>>
>>        protected abstract String getAttributeValue(int idx);
>>   @@ -91,5 +100,13 @@
>>        protected abstract QName getAttributeName(int idx);
>>
>>        protected abstract CharSequence getCharData();
>>   +
>>   +    public String toString()
>>   +    {
>>   +        return this.getClass().getName() +
>>   +            " prop=" + bindingProperty.getName() +
>>   +            " type=" + bindingProperty.getType().getName();
>>   +    }
>>   +
>>
>>    }
>>
>>
>>
>>   1.1
> xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ 
> NamedXmlTypeVis
> itor.java
>>
>>   Index: NamedXmlTypeVisitor.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;
>>
>>   import javax.xml.namespace.QName;
>>   import javax.xml.stream.XMLStreamReader;
>>
>>   abstract class NamedXmlTypeVisitor
>>       extends XmlTypeVisitor
>>   {
>>       private String prefix;
>>
>>       NamedXmlTypeVisitor(Object parentObject,
>>                           RuntimeBindingProperty property,
>>                           MarshalContext context)
>>       {
>>           super(parentObject, property, context);
>>       }
>>
>>       protected QName getName()
>>       {
>>           //TODO: optimize this method (and related)
>>           final QName pname = bindingProperty.getName();
>>           final String uri = pname.getNamespaceURI();
>>
>>           assert uri != null;  //QName's should use "" for no  
>> namespace
>>
>>           if (uri.length() == 0) {
>>               return new QName(pname.getLocalPart());
>>           } else {
>>
>>               if (prefix == null) {
>>                   prefix = marshalContext.ensurePrefix(uri);
>>               }
>>
>>               return new QName(uri, pname.getLocalPart(), prefix);
>>           }
>>       }
>>
>>
>>   }
>>
>>
>>
>>   1.5       +74 -39
> 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.4
>>   retrieving revision 1.5
>>   diff -u -r1.4 -r1.5
>>   --- MarshalTests.java 2 Nov 2003 20:21:47 -0000 1.4
>>   +++ MarshalTests.java 6 Nov 2003 02:42:02 -0000 1.5
>>   @@ -19,6 +19,9 @@
>>    import javax.xml.namespace.QName;
>>    import javax.xml.stream.XMLInputFactory;
>>    import javax.xml.stream.XMLStreamReader;
>>   +import javax.xml.stream.XMLStreamException;
>>   +import javax.xml.stream.XMLOutputFactory;
>>   +import javax.xml.stream.XMLStreamWriter;
>>    import java.io.CharArrayReader;
>>    import java.io.CharArrayWriter;
>>    import java.io.File;
>>   @@ -27,6 +30,7 @@
>>    import java.io.Reader;
>>    import java.io.StringReader;
>>    import java.io.Writer;
>>   +import java.io.StringWriter;
>>    import java.util.ArrayList;
>>    import java.util.Iterator;
>>    import java.util.List;
>>   @@ -44,6 +48,18 @@
>>            return new TestSuite(MarshalTests.class);
>>        }
>>
>>   +    //does not test any xmlbeans code, but rather a quick sanity  
>> check
>>   +    //of the current jsr 173 impl
>>   +    public void testAStream() throws XMLStreamException
>>   +    {
>>   +        String doc = "<a>foo</a>";
>>   +        StringReader sr = new StringReader(doc);
>>   +        final XMLStreamReader reader =
>>   +             
>> XMLInputFactory.newInstance().createXMLStreamReader(sr);
>>   +
>>   +        dumpReader(reader);
>>   +    }
>>   +
>>        public void testManySimpleTypesUnmarshall()
>>            throws Exception
>>        {
>>   @@ -111,50 +127,69 @@
>>
>>
>>            System.out.println("==================OBJ: " + orig);
>>   -        while (reader.hasNext()) {
>>   -            System.out.println("STATE: " +
> XmlStreamUtils.printEvent(reader));
>>   -            final int state = reader.next();
>>   -            System.out.println("next is " + state);
>>   -        }
>>   +        dumpReader(reader);
>>        }
>>
>>   +
>>   +    public void testByNameMarshal()
>>   +        throws Exception
>>   +    {
>>   +        com.mytest.MyClass mc = new com.mytest.MyClass();
>>   +        mc.setMyatt("attval");
>>   +
>>   +
>>   +        BindingConfigDocument bcdoc = getBindingConfigDocument();
>>   +
>>   +        BindingContext bindingContext =
>>   +            BindingContextFactory.createBindingContext(bcdoc);
>>   +
>>   +        Marshaller m = bindingContext.createMarshaller();
>>   +
>>   +        EmptyNamespaceContext namespaceContext = new
> EmptyNamespaceContext();
>>   +        final ArrayList errors = new ArrayList();
>>   +        MarshalContext ctx =
>>   +            bindingContext.createMarshallContext(namespaceContext,
> errors);
>>   +
>>   +        final XMLStreamReader reader =
>>   +            m.marshallType(mc, new QName("uri", "lname"),
>>   +                           new QName("java:com.mytest", "MyClass"),
>>   +                           mc.getClass().getName(),
>>   +                           ctx);
>>   +
>>   +        System.out.println("==================OBJ: " + mc);
>>   +
>>   +
>>   +        dumpReader(reader);
>>   +
>>   +    }
>>   +
>>   +    private static void dumpReader(final XMLStreamReader reader)
>>   +        throws XMLStreamException
>>   +    {
>>   +        final boolean write_doc = false;
>>   +        if (write_doc) {
>>   +//            StringWriter sw = new StringWriter();
>>   +//            XMLStreamWriter xsw =
>>   +//
> XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
>>    //
>>   -//    //only works for values where .toString() is equivalent to
> marshalling
>>   -//    public void __testByNameMarshal()
>>   -//        throws Exception
>>   -//    {
>>   -//        MyClass mc = new MyClass();
>>   -//        mc.setMyatt("attval");
>>   -//
>>   -//        BindingFile bf = new BindingFile();
>>   -//        BindingConfigDocument bindingConfigDocument = bf.write();
>>   -//
>>   -//        BindingContext bindingContext =
>>   -//
> BindingContextFactory.createBindingContext(bindingConfigDocument);
>>   -//
>>   -//        Marshaller m = bindingContext.createMarshaller();
>>   -//
>>   -//        EmptyNamespaceContext namespaceContext = new
> EmptyNamespaceContext();
>>   -//        final ArrayList errors = new ArrayList();
>>   -//        MarshalContext ctx =
>>   -//             
>> bindingContext.createMarshallContext(namespaceContext,
> errors);
>>   -//
>>   -//        final XMLStreamReader reader =
>>   -//            m.marshallType(mc, new QName("uri", "lname"),
>>   -//                           new QName("java:com.mytest",  
>> "MyClass"),
>>   -//                           mc.getClass().getName(),
>>   -//                           ctx);
>>   -//
>>   -//
>>   -//        System.out.println("==================OBJ: " + mc);
>>   -//        while (reader.hasNext()) {
>>   -//            System.out.println("STATE: " +
> XmlStreamUtils.printEvent(reader));
>>   -//            final int state = reader.next();
>>   -//            System.out.println("next is " + state);
>>   -//        }
>>   +//            //NOTE: next two lines depend on the 173_ri to even
> compile
>>   +//            com.bea.xml.stream.ReaderToWriter rtow =
>>   +//                new com.bea.xml.stream.ReaderToWriter(xsw);
>>   +//            rtow.writeAll(reader);
>>    //
>>   +//            xsw.close();
>>    //
>>   -//    }
>>   +//            System.out.println("doc = " + sw.getBuffer());
>>   +
>>   +        } else {
>>   +            int i = 0;
>>   +            System.out.println((i++) + "\tSTATE: " +
> XmlStreamUtils.printEvent(reader));
>>   +            while (reader.hasNext()) {
>>   +                final int state = reader.next();
>>   +                System.out.println((i++) + "\tSTATE: " +
> XmlStreamUtils.printEvent(reader));
>>   +            }
>>   +        }
>>   +    }
>>
>>        public void testByNameBeanUnmarshal()
>>            throws Exception
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org
>>
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message