You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ra...@apache.org on 2009/06/03 00:45:53 UTC

svn commit: r781199 - in /xmlbeans/trunk: src/typeimpl/org/apache/xmlbeans/impl/schema/ src/typeimpl/org/apache/xmlbeans/impl/validator/ src/typeimpl/org/apache/xmlbeans/impl/values/ src/xmlpublic/org/apache/xmlbeans/ test/src/compile/scomp/detailed/

Author: radup
Date: Tue Jun  2 22:45:52 2009
New Revision: 781199

URL: http://svn.apache.org/viewvc?rev=781199&view=rev
Log:
Partial implementation of the NOTATION built-in type

Modified:
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaNotationHolderEx.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolderEx.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/message.properties
    xmlbeans/trunk/test/src/compile/scomp/detailed/DetailedCompTests.java

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscChecker.java Tue Jun  2 22:45:52 2009
@@ -28,6 +28,7 @@
 import org.apache.xmlbeans.XmlID;
 import org.apache.xmlbeans.XmlAnySimpleType;
 import org.apache.xmlbeans.XmlErrorCodes;
+import org.apache.xmlbeans.XmlNOTATION;
 import org.apache.xmlbeans.XmlString;
 import org.apache.xmlbeans.impl.common.XBeanDebug;
 import org.apache.xmlbeans.impl.common.QNameHelper;
@@ -73,7 +74,8 @@
     
     /**
      * The following code checks rule #5 of http://www.w3.org/TR/xmlschema-1/#coss-ct
-     * as well as attribute + element default/fixed validity.
+     * as well as attribute + element default/fixed validity. <p/>
+     * Checks that xs:NOTATION is not used directly
      */
     public static void checkFields(SchemaTypeImpl sType)
     {
@@ -108,6 +110,35 @@
                             null, attrLocation != null ? attrLocation : location);
                     }
                 }
+                else if (XmlNOTATION.type.isAssignableFrom(sAttrs[i].getType()))
+                {
+                    if (sAttrs[i].getType().getBuiltinTypeCode() == SchemaType.BTC_NOTATION)
+                    {
+                        StscState.get().recover(XmlErrorCodes.ATTR_NOTATION_TYPE_FORBIDDEN,
+                            new Object[]{ QNameHelper.pretty(sAttrs[i].getName()) },
+                            attrLocation != null ? attrLocation : location);
+                    }
+                    else
+                    {
+                        // Check that the Schema in which this is present doesn't have a targetNS
+                        boolean hasNS;
+                        if (sType.isAttributeType())
+                            hasNS = sAttrs[i].getName().getNamespaceURI().length() > 0;
+                        else
+                        {
+                            SchemaType t = sType;
+                            while (t.getOuterType() != null)
+                                t = t.getOuterType();
+                            if (t.isDocumentType())
+                                hasNS = t.getDocumentElementName().getNamespaceURI().length() > 0;
+                            else hasNS = t.getName().getNamespaceURI().length() > 0;
+                        }
+                        if (hasNS)
+                            StscState.get().warning(XmlErrorCodes.ATTR_COMPATIBILITY_TARGETNS,
+                                new Object[] {QNameHelper.pretty(sAttrs[i].getName()) },
+                                attrLocation != null ? attrLocation : location);
+                    }
+                }
                 else
                 {
                     String valueConstraint = sAttrs[i].getDefaultText();
@@ -151,7 +182,15 @@
         
         checkElementDefaults(sType.getContentModel(), location, sType);
     }
-    
+
+    /**
+     * Checks the default values of elements.<p/>
+     * Also checks that the type of elements is not one of ID, IDREF, IDREFS, ENTITY, ENTITIES or
+     * NOTATION as per XMLSchema part 2.
+     * @param model
+     * @param location
+     * @param parentType
+     */
     private static void checkElementDefaults(SchemaParticle model, XmlObject location, SchemaType parentType)
     {
         if (model == null)
@@ -244,8 +283,54 @@
                             (constraintLocation==null ? location : constraintLocation));
                     }
                 }
