You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2004/10/09 23:32:41 UTC

cvs commit: xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator ValidatingXMLStreamReader.java

cezar       2004/10/09 14:32:41

  Modified:    v2/src/tools/org/apache/xmlbeans/impl/inst2xsd
                        RussianDollStrategy.java
               v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util
                        Type.java TypeSystemHolder.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/validator
                        ValidatingXMLStreamReader.java
  Log:
  Bug fixes: inst2xsd QName enumerations and source names in validation errors.
  
  Revision  Changes    Path
  1.6       +2 -6      xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
  
  Index: RussianDollStrategy.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RussianDollStrategy.java	15 Sep 2004 00:53:54 -0000	1.5
  +++ RussianDollStrategy.java	9 Oct 2004 21:32:40 -0000	1.6
  @@ -197,7 +197,7 @@
   
                   // add enumeration value
                   String enumValue = XmlString.type.getName().equals(elemType.getName()) ? textBuff.toString() : collapsedText;
  -                elemType.addEnumerationValue(enumValue);
  +                elemType.addEnumerationValue(enumValue, xc);
               }
   
               xc.toEndToken(); // end hack
  @@ -581,11 +581,7 @@
           // take care of enumeration values
           if (options.isUseEnumerations())
           {
  -            for (int i = 0; i < with.getEnumerationValues().size(); i++)
  -            {
  -                String enumValue = (String) with.getEnumerationValues().get(i);
  -                into.addEnumerationValue(enumValue);
  -            }
  +            into.addAllEnumerationsFrom(with);
   
               if (into.getEnumerationValues().size()>options.getUseEnumerations())
               {
  
  
  
  1.3       +68 -1     xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/Type.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Type.java	15 Sep 2004 00:53:54 -0000	1.2
  +++ Type.java	9 Oct 2004 21:32:40 -0000	1.3
  @@ -14,6 +14,11 @@
    */
   package org.apache.xmlbeans.impl.inst2xsd.util;
   
  +import org.apache.xmlbeans.XmlQName;
  +import org.apache.xmlbeans.XmlCursor;
  +import org.apache.xmlbeans.impl.common.PrefixResolver;
  +import org.apache.xmlbeans.impl.values.XmlQNameImpl;
  +
   import javax.xml.namespace.QName;
   import java.util.List;
   import java.util.ArrayList;
  @@ -45,6 +50,9 @@
   
       private List _enumerationValues;
       private boolean _acceptsEnumerationValue = true;
  +    private List _enumerationQNames;                    // This is a special case where the lexical representation
  +                                                        // is not enough for a value, the QNames need to be remembered
  +                                                        // in case the _extensionType is QName
   
       private Type()
       {}
  @@ -216,20 +224,43 @@
           return _enumerationValues;
       }
   
  -    public void addEnumerationValue(String enumerationValue)
  +    public List getEnumerationQNames()
  +    {
  +        ensureEnumerationValues();
  +        return _enumerationQNames;
  +    }
  +
  +    public void addEnumerationValue(String enumerationValue, final XmlCursor xc)
       {
           assert _kind==SIMPLE_TYPE_SIMPLE_CONTENT || _kind==COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple content";
           ensureEnumerationValues();
           if (_acceptsEnumerationValue && !_enumerationValues.contains(enumerationValue))
           {
               _enumerationValues.add(enumerationValue);
  +            if (_name.equals(XmlQName.type.getName()))
  +            {
  +                // check for QName
  +                PrefixResolver prefixResolver = new PrefixResolver()
  +                {
  +                    public String getNamespaceForPrefix(String prefix)
  +                    {  return xc.namespaceForPrefix(prefix); }
  +                };
  +
  +                QName qname = XmlQNameImpl.validateLexical(enumerationValue, null, prefixResolver);
  +
  +                assert qname!=null : "The check for QName should allready have happened.";
  +                _enumerationQNames.add(qname);
  +            }
           }
       }
   
       private void ensureEnumerationValues()
       {
           if (_enumerationValues==null)
  +        {
               _enumerationValues = new ArrayList();
  +            _enumerationQNames = new ArrayList();
  +        }
       }
   
       public boolean isEnumeration()
  @@ -237,6 +268,11 @@
           return _acceptsEnumerationValue && _enumerationValues!=null && _enumerationValues.size()>1;
       }
   
  +    public boolean isQNameEnumeration()
  +    {
  +        return isEnumeration() && _name.equals(XmlQName.type.getName()) && _enumerationQNames!=null && _enumerationQNames.size()>1;
  +    }
  +
       public void closeEnumeration()
       {
           _acceptsEnumerationValue=false;
  @@ -251,5 +287,36 @@
               ", _elements = " + _elements +
               ", _attributes = " + _attributes +
               "}";
  +    }
  +
  +    public void addAllEnumerationsFrom(Type from)
  +    {
  +        assert _kind==SIMPLE_TYPE_SIMPLE_CONTENT || _kind==COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple content";
  +        ensureEnumerationValues();
  +
  +        if (_name.equals(XmlQName.type.getName()) && from._name.equals(XmlQName.type.getName()))
  +        {
  +            for (int i = 0; i < from.getEnumerationValues().size(); i++)
  +            {
  +                String enumValue = (String) from.getEnumerationValues().get(i);
  +                QName enumQNameValue = (QName) from.getEnumerationQNames().get(i);
  +                if (_acceptsEnumerationValue && !_enumerationQNames.contains(enumQNameValue))
  +                {
  +                        _enumerationValues.add(enumValue);
  +                        _enumerationQNames.add(enumQNameValue);
  +                }
  +            }
  +        }
  +        else
  +        {
  +            for (int i = 0; i < from.getEnumerationValues().size(); i++)
  +            {
  +                String enumValue = (String) from.getEnumerationValues().get(i);
  +                if (_acceptsEnumerationValue && !_enumerationValues.contains(enumValue))
  +                {
  +                    _enumerationValues.add(enumValue);
  +                }
  +            }
  +        }
       }
   }
  
  
  
  1.4       +25 -3     xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/TypeSystemHolder.java
  
  Index: TypeSystemHolder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/tools/org/apache/xmlbeans/impl/inst2xsd/util/TypeSystemHolder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypeSystemHolder.java	7 Sep 2004 22:02:37 -0000	1.3
  +++ TypeSystemHolder.java	9 Oct 2004 21:32:40 -0000	1.4
  @@ -16,6 +16,8 @@
   
   import org.w3.x2001.xmlSchema.SchemaDocument;
   import org.apache.xmlbeans.XmlString;
  +import org.apache.xmlbeans.XmlQName;
  +import org.apache.xmlbeans.XmlCursor;
   
   import javax.xml.namespace.QName;
   import java.math.BigInteger;
  @@ -226,10 +228,30 @@
           assert type.isEnumeration() && !type.isComplexType() : "Enumerations must be on simple types only.";
           org.w3.x2001.xmlSchema.RestrictionDocument.Restriction restriction = parentSElement.addNewSimpleType().addNewRestriction();
           restriction.setBase(type.getName());
  -        for (int i = 0; i < type.getEnumerationValues().size(); i++)
  +        if (type.isQNameEnumeration())
           {
  -            String value = (String) type.getEnumerationValues().get(i);
  -            restriction.addNewEnumeration().setValue(XmlString.Factory.newValue(value));
  +            for (int i = 0; i < type.getEnumerationQNames().size(); i++)
  +            {
  +                QName value = (QName) type.getEnumerationQNames().get(i);
  +                XmlQName xqname = XmlQName.Factory.newValue(value);
  +
  +                org.w3.x2001.xmlSchema.NoFixedFacet enumSElem = restriction.addNewEnumeration();
  +                XmlCursor xc  = enumSElem.newCursor();
  +
  +                String newPrefix = xc.prefixForNamespace(value.getNamespaceURI());
  +                xc.dispose();
  +
  +                enumSElem.setValue( XmlQName.Factory.newValue(
  +                    new QName(value.getNamespaceURI(), value.getLocalPart(), newPrefix)));
  +            }
  +        }
  +        else
  +        {
  +            for (int i = 0; i < type.getEnumerationValues().size(); i++)
  +            {
  +                String value = (String) type.getEnumerationValues().get(i);
  +                restriction.addNewEnumeration().setValue(XmlString.Factory.newValue(value));
  +            }
           }
       }
   
  
  
  
  1.7       +24 -11    xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/ValidatingXMLStreamReader.java
  
  Index: ValidatingXMLStreamReader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/ValidatingXMLStreamReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ValidatingXMLStreamReader.java	27 May 2004 23:36:20 -0000	1.6
  +++ ValidatingXMLStreamReader.java	9 Oct 2004 21:32:40 -0000	1.7
  @@ -26,6 +26,7 @@
   import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamException;
   import javax.xml.stream.XMLStreamReader;
  +import javax.xml.stream.Location;
   import javax.xml.stream.events.XMLEvent;
   import javax.xml.stream.util.StreamReaderDelegate;
   import java.util.ArrayList;
  @@ -505,8 +506,7 @@
               {
                   if (_contentType==null)
                   {
  -                    _errorListener.add(XmlError.forMessage("No content type provided for validation of a content model.",
  -                        XmlError.SEVERITY_ERROR));
  +                    addError("No content type provided for validation of a content model.");
                       _state = STATE_ERROR;
                       break;
                   }
  @@ -553,8 +553,8 @@
                   }
                   else
                   {
  -                    _errorListener.add(XmlError.forMessage("Specified type '" + _contentType +
  -                        "' not compatible with found xsi:type '" + _xsiType + "'.", XmlError.SEVERITY_ERROR));
  +                    addError("Specified type '" + _contentType +
  +                        "' not compatible with found xsi:type '" + _xsiType + "'.");
                       _state = STATE_ERROR;
                       return;
                   }
  @@ -573,8 +573,8 @@
                   validationType = _stl.findAttributeType((QName)_attNamesList.get(0));
                   if (validationType==null)
                   {
  -                    _errorListener.add(XmlError.forMessage("A schema global element with name '" + _attNamesList.get(0) +
  -                        "' could not be found in the current schema type loader.", XmlError.SEVERITY_ERROR));
  +                    addError("A schema global element with name '" + _attNamesList.get(0) +
  +                        "' could not be found in the current schema type loader.");
                       _state = STATE_ERROR;
                       return;
                   }
  @@ -582,15 +582,14 @@
               }
               else
               {
  -                _errorListener.add(XmlError.forMessage("No content type provided for validation of a content model.",
  -                    XmlError.SEVERITY_ERROR));
  +                addError("No content type provided for validation of a content model.");
                   _state = STATE_ERROR;
                   return;
               }
           }
   
           // here validationType is the right type, start pushing all acumulated attributes
  -        _validator = new Validator(validationType, null, _stl, _options, _errorListener);
  +        initValidator(validationType);
           _validator.nextEvent(Validator.BEGIN, _simpleEvent);
   
           for (int i=0; i<_attNamesList.size(); i++)
  @@ -633,11 +632,25 @@
   
           if (docType==null)
           {
  -            _errorListener.add(XmlError.forMessage("Schema document type not found for element '" + qname + "'.",
  -                XmlError.SEVERITY_ERROR));
  +            addError("Schema document type not found for element '" + qname + "'.");
               _state = STATE_ERROR;
           }
           return docType;
  +    }
  +
  +    private void addError(String msg)
  +    {
  +        String source = null;
  +        Location location = getLocation();
  +
  +        if (location!=null)
  +        {
  +            source = location.getPublicId();
  +            if (source==null)
  +                source = location.getSystemId();
  +        }
  +
  +        _errorListener.add(XmlError.forLocation(msg, source, getLocation()));
       }
   
       /**
  
  
  

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