You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by co...@apache.org on 2009/09/30 23:42:00 UTC

[CONF] Apache Tuscany Docs 2.x > Converting Tuscany 1.x Extensions

Space: Apache Tuscany Docs 2.x (http://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x)
Page: Converting Tuscany 1.x Extensions (http://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/Converting+Tuscany+1.x+Extensions)


Edited by Luciano Resende:
---------------------------------------------------------------------
h1. Converting 1.x dependencies

You should configure the project pom.xml and

|| 1.x Dependencies || || 2.xDependencies ||
| <dependency> \\
<groupId>org.apache.tuscany.sca</groupId> \\
<artifactId>tuscany-assembly</artifactId> \\
<version>1.6-SNAPSHOT</version> \\
</dependency> | ===> | <dependency> \\
<groupId>org.apache.tuscany.sca</groupId> \\
<artifactId>tuscany-assembly</artifactId> \\
<version>2.0-SNAPSHOT</version> \\
</dependency> |

The following core modules are not ported yet :

* data-api
* some policies

The following modules are deprecated :

* host-embedded
** use the new Node APIs


h1. Generating OSGi Manifest

Configure pom to use Apache Felix [maven-bundle-plugin|http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html]

{code}
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>

                <configuration>
                    <instructions>
                        <Bundle-Version>${tuscany.version}</Bundle-Version>
                        <Bundle-SymbolicName>org.apache.tuscany.sca.binding.atom</Bundle-SymbolicName>
                        <Bundle-Description>${pom.name}</Bundle-Description>
                        <Export-Package>org.apache.tuscany.sca.binding.atom*</Export-Package>
                        <Import-Package>org.apache.tuscany.sca.assembly.xml;version="2.0.0", *</Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

{code}

Generate the manifest

{code}
mvn org.apache.felix:maven-bundle-plugin:manifest
{code}

Copy the generated manifest from target folder to

{code}
<module-root>/META_INF/manifest.mf
{code}

Add manifest to source control

{code}
git add META-INF
or
svn add META-INF
{code}

Make any manual modifications as necessary

h1. Converting your extension model

Your extension model needs to provide a new getType method

{code}
public interface JSONRPCBinding extends Binding {
   QName TYPE = new QName(SCA11_TUSCANY_NS, "binding.jsonrpc");
   ...
}

public class JSONRPCBindingImpl implements JSONRPCBinding {
   private String name;
   private String uri;

   public QName getType() {
	return TYPE;
   }

    ...
}
{code}

h1. Converting you runtime artifacts

h3. Provider Factory

* The provider factory interface has changed to accommodate the new Endpoint/EndPointReference support
** Although the interface has changed, all the previous available information are encapsulated and available from the Endpoint and EndpointReference object


{code}
public interface BindingProviderFactory<M extends Binding> extends ProviderFactory<M> {

    /**
     * Creates a new reference binding provider for the given endpoint reference
     *
     * @param endpointReference defines the component/reference/binding against which to create the provider
     * @return The binding provider
     */
    ReferenceBindingProvider createReferenceBindingProvider(EndpointReference endpointReference);

    /**
     * Creates a new service binding provider for the given component and
     * service.
     *
     * @param endpoint defines the component/service/binding against which to create the provider
     * @return The binding provider
     */
    ServiceBindingProvider createServiceBindingProvider(Endpoint endpoint);

}
{code}

* If you are using ModelFactoryExtensionPoint, it was renamed to FactoryExtensionPoint


{code}
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
{code}


h3. ReferenceBindingProvider and ServiceBindingProvider

The previous SCA Models that were previously passed directly to these SPIs, is now available via Endpoint and EndpointReference as described in the code below:

{code}
public class AtomReferenceBindingProvider implements ReferenceBindingProvider {

    private RuntimeComponentReference reference;
    private AtomBinding binding;

    public AtomReferenceBindingProvider(EndpointReference endpointReference,
                                        AtomBinding binding) {

    	this.reference = (RuntimeComponentReference) endpointReference.getReference();
        this.binding = (AtomBinding) endpointReference.getBinding();
    }

    ...
}

public class AtomServiceBindingProvider implements ServiceBindingProvider {


    private MessageFactory messageFactory;

    private Endpoint endpoint;
    private RuntimeComponent component;
    private RuntimeComponentService service;
    private InterfaceContract serviceContract;
    private AtomBinding binding;
    private ServletHost servletHost;

    ...

    public AtomServiceBindingProvider(Endpoint endpoint,
                                         MessageFactory messageFactory,
                                         ServletHost servletHost) {
        this.endpoint = endpoint;
        this.component = (RuntimeComponent)endpoint.getComponent();
        this.service = (RuntimeComponentService)endpoint.getService();
        this.binding = (AtomBinding) endpoint.getBinding();
        this.messageFactory = messageFactory;
        this.servletHost = servletHost;

    }

    ....

{code}

h3.Converting test cases 

In 2.x we removed the Host-Embedded module and the SCADomain, and the recommended way is to use the Node SPI to build your test cases. We also are recommending using JUnit 4.5 test styles. See below a quick

*1.x Style*
{code}
public class AtomTestCase {

	private SCADomain domain;

	@Before
	public void setUp() throws Exception {
		domain = SCADomain.newInstance("AtomBinding.composite");
	}

	@After
	public void tearDown() throws Exception {
		domain.close();
	}

        ....
}
{code}

*2.x Style*
{code}
public class AtomTestCase {

	private static Node node;

	@BeforeClass
	public static void setUp() throws Exception {
		try {
    		String contribution = ContributionLocationHelper.getContributionLocation(AtomTestCase.class);
    		node = NodeFactory.newInstance().createNode("AtomBinding.composite", new Contribution("test", contribution));
    		node.start();
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
	}

	@AfterClass
	public static void tearDown() throws Exception {
		node.stop();
    	node.destroy();
	}

        ...
}
{code}

*NOTE* You will need to add the node-impl as test dependency to your modules
{code}
        <dependency>
            <groupId>org.apache.tuscany.sca</groupId>
            <artifactId>tuscany-node-impl</artifactId>
            <version>2.0-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>
{code}

Change your notification preferences: http://cwiki.apache.org/confluence/users/viewnotifications.action