+                // Checks if the type is one of the "attribute-specific" types
+                String warningType = null;
+                if (BuiltinSchemaTypeSystem.ST_ID.isAssignableFrom(model.getType()))
+                    warningType = BuiltinSchemaTypeSystem.ST_ID.getName().getLocalPart();
+                else if (BuiltinSchemaTypeSystem.ST_IDREF.isAssignableFrom(model.getType()))
+                    warningType = BuiltinSchemaTypeSystem.ST_IDREF.getName().getLocalPart();
+                else if (BuiltinSchemaTypeSystem.ST_IDREFS.isAssignableFrom(model.getType()))
+                    warningType = BuiltinSchemaTypeSystem.ST_IDREFS.getName().getLocalPart();
+                else if (BuiltinSchemaTypeSystem.ST_ENTITY.isAssignableFrom(model.getType()))
+                    warningType = BuiltinSchemaTypeSystem.ST_ENTITY.getName().getLocalPart();
+                else if (BuiltinSchemaTypeSystem.ST_ENTITIES.isAssignableFrom(model.getType()))
+                    warningType = BuiltinSchemaTypeSystem.ST_ENTITIES.getName().getLocalPart();
+                else if (BuiltinSchemaTypeSystem.ST_NOTATION.isAssignableFrom(model.getType()))
+                {
+                    if (model.getType().getBuiltinTypeCode() == SchemaType.BTC_NOTATION)
+                    {
+                        StscState.get().recover(XmlErrorCodes.ELEM_NOTATION_TYPE_FORBIDDEN,
+                            new Object[]{ QNameHelper.pretty(model.getName()) },
+                            ((SchemaLocalElementImpl) model)._parseObject == null ? location :
+                            ((SchemaLocalElementImpl) model)._parseObject.selectAttribute("", "type"));
+                    }
+                    else
+                        warningType = BuiltinSchemaTypeSystem.ST_NOTATION.getName().getLocalPart();
+
+                    // Check that the Schema in which this is present doesn't have a targetNS
+                    boolean hasNS;
+                    SchemaType t = parentType;
+                    while (t.getOuterType() != null)
+                        t = t.getOuterType();
+                    if (t.isDocumentType())
+                        hasNS = t.getDocumentElementName().getNamespaceURI().length() > 0;
+                    else
+                        hasNS = t.getName().getNamespaceURI().length() > 0;
+                    if (hasNS)
+                        StscState.get().warning(XmlErrorCodes.ELEM_COMPATIBILITY_TARGETNS,
+                            new Object[] {QNameHelper.pretty(model.getName()) },
+                            ((SchemaLocalElementImpl) model)._parseObject == null ? location :
+                            ((SchemaLocalElementImpl) model)._parseObject);
+                }
+
+                if (warningType != null)
+                    StscState.get().warning(XmlErrorCodes.ELEM_COMPATIBILITY_TYPE, new Object[]
+                        { QNameHelper.pretty(model.getName()), warningType },
+                        ((SchemaLocalElementImpl) model)._parseObject == null ? location :
+                        ((SchemaLocalElementImpl) model)._parseObject.selectAttribute("", "type"));
+
                 break;
-                
+
            default:
                 // nothing to do.
                 break;

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/StscSimpleTypeResolver.java Tue Jun  2 22:45:52 2009
@@ -24,18 +24,18 @@
 import org.apache.xmlbeans.impl.regex.RegularExpression;
 import org.apache.xmlbeans.impl.regex.ParseException;
 import org.apache.xmlbeans.impl.common.QNameHelper;
-import org.apache.xmlbeans.XmlErrorCodes;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlInteger;
 import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlAnySimpleType;
 import org.apache.xmlbeans.SimpleValue;
+import org.apache.xmlbeans.XmlAnySimpleType;
 import org.apache.xmlbeans.XmlByte;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlErrorCodes;
+import org.apache.xmlbeans.XmlInteger;
+import org.apache.xmlbeans.XmlNonNegativeInteger;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlPositiveInteger;
 import org.apache.xmlbeans.XmlShort;
 import org.apache.xmlbeans.XmlUnsignedByte;
