xsdata.codegen.handlers.class_extension module

class xsdata.codegen.handlers.class_extension.ClassExtensionHandler(container)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Reduce class extensions by copying or creating new attributes.

Parameters

container (ContainerInterface) –

REMOVE_EXTENSION = 0
FLATTEN_EXTENSION = 1
IGNORE_EXTENSION = 2
container: xsdata.codegen.mixins.ContainerInterface
process(target)[source]

Iterate and process the target class’s extensions in reverser order.

The reverse order is necessary in order to maintain the correct attributes ordering during cloning.

Parameters

target (Class) –

process_extension(target, extension)[source]

Slit the process of extension into schema data types and user defined types.

Parameters
classmethod process_native_extension(target, extension)[source]

Native type flatten handler.

In case of enumerations copy the native data type to all enum members, otherwise create a default text value with the extension attributes.

Parameters
process_dependency_extension(target, extension)[source]

User defined type flatten handler.

Parameters
classmethod process_simple_extension(source, target, ext)[source]

Simple flatten extension handler for common classes eg SimpleType, Restriction.

Steps:
  1. If target is source: drop the extension.

  2. If source is enumeration and target isn’t create default value attribute.

  3. If both source and target are enumerations copy all attributes.

  4. If both source and target are not enumerations copy all attributes.

  5. If target is enumeration: drop the extension.

Parameters
classmethod process_complex_extension(source, target, ext)[source]

Complex flatten extension handler for primary classes eg ComplexType, Element.

Compare source and target classes and either remove the extension completely, copy all source attributes to the target class or leave the extension alone.

Parameters
find_dependency(attr_type)[source]

Find dependency for the given extension type with priority.

Search priority: xs:SimpleType > xs:ComplexType

Parameters

attr_type (AttrType) –

Return type

Optional[Class]

classmethod compare_attributes(source, target)[source]

Compare the attributes of the two classes and return whether the source class can and should be flattened.

Remove:
  1. Source is the Target

  2. Target includes all the source attributes

Flatten:
  1. Source includes some of the target attributes

  2. The source class is marked to be forced flattened

  3. Source class includes an attribute that needs to be last

  4. Target class includes an attribute that needs to be last

  5. Source class is a simple type

Parameters
Return type

int

classmethod copy_extension_type(target, extension)[source]

Add the given extension type to all target attributes types and remove it from the target class extensions.

Parameters
classmethod add_default_attribute(target, extension)[source]

Add a default value field to the given class based on the extension type.

Parameters
classmethod get_or_create_attribute(target, name, tag)[source]

Find or create for the given parameters an attribute in the target class.

Parameters
Return type

Attr