CSDLDocument

open class CSDLDocument : ObjectBase

Encapsulates the definitions from a parsed Open Data Protocol (OData) service metadata (CSDL) document.

See also

CsdlParser.
  • A unique key to identify the CSDLDocument when it is inserted into the Decoder class’s userInfo property

    Declaration

    Swift

    public static let csdlInfoKey: CodingUserInfoKey
  • A map of vocabulary namespaces that are builtin to and resolvable by CsdlParser. Each map key is an OData schema namespace, and each corresponding map value is a recommended namespace alias.

    Declaration

    Swift

    public static let builtinVocabularyNamespaces: StringMap
  • Logger which may be used for debugging.

    Declaration

    Swift

    final public var logger: AnyObject?
  • Allows any model element to be changed in the latest service metadata before calling DataService.refreshMetadata. Defaults to false. Warning: enabling this option can result in application instability (depending on the changes) if the application uses proxy classes!

    Declaration

    Swift

    final public var canChangeAnything: Bool
  • Allows any model element to be removed in the latest service metadata before calling DataService.refreshMetadata. Defaults to false. Warning: enabling this option can result in application instability unless the application checks isRemoved flags on model elements!

    Declaration

    Swift

    final public var canRemoveAnything: Bool
  • true if this metadata is associated with generated proxy classes. Defaults to false (generated proxies will override to true).

    Declaration

    Swift

    final public var hasGeneratedProxies: Bool
  • Allows addition of enumeration members in the latest service metadata before calling DataService.refreshMetadata. Defaults to false. Warning: enabling this option can result in application instability if the application uses proxy classes without “-open:enumerations”.

    Declaration

    Swift

    final public var hasOpenEnumerations: Bool
  • Was this document loaded from the local metadata cache?

    Declaration

    Swift

    final public var loadedFromCache: Bool
  • Was this document modified in the local metadata cache?

    Declaration

    Swift

    final public var modifiedInCache: Bool
  • If this metadata was parsed by generated proxy classes, then the framework version that generated the proxies. Otherwise nil.

    Declaration

    Swift

    final public var proxyVersion: String?
  • Code for the OData version, e.g. 400. If the OData version is considered as a decimal number (e.g. 4.0), then multiplying by 100 will give the code (e.g. 400).

    See also

    DataVersion.

    Declaration

    Swift

    final public var versionCode: Int
  • Text for the OData version, e.g. “4.0”.

    Declaration

    Swift

    final public var versionText: String
  • Compact CSDL (XML) text.

    Declaration

    Swift

    final public var compactXML: String?
  • Original CSDL (XML) text.

    See also

    CsdlOption.RETAIN_ORIGINAL_TEXT.

    Declaration

    Swift

    final public var originalText: String?
  • Resolved CSDL (XML) text, with inline references and expanded aliases.

    See also

    CsdlOption.RETAIN_RESOLVED_TEXT.

    Declaration

    Swift

    final public var resolvedText: String?
  • Main data schema defined by the CSDL (or nil if there are no schemas defined).

    Declaration

    Swift

    final public var mainSchema: DataSchema?
  • Default entity container defined by the CSDL (or nil if there are no containers defined).

    Declaration

    Swift

    final public var defaultContainer: EntityContainer?
  • Source file name if known, otherwise nil.

    Declaration

    Swift

    final public var sourceFile: String?
  • Default initializer.

    Declaration

    Swift

    override public init()
  • If this model contains navigation properties without defined partners, then set Property.partnerPath on each navigation property so as to make the relationship appear bidirectional. Such a change will only be made if there is one partnerless navigation property on each entity type, referring to the candidate partner type. This is primarily helpful for model visualization.

    Declaration

    Swift

    open func addNavigationPartners()
  • Register owner as an owner of this metadata document.

    Declaration

    Swift

    open func addOwner(_ owner: AnyObject)

    Parameters

    owner

    Metadata owner.

  • Add a well-known vocabulary reference to this metadata. If this metadata already has a reference to the well-known vocabulary, then no change is made. If the reference is to one of the builtinVocabularyNamespaces, then all defined annotation terms/types from the vocabulary will also be added to the current metadata.

    Declaration

    Swift

    open func addVocabularyReference(ns: String, uri: String? = nil, alias: String? = nil) throws

    Parameters

    ns

    CSDL namespace.

    uri

    Optional namespace URI. For builtin vocabulary namespaces, this can be derived from the namespace. For references to non-builtin vocabularies, it must be provided.

    alias

    Optional namespace alias. For builtin vocabulary namespaces, this can be derived from the namespace. For references to non-builtin vocabularies, it can be provided.

  • Map of annotation terms defined by the CSDL.

    Declaration

    Swift

    public final var annotationTerms: AnnotationTermMap { get }
  • Apply any database-related and security-related annotations (from OData namespaces “com.sap.cloud.server.odata.*”) to this metadata.

    Declaration

    Swift

    open func applyAnnotations()
  • Map of predefined CSDL data types.

    Declaration

    Swift

    public final var builtinTypes: DataTypeMap { get }
  • Lookup a complex type by qualified name. If the complex type does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet:

    Example checking if a complex type exists

    open func checkComplexTypeExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.complexTypes.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation") {
            _ = csdlDocument.complexType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.EventLocation")
        } else {
        }
    }
    

    See also

    complexTypes, for looking up types that might not exist.

    Declaration

    Swift

    open func complexType(withName name: String) -> ComplexType

    Parameters

    name

    Name of the complex type to be returned.

    Return Value

    The complex type, which must exist.

  • Map of complex types defined by the CSDL.

    Declaration

    Swift

    public final var complexTypes: ComplexTypeMap { get }
  • Lookup a data method by qualified name (for function/action definitions) or by unqualified name (for function/action imports). If the data method does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up data methods before calling this method like in the following code snippet:

    Example checking if a data method exists

    open func checkDataMethodInCsdlDocumentExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.lookupMethods.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person.UpdatePersonLastName") {
            _ = csdlDocument.dataMethod(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person.UpdatePersonLastName")
        } else {
        }
    }
    

    See also

    dataMethods, for looking up methods that might not exist.

    Declaration

    Swift

    open func dataMethod(withName name: String) -> DataMethod

    Parameters

    name

    Name of the data method to be returned.

    Return Value

    The data method, which must exist.

  • Map of data methods (actions, functions) defined by the CSDL.

    Declaration

    Swift

    public final var dataMethods: DataMethodMap { get }
  • Lookup a data schema by name. If the data schema does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up data schemas before calling this method like in the following code snippet:

    Example checking if a data schema exists

    open func checkDataSchemaExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.dataSchemas.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models") {
            _ = csdlDocument.dataSchema(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models")
        } else {
        }
    }
    

    See also

    dataSchemas, for looking up schemas that might not exist.

    Declaration

    Swift

    open func dataSchema(withName name: String) -> DataSchema

    Parameters

    name

    Name of the data schema to be returned.

    Return Value

    The data schema, which must exist.

  • Map of data schemas defined by the CSDL.

    Declaration

    Swift

    public final var dataSchemas: DataSchemaMap { get }
  • Entity sets that are mapped to database tables.

    Declaration

    Swift

    open var databaseTables: EntitySetMap { get }
  • Map of entity containers defined by the CSDL.

    Declaration

    Swift

    public final var entityContainers: EntityContainerMap { get }
  • Lookup an entity set (or singleton entity) by name. If the entity set does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet: Note that OData singleton entities are represented by entity sets where EntitySet.isSingleton is true.

    Example checking if a entity set exists

    open func checkEntitySetInCsdlDocumentExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.entitySets.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airlines") {
            _ = csdlDocument.entitySet(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airlines")
        } else {
        }
    }
    

    See also

    entitySets, for looking up sets that might not exist.

    Declaration

    Swift

    open func entitySet(withName name: String) -> EntitySet

    Parameters

    name

    Name of the entity set to be returned.

    Return Value

    The entity set, which must exist.

  • Map of entity sets defined by the CSDL.

    Declaration

    Swift

    public final var entitySets: EntitySetMap { get }
  • Lookup an entity type by qualified name. If the entity type does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet:

    Example checking if a entity type exists

    open func checkEntityTypeExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.entityTypes.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport") {
            _ = csdlDocument.entityType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport")
        } else {
        }
    }
    

    See also

    entityTypes, for looking up types that might not exist.

    Declaration

    Swift

    open func entityType(withName name: String) -> EntityType

    Parameters

    name

    Name of the entity type to be returned.

    Return Value

    The entity type, which must exist.

  • Map of entity types defined by the CSDL.

    Declaration

    Swift

    public final var entityTypes: EntityTypeMap { get }
  • Lookup an enum type by qualified name. If the enum type does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet:

    Example checking if an enum type exists

    open func checkEnumTypeExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.enumTypes.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender") {
            _ = csdlDocument.enumType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender")
        } else {
        }
    }
    

    See also

    enumTypes, for looking up types that might not exist.

    Declaration

    Swift

    open func enumType(withName name: String) -> EnumType

    Parameters

    name

    Name of the enum type to be returned.

    Return Value

    The enum type, which must exist.

  • Map of enum types defined by the CSDL.

    Declaration

    Swift

    public final var enumTypes: EnumTypeMap { get }
  • See also

    topReferences.

    Declaration

    Swift

    open func hasTopReference(ns: String) -> Bool

    Parameters

    ns

    CSDL namespace.

    Return Value

    true if this document includes a top-level reference for CSDL namespace ns.

  • See also

    topSchemas.

    Declaration

    Swift

    open func hasTopSchema(ns: String) -> Bool

    Parameters

    ns

    CSDL namespace.

    Return Value

    true if this document includes a top-level schema for CSDL namespace ns.

  • Mark this document and its elements as being immortal. Helps to improve performance in reference counted environments (e.g. Swift). Should only be used for metadata documents with process lifetime. Otherwise a memory leak could be caused.

    Declaration

    Swift

    open func immortalize() -> CSDLDocument

    Return Value

    This document.

  • Inherit annotations from entity types to entity sets in this metadata.

    Declaration

    Swift

    open func inheritAnnotations()
  • Declaration

    Swift

    open func owners() -> ObjectList

    Return Value

    all the current registered owners of this metadata document.

  • Map of path annotations defined by the CSDL (where the TargetPath does not directly reference a model element).

    Declaration

    Swift

    public final var pathAnnotations: PathAnnotationsMap { get }
  • Unregister owner as an owner of this metadata document.

    Declaration

    Swift

    open func removeOwner(_ owner: AnyObject)

    Parameters

    owner

    Metadata owner.

  • Resolve the EntityValue.entitySet of `entity’ (if it is not already set).

    Throws

    DataServiceException if entity.entitySet is not set, and is not unique (i.e. multiple entity sets use the same entity type) or there is a circular dependency in related entities (parent entity is set as child as well) or an entity is resolved multiple times meaning that it is embedded as child more than once.

    Declaration

    Swift

    open func resolveEntity(_ entity: EntityValue) throws

    Parameters

    entity

    Entity to resolve.

  • Lookup a simple type by qualified name. If the simple type does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet:

    Example checking if a simple type exists

    open func checkSimpleTypeExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.simpleTypes.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.MySimpleType") {
            _ = csdlDocument.simpleType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.MySimpleType")
        } else {
        }
    }
    

    See also

    simpleTypes, for looking up types that might not exist.

    Declaration

    Swift

    open func simpleType(withName name: String) -> SimpleType

    Parameters

    name

    Name of the simple type to be returned.

    Return Value

    The simple type, which must exist.

  • Map of simple types defined by the CSDL.

    Declaration

    Swift

    public final var simpleTypes: SimpleTypeMap { get }
  • Lookup a singleton entity by name. If the singleton entity does not exist it indicates a fundamental implementation problem, therefore a non-catchable FatalException will be thrown, and the app intentionally crashes. The reason behind this drastic behaviour is to avoid mismatch between server and client. It is still possible to avoid the FatalException by looking up simplet types before calling this method like in the following code snippet: Note that OData singleton entities are represented by entity sets where EntitySet.isSingleton is true.

    Example checking if a ingleton entity exists

    open func checkSingletonExistsExample() throws -> Void {
        let csdlDocument = self.service.metadata
        if csdlDocument.singletons.containsValue(forKey: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Container/Me") {
            _ = csdlDocument.singleton(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Container/Me")
        } else {
        }
    }
    

    See also

    entitySets, for looking up sets that might not exist.

    Declaration

    Swift

    open func singleton(withName name: String) -> EntitySet

    Parameters

    name

    Name of the entity set to be returned.

    Return Value

    The entity set, which must exist.

  • Map of singletons defined by the CSDL. Each singleton is represented by an EntitySet with isSingleton == true

    Declaration

    Swift

    public final var singletons: EntitySetMap { get }
  • Top-level aliases defined by the CSDL. This is a map from schema namespace to schema alias.

    Declaration

    Swift

    public final var topAliases: StringMap { get }
  • Top-level references defined by the CSDL.

    Declaration

    Swift

    public final var topReferences: CsdlReferenceList { get }
  • Top-level schemas defined by the CSDL.

    Declaration

    Swift

    public final var topSchemas: DataSchemaList { get }
  • Map of XML namespaces defined by the CSDL.

    Declaration

    Swift

    public final var xmlNamespaces: StringMap { get }