-import org.apache.xmlbeans.XmlPositiveInteger;
-import org.apache.xmlbeans.XmlNonNegativeInteger;
 import org.apache.xmlbeans.impl.xb.xsdschema.*;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument.Schema;
 
@@ -622,6 +622,7 @@
                         return true;
                 }
                 return false;
+
             default:
                 assert(false);
                 return false;
@@ -676,6 +677,13 @@
                         new Object[] { facetName, QNameHelper.pretty(baseImpl.getName()) }, facet);
                     continue;
                 }
+                else if (baseImpl.getPrimitiveType().getBuiltinTypeCode() == SchemaType.BTC_NOTATION
+                    && (code == SchemaType.FACET_LENGTH || code == SchemaType.FACET_MIN_LENGTH ||
+                    code == SchemaType.FACET_MAX_LENGTH))
+                {
+                    state.warning(XmlErrorCodes.FACETS_DEPRECATED_NOTATION,
+                        new Object[] {facetName, QNameHelper.pretty(baseImpl.getName()) }, facet);
+                }
                 if (seenFacet[code] && !isMultipleFacet(code))
                 {
                     state.error(XmlErrorCodes.DATATYPE_SINGLE_FACET_VALUE, null, facet);
@@ -984,6 +992,12 @@
             patternArray = EMPTY_REGEX_ARRAY;
         sImpl.setPatternFacet((patternArray.length > 0 || baseImpl.hasPatternFacet()));
         sImpl.setPatterns(patternArray);
+
+        // Check that, if the base type is NOTATION, there is an enumeration facet
+        // http://www.w3.org/TR/xmlschema-2/#NOTATION
+        if (baseImpl.getBuiltinTypeCode() == SchemaType.BTC_NOTATION)
+            if (sImpl.getEnumerationValues() == null)
+                state.recover(XmlErrorCodes.DATATYPE_ENUM_NOTATION, null, restriction);
     }
 
     private static XmlValueRef[] makeValueRefArray(XmlAnySimpleType[] source)

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java Tue Jun  2 22:45:52 2009
@@ -18,27 +18,27 @@
 import org.apache.xmlbeans.impl.common.IdentityConstraint;
 import org.apache.xmlbeans.impl.common.QNameHelper;
 import org.apache.xmlbeans.impl.common.ValidationContext;
-import org.apache.xmlbeans.impl.common.ValidatorListener.Event;
 import org.apache.xmlbeans.impl.common.ValidatorListener;
 import org.apache.xmlbeans.impl.common.XmlWhitespace;
 import org.apache.xmlbeans.impl.schema.SchemaTypeVisitorImpl;
 import org.apache.xmlbeans.impl.schema.SchemaTypeImpl;
-import org.apache.xmlbeans.impl.values.NamespaceContext;
-import org.apache.xmlbeans.impl.values.JavaUriHolderEx;
 import org.apache.xmlbeans.impl.values.JavaBase64HolderEx;
+import org.apache.xmlbeans.impl.values.JavaBooleanHolder;
 import org.apache.xmlbeans.impl.values.JavaBooleanHolderEx;
-import org.apache.xmlbeans.impl.values.XmlDateImpl;
 import org.apache.xmlbeans.impl.values.JavaDecimalHolderEx;
 import org.apache.xmlbeans.impl.values.JavaDoubleHolderEx;
-import org.apache.xmlbeans.impl.values.XmlDurationImpl;
 import org.apache.xmlbeans.impl.values.JavaFloatHolderEx;
 import org.apache.xmlbeans.impl.values.JavaHexBinaryHolderEx;
-import org.apache.xmlbeans.impl.values.JavaBooleanHolder;
-import org.apache.xmlbeans.impl.values.XmlQNameImpl;
+import org.apache.xmlbeans.impl.values.JavaNotationHolderEx;
 import org.apache.xmlbeans.impl.values.JavaQNameHolderEx;
 import org.apache.xmlbeans.impl.values.JavaStringEnumerationHolderEx;
-import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+import org.apache.xmlbeans.impl.values.JavaUriHolderEx;
+import org.apache.xmlbeans.impl.values.NamespaceContext;
+import org.apache.xmlbeans.impl.values.XmlDateImpl;
+import org.apache.xmlbeans.impl.values.XmlDurationImpl;
 import org.apache.xmlbeans.impl.values.XmlListImpl;
