com.saxonica.schema
Class AttributeGroupDecl

java.lang.Object
  extended by com.saxonica.schema.SchemaStructure
      extended by com.saxonica.schema.AttributeGroupDecl
All Implemented Interfaces:
SerializableSchemaComponent, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent

public final class AttributeGroupDecl
extends SchemaStructure
implements UserSchemaComponent, SerializableSchemaComponent

An XML Schema Attribute Group Declaration. This represents a named attribute group, but not an attribute group reference. As well as attribute groups explicitly written in the schema using xsl:attributeGroup, this class is also used to represent any collection of attributes defined using xsl:attribute elements as part of a complex type definition.

In contrast with the Attribute Group Definition schema component as defined in the W3C specification, the model retains explicit references to subsidiary attribute group definitions. However, the method getAttributeUses() performs the transitive closure of these references, returning all the attributes at the leaves of the tree.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.saxon.type.SchemaComponent
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
AttributeGroupDecl(SchemaAwareConfiguration config)
          Creates a new AttributeGroup definition.
 
Method Summary
 void addAttributeGroupReference(AttributeGroupReference attrGroup)
          Adds the given AttributeGroupReference to this AttributeGroup.
 void addAttributeUse(AttributeUse use)
          Add the given attribute use to this AttributeGroup.
 boolean fixup(SchemaCompiler compiler)
          Check references from this component to other components
 void gatherAttributeUses(List list)
          Append all attribute declarations contained directly or indirectly in this attribute group to a supplied List.
 AttributeUse getAttributeUse(int fingerprint)
          Get the attribute use with a specific name, if there is one.
 Iterator getAttributeUses()
          Returns an Iterator over all the attribute uses of this attribute group.
 AttributeWildcard getAttributeWildcard(SchemaCompiler compiler)
          Get the complete attribute wildcard used in this attribute group.
 IntHashMap getDeclaredAttributes()
          Get a HashMap containing all the attributes in this attribute group, expanded recursively.
 String getDisplayName()
          Return the name of this AttributeGroup, for display purposes
 int getFingerprint()
          Get the fingerprint of the name of the attribute group
 Iterator getLocalAttributeGroupReferences()
          Returns the AttributeGroup references contained locally in this attribute group.
 Iterator getLocalAttributes()
          Returns the attributes defined locally in this attribute group.
 AttributeWildcard getLocalAttributeWildcard()
          Get the local attribute wildcard used in this attribute group
 String getName()
          Returns the local part of the name of this named AttributeGroup.
 String getTargetNamespace()
          Returns the namespace URI of the name of this named AttributeGroup.
 boolean isSameDeclaration(AttributeGroupDecl other)
          Test whether this is the same type as another type.
 boolean isValidRestriction(AttributeGroupDecl base, SchemaCompiler compiler)
          Test whether this attribute group is a valid restriction of another attribute group.
 void lookForCycles(Stack references, SchemaCompiler compiler)
          Check for cycles in the attribute group.
 void serialize(SchemaModelSerializer serializer)
          Serialize the schema component
 void serializeContents(SchemaModelSerializer serializer)
          Serialize the list of attribute users and wildcard
 void setAnyAttribute(AttributeWildcard wildcard)
          Sets the wildcard (anyAttribute) of this attribute Group.
 void setNameCode(int nameCode)
          Set the nameCode of the name of this attribute group.
 void setRedefinedAttributeGroupDecl(AttributeGroupDecl other)
          Set the attribute group that this attribute group redefines.
 boolean validate(SchemaCompiler compiler)
          Check the validity of this AttributeGroup declaration.
 
Methods inherited from class com.saxonica.schema.SchemaStructure
elaborate, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getSystemId, getValidationStatus, setConfiguration, setFixupStatus, setLineNumber, setLocator, setSystemId, setValidationStatus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.saxonica.schema.UserSchemaComponent
elaborate
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getValidationStatus
 

Constructor Detail

AttributeGroupDecl

public AttributeGroupDecl(SchemaAwareConfiguration config)
Creates a new AttributeGroup definition. For internal use only.

Parameters:
config - the SchemaAwareConfiguration that this AttributeGroup belongs to.
Method Detail

getName

public String getName()
Returns the local part of the name of this named AttributeGroup.

Returns:
the local name of this named AttributeGroup.

getTargetNamespace

public String getTargetNamespace()
Returns the namespace URI of the name of this named AttributeGroup.

Returns:
the namespace URI of this named AttributeGroup: null if the attribute group is in no namespace

addAttributeUse

public void addAttributeUse(AttributeUse use)
Add the given attribute use to this AttributeGroup. Doesn't throw an error if it's a duplicate: this is left until validation time. For internal use only.

Parameters:
use - the AttributeUse to add

addAttributeGroupReference

public void addAttributeGroupReference(AttributeGroupReference attrGroup)
Adds the given AttributeGroupReference to this AttributeGroup. For internal use only.

Parameters:
attrGroup - the AttributeGroupReference to add

setRedefinedAttributeGroupDecl

public void setRedefinedAttributeGroupDecl(AttributeGroupDecl other)
Set the attribute group that this attribute group redefines. This is called only for an attribute group that redefined another one, *without* a self-reference

Parameters:
other - the attribute group declaration that this attribute group redefines

getLocalAttributes

public Iterator getLocalAttributes()
Returns the attributes defined locally in this attribute group. (not those of the nested groups)

Returns:
an iterator over the attribute uses defined locally in this attribute group. The objects returned by the iterator are instances of AttributeDecl

getLocalAttributeGroupReferences

public Iterator getLocalAttributeGroupReferences()
Returns the AttributeGroup references contained locally in this attribute group. (not those of the nested groups)

