Poco::OSP

class ExtensionPointService

Library: OSP
Package: ExtensionPointService
Header: Poco/OSP/ExtensionPointService.h

Description

The ExtensionPointService allows a bundle to define extension points (or "hooks") where other bundles can "hook in" functionality, thus extending the bundle.

The service listens for EV_BUNDLE_STARTED events. For every started bundle, the service tries to retrieve the bundle's "extensions.xml" file. If the file exists, the file is parsed using a DOM parser.

The ExtensionPointService then iterates over all "extension" elements in that document. Every "extension" element must specify an attribute named "point" that specifies the ExtensionPoint object to invoke for this element. The service then invokes the ExtensionPoint::handleExtension() member function with the bundle and the "extension" element as arguments.

The "extensions.xml" file basically looks as follows:

<extensions>
    <extension point="<id>">
        <!-- extension point specific content -->
    </extension>
    <!-- more extension elements -->
</extensions>

The service name of the ExtensionPointService is "osp.core.xp".

Inheritance

Direct Base Classes: Service

All Base Classes: Service, Poco::RefCountedObject

Member Summary

Member Functions: findExtensionPoint, handleExtension, isA, onBundleStarted, onBundleStopped, parseExtensions, registerExtensionPoint, type, unregisterExtensionPoint

Inherited Functions: duplicate, isA, referenceCount, release, type

Constructors

ExtensionPointService

ExtensionPointService(
    BundleEvents & events
);

Creates the ExtensionPointService.

Destructor

~ExtensionPointService protected virtual

~ExtensionPointService();

Destroys the ExtensionPointService.

Member Functions

isA virtual

bool isA(
    const std::type_info & otherType
) const;

See also: Poco::OSP::Service::isA()

registerExtensionPoint

void registerExtensionPoint(
    Bundle::ConstPtr pBundle,
    const std::string & id,
    ExtensionPoint::Ptr pExtensionPoint
);

Registers the given extension point under the given ID. If the bundle registering the extension point is stopped, the extension point will be automatically unregistered.

Throws a Poco::ExistsException if an extension point with the given ID has already been registered.

type virtual

const std::type_info & type() const;

See also: Poco::OSP::Service::type()

unregisterExtensionPoint

void unregisterExtensionPoint(
    const std::string & id
);

Unregisters the extension point with the given ID.

Throws a Poco::NotFoundException if the extension point with the given ID does not exist.

findExtensionPoint protected

ExtensionPoint::Ptr findExtensionPoint(
    const std::string & id
);

Returns the extension point with the given ID.

handleExtension protected

void handleExtension(
    Bundle::ConstPtr pBundle,
    const std::string & id,
    Poco::XML::Element * pExtensionElement
);

Handles a single "extension" element.

onBundleStarted protected

void onBundleStarted(
    const void * pSender,
    BundleEvent & event
);

Handles an EV_BUNDLE_STARTED event.

onBundleStopped protected

void onBundleStopped(
    const void * pSender,
    BundleEvent & event
);

Handles an EV_BUNDLE_STOPPED event.

parseExtensions protected

void parseExtensions(
    Bundle::ConstPtr pBundle,
    std::istream & istr
);

Parses the "extensions.xml" file.

Variables

EXTENSIONS_ELEM static

static const std::string EXTENSIONS_ELEM;

EXTENSIONS_XML static

static const std::string EXTENSIONS_XML;

EXTENSION_ELEM static

static const std::string EXTENSION_ELEM;

POINT_ATTR static

static const std::string POINT_ATTR;

SERVICE_NAME static

static const std::string SERVICE_NAME;