+import org.apache.xmlbeans.impl.values.XmlQNameImpl;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
 import org.apache.xmlbeans.GDate;
 import org.apache.xmlbeans.GDuration;
 import org.apache.xmlbeans.QNameSet;
@@ -178,15 +178,6 @@
         }
     }
 
-    // KHK: remove this
-    private void emitFieldError ( Event event, String message, QName offendingQName,
-                                  SchemaType expectedSchemaType, List expectedQNames,
-                                  int errorType, SchemaType badSchemaType )
-    {
-        emitFieldError(event, message, null, null, XmlError.SEVERITY_ERROR, offendingQName,
-            expectedSchemaType, expectedQNames, errorType, badSchemaType);
-    }
-
     private void emitFieldError ( Event event, String code, Object[] args, QName offendingQName,
                                   SchemaType expectedSchemaType, List expectedQNames,
                                   int errorType, SchemaType badSchemaType )
@@ -1398,9 +1389,17 @@
             break;
         }
         case SchemaType.BTC_NOTATION :
-            // Unimplemented.
-            _stringValue = value;
+        {
+            QName n =
+                JavaNotationHolderEx.validateLexical(
+                    value, type, _vc, event );
+
+            if (errorState == _errorState)
+                JavaNotationHolderEx.validateValue( n, type, _vc );
+
+            _qnameValue = n;
             break;
+        }
 
         default :
             throw new RuntimeException( "Unexpected primitive type code" );
@@ -1711,8 +1710,8 @@
                 }
             case SchemaType.BTC_NOTATION :
                 {
-                    _listValue.add(_stringValue);
-                    _stringValue = null;
+                    _listValue.add(_qnameValue);
+                    _qnameValue = null;
                     break;
                 }
 

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaNotationHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaNotationHolderEx.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaNotationHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaNotationHolderEx.java Tue Jun  2 22:45:52 2009
@@ -17,6 +17,13 @@
 
 import org.apache.xmlbeans.SchemaType;
 import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlAnySimpleType;
+import org.apache.xmlbeans.XmlErrorCodes;
+import org.apache.xmlbeans.impl.common.ValidationContext;
+import org.apache.xmlbeans.impl.common.PrefixResolver;
+import org.apache.xmlbeans.impl.common.QNameHelper;
+
+import javax.xml.namespace.QName;
 
 public abstract class JavaNotationHolderEx extends JavaNotationHolder
 {
@@ -51,13 +58,49 @@
     protected void set_notation(String v)
     { set_text(v); }
 
+    protected void set_xmlanysimple(XmlAnySimpleType value)
+    {
+        QName v;
+        if (_validateOnSet())
+        {
+            v = validateLexical(value.getStringValue(), _schemaType, _voorVc, NamespaceContext.getCurrent());
+
+            if (v != null)
+                validateValue(v, _schemaType, _voorVc);
+        }
+        else
+            v = JavaNotationHolder.validateLexical(value.getStringValue(), _voorVc, NamespaceContext.getCurrent());
+
+        super.set_QName(v);
+    }
+
+    public static QName validateLexical(String v, SchemaType sType, ValidationContext context, PrefixResolver resolver)
+    {
+        QName name = JavaQNameHolder.validateLexical(v, context, resolver);
+
+        // check pattern
+        if (sType.hasPatternFacet())
+        {
+            if (!sType.matchPatternFacet(v))
+            {
+                // TODO - describe string and pattern here in error
+                context.invalid(XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
+                    new Object[] { "NOTATION", v, QNameHelper.readable(sType) });
+            }
+        }
+
+        check(v, sType);
+
+        return name;
+    }
+
     private static boolean check(String v, SchemaType sType)
     {
         // check against length
         XmlObject len = sType.getFacet(SchemaType.FACET_LENGTH);
         if (len != null)
         {
-            int m = ((XmlObjectBase)len).bigIntegerValue().intValue();
+            int m = ((XmlObjectBase)len).getBigIntegerValue().intValue();
             if (!(v.length() != m))
                 return false;
         }
@@ -66,7 +109,7 @@
         XmlObject min = sType.getFacet(SchemaType.FACET_MIN_LENGTH);
         if (min != null)
         {
-            int m = ((XmlObjectBase)min).bigIntegerValue().intValue();
+            int m = ((XmlObjectBase)min).getBigIntegerValue().intValue();
             if (!(v.length() >= m))
                 return false;
         }
@@ -75,7 +118,7 @@
         XmlObject max = sType.getFacet(SchemaType.FACET_MAX_LENGTH);
         if (max != null)
         {
-            int m = ((XmlObjectBase)max).bigIntegerValue().intValue();
+            int m = ((XmlObjectBase)max).getBigIntegerValue().intValue();
             if (!(v.length() <= m))
                 return false;
         }
@@ -83,4 +126,17 @@
         return true;
     }
 
+    public static void validateValue(QName v, SchemaType sType, ValidationContext context)
+    {
+        XmlObject[] vals = sType.getEnumerationValues();
+        if (vals != null)
+        {
+            for (int i = 0; i < vals.length; i++)
+                if (v.equals(((XmlObjectBase)vals[i]).getQNameValue()))
+                    return;
+            context.invalid(XmlErrorCodes.DATATYPE_ENUM_VALID,
+                new Object[] { "NOTATION", v, QNameHelper.readable(sType) });
+        }
+    }
+
 }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolderEx.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolderEx.java Tue Jun  2 22:45:52 2009