Returns:
an iterator over the locally-defined attribute groups. The objects returned by this iterator are instances of AttributeGroupReference

lookForCycles

public void lookForCycles(Stack references,
                          SchemaCompiler compiler)
                   throws SchemaException
Check for cycles in the attribute group.

Specified by:
lookForCycles in interface UserSchemaComponent
Overrides:
lookForCycles in class SchemaStructure
Parameters:
references - The attribute groups that contain direct or indirect references to this attribute group
compiler - used to report errors and warnings
Throws:
SchemaException - if a circularity is detected.

getLocalAttributeWildcard

public AttributeWildcard getLocalAttributeWildcard()
Get the local attribute wildcard used in this attribute group

Returns:
the wildcard used in this complexType if there is one; otherwise return null.

getAttributeWildcard

public AttributeWildcard getAttributeWildcard(SchemaCompiler compiler)
                                       throws UnresolvedReferenceException
Get the complete attribute wildcard used in this attribute group. This takes into account any attribute wildcards used in contained attribute groups. The rules are given in Schema Part 1 section 3.4.2. The returned wildcard is the intersection of the attribute wildcards in the various attribute groups: that is, a wildcard that allows only what each one of these wildcards allows.

Parameters:
compiler - Used for error reporting. May be null if used at validation time.
Returns:
the combined wildcard used in this attribute group. This can be null. It can also be "inexpressible". This results in an AttributeWildcard marked as being inexpressible, an error condition that the caller is left to deal with.
Throws:
UnresolvedReferenceException

getAttributeUses

public Iterator getAttributeUses()
Returns an Iterator over all the attribute uses of this attribute group. The iteration includes attributes from all attribute groups references contained in this AttributeGroup.

Returns:
an Iterator over all the attributes of this attribute group, expanded recursively. The objects returned by this Iterator are AttributeDecl objects. The iterator does not include attribute wildcards.

gatherAttributeUses

public void gatherAttributeUses(List list)
Append all attribute declarations contained directly or indirectly in this attribute group to a supplied List. The AttributeGroupDecl must have been validated before this method is called.

Parameters:
list - the list to which the contained attribute declarations should be appended

getDisplayName

public String getDisplayName()
Return the name of this AttributeGroup, for display purposes

Returns:
the name of this AttributeGroup, or null, if no name was defined.

setAnyAttribute

public void setAnyAttribute(AttributeWildcard wildcard)
Sets the wildcard (anyAttribute) of this attribute Group. It is the caller's responsibility to ensure that only one attribute wildcard is defined in an attribute group.

Parameters:
wildcard - the wildcard defining the xs:anyAttribute content of this attribute group, if any.

fixup

public boolean fixup(SchemaCompiler compiler)
              throws SchemaException
Check references from this component to other components

Specified by:
fixup in interface UserSchemaComponent
Overrides:
fixup in class SchemaStructure
Parameters:
compiler - used for reporting errors and warnings
Returns:
true if all is well, false if errors found
Throws:
SchemaException

validate

public boolean validate(SchemaCompiler compiler)
                 throws SchemaException
Check the validity of this AttributeGroup declaration. For internal use only. Any errors found are reported to the error listener.

Specified by:
validate in interface UserSchemaComponent
Parameters:
compiler - used for reporting errors and warnings
Returns:
true if the declaration is valid, false if not
Throws:
SchemaException - if this Attribute declaration is invalid and the error listener chooses to treat the error as fatal.

isValidRestriction

public boolean isValidRestriction(AttributeGroupDecl base,
                                  SchemaCompiler compiler)
                           throws SchemaException
Test whether this attribute group is a valid restriction of another attribute group. If it is not a valid restriction, an error is reported to the error listener and the method returns false.

Parameters:
base - the other attribute group
compiler - user for reporting errors and warnings
Returns:
true if this is a valid restriction, false if not
Throws:
SchemaException - if an error is detected and the error listener decides to treat the error as fatal.

isSameDeclaration

public boolean isSameDeclaration(AttributeGroupDecl other)
Test whether this is the same type as another type. They are considered to be the same type if they are derived from the same type definition in the original XML representation (which can happen when there are multiple includes of the same file)

Parameters:
other - the attribute group declaration that we are comparing with
Returns:
true if the two attribute group declarations are identical

getFingerprint

public int getFingerprint()
Get the fingerprint of the name of the attribute group

Returns:
the NamePool fingerprint of the attribute group's expanded name

setNameCode

public void setNameCode(int nameCode)
Set the nameCode of the name of this attribute group. For internal use only.

Parameters:
nameCode - the fingerprint of the name, in the NamePool

getDeclaredAttributes

public IntHashMap getDeclaredAttributes()
Get a HashMap containing all the attributes in this attribute group, expanded recursively. The key is the integer fingerprint identifying the name of the attribute. The value is an AttributeUse object identifying the attribute declaration.

Returns:
a map defining the attributes in the attribute group

getAttributeUse

public final AttributeUse getAttributeUse(int fingerprint)
Get the attribute use with a specific name, if there is one. Otherwise return null.

Parameters:
fingerprint - the fingerprint identifying the expanded name of the required attribute in the name pool.
Returns:
the attribute with a given name, from among the transitively-expanded definition of this attribute group.

serialize

public void serialize(SchemaModelSerializer serializer)
               throws XPathException
Serialize the schema component

Specified by:
serialize in interface SerializableSchemaComponent
Throws:
XPathException

serializeContents

public void serializeContents(SchemaModelSerializer serializer)
                       throws XPathException
Serialize the list of attribute users and wildcard

Parameters:
serializer - the object to which the information is to be sent
Throws:
XPathException


Copyright (C) Michael H. Kay. All rights reserved.