diff options
author | coreyg <coreyg@13f79535-47bb-0310-9956-ffa450edef68> | 2014-11-21 09:30:19 +0000 |
---|---|---|
committer | coreyg <coreyg@13f79535-47bb-0310-9956-ffa450edef68> | 2014-11-21 09:30:19 +0000 |
commit | 200a40b332420f94992eb39a6d0ea1cf1490ffc4 (patch) | |
tree | 1c76ef1d254c7bfc91128a313d319bd60da9d01e /site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html | |
parent | 85f53ab6ab4f664d63774c94b672a875c9e52b8a (diff) |
Adding tuscany's website to their svn repo for svnpubsub
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1640879 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html')
-rw-r--r-- | site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html | 650 |
1 files changed, 650 insertions, 0 deletions
diff --git a/site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html b/site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html new file mode 100644 index 0000000000..dbf457d763 --- /dev/null +++ b/site/trunk/site-publish/getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.html @@ -0,0 +1,650 @@ + +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE- 2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<HTML> + <HEAD> + <!-- generateKeywords macro --> + <META name="description" content="Apache Tuscany"> + <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource"> + <!-- generateKeywords macro end --> + + <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css"> + <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico"> + <TITLE>Apache Tuscany : Getting Started with Tuscany (using Tuscany Eclipse Plugin 1.1)</TITLE> + <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD> + + <BODY onload="init()"> + <!-- topNav macro --> + <TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg"> + <TR> + <TD valing="top" align="left"> + <A href="https://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A> + </TD> + <TD> + <A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A> + </TD> + + <TD width="100%"> + + </TD> + + <!-- Adds the edit page link to the top banner--> + <TD valign="bottom"> + <DIV style="padding: 2px 10px; margin: 0px;"> + <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=85984"> + <IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A> + </DIV> + </TD> + + </TR> + </TABLE> + <!-- topNav macro end --> + + <!-- breadCrumbs macro --> + <TABLE border="0" cellpadding="2" cellspacing="0" width="100%"> + <TR class="topBar"> + <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%"> + <A href="home.html" title="Apache Tuscany">Apache Tuscany</A> > <A href="home.html" title="Home">Home</A> > <A href="sca-overview.html" title="SCA Overview">SCA Overview</A> > <A href="sca-java.html" title="SCA Java">SCA Java</A> > <A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A> > <A href="" title="Getting Started with Tuscany (using Tuscany Eclipse Plugin 1.1)">Getting Started with Tuscany (using Tuscany Eclipse Plugin 1.1)</A> + </TD> + + <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true"> + <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A> + </TD> + </TR> + </TABLE> + <!-- breadCrumbs macro end --> + + + <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF"> + <TR> + <TD align="left" valign="top"> + + <!-- pageContent macro --> + <DIV id="PageContent"> + + <DIV class="pagecontent"> + <DIV class="wiki-content"> + <H1><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-Ready%2CSet%2CGoGettingstartedwithTuscany"></A>Ready, Set, Go - Getting started with Tuscany</H1> + + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-InstalltheTuscanyEclipsePlugin%26nbsp%3B"></A>Install the Tuscany Eclipse Plugin </H2> + +<P>The first thing you do is to start Eclipse and go to <B>Help -> Software Updates -> Find and Install</B>,<BR> +select "Search for new features to install" and then click next</P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update.jpg" style="border: 0px solid black"></SPAN></P> + +<P>On the next dialog, click on <B>"New Remote Site..."</B> to create a new site entry. Give it a name such as<BR> +"Tuscany" and add the site URL as *<A href="http://people.apache.org/~jsdelfino/tuscany/tools/updatesite/*" class="external-link" rel="nofollow">http://people.apache.org/~jsdelfino/tuscany/tools/updatesite/*</A></P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_new_site.jpg" style="border: 0px solid black"></SPAN></P> + +<P>Make sure the <B>"Remote Site"</B> that was just created is selected, and click <B>"Finish"</B></P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_finish.jpg" style="border: 0px solid black"></SPAN></P> + +<P>Select the <B>"Apache Tuscany SCA Tools"</B> and click <B>"Next"</B>, and then, on the next dialog, click <B>"Finish"</B></P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_search_results.jpg" style="border: 0px solid black"></SPAN></P> + +<P>Accept the <B>"Plugin License"</B></P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_feature_license.jpg" style="border: 0px solid black"></SPAN></P> + +<P>and next click on <B>"Install All"</B></P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_feature_verification.jpg" style="border: 0px solid black"></SPAN></P> + +<P>When asked to <B>"restart eclipse"</B>, click the <B>"yes"</B> button. </P> + +<P><SPAN class="image-wrap" style=""><IMG src="tools-install-tuscany-eclipse-plugins-11.data/install_update_restart_eclipse.jpg" style="border: 0px solid black"></SPAN></P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-Createyour1stCompositeServiceApplication"></A>Create your 1st Composite Service Application</H2> + +<P>The following shows the composition diagram for the composite service application you are about<BR> +to create.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/first_composite.png" style="border: 0px solid black"></SPAN></P> + +<P>The composite service application you will create is a composition of four services. The composed<BR> +service provided is that of an on-line store.<BR> +There is a Catalog service which you can ask for catalog items, and depending on its currency<BR> +code property configuration it will provide the item prices in USD or EUR. The Catalog service is not<BR> +doing the currency conversion itself it references a CurrencyConverter service to do that task. Then<BR> +there is the ShoppingCart service into which items chosen from the catalog can be added, it is<BR> +implemented as a REST service. The Catalog is bound using the JSONRPC binding, and the<BR> +ShoppingCart service is bound using the ATOM binding. Finally there is the Store user facing<BR> +service that provides the browser based user interface of the store. The Store service makes use of<BR> +the Catalog and ShoppingCart service using the JSONRPC, and ATOM binding respectively.</P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-CreateaJavaProject"></A>Create a Java Project</H2> + +<P>In this step you create a Java Project in Eclipse to hold the composite service application.<BR> +Click on the <B><EM>New Java Project</EM></B> button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_project.png" style="border: 0px solid black"></SPAN> in the toolbar to launch the project creation dialog.<BR> +Next you enter "store" as the <B><EM>Project name</EM></B>, and for <B><EM>Project Layout</EM></B> select <B><EM>Create separate</EM></B><BR> +<B><EM>folders for sources and class files.</EM></B><BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_project_dlg.png" style="border: 0px solid black"></SPAN><BR> + <BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/project_layout.png" style="border: 0px solid black"></SPAN><BR> + <BR> +Hit the <B><EM>Next</EM></B> button, and on the following page go to the <B><EM>Libraries</EM></B> tab. Use the <B><EM>Add Library...</EM></B><BR> +button on the right to add the <B>Tuscany Library</B> library to the project.<BR> + <BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_project_lib.png" style="border: 0px solid black"></SPAN><BR> + <BR> + <BR> +Hit the <B><EM>Finish</EM></B> button to complete the <B><EM>New Java Project</EM></B> dialog to create the "store" java project. <BR> + <BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_project_folder.png" style="border: 0px solid black"></SPAN><BR> + <BR> + </P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-ConstructServices"></A>Construct Services</H2> + +<P>First you create two package folders into which later in this step you place service implementations.<BR> +Select the "store" project and click on the <B><EM>New Java Package</EM></B> button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_pkg_btn.png" style="border: 0px solid black"></SPAN> in the toolbar to launch<BR> +the package creation dialog.</P> + +<P>Next you enter "services" as the package <B><EM>Name</EM></B>, and press the <B><EM>Finish</EM></B> button to complete the<BR> +dialog.<BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_pkg_dlg.png" style="border: 0px solid black"></SPAN><BR> + <BR> +Repeat the previous step to create another package named "ufservices". The store project now<BR> +should look as follows.<BR> + <BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_pkg_folder.png" style="border: 0px solid black"></SPAN><BR> + <BR> +In the following you will place in the "services" package the regular services, and in the "ufservices"<BR> +package the user facing services of the composite service application you create.</P> + +<H3><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-Catalog"></A><EM>Catalog</EM></H3> + +<P>In this step you create the Catalog service interface and implementation.<BR> +Select the "services" package. Next you click on the dropdown arrow next to the <B><EM>New Java Class</EM></B><BR> +button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/class_btn.png" style="border: 0px solid black"></SPAN> and select the <B><EM>New Java Interface</EM></B> <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/interface_btn.png" style="border: 0px solid black"></SPAN> option from the dropdown list. In the dialog<BR> +enter "Catalog" as the <B><EM>Name</EM></B> of the interface and select the Finish button to complete the dialog.<BR> +The Java editor will open on the new created Java interface. Replace the content of the editor by<BR> +<B><EM>copy-paste</EM></B> of the following Java interface code snippet.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> services; +<SPAN class="code-keyword">import</SPAN> org.osoa.sca.annotations.Remotable; +@Remotable +<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> Catalog { + <SPAN class="code-object">String</SPAN>[] get(); +} +</PRE> +</DIV></DIV> +<P>Select the "services" package again. Select the <B><EM>New Java Class</EM></B> button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/class_btn.png" style="border: 0px solid black"></SPAN> . In the dialog enter<BR> +"CatalogImpl" as the <B><EM>Name</EM></B> of the class, add "Catalog" as the interface this class implements, and<BR> +then select <B><EM>Finish</EM></B> to complete the dialog.</P> + +<P>The Java editor will open on the new created Java class. Replace the content of the editor by<BR> +<B><EM>copy-paste</EM></B> of the following Java class code snippet.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> services; +<SPAN class="code-keyword">import</SPAN> java.util.ArrayList; +<SPAN class="code-keyword">import</SPAN> java.util.List; +<SPAN class="code-keyword">import</SPAN> org.osoa.sca.annotations.Init; +<SPAN class="code-keyword">import</SPAN> org.osoa.sca.annotations.Property; +<SPAN class="code-keyword">import</SPAN> org.osoa.sca.annotations.Reference; +<SPAN class="code-keyword">public</SPAN> class CatalogImpl <SPAN class="code-keyword">implements</SPAN> Catalog { + @Property + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> currencyCode = <SPAN class="code-quote">"USD"</SPAN>; + @Reference + <SPAN class="code-keyword">public</SPAN> CurrencyConverter currencyConverter; + <SPAN class="code-keyword">private</SPAN> List<<SPAN class="code-object">String</SPAN>> catalog = <SPAN class="code-keyword">new</SPAN> ArrayList<<SPAN class="code-object">String</SPAN>>(); + @Init + <SPAN class="code-keyword">public</SPAN> void init() { + <SPAN class="code-object">String</SPAN> currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); + catalog.add(<SPAN class="code-quote">"Apple - "</SPAN> + currencySymbol + + currencyConverter.getConversion(<SPAN class="code-quote">"USD"</SPAN>, currencyCode, 2.99f)); + catalog.add(<SPAN class="code-quote">"Orange - "</SPAN> + currencySymbol + + currencyConverter.getConversion(<SPAN class="code-quote">"USD"</SPAN>, currencyCode, 3.55f)); + catalog.add(<SPAN class="code-quote">"Pear - "</SPAN> + currencySymbol + + currencyConverter.getConversion(<SPAN class="code-quote">"USD"</SPAN>, currencyCode, 1.55f)); + } + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN>[] get() { + <SPAN class="code-object">String</SPAN>[] catalogArray = <SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">String</SPAN>[catalog.size()]; + catalog.toArray(catalogArray); + <SPAN class="code-keyword">return</SPAN> catalogArray; + } +} +</PRE> +</DIV></DIV> +<P>After completing these steps the content of the "store" project will look as follows.<BR> +<SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project.png" style="border: 0px solid black"></SPAN><BR> + <BR> +<B>Note:</B> CatalogImpl is red x'ed because it makes use of the CurrencyConverter interface that we<BR> +have not implemented yet.<BR> + </P> + +<H3><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-CurrencyConverter"></A><EM>CurrencyConverter</EM></H3> + +<P>In this step you create the CurrencyConverter service interface and implementation.<BR> +You follow the same steps that you learned previously to create the interface and implementation.<BR> +First create a Java interface in the "services" package named "CurrencyConverter" and <B><EM>copy-paste</EM></B><BR> +the following Java interface code snippet into it.<BR> + </P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> services; +<SPAN class="code-keyword">import</SPAN> org.osoa.sca.annotations.Remotable; +@Remotable +<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> CurrencyConverter { + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">float</SPAN> getConversion(<SPAN class="code-object">String</SPAN> fromCurrenycCode, + <SPAN class="code-object">String</SPAN> toCurrencyCode, <SPAN class="code-object">float</SPAN> amount); + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> getCurrencySymbol(<SPAN class="code-object">String</SPAN> currencyCode); +} +</PRE> +</DIV></DIV> +<P>Next create a Java class in the "services" package named "CurrencyConverterImpl" and <B><EM>copy-paste</EM></B><BR> +the following Java class code snippet into it.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> services; +<SPAN class="code-keyword">public</SPAN> class CurrencyConverterImpl <SPAN class="code-keyword">implements</SPAN> CurrencyConverter { + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">float</SPAN> getConversion(<SPAN class="code-object">String</SPAN> fromCurrencyCode, + <SPAN class="code-object">String</SPAN> toCurrencyCode, <SPAN class="code-object">float</SPAN> amount) { + <SPAN class="code-keyword">if</SPAN> (toCurrencyCode.equals(<SPAN class="code-quote">"USD"</SPAN>)) + <SPAN class="code-keyword">return</SPAN> amount; + <SPAN class="code-keyword">else</SPAN> <SPAN class="code-keyword">if</SPAN> (toCurrencyCode.equals(<SPAN class="code-quote">"EUR"</SPAN>)) + <SPAN class="code-keyword">return</SPAN> amount*0.7256f; + <SPAN class="code-keyword">return</SPAN> 0; + } + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> getCurrencySymbol(<SPAN class="code-object">String</SPAN> currencyCode) { + <SPAN class="code-keyword">if</SPAN> (currencyCode.equals(<SPAN class="code-quote">"USD"</SPAN>)) + <SPAN class="code-keyword">return</SPAN> <SPAN class="code-quote">"$"</SPAN>; + <SPAN class="code-keyword">else</SPAN> + <SPAN class="code-keyword">if</SPAN> (currencyCode.equals(<SPAN class="code-quote">"EUR"</SPAN>)) + <SPAN class="code-keyword">return</SPAN> <SPAN class="code-quote">"€"</SPAN>; + <SPAN class="code-keyword">return</SPAN> <SPAN class="code-quote">"?"</SPAN>; + } +} +</PRE> +</DIV></DIV> +<P>After completing these steps the content of the "store" project will look as follows.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project_1.png" style="border: 0px solid black"></SPAN></P> + +<H3><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-ShoppingCart"></A><EM>ShoppingCart</EM></H3> + +<P>In this step you create the ShoppingCart service implementation.</P> + +<P>You follow the same steps that you learned previously to create the implementation.</P> + +<P>Create a Java class in the "services" package named "ShoppingCartImpl" and <B><EM>copy-paste</EM></B> the<BR> +following Java class code snippet into it.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> services; +<SPAN class="code-keyword">import</SPAN> java.util.Date; +<SPAN class="code-keyword">import</SPAN> java.util.HashMap; +<SPAN class="code-keyword">import</SPAN> java.util.Map; +<SPAN class="code-keyword">import</SPAN> java.util.UUID; +<SPAN class="code-keyword">import</SPAN> org.apache.tuscany.sca.binding.feed.collection.Collection; +<SPAN class="code-keyword">import</SPAN> org.apache.tuscany.sca.binding.feed.collection.NotFoundException; +<SPAN class="code-keyword">import</SPAN> com.sun.syndication.feed.atom.Content; +<SPAN class="code-keyword">import</SPAN> com.sun.syndication.feed.atom.Entry; +<SPAN class="code-keyword">import</SPAN> com.sun.syndication.feed.atom.Feed; +<SPAN class="code-keyword">import</SPAN> com.sun.syndication.feed.atom.Link; +<SPAN class="code-keyword">public</SPAN> class ShoppingCartImpl <SPAN class="code-keyword">implements</SPAN> Collection { + <SPAN class="code-comment">// needs to change to instance <SPAN class="code-keyword">var</SPAN> once conversation scope works +</SPAN> <SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">static</SPAN> Map<<SPAN class="code-object">String</SPAN>, Entry> cart = <SPAN class="code-keyword">new</SPAN> HashMap<<SPAN class="code-object">String</SPAN>, Entry>(); + <SPAN class="code-keyword">public</SPAN> Feed getFeed() { + Feed feed = <SPAN class="code-keyword">new</SPAN> Feed(); + feed.setTitle(<SPAN class="code-quote">"shopping cart"</SPAN>); + Content subtitle = <SPAN class="code-keyword">new</SPAN> Content(); + subtitle.setValue(<SPAN class="code-quote">"Total : "</SPAN> + getTotal()); + feed.setSubtitle(subtitle); + feed.getEntries().addAll(cart.values()); + <SPAN class="code-keyword">return</SPAN> feed; + } + <SPAN class="code-keyword">public</SPAN> Entry get(<SPAN class="code-object">String</SPAN> id) <SPAN class="code-keyword">throws</SPAN> NotFoundException { + <SPAN class="code-keyword">return</SPAN> cart.get(id); + } + <SPAN class="code-keyword">public</SPAN> Entry post(Entry entry) { + <SPAN class="code-object">String</SPAN> id = <SPAN class="code-quote">"cart-"</SPAN> + UUID.randomUUID().toString(); + entry.setId(id); + Link link = <SPAN class="code-keyword">new</SPAN> Link(); + link.setRel(<SPAN class="code-quote">"edit"</SPAN>); + link.setHref("" + id); + entry.getOtherLinks().add(link); + link = <SPAN class="code-keyword">new</SPAN> Link(); + link.setRel(<SPAN class="code-quote">"alternate"</SPAN>); + link.setHref("" + id); + entry.getAlternateLinks().add(link); + entry.setCreated(<SPAN class="code-keyword">new</SPAN> Date()); + cart.put(id, entry); + <SPAN class="code-keyword">return</SPAN> entry; + } + <SPAN class="code-keyword">public</SPAN> void put(<SPAN class="code-object">String</SPAN> id, Entry entry) <SPAN class="code-keyword">throws</SPAN> NotFoundException { + entry.setUpdated(<SPAN class="code-keyword">new</SPAN> Date()); + cart.put(id, entry); + } + <SPAN class="code-keyword">public</SPAN> void delete(<SPAN class="code-object">String</SPAN> id) <SPAN class="code-keyword">throws</SPAN> NotFoundException { + <SPAN class="code-keyword">if</SPAN> (id.equals("")) + cart.clear(); + <SPAN class="code-keyword">else</SPAN> + cart.remove(id); + } <SPAN class="code-keyword">private</SPAN> <SPAN class="code-object">String</SPAN> getTotal() { + <SPAN class="code-object">float</SPAN> total = 0; + <SPAN class="code-object">String</SPAN> symbol = ""; + <SPAN class="code-keyword">if</SPAN> (!cart.isEmpty()) { + Entry entry = cart.values().iterator().next(); + <SPAN class="code-object">String</SPAN> item = ((Content)entry.getContents().get(0)).getValue(); + symbol = item.substring(item.indexOf(<SPAN class="code-quote">"-"</SPAN>)+2, item.indexOf(<SPAN class="code-quote">"-"</SPAN>)+3); + } + <SPAN class="code-keyword">for</SPAN> (Entry entry : cart.values()) { + <SPAN class="code-object">String</SPAN> item = ((Content)entry.getContents().get(0)).getValue(); + total += <SPAN class="code-object">Float</SPAN>.valueOf(item.substring(item.indexOf(<SPAN class="code-quote">"-"</SPAN>)+3)); + } + <SPAN class="code-keyword">return</SPAN> symbol + <SPAN class="code-object">String</SPAN>.valueOf(total); + } +} +</PRE> +</DIV></DIV> +<P><B>Note:</B> Since the Tuscany conversational support is not ready yet the cart is realized through a hack.<BR> +The cart field is defined as static.</P> + +<P>After completing these steps the content of the "store" project will look as follows.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project_2.png" style="border: 0px solid black"></SPAN><BR> + </P> + +<H3><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-%7B%7DStore%7B%7D"></A><B><EM>Store</EM></B></H3> + +<P>In this step you create the user facing Store service that will run in a Web browser and provide the<BR> +user interface to the other services you created.</P> + +<P>Select the "ufservices" package. <B><EM>Right click</EM></B> to get the context menu, select <B><EM>New</EM></B>, and then <B><EM>File</EM></B>. In<BR> +the <B><EM>New File</EM></B> dialog enter "store.html" for the <B><EM>File name</EM></B>, and then select <B><EM>Finish</EM></B> to complete the<BR> +dialog.</P> + +<P>The Text editor will open on the new created html file. Replace the content of the editor by <B><EM>copy-paste</EM></B><BR> +of the following html snippet.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<html> +<head> +<title>Store</TITLE> + +<script type=<SPAN class="code-quote">"text/javascript"</SPAN> src=<SPAN class="code-quote">"store.js"</SPAN>></script> + +<script language=<SPAN class="code-quote">"JavaScript"</SPAN>> + + <SPAN class="code-comment">//@Reference +</SPAN> <SPAN class="code-keyword">var</SPAN> catalog = <SPAN class="code-keyword">new</SPAN> Reference(<SPAN class="code-quote">"catalog"</SPAN>); + + <SPAN class="code-comment">//@Reference +</SPAN> <SPAN class="code-keyword">var</SPAN> shoppingCart = <SPAN class="code-keyword">new</SPAN> Reference(<SPAN class="code-quote">"shoppingCart"</SPAN>); + + + function catalog_getResponse(items) { + <SPAN class="code-keyword">var</SPAN> catalog = ""; + <SPAN class="code-keyword">for</SPAN> (<SPAN class="code-keyword">var</SPAN> i=0; i<items.length; i++) + catalog += '<input name=<SPAN class="code-quote">"items"</SPAN> type=<SPAN class="code-quote">"checkbox"</SPAN> value="' + + items[i] + '">' + items[i]+ ' <br>'; + document.getElementById('catalog').innerHTML=catalog; + } + + function shoppingCart_getResponse(feed) { + <SPAN class="code-keyword">if</SPAN> (feed != <SPAN class="code-keyword">null</SPAN>) { + <SPAN class="code-keyword">var</SPAN> entries = feed.getElementsByTagName(<SPAN class="code-quote">"entry"</SPAN>); + <SPAN class="code-keyword">var</SPAN> list = ""; + <SPAN class="code-keyword">for</SPAN> (<SPAN class="code-keyword">var</SPAN> i=0; i<entries.length; i++) { + <SPAN class="code-keyword">var</SPAN> item = entries[i].getElementsByTagName(<SPAN class="code-quote">"content"</SPAN>)[0].firstChild.nodeValue; + list += item + ' <br>'; + } + document.getElementById(<SPAN class="code-quote">"shoppingCart"</SPAN>).innerHTML = list; + document.getElementById('total').innerHTML = feed.getElementsByTagName(<SPAN class="code-quote">"subtitle"</SPAN>)[0].firstChild.nodeValue; + } + } + function shoppingCart_postResponse(entry) { + shoppingCart.get("", shoppingCart_getResponse); + } + + + function addToCart() { + <SPAN class="code-keyword">var</SPAN> items = document.catalogForm.items; + <SPAN class="code-keyword">var</SPAN> j = 0; + <SPAN class="code-keyword">for</SPAN> (<SPAN class="code-keyword">var</SPAN> i=0; i<items.length; i++) + <SPAN class="code-keyword">if</SPAN> (items[i].checked) { + <SPAN class="code-keyword">var</SPAN> entry = '<entry xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2005/Atom"</SPAN>><title>cart-item</title><content type=<SPAN class="code-quote">"text"</SPAN>>'+items[i].value+'</content></entry>' +</SPAN> shoppingCart.post(entry, shoppingCart_postResponse); + items[i].checked = <SPAN class="code-keyword">false</SPAN>; + } + } + function checkoutCart() { + document.getElementById('store').innerHTML='<h2>' + + 'Thanks <SPAN class="code-keyword">for</SPAN> Shopping With Us!</h2>'+ + '<h2>Your Order</h2>'+ + '<form name=<SPAN class="code-quote">"orderForm"</SPAN> action=<SPAN class="code-quote">"store.html"</SPAN>>'+ + document.getElementById('shoppingCart').innerHTML+ + '<br>'+ + document.getElementById('total').innerHTML+ + '<br>'+ + '<br>'+ + '<input type=<SPAN class="code-quote">"submit"</SPAN> value=<SPAN class="code-quote">"Continue Shopping"</SPAN>>'+ + '</form>'; + shoppingCart.del("", <SPAN class="code-keyword">null</SPAN>); + } + function deleteCart() { + shoppingCart.del("", <SPAN class="code-keyword">null</SPAN>); + document.getElementById('shoppingCart').innerHTML = ""; + document.getElementById('total').innerHTML = ""; + } + + catalog.get(catalog_getResponse); + shoppingCart.get("", shoppingCart_getResponse); +</script> + +</head> + +<body> +<h1>Store</h1> + <div id=<SPAN class="code-quote">"store"</SPAN>> + <h2>Catalog</h2> + <form name=<SPAN class="code-quote">"catalogForm"</SPAN>> + <div id=<SPAN class="code-quote">"catalog"</SPAN> ></div> + <br> + <input type=<SPAN class="code-quote">"button"</SPAN> onClick=<SPAN class="code-quote">"addToCart()"</SPAN> value=<SPAN class="code-quote">"Add to Cart"</SPAN>> + </form> + + <br> + + <h2>Your Shopping Cart</h2> + <form name=<SPAN class="code-quote">"shoppingCartForm"</SPAN>> + <div id=<SPAN class="code-quote">"shoppingCart"</SPAN>></div> + <br> + <div id=<SPAN class="code-quote">"total"</SPAN>></div> + <br> + <input type=<SPAN class="code-quote">"button"</SPAN> onClick=<SPAN class="code-quote">"checkoutCart()"</SPAN> value=<SPAN class="code-quote">"Checkout"</SPAN>> + <input type=<SPAN class="code-quote">"button"</SPAN> onClick=<SPAN class="code-quote">"deleteCart()"</SPAN> value=<SPAN class="code-quote">"Empty"</SPAN>> + <a href=<SPAN class="code-quote">"../ShoppingCart/"</SPAN>>(feed)</a> + </form> + </div> +</body> +</html> +</PRE> +</DIV></DIV> +<P>After completing these steps the content of the "store" project will look as follows.</P> + +<P> <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project_3.jpg" style="border: 0px solid black"></SPAN></P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-ComposeServices"></A>Compose Services</H2> + +<P>Now that you have all the required service implementations you compose them together to provide<BR> +the store composite service. The composition is stored in a .composite file.</P> + +<P>Select the "src" folder of the "store" project. <B><EM>Right click</EM></B> to get the context menu, select <B><EM>New</EM></B>, and<BR> +then <B><EM>File</EM></B>. In the <B><EM>New File</EM></B> dialog enter "store.composite" for the <B><EM>File name</EM></B>, and then select <B><EM>Finish</EM></B><BR> +to complete the dialog.</P> + +<P>The Text editor will open on the new created composite file. Replace the content of the editor by<BR> +<B><EM>copy-paste</EM></B> of the following composite snippet.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<?xml version=<SPAN class="code-quote">"1.0"</SPAN> encoding=<SPAN class="code-quote">"UTF-8"</SPAN>?> +<composite xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.osoa.org/xmlns/sca/1.0"</SPAN> +</SPAN> xmlns:t=<SPAN class="code-quote">"http:<SPAN class="code-comment">//tuscany.apache.org/xmlns/sca/1.0"</SPAN> +</SPAN> xmlns:s=<SPAN class="code-quote">"http:<SPAN class="code-comment">//store"</SPAN> +</SPAN> name=<SPAN class="code-quote">"store"</SPAN>> + <component name=<SPAN class="code-quote">"store"</SPAN>> + <t:implementation.widget location=<SPAN class="code-quote">"ufservices/store.html"</SPAN>/> + <service name=<SPAN class="code-quote">"Widget"</SPAN>> + <t:binding.http/> + </service> + <reference name=<SPAN class="code-quote">"catalog"</SPAN> target=<SPAN class="code-quote">"Catalog"</SPAN>> + <t:binding.jsonrpc/> + </reference> + <reference name=<SPAN class="code-quote">"shoppingCart"</SPAN> target=<SPAN class="code-quote">"ShoppingCart"</SPAN>> + <t:binding.atom/> + </reference> + </component> + <component name=<SPAN class="code-quote">"Catalog"</SPAN>> + <implementation.java class=<SPAN class="code-quote">"services.CatalogImpl"</SPAN>/> + <property name=<SPAN class="code-quote">"currencyCode"</SPAN>>USD</property> + <service name=<SPAN class="code-quote">"Catalog"</SPAN>> + <t:binding.jsonrpc/> + </service> + <reference name=<SPAN class="code-quote">"currencyConverter"</SPAN> target=<SPAN class="code-quote">"CurrencyConverter"</SPAN>/> + </component> + <component name=<SPAN class="code-quote">"ShoppingCart"</SPAN>> + <implementation.java class=<SPAN class="code-quote">"services.ShoppingCartImpl"</SPAN>/> + <service name=<SPAN class="code-quote">"Collection"</SPAN>> + <t:binding.atom/> + </service> + </component> + <component name=<SPAN class="code-quote">"CurrencyConverter"</SPAN>> + <implementation.java class=<SPAN class="code-quote">"services.CurrencyConverterImpl"</SPAN>/> + </component> +</composite> +</PRE> +</DIV></DIV> +<P>After completing these steps the content of the "store" project will look as follows.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project_4.jpg" style="border: 0px solid black"></SPAN><BR> + </P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-LaunchServices"></A>Launch Services</H2> + +<P>In this step you create the code to launch the Tuscany runtime with the new store composite<BR> +service you created.</P> + +<P>Select the "store" project and click on the <B><EM>New Java Package</EM></B> button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/new_java_pkg_btn.png" style="border: 0px solid black"></SPAN> in the toolbar to start the</P> + +<P>package creation dialog. Use the dialog to create a new package named "launch". <BR> +Select the "launch" package. Select the <B><EM>New Java Class</EM></B> button <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/class_btn.png" style="border: 0px solid black"></SPAN> . In the dialog enter "Launch"<BR> +as the <B><EM>Name</EM></B> of the class, check the <B><EM>checkbox for creating a main method stub</EM></B>, and then select<BR> +<B><EM>Finish</EM></B> to complete the dialog.</P> + +<P>The Java editor will open on the new created Java class. Replace the content of the editor by<BR> +<B><EM>copy-paste</EM></B> of the following Java class code snippet.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<SPAN class="code-keyword">package</SPAN> launch; +<SPAN class="code-keyword">import</SPAN> org.apache.tuscany.sca.host.embedded.SCADomain; +<SPAN class="code-keyword">public</SPAN> class Launch { + <SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">static</SPAN> void main(<SPAN class="code-object">String</SPAN>[] args) <SPAN class="code-keyword">throws</SPAN> Exception { + <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"Starting ..."</SPAN>); + SCADomain scaDomain = SCADomain.newInstance(<SPAN class="code-quote">"store.composite"</SPAN>); + <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"store.composite ready <SPAN class="code-keyword">for</SPAN> big business !!!"</SPAN>); + <SPAN class="code-object">System</SPAN>.out.println(); + <SPAN class="code-object">System</SPAN>.in.read(); + scaDomain.close(); + } +} +</PRE> +</DIV></DIV> +<P> After completing these steps the content of the "store" project will look as follows.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_project_5.jpg" style="border: 0px solid black"></SPAN><BR> +Congratulations you completed your 1st composite service applications, now its time to take it into<BR> +action.</P> + +<H2><A name="GettingStartedwithTuscany%28usingTuscanyEclipsePlugin1.1%29-UseServices"></A>Use Services</H2> + +<P>In this step you launch and use the store composite service application you created.</P> + +<P>First select the "Launch" class in the "launch" package of your "store" project. <B><EM>Right click</EM></B> to get the<BR> +context menu, select <B><EM>Run As</EM></B>, and then <B><EM>Java application</EM></B>. The Tuscany runtime will start up adding<BR> +the store composition to its domain.</P> + +<P>The Eclipse console will show the following messages.</P> + +<P> <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/eclipse_console.png" style="border: 0px solid black"></SPAN></P> + +<P> Next Launch your Web browser and enter the following address:</P> + +<P><A href="http://localhost:8080/store/store.html" class="external-link" rel="nofollow">http://localhost:8080/store/store.html</A> </P> + +<P> You get to the Store user facing service of the composite service application.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_page.png" style="border: 0px solid black"></SPAN></P> + +<P>You can select items from the Catalog and add them to your Shopping Cart.</P> + +<P><B>Note:</B> When adding items for the first time you will be asked for <B><EM>userid and password</EM></B> by the<BR> +browser. Enter "admin" for both.</P> + +<P> <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_page_1.png" style="border: 0px solid black"></SPAN></P> + +<P>Since the ShoppingCart service is bound using the ATOM binding, you can also look at the<BR> +shopping card content in ATOM feed form by clicking on the feed icon <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/atom_feed.png" style="border: 0px solid black"></SPAN>. You get the browsers default rendering for ATOM feeds.</P> + +<P> <SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/atom_feeds_page.png" style="border: 0px solid black"></SPAN></P> + +<P> Use the browser back button to get back to the Store page.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_page_2.png" style="border: 0px solid black"></SPAN></P> + +<P>And then you can Checkout to complete your order.</P> + +<P><SPAN class="image-wrap" style=""><IMG src="getting-started-with-tuscany-using-tuscany-eclipse-plugin-11.data/store_page_3.png" style="border: 0px solid black"></SPAN></P> + </DIV> + </DIV> + </DIV> + <!-- pageContent macro end --> + + </TD> + </TR> + </TABLE> + + <!-- footer macro --> + <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript"> + </SCRIPT> + <SCRIPT type="text/javascript"> + _uacct = "UA-1174707-5"; + urchinTracker(); + </SCRIPT> + + <A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A> + + <DIV class="footer"> + Copyright � 2003-2012, The Apache Software Foundation </BR> + Apache Tuscany and the Apache Tuscany project logo are trademarks of The Apache Software Foundation. + </DIV> + <!-- footer macro end --> + + </BODY> +</HTML> |