Pitney Bowes MapXtreme User Manual

Page 501

Advertising
background image

Appendix D: Extensible Data Providers

Sample: COTW (Center of the World) Data Provider

MapXtreme v7.1

508

Developer Guide

Note that this class is extended from AbstractDataProvider - not IDataProvider itself. As discussed in
the

Optional Building Blocks: Base Classes, Helpers and Utilities

, we provide abstract base

classes as building blocks to help provide suitable default implementations wherever possible. In the
case of IDataProvider, this abstract class manages the name property and default the
implementations of its OpenDataSource and OpenTable methods to throw a not implemented
exception. This allows us to decide which are relevant and provide implementations for only those
thereby keeping our implementation uncluttered.

Since the table we're defining has a fixed structure, we don't need much for the ITableDefinition
implementation. To make it non-trivial, we'll have the table definition accept a string value that can be
used as an externally specified label to be used for the point. A complete implementation would look
something like this:

using System;
using MapInfo.Data.Provider;

namespace COTW
{
public sealed class COTWTableDefinition : AbstractTableDefinition
{
private string m_label;

public COTWTableDefinition(string label)
: base()
{
if (label == null)
throw new ArgumentNullException("label");
m_label = label;
}

public override IDataProvider DataProvider
{
get { return COTWDataProvider.GetInstance(); }
}

public string Label
{
get
{
return m_label;
}
}
}
}

We've once again used the abstract base class instead of the interface directly. In this case, it allows
us to ignore anything related to accept the defaults for the DataSourceDefinition and
CustomMetadata properties on the interface. Note how the DataProvider property references the
singleton COTWDataProvider instance implemented earlier. This example also introduces a new
property of our own.

Advertising