@@ -87,7 +87,7 @@
     public static QName validateLexical(String v, SchemaType sType, ValidationContext context, PrefixResolver resolver)
     {
         QName name = JavaQNameHolder.validateLexical(v, context, resolver);
-        
+
         // check pattern
         if (sType.hasPatternFacet())
         {
@@ -128,7 +128,7 @@
         if (vals != null)
         {
             for (int i = 0; i < vals.length; i++)
-                if (v.equals(((XmlObjectBase)vals[i]).qNameValue()))
+                if (v.equals(((XmlObjectBase)vals[i]).getQNameValue()))
                     return;
             context.invalid(XmlErrorCodes.DATATYPE_ENUM_VALID,
                 new Object[] { "QName", v, QNameHelper.readable(sType) });
@@ -137,7 +137,7 @@
 
     protected void validate_simpleval(String lexical, ValidationContext ctx)
     {
-        validateValue(qNameValue(), schemaType(), ctx);
+        validateValue(getQNameValue(), schemaType(), ctx);
     }
 
 }

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java Tue Jun  2 22:45:52 2009
@@ -951,6 +951,12 @@
     public static final String FACETS_APPLICABLE = "cos-applicable-facets"; // KHK: name ok?
 
     /**
+     * notation-facets: See
+     * http://www.w3.org/TR/xmlschema-2/#NOTATION-facets
+     */
+    public static final String FACETS_DEPRECATED_NOTATION = "notation-facets";
+
+    /**
      * cos-aw-intersect: See
      * <a href="http://www.w3c.org/TR/xmlschema-1/#cos-aw-intersect">XMLSchema Structures 1.0: Attribute Wildcard Intersection</a>
      */
@@ -963,6 +969,17 @@
     public static final String ATTR_WILDCARD_UNION = "cos-aw-union";
 
     /**
+     * enumeration-required-notation: See
+     * <a href="http://www.w3.org/TR/xmlschema-2/#enumeration-required-notation">XMLSchema Datatypes 1.0: Schema Component Constraint: enumeration facet value required for NOTATION</a>
+     */
+    public static final String ATTR_NOTATION_TYPE_FORBIDDEN = "enumeration-required-notation-attr";
+
+    /**
+     * <a href="http://www.w3c.org/TR/xmlschema-2/#NOTATION">XMLSchema Datatypes 1.0: Definition of type NOTATION</>
+     */
+    public static final String ATTR_COMPATIBILITY_TARGETNS = "notation-targetns-attr";
+
+    /**
      * cos-choice-range: See
      * <a href="http://www.w3c.org/TR/xmlschema-1/#cos-choice-range">XMLSchema Structures 1.0: Effective Total Range (choice)</a>
      */
@@ -1131,6 +1148,16 @@
     public static final String ELEM_DEFAULT_VALID$MIXED_AND_EMPTIABLE = "cos-valid-default.2.2.2";
 
     /**
+     * <a href="http://www.w3c.org/TR/xmlschema-2/#ID">XMLSchema Datatypes 1.0: Definitions of types ID, IDREF, IDREFS, ENTITY, ENTITIES, NOTATION</>
+     */
+    public static final String ELEM_COMPATIBILITY_TYPE = "id-idref-idrefs-entity-entities-notation";
+
+    /**
+     * <a href="http://www.w3c.org/TR/xmlschema-2/#NOTATION">XMLSchema Datatypes 1.0: Definition of type NOTATION</>
+     */
+    public static final String ELEM_COMPATIBILITY_TARGETNS = "notation-targetns-elem";
+
+    /**
      * ct-props-correct: See
      * <a href="http://www.w3c.org/TR/xmlschema-1/#ct-props-correct">XMLSchema Structures 1.0: Complex Type Definition Properties Correct</a>
      */
@@ -1264,6 +1291,12 @@
 
     /**
      * enumeration-required-notation: See
+     * <a href="http://www.w3.org/TR/xmlschema-2/#enumeration-required-notation">XMLSchema Datatypes 1.0: Schema Component Constraint: enumeration facet value required for NOTATION</a>
+     */
+    public static final String ELEM_NOTATION_TYPE_FORBIDDEN = "enumeration-required-notation-elem";
+
+    /**
+     * enumeration-required-notation: See
      * <a href="http://www.w3c.org/TR/xmlschema-2/#enumeration-required-notation">XMLSchema Datatypes 1.0: enumeration facet value required for NOTATION</a>
      */
     public static final String DATATYPE_ENUM_NOTATION = "enumeration-required-notation";

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/message.properties
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/message.properties?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/message.properties (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/message.properties Tue Jun  2 22:45:52 2009
@@ -585,6 +585,9 @@
 cos-valid-default.2.2.2 = \
 The {0} element cannot have a {1} value ''{2}'' because it's content is mixed but not emptiable.
 
+id-idref-idrefs-entity-entities-notation = \
+For compatibility, type ''{1}'' should only be used for attributes (used for element ''{0}'').
+
 ct-props-correct = \
 Complex Type Definition Properties Correct
 
@@ -651,9 +654,18 @@
 e-props-correct.4a = \
 Element ''{0}'' is not a valid substitution for element ''{1}'' with final=''{2}''
 
+notation-targetns-attr = \
+For compatibility, NOTATION should only be used in schemas with no target namespace (attribute ''{0}'').
+
+notation-targetns-elem = \
+For compatibility, NOTATION should only be used in schemas with no target namespace (element ''{0}'').
+
 enumeration-required-notation = \
 enumeration facet value required for NOTATION
 
+notation-facets = \
+The use of {0} on datatypes derived from NOTATION (''{1}'') is deprecated.
+
 enumeration-valid-restriction = \
 Enumerated value ''{0}'' invalid: {1}
 
@@ -726,6 +738,12 @@
 no-xsi = \
 Illegal namespace for attribute declaration: {0}
 
+enumeration-required-notation-attr = \
+It is an error for NOTATION to be used directly in a schema. Only datatypes that are derived from NOTATION by specifying a value for enumeration can be used in a schema (attribute ''{0}'').
+
+enumeration-required-notation-elem = \
+It is an error for NOTATION to be used directly in a schema. Only datatypes that are derived from NOTATION by specifying a value for enumeration can be used in a schema (element ''{0}'').
+
 p-props-correct = \
 Particle Correct
 

Modified: xmlbeans/trunk/test/src/compile/scomp/detailed/DetailedCompTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/test/src/compile/scomp/detailed/DetailedCompTests.java?rev=781199&r1=781198&r2=781199&view=diff
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/detailed/DetailedCompTests.java (original)
+++ xmlbeans/trunk/test/src/compile/scomp/detailed/DetailedCompTests.java Tue Jun  2 22:45:52 2009
@@ -20,6 +20,7 @@
 import junit.framework.TestSuite;
 import junit.framework.Assert;
 import org.apache.xmlbeans.*;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
 
 import java.io.File;
 import java.util.*;
@@ -114,4 +115,175 @@
 
     }
 
+    private static final String schema_begin = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n";
+    private static final String root_decl    = "<xs:element name=\"root\">\n  <xs:complexType>\n";
+    private static final String att_decl     = "    <xs:attribute name=\"att\" type=\"simpleNotType\"/>\n";
+    private static final String root_end     = "  </xs:complexType>\n</xs:element>\n";
+    private static final String schema_end   = "</xs:schema>\n";
+
+    private static final String notation1    = "    <xs:attribute name=\"att\" type=\"xs:NOTATION\"/>\n";
+    private static final String notation2    = "<xs:simpleType name=\"simpleNotType\">\n" +
+                                               "  <xs:restriction base=\"xs:NOTATION\">\n" +
+                                               "    <xs:pattern value=\"ns:.*\"/>\n" +
+                                               "  </xs:restriction>\n</xs:simpleType>\n";
+    private static final String notation3    = "    <xs:sequence>\n      " +
+                                               "<xs:element name=\"elem\" type=\"xs:ID\"/>\n" +
+                                               "    </xs:sequence>\n";
+    private static final String notation4    = " targetNamespace=\"scomp.detailed.CompilationTests\" " +
+                                               "xmlns=\"scomp.detailed.CompilationTests\">\n";
+    private static final String simpleTypeDef= "<xs:simpleType name=\"simpleNotType\">\n" +
+                                               "  <xs:restriction base=\"enumDef\">\n";
+    private static final String notation6    = "    <xs:pattern value=\"ns:.*\"/>\n";
+    private static final String notation5    = "    <xs:length value=\"6\"/>\n";
+    private static final String enumDef      = "  </xs:restriction>\n</xs:simpleType>\n" +
+                                               "<xs:simpleType name=\"enumDef\">\n" +
+                                               "  <xs:restriction base=\"xs:NOTATION\" xmlns:ns=\"namespace.notation\">\n" +
+                                               "    <xs:enumeration value=\"ns:app1\"/>\n" +
+                                               "    <xs:enumeration value=\"ns:app2\"/>\n" +
+                                               "  </xs:restriction>\n</xs:simpleType>\n";
+
+    private static final String doc_begin    = "<root xmlns:ns=\"namespace.notation\" " +
+                                               "xmlns:app=\"namespace.notation\" att=\"";
+    private static final String doc_end      = "\"/>";
+    private static final String notation7    = "ns1:app1";
+    private static final String notation8    = "ns:app";
+    private static final String notation9    = "app:app1";
+    private static final String notation10   = "ns:app1";
+
+    /**
+     * This tests usage of the xs:NOTATION type
+     * @throws Exception
+     */
+    public void testNotation() throws Exception
+    {
+        String schema;
+        String xml;
+        SchemaTypeSystem typeSystem;
+        XmlObject[] parsedSchema = new XmlObject[1];
+        XmlObject parsedDoc;
+        XmlOptions opts = new XmlOptions();
+        ArrayList errors = new ArrayList();
+        opts.setErrorListener(errors);
+        opts.put("COMPILE_PARTIAL_TYPESYSTEM");
+
+        // 1. Negative test - Error if xs:NOTATION used directly
+        schema = schema_begin + root_decl + notation1 + root_end + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected error: NOTATION type cannot be used directly", errors.size() == 1);
+        assertEquals("Expected error: NOTATION type cannot be used directly",
+            XmlErrorCodes.ATTR_NOTATION_TYPE_FORBIDDEN, ((XmlError)errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
+
+        // 2. Negative test - Error if xs:NOTATION restricted without enumeration
+        schema = schema_begin + root_decl + att_decl + root_end + notation2 + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected error: restriction of NOTATION must use enumeration facet", errors.size() == 1);
+        assertEquals("Expected error: restriction of NOTATION must use enumeration facet",
+            XmlErrorCodes.DATATYPE_ENUM_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
+
+        // 3. Warning if xs:NOTATION used as type of an element
+        final String correctTypes = simpleTypeDef + notation6 + enumDef;
+        schema = schema_begin + root_decl + notation3 + root_end + correctTypes + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected warning: NOTATION-derived type should not be used on elements", errors.size() == 1);
+        assertEquals("Expected warning: NOTATION-derived type should not be used on elements",
+            XmlErrorCodes.ELEM_COMPATIBILITY_TYPE, ((XmlError)errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+        // 4. Warning if xs:NOTATION is used in a Schema with target namespace
+        schema = schema_begin.substring(0, schema_begin.length() - 2) + notation4 + root_decl +
+            att_decl + root_end + correctTypes + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace", errors.size() == 1);
+        assertEquals("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace",
+            XmlErrorCodes.ATTR_COMPATIBILITY_TARGETNS, ((XmlError)errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+        // 5. Warning - Deprecation of minLength, maxLength and length facets
+        schema = schema_begin + root_decl + att_decl + root_end + simpleTypeDef + notation5 +
+            enumDef + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected warning: length facet cannot be used on a type derived from NOTATION", errors.size() == 1);
+        assertEquals("Expected warning: length facet cannot be used on a type derived from NOTATION",
+            XmlErrorCodes.FACETS_DEPRECATED_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+        // 6. Positive test - Test restriction via enumeration, then same as 2
+        schema = schema_begin + root_decl + att_decl + root_end + correctTypes + schema_end;
+//        System.out.println(schema);
+        parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+        errors.clear();
+        typeSystem = XmlBeans.compileXsd(parsedSchema, null, opts);
+        assertTrue("Expected no errors or warnings", errors.size() == 0);
+        SchemaType docType = typeSystem.findDocumentType(new QName("", "root"));
+        SchemaType type = docType.getElementProperty(new QName("", "root")).getType().
+            getAttributeProperty(new QName("", "att")).getType();
+        assertEquals(type.getPrimitiveType().getBuiltinTypeCode(), SchemaType.BTC_NOTATION);
+
+        SchemaTypeLoader loader = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] {typeSystem,
+            XmlBeans.getBuiltinTypeSystem()});
+
+        // 7. Validation negative - Test error if QName has bad prefix
+        xml = doc_begin + notation7 + doc_end;
+        parsedDoc = loader.parse(xml, null, opts);
+        assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+        errors.clear();
+        parsedDoc.validate(opts);
+        // Both "prefix not found" and "pattern doesn't match" errors
+        assertTrue("Expected validation errors", errors.size() == 2);
+        // Unfortunately, can't get the error code because it is logged via an intermediate exception
+        assertTrue("Expected prefix not found error", ((XmlError) errors.get(0)).getMessage().
+            indexOf("Invalid QName") >= 0);
+        assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+//        System.out.println(xml);
+
+        // 8. Validation negative - Test error if QName has correct prefix but not in enumeration
+        xml = doc_begin + notation8 + doc_end;
+        parsedDoc = loader.parse(xml, null, opts);
+        assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+        errors.clear();
+        parsedDoc.validate(opts);
+        assertTrue("Expected validation errors", errors.size() == 1);
+        assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_ENUM_VALID,
+            ((XmlError) errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+//        System.out.println(xml);
+
+        // 9. Validation negative - Test error if QName doesn't match the extra facet
+        xml = doc_begin + notation9 + doc_end;
+        parsedDoc = loader.parse(xml, null, opts);
+        assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+        errors.clear();
+        parsedDoc.validate(opts);
+        assertTrue("Expected validation errors", errors.size() == 1);
+        assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
+            ((XmlError) errors.get(0)).getErrorCode());
+        assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+//        System.out.println(xml);
+
+        // 10. Validation positive - Test that validation can be performed correctly
+        xml = doc_begin + notation10 + doc_end;
+        parsedDoc = loader.parse(xml, null, opts);
+        assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+        errors.clear();
+        parsedDoc.validate(opts);
+        assertTrue("Expected no validation errors", errors.size() == 0);
+//        System.out.println(xml);
+    }
 }



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