Appendix D. Spring.NET's spring-objects.xsd

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns="http://www.springframework.net" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense" targetNamespace="http://www.springframework.net" elementFormDefault="qualified" attributeFormDefault="unqualified" vs:friendlyname="Spring.NET Configuration" vs:ishtmlschema="false" vs:iscasesensitive="true" vs:requireattributequotes="true" vs:defaultnamespacequalifier="" vs:defaultnsprefix="">
    <xs:annotation>
        <xs:documentation>
            Spring Objects XML Schema Definition
            Based on Spring Beans DTD, authored by Rod Johnson &amp; Juergen Hoeller
            
            Author: Griffin Caprio
            
            This defines a simple and consistent way of creating a namespace
            of managed objects configured by a Spring XmlObjectFactory.
            This document type is used by most Spring functionality, including
            web application contexts, which are based on object factories.
            
            Each object element in this document defines an object.
            Typically the object type (System.Type is specified, along with plain vanilla
            object properties.
            
            Object instances can be "singletons" (shared instances) or "prototypes"
            (independent instances).
            
            References among objects are supported, i.e. setting an object property
            to refer to another object in the same factory or an ancestor factory.
            
            As alternative to object references, "inner object definitions" can be used.
            Singleton flags and names of such "inner object" are always ignored:
            Inner object are anonymous prototypes.
            
            There is also support for lists, dictionaries, and sets.
        </xs:documentation>
    </xs:annotation>
    <xs:annotation>
        <xs:documentation>Defines a base type for any required string.  Defines a string with a minimum length of 0</xs:documentation>
    </xs:annotation>
    <xs:simpleType name="nonNullString">
        <xs:restriction base="xs:string">
            <xs:minLength value="0"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:annotation>
        <xs:documentation>
            Element containing informative text describing the purpose of the enclosing
            element. Always optional.
            Used primarily for user documentation of XML object definition documents.
        </xs:documentation>
    </xs:annotation>
    <xs:simpleType name="description">
        <xs:restriction base="nonNullString"/>
    </xs:simpleType>
    <xs:complexType name="valueObject">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="type" type="nonNullString" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="expression">
      <xs:sequence>
        <xs:element name="property" type="property" minOccurs="0" maxOccurs="2"/>
      </xs:sequence>
      <xs:attribute name="value" type="nonNullString" use="required"/>
    </xs:complexType>
    <!--
         Defines a reference to another object in this factory or an external
         factory (parent or included factory).
    -->
    <xs:complexType name="objectReference">
        <xs:attribute name="object" type="nonNullString" use="optional"/>
        <xs:attribute name="local" type="xs:IDREF" use="optional"/>
        <xs:attribute name="parent" type="nonNullString" use="optional"/>
        <!--
             References must specify a name of the target object.
             The "object" attribute can reference any name from any object in the context,
             to be checked at runtime.
             Local references, using the "local" attribute, have to use object ids;
             they can be checked by this DTD, thus should be preferred for references
             within the same object factory XML file.
        -->
    </xs:complexType>
    <!-- Defines a reference to another object or a type. -->
    <xs:complexType name="objectOrClassReference">
        <xs:attribute name="object" type="nonNullString" use="optional"/>
        <xs:attribute name="local" type="xs:IDREF" use="optional"/>
        <xs:attribute name="type" type="nonNullString" use="optional"/>
    </xs:complexType>
    <xs:group name="objectList">
        <xs:sequence>
            <xs:element name="description" type="description" minOccurs="0"/>
            <xs:choice>
                <xs:element name="object" type="vanillaObject"/>
                <!--
                     Defines a reference to another object in this factory or an external
                     factory (parent or included factory).
                -->
                <xs:element name="ref" type="objectReference"/>
                <!--
                     Defines a string property value, which must also be the id of another
                     object in this factory or an external factory (parent or included factory).
                     While a regular 'value' element could instead be used for the same effect,
                     using idref in this case allows validation of local object ids by the xml
                     parser, and name completion by helper tools.
                -->
                <xs:element name="idref" type="objectReference"/>
                <!--
                     A objectList can contain multiple inner object, ref, collection, or value elements.
                     Lists are untyped, pending generics support, although references will be
                     strongly typed.
                     A objectList can also map to an array type. The necessary conversion
                     is automatically performed by AbstractObjectFactory.
                -->
                <xs:element name="list">
                    <xs:complexType>
                        <xs:group ref="objectList" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:attribute name="element-type" type="nonNullString" use="optional"/>
                    </xs:complexType>
                </xs:element>
                <!--
                     A set can contain multiple inner object, ref, collection, or value elements.
                     Sets are untyped, pending generics support, although references will be
                     strongly typed.
                -->
                <xs:element name="set">
                    <xs:complexType>
                        <xs:group ref="objectList" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:complexType>
                </xs:element>
                <!--
                     A Spring map is a mapping from a string key to object (a .NET IDictionary).
                     Maps may be empty.
                -->
                <xs:element name="dictionary" type="objectMap"/>
                <!--
                     Name-values elements differ from map elements in that values must be strings.
                     Name-values may be empty.
                -->
                <xs:element name="name-values" type="objectNameValues"/>
                <!--
                     Contains a string representation of a property value.
                     The property may be a string, or may be converted to the
                     required type using the System.ComponentModel.TypeConverter
                     machinery. This makes it possible for application developers
                     to write custom TypeConverter implementations that can
                     convert strings to objects.
                     
                     Note that this is recommended for simple objects only.
                     Configure more complex objects by setting properties to references
                     to other objects.
                -->
                <xs:element name="value" type="valueObject"/>
                <!--
                     Contains a string representation of an expression.
                -->
                <xs:element name="expression" type="expression"/>
                <!--
                     Denotes a .NET null value. Necessary because an empty "value" tag
                     will resolve to an empty String, which will not be resolved to a
                     null value unless a special TypeConverter does so.
                -->
                <xs:element name="null"/>
            </xs:choice>
        </xs:sequence>
    </xs:group>
    <xs:complexType name="objectNameValues">
        <xs:sequence>
            <!--
                 The "value" attribute is the string value of the property. The "key"
                 attribute is the name of the property.
            -->
            <xs:element name="add" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType mixed="true">
                    <xs:attribute name="key" type="nonNullString" use="required"/>
                    <xs:attribute name="value" use="required" type="xs:string"/>
                    <xs:attribute name="delimiters" use="optional" type="xs:string"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="importElement">
        <xs:attribute name="resource" type="nonNullString" use="required"/>
    </xs:complexType>
    <xs:complexType name="aliasElement">
        <xs:attribute name="name" type="nonNullString" use="required"/>
        <xs:attribute name="alias" type="nonNullString" use="required"/>
    </xs:complexType>
    <xs:complexType name="objectMap">
        <xs:sequence>
            <xs:element type="mapEntryElement" name="entry" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="key-type" type="nonNullString" use="optional"/>
        <xs:attribute name="value-type" type="nonNullString" use="optional"/>
    </xs:complexType>
    <xs:complexType name="mapEntryElement">
        <xs:sequence>
            <xs:element type="mapKeyElement" name="key" minOccurs="0" maxOccurs="1"/>
            <xs:group ref="objectList" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="key" type="nonNullString" use="optional"/>
        <xs:attribute name="value" type="nonNullString" use="optional"/>
        <xs:attribute name="expression" type="nonNullString" use="optional"/>
        <xs:attribute name="key-ref" type="nonNullString" use="optional"/>
        <xs:attribute name="value-ref" type="nonNullString" use="optional"/>
    </xs:complexType>
    <xs:complexType name="mapKeyElement">
        <xs:group ref="objectList" minOccurs="1"/>
    </xs:complexType>
    <xs:annotation>
        <xs:documentation>Defines constructor argument.</xs:documentation>
    </xs:annotation>
    <xs:complexType name="lookupMethod">
        <xs:attribute name="name" type="nonNullString" use="required"/>
        <xs:attribute name="object" type="nonNullString" use="required"/>
    </xs:complexType>
    <xs:complexType name="constructorArgument">
        <xs:group ref="objectList" minOccurs="0"/>
        <!--
              The constructor-arg tag can have an optional named parameter attribute,
              to specify a named parameter in the constructor argument list.
        -->
        <xs:attribute name="name" type="nonNullString" use="optional"/>
        <!--
              The constructor-arg tag can have an optional index attribute,
              to specify the exact index in the constructor argument list. Only needed
              to avoid ambiguities, e.g. in case of 2 arguments of the same type.
        -->
        <xs:attribute name="index" type="nonNullString" use="optional"/>
       <!--
              The constructor-arg tag can have an optional type attribute,
              to specify the exact type of the constructor argument. Only needed
              to avoid ambiguities, e.g. in case of 2 single argument constructors
              that can both be converted from a String.
        -->
        <xs:attribute name="type" type="nonNullString" use="optional"/>
        <xs:attribute name="value" type="nonNullString" use="optional"/>
        <xs:attribute name="expression" type="nonNullString" use="optional"/>
        <xs:attribute name="ref" type="nonNullString" use="optional"/>
    </xs:complexType>
    <xs:annotation>
        <xs:documentation>Defines property.</xs:documentation>
    </xs:annotation>
    <xs:complexType name="property">
        <xs:group ref="objectList" minOccurs="0"/>
        <!-- The property name attribute is the name of the objects property. -->
        <xs:attribute name="name" type="nonNullString" use="required"/>
        <xs:attribute name="value" type="nonNullString" use="optional"/>
        <xs:attribute name="expression" type="nonNullString" use="optional"/>
        <xs:attribute name="ref" type="nonNullString" use="optional"/>
    </xs:complexType>
    <xs:annotation>
        <xs:documentation>Defines a single named object.</xs:documentation>
    </xs:annotation>
    <xs:complexType name="vanillaObject">
        <xs:sequence>
            <xs:element name="description" type="description" minOccurs="0" maxOccurs="1"/>
            <!--
                 Object definitions can specify zero or more constructor arguments.
                 They correspond to either a specific index of the constructor argument list
                 or are supposed to be matched generically by type.
                 This is an alternative to "autowire constructor".
            -->
            <xs:element name="constructor-arg" type="constructorArgument" minOccurs="0" maxOccurs="unbounded"/>
            <!--
                 Object definitions can have zero or more properties.
                 Spring supports primitives, references to other objects in the same or
                 related factories, lists, dictionaries and properties.
            -->
            <xs:element name="property" type="property" minOccurs="0" maxOccurs="unbounded"/>
            <!--
                 Object definitions can specify zero or more lookup-methods.
            -->
            <xs:element name="lookup-method" type="lookupMethod" minOccurs="0" maxOccurs="unbounded"/>
            <!-- Object definitions can have zero or more replaced-methods. -->
            <xs:element name="replaced-method" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="arg-type" minOccurs="0" maxOccurs="unbounded">
                             <xs:complexType>
                                  <xs:attribute name="match" type="nonNullString" use="required"/>
                             </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                    <xs:attribute name="name" type="nonNullString" use="required"/>
                    <xs:attribute name="replacer" type="nonNullString" use="required"/>
                </xs:complexType>
            </xs:element>
            <!-- Object definitions can have zero or more subscriptions. -->
            <xs:element name="listener" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="ref" type="objectOrClassReference" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <!-- The event(s) the object is interested in. -->
                    <xs:attribute name="event" type="nonNullString" use="optional"/>
                    <!-- The name or name pattern of the method that will handle the event(s). -->
                    <xs:attribute name="method" type="nonNullString" use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <!--
             Objects can be identified by an id, to enable reference checking.
             There are constraints on a valid XML id: if you want to reference your object
             in .NET code using a name that's illegal as an XML id, use the optional
             "name" attribute. If neither given, the object type name is used as id.
        -->
        <xs:attribute name="id" type="xs:ID" use="optional"/>
        <!--
             Optional. Can be used to create one or more aliases illegal in an id.
             Multiple aliases can be separated by any number of spaces or commas.
        -->
        <xs:attribute name="name" type="nonNullString" use="optional"/>
        <!--
             Each object definition must specify the full, assembly qualified of the type,
             or the name of the parent object from which the type can be worked out.
             
             Note that a child object definition that references a parent will just
             add respectively override property values and be able to change the
             singleton status. It will inherit all of the parent's other parameters
             like lazy initialization or autowire settings.
        -->
        <xs:attribute name="type" type="nonNullString" use="optional"/>
        <xs:attribute name="parent" type="nonNullString" use="optional"/>
        <!--
             Is this object "abstract", i.e. not meant to be instantiated itself but
             rather just serving as parent for concrete child object definitions?
             Default is false. Specify true to tell the object factory to not try to
             instantiate that particular object in any case.
        -->
        <xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/>
        <!--
             Is this object a "singleton" (one shared instance, which will
             be returned by all calls to GetObject() with the id),
             or a "prototype" (independent instance resulting from each call to
             getObject(). Default is singleton.
             
             Singletons are most commonly used, and are ideal for multi-threaded
             service objects.
        -->
        <xs:attribute name="singleton" type="xs:boolean" use="optional" default="true"/>
        <!--
             Optional attribute controlling the scope of singleton instances. It is
             only applicable to ASP.Net web applications and it has no effect on prototype
             objects. Applications other than ASP.Net web applications simply ignore this attribute.
             It has 3 possible values:
             1. "application"
             Default object scope. Objects defined with application scope will behave like
             traditional singleton objects. Same instance will be returned from every call
             to IApplicationContext.GetObject()
             
             2. "session"
             Objects with this scope will be stored within user's HTTP session. Session scope
             is typically used for objects such as shopping cart, user profile, etc.
             
             3. "request"
             Object with this scope will be initialized for each HTTP request, but unlike with prototype
             objects, same instance will be returned from all calls to IApplicationContext.GetObject()
             within the same HTTP request. For example, if one ASP page forwards request to another using
             Server.Transfer method, they can easily share the state by configuring dependency to the same
             request-scoped object.
        -->
        <xs:attribute name="scope" use="optional" default="application">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="application"/>
                    <xs:enumeration value="session"/>
                    <xs:enumeration value="request"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <!--
             Is this object to be lazily initialized?
             If false, it will get instantiated on startup by object factories
             that perform eager initialization of singletons.
        -->
        <xs:attribute name="lazy-init" use="optional" default="default">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="true"/>
                    <xs:enumeration value="false"/>
                    <xs:enumeration value="default"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <!--
             Optional attribute controlling whether to "autowire" object properties.
             This is an automagical process in which object references don't need to be coded
             explicitly in the XML object definition file, but Spring works out dependencies.
             
             There are 5 modes:
             
             1. "no"
             The traditional Spring default. No automagical wiring. Object references
             must be defined in the XML file via the <ref> element. We recommend this
             in most cases as it makes documentation more explicit.
             
             2. "byName"
             Autowiring by property name. If a object of class Cat exposes a dog property,
             Spring will try to set this to the value of the object "dog" in the current factory.
             
             3. "byType"
             Autowiring if there is exactly one object of the property type in the object factory.
             If there is more than one, a fatal error is raised, and you can't use byType
             autowiring for that object. If there is none, nothing special happens - use
             dependency-check="objects" to raise an error in that case.
             
             4. "constructor"
             Analogous to "byType" for constructor arguments. If there isn't exactly one object
             of the constructor argument type in the object factory, a fatal error is raised.
             
             5. "autodetect"
             Chooses "constructor" or "byType" through introspection of the object class.
             If a default constructor is found, "byType" gets applied.
             
             The latter two are similar to PicoContainer and make object factories simple to
             configure for small namespaces, but doesn't work as well as standard Spring
             behaviour for bigger applications.
             
             Note that explicit dependencies, i.e. "property" and "constructor-arg" elements,
             always override autowiring. Autowire behaviour can be combined with dependency
             checking, which will be performed after all autowiring has been completed.
        -->
        <xs:attribute name="autowire" use="optional" default="default">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="no"/>
                    <xs:enumeration value="byName"/>
                    <xs:enumeration value="byType"/>
                    <xs:enumeration value="constructor"/>
                    <xs:enumeration value="autodetect"/>
                    <xs:enumeration value="default"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <!--
             Optional attribute controlling whether to check whether all this
             objects dependencies, expressed in its properties, are satisfied.
             Default is no dependency checking.
             
             "simple" type dependency checking includes primitives and String
             "object" includes collaborators (other objects in the factory)
             "all" includes both types of dependency checking
        -->
        <xs:attribute name="dependency-check" use="optional" default="default">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="none"/>
                    <xs:enumeration value="objects"/>
                    <xs:enumeration value="simple"/>
                    <xs:enumeration value="all"/>
                    <xs:enumeration value="default"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <!--
             The names of the objects that this object depends on being initialized.
             The object factory will guarantee that these objects get initialized before.
             
             Note that dependencies are normally expressed through object properties or
             constructor arguments. This property should just be necessary for other kinds
             of dependencies like statics (*ugh*) or database preparation on startup.
        -->
        <xs:attribute name="depends-on" type="nonNullString" use="optional"/>
        <!--
             Optional attribute for the name of the custom initialization method
             to invoke after setting object properties. The method must have no arguments,
             but may throw any exception.
        -->
        <xs:attribute name="init-method" type="nonNullString" use="optional"/>
        <!--
             Optional attribute for the name of the custom destroy method to invoke
             on object factory shutdown. The method must have no arguments,
             but may throw any exception. Note: Only invoked on singleton objects!
        -->
        <xs:attribute name="destroy-method" type="nonNullString" use="optional"/>
        <xs:attribute name="factory-method" type="nonNullString" use="optional"/>
        <xs:attribute name="factory-object" type="nonNullString" use="optional"/>
    </xs:complexType>
    
    <xs:annotation>
        <xs:documentation>The document root.  At least one object definition is required.</xs:documentation>
    </xs:annotation>
    <xs:element name="objects">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="description" type="description" minOccurs="0" maxOccurs="1"/>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="import" type="importElement"/>
                    <xs:element name="alias" type="aliasElement"/>
                    <xs:element name="object" type="vanillaObject"/>
                    <xs:any namespace="##other" processContents="strict"/>
                </xs:choice>
            </xs:sequence>
            <!--
                 Default values for all object definitions. Can be overridden at
                 the "object" level. See those attribute definitions for details.
            -->
            <xs:attribute name="default-lazy-init" type="xs:boolean" use="optional" default="false"/>
            <xs:attribute name="default-dependency-check" use="optional" default="none">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="none"/>
                        <xs:enumeration value="objects"/>
                        <xs:enumeration value="simple"/>
                        <xs:enumeration value="all"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="default-autowire" use="optional" default="no">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="no"/>
                        <xs:enumeration value="byName"/>
                        <xs:enumeration value="byType"/>
                        <xs:enumeration value="constructor"/>
                        <xs:enumeration value="autodetect"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    
</xs:schema>