SCA Java Extension Development Guide (TUSCANY) edited by Raymond Feng
Page:
http://cwiki.apache.org/confluence/display/TUSCANY/SCA+Java+Extension+Development+Guide
Changes:
http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=51879&originalVersion=32&revisedVersion=33
Content:
---------------------------------------------------------------------
{section:border=false}{column:width=15%}
{include: SCA Java Subproject Menu}
{include: Java SCA Menu New}{column}{column:width=85%}
{panel:title=Apache Tuscany SCA Java Extension Guide
|borderStyle=solid|borderColor=#C3CDA1|titleBGColor=#C3CDA1|bgColor=#ECF4D1}
This is a guide for developers who would like to extend Tuscany SCA Java.
* [What is an extension?|#extension]
* [How to add a new component implementation? | #component]
* [How to add a new binding? |#binding]
* [How to add a new interface binding? |#interface]
* [How to add a databinding | #databinding ]
* [General guide for developing extensions| #general guide]
* [Details on extension architecture|#details] *can move to architecture doc*
* [Extension Modules| Java SCA Extension Modules]
{panel}{note:title:Notification}{center}This page is under construction\- You
are welcome to help and complete it {center}{note}
h3. {anchor:extension} {bgcolor:#C3CDA1}A presentation on how to extend Tuscany
in Microsoft PowerPoint format {bgcolor}
*Extending Tuscany* [PPT|^ExtendingTuscany.ppt] [PDF|^ExtendingTuscany-V01.pdf]
h3. {anchor:extension} {bgcolor:#C3CDA1}What is an extension? {bgcolor}
Extension is a module (or a set of modules),when built with Tuscany SCA, can
extend it to work with additional bindings, language implementations,
programming models or databindings.
SCA assembly model is defined such that extensions can be added for new
interface types or for new implementation types such as ruby and python, or new
binding types such as CXF. However, the definition of extension SPIs is left to
the implementor. Tuscany SCA Java provides a simple set of SPIs for
implementing extensions. It also defines additional extension points such as
data binding, for example support for SDO and JAXB.
This guide explains the steps to add each of these extension types. Please help
us refine the guide as you go through the steps of adding extensions.
h3. Name spaces used by extensions
Extensions sometimes contribute addtional elements or attributes to the SCA XML
configuration model. These elements or attributes should be qualified as
follows:
* [http://www.osoa.org/xmlns/sca/1.0:] if the extension is defined by the SCA
spec.
* [http://tuscany.apache.org/xmlns/sca/1.0:] if the extesion is defined by
Tuscany
h3. {anchor:component} {bgcolor:#C3CDA1}How to add a new component
implementation? {bgcolor}
[Musings on Adding a New Implementation Type by Mike E|Mike Edwards Ramble
through Adding a New Implementation Type]
h3. {anchor:binding} {bgcolor:#C3CDA1}How to add a new binding? {bgcolor}
h3. {anchor:interface} {bgcolor:#C3CDA1}How to add a new interface binding?
{bgcolor}
h3. {anchor:databinding} {bgcolor:#C3CDA1}How to add a new databinding?
{bgcolor}
h3. {anchor:general guide} {bgcolor:#C3CDA1}General guide for developing
extensions {bgcolor}
* Familiarize yourself with SCA 1.0 Assembly and the SCA Java 1.0 programming
model. Specifications can be found at www.osoa.org.
* Never reference any classes in core. These classes are
implementation-specific and subject to change; they are not part of the public
SPI contract.
* Use autowire when assembling extension components.
* Do not play with classloaders such as setting the current context classloader
unless it is absolutely necessary, i.e. a library used by an extension makes
assumptions about context classloaders. Ideally the library can be refactored
to not make these assumptions. If not, make sure the extension properly resets
the current context classloader.
h3. {anchor:details} {bgcolor:#C3CDA1}Detail on extension architecture {bgcolor}
h4. The ExtensionPointRegistry
{code}
package org.apache.tuscany.sca.core;
/**
* The registry for the Tuscany core extension points. As the point of contact
* for all extension artifacts this registry allows loaded extensions to find
* all other parts of the system and register themselves appropriately.
*
* @version $Rev: 539355 $ $Date: 2007-05-18 03:05:14 -0700 (Fri, 18 May 2007) $
*/
public interface ExtensionPointRegistry {
/**
* Add an extension point to the registry
* @param extensionPoint The instance of the extension point
*/
void addExtensionPoint(Object extensionPoint);
/**
* Get the extension point by the interface
* @param extensionPointType The lookup key (extension point interface)
* @return The instance of the extension point
*/
<T> T getExtensionPoint(Class<T> extensionPointType);
/**
* Remove an extension point
* @param extensionPoint The extension point to remove
*/
void removeExtensionPoint(Object extensionPoint);
}
{code}
h4. The ModuleActivator
{code}
package org.apache.tuscany.sca.core;
/**
* ModuleActivator represents a module that plugs into the Tuscany system. Each
* module should provide an implementation of this interface and register the
* ModuleActivator implementation class by defining a file named
*
* "META-INF/services/org.apache.tuscany.core.ModuleActivator"
*
* The content of the file is the class name of the ModuleActivator
implementation.
* The implementation class must have a no-arg constructor. The same instance
* will be used to invoke all the methods during different phases of the module
* activation. Note that the start and stop methods defined by this interface
* take a reference to the Tuscany SCA runtime ExtensionPointRegistry. This
* gives the ModuleActivator the oppotunity to add extension points to the
* registry as it is requested to start up and remove them when it is requested
* to shut down.
*
* @version $Rev: 564429 $ $Date: 2007-08-09 16:49:11 -0700 (Thu, 09 Aug 2007) $
*/
public interface ModuleActivator {
/**
* This method is invoked when the module is started by the Tuscany system.
* It can be used by this module to registr extensions against extension
* points.
*
* @param registry The extension point registry
*/
void start(ExtensionPointRegistry registry);
/**
* This method is invoked when the module is stopped by the Tuscany system.
* It can be used by this module to unregister extensions against the
* extension points.
*
* @param registry The extension point registry
*/
void stop(ExtensionPointRegistry registry);
}
{code}
The ModuleActivator represents a module that plugs into the Tuscany system.
Each module can optionally provide an implementation of this interface and
register the implementation class by defining a file named as
"{color:#0000ff}META-INF/services/org.apache.tuscany.sca.core.ModuleActivator{color}".
The content of the file is the class name of the implementation. The
implementation class must have a no-arg constructor. The same instance will be
used to invoke all the methods during different phases of the module activation.
During bootstraping, the following sequence will happen:
1) All the module activators will be discovered by the presence of
"{color:#0000ff}META-INF/services/org.apache.tuscany.sca.core.ModuleActivator{color}"
2) The activator class is instantiated using the no-arg constructor.
3) ModuleActivator.getExtensionPoints() is invoked for all modules and the
extension points contributed by each module are added to the ExtensionRegistry.
4) ModuleActivator.start(ExtensionRegistry) is invoked for all the modules. The
module can then get interested extension points and contribute
extensions to them. The contract bwteen the extension and extension point is
private to the extension point. The extension point can follow similar
patterns such as Registry. If it happens that one extension point has a
dependency on another extension point, they can linked at this phase.
During shutting down, the stop() method is invoked for all the modules to
perform cleanups. A module can choose to unregister the extension from the
extension points.
h4. Lazy instantiation of extensions
To reduce the startup time and memory footprint, most of the extension points
in Tuscany now supports lazy instantiation of the registered extensions. The
following describes the pattern using
org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor as an
example.
1) Create a plain text file named as
"{color:#0000ff}META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor{color}"
2) Register an extension by adding a line in the file
{code}
org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#implementation.java,model=org.apache.tuscany.sca.implementation.java.JavaImplementation
{code}
The simple syntax is:
{color:#990000}<implementation_class_name>{color}{color:#0000ff};{color}{color:#990000}<parameter_name>{color}{color:#0000ff}={color}{color:#990000}<parameter_value>{color}{color:#0000ff},{color}{color:#990000}<parameter_name>{color}{color:#0000ff}={color}{color:#990000}<parameter_value>{color}{column}{section}
---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence
Unsubscribe or edit your notifications preferences
http://cwiki.apache.org/confluence/users/viewnotifications.action
If you think it was sent incorrectly contact one of the administrators
http://cwiki.apache.org/confluence/administrators.action
If you want more information on Confluence, or have a bug to report see
http://www.atlassian.com/software/confluence
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]