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 2004/10/30 23:48:46 UTC

cvs commit: xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans GDuration.java XmlErrorCodes.java message.properties

radup       2004/10/30 14:48:46

  Modified:    v2/src/common/org/apache/xmlbeans/impl/common
                        IdentityConstraint.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/schema
                        StscTranslator.java
               v2/src/xmlpublic/org/apache/xmlbeans GDuration.java
                        XmlErrorCodes.java message.properties
  Log:
  Fixed a bug in keyref validation and added a check of the fixed value for attribute ref.
  
  Revision  Changes    Path
  1.7       +38 -8     xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/IdentityConstraint.java
  
  Index: IdentityConstraint.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/IdentityConstraint.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IdentityConstraint.java	26 Sep 2004 05:08:38 -0000	1.6
  +++ IdentityConstraint.java	30 Oct 2004 21:48:46 -0000	1.7
  @@ -298,8 +298,8 @@
                   if (cs instanceof KeyrefState)
                   {
                       KeyrefState kr = (KeyrefState)cs;
  -                    if (kr._constraint.getReferencedKey() == this)
  -                        kr.addKeyValues(_values);
  +                    if (kr._constraint.getReferencedKey() == this._constraint)
  +                        kr.addKeyValues(_values, true);
                   }
               }
           }
  @@ -309,16 +309,46 @@
       }
   
       public class KeyrefState extends SelectorState {
  -        Set _keyValues = new HashSet();
  +        Map _keyValues = new HashMap();
  +        private Object CHILD_ADDED = new Object();
  +        private Object CHILD_REMOVED = new Object();
  +        private Object SELF_ADDED = new Object();
   
           KeyrefState(SchemaIdentityConstraint constraint, Event e, SchemaType st) {
               super(constraint, e, st);
           }
   
  -        void addKeyValues(final Set values)
  +        void addKeyValues(final Set values, boolean child)
           {
  -            // BUG: remove duplicates
  -            _keyValues.addAll(values);
  +            /** If the key values are added by children, then if two or
  +             more children add the same value, the value dissapears from the map
  +             but if is added by the element in question directly then it will
  +             be present in the map regardless of what children contained */
  +            for (Iterator it = values.iterator(); it.hasNext();)
  +            {
  +                Object key = it.next();
  +                Object value = _keyValues.get(key);
  +                if (value == null)
  +                    _keyValues.put(key, child ? CHILD_ADDED : SELF_ADDED);
  +                else if (value == CHILD_ADDED)
  +                {
  +                    if (child)
  +                        _keyValues.put(key, CHILD_REMOVED);
  +                    else
  +                        _keyValues.put(key, SELF_ADDED);
  +                }
  +                else if (value == CHILD_REMOVED)
  +                {
  +                    if (!child)
  +                        _keyValues.put(key, SELF_ADDED);
  +                }
  +            }
  +        }
  +
  +        private boolean hasKeyValue(Object key)
  +        {
  +            Object value = _keyValues.get(key);
  +            return value != null && value != CHILD_REMOVED;
           }
   
           void remove(Event e) {
  @@ -330,7 +360,7 @@
                   {
                       SelectorState sel = (SelectorState)cs;
                       if (sel._constraint == _constraint.getReferencedKey())
  -                        addKeyValues(sel._values);
  +                        addKeyValues(sel._values, false);
                   }
               }
   
  @@ -340,7 +370,7 @@
               {
   
                   XmlObjectList fields = (XmlObjectList)it.next();
  -                if (fields.unfilled() < 0 && ! _keyValues.contains(fields))
  +                if (fields.unfilled() < 0 && ! hasKeyValue(fields))
                   {
                       // KHK: cvc-identity-constraint.4.3 ?
                       emitError(e, "Key '" + fields + "' not found (keyRef " + QNameHelper.pretty(_constraint.getName()) + ")");
  
  
  
  1.13      +11 -0     xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java
  
  Index: StscTranslator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/StscTranslator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StscTranslator.java	29 Sep 2004 01:26:57 -0000	1.12
  +++ StscTranslator.java	30 Oct 2004 21:48:46 -0000	1.13
  @@ -1036,6 +1036,7 @@
   
           boolean isFixed = false;
           String deftext = null;
  +        String fmrfixedtext = null;
           QName qname;
           SchemaLocalAttributeImpl sAttr;
           SchemaType sType = null;
  @@ -1084,6 +1085,8 @@
               if (deftext != null)
               {
                   isFixed = referenced.isFixed();
  +                if (isFixed)
  +                    fmrfixedtext = deftext;
               }
           }
           else
  @@ -1180,6 +1183,14 @@
                   isFixed = false;
               }
               deftext = isFixed ? xsdAttr.getFixed() : xsdAttr.getDefault();
  +            // BUGBUG(radup) this is not good, since they should be compared by value
  +            // in StscChecker; but there we don't have yet access to the referred attr
  +            if (fmrfixedtext != null && !fmrfixedtext.equals(deftext))
  +            {
  +                state.error(XmlErrorCodes.SCHEMA_ATTR$FIXED_NOT_MATCH, null, xsdAttr.xgetFixed());
  +                // recovery: reset fixed to the original value
  +                deftext = fmrfixedtext;
  +            }
           }
   
           if (!local)
  
  
  
  1.3       +1 -0      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/GDuration.java
  
  Index: GDuration.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/GDuration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GDuration.java	12 Feb 2004 20:06:27 -0000	1.2
  +++ GDuration.java	30 Oct 2004 21:48:46 -0000	1.3
  @@ -201,6 +201,7 @@
        * Constructs a GDuration with the specified sign,
        * year, month, day, hours, minutes, seconds, and optional
        * fractional seconds.
  +     * @parameter sign +1 for a positive duration, -1 for a negative duration
        */
       public GDuration(
               int sign,
  
  
  
  1.7       +6 -0      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java
  
  Index: XmlErrorCodes.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlErrorCodes.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XmlErrorCodes.java	29 Sep 2004 01:26:57 -0000	1.6
  +++ XmlErrorCodes.java	30 Oct 2004 21:48:46 -0000	1.7
  @@ -550,6 +550,12 @@
       public static final String SCHEMA_ATTR$DEFAULT_OR_FIXED = "src-attribute.1";
   
       /**
  +     * au-value_constraint: See description for
  +     * <a href="http://www.w3.org/TR/xmlschema-1/#au-value_constraint">XMLSchema Structures 1.0: The Attribute Use Schema Component</a>
  +     */
  +    public static final String SCHEMA_ATTR$FIXED_NOT_MATCH = "au-value_constraint";
  +
  +    /**
        * src-attribute.2: See clause 2 of
        * <a href="http://www.w3c.org/TR/xmlschema-1/#src-attribute">XMLSchema Structures 1.0: Attribute Declaration Representation OK</a>
        */
  
  
  
  1.7       +3 -0      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/message.properties
  
  Index: message.properties
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/message.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- message.properties	29 Sep 2004 01:26:57 -0000	1.6
  +++ message.properties	30 Oct 2004 21:48:46 -0000	1.7
  @@ -269,6 +269,9 @@
   src-attribute.1 = \
   Either default or fixed may be present on attribute ''{0}'', but not both.
   
  +au-value_constraint = \
  +The fixed value on attribute must match that of the referenced attribute.
  +
   src-attribute.2 = \
   The attribute ''{0}'' declaration must be optional in order to specify a default.
   
  
  
  

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