I checked in a version of the Store sample described in the Getting
Started document a while ago.
I'd like to describe a few thoughts on how to improve the sample with
small changes to the sample itself and some improvements to the
implementation.resource extension and how it integrates with Web
2.0-friendly bindings.
The current Store sample looks like this:
store.composite
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:s="http://store"
name="store">
<component name="ufs">
<t:implementation.resource location="ufservices"/>
<service name="Resource">
<t:binding.http/>
</service>
</component>
<component name="Catalog">
<implementation.java class="services.CatalogImpl"/>
<property name="currencyCode">USD</property>
<service name="Catalog">
<t:binding.jsonrpc/>
</service>
<reference name="currencyConverter"
target="CurrencyConverter"/>
</component>
<component name="ShoppingCart">
<implementation.java class="services.ShoppingCartImpl"/>
<service name="Collection">
<t:binding.atom/>
</service>
</component>
<component name="CurrencyConverter">
<implementation.java class="services.CurrencyConverterImpl"/>
</component>
</composite>
store.html
<html>
<head>
<title>Store</title>
<script type="text/javascript" src="binding-atom.js"></script>
<script type="text/javascript" src="binding-jsonrpc.js"></script>
<script language="JavaScript">
//Reference
catalog = (new JSONRpcClient("../Catalog/")).Catalog;
//Reference
shoppingCart = new AtomClient("../ShoppingCart/");
We can see that the Catalog and ShoppingCart services offered to the
Store client are properly modeled and configured with <binding.jsonrpc>
and <binding.atom>. However the Composite does not describe any
references on the UFS component. When you look at the composite you
don't see that the client Javascript code in store.html actually
references the Catalog and ShoppingCart services, and proxies to these
services are constructed by hand in the client Javascript code.
I think it would be better if we could write something like follows:
store.composite
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:s="http://store"
name="store">
<component name="ufs">
<!-- Point directly to the HTML page -->
<t:implementation.resource location="store.html"/>
<service name="Resource">
<t:binding.http/>
</service>
<!-- Describe references to the target services -->
<reference name="catalog" target="Catalog">
<t:binding.jsonrpc/>
</reference>
<reference name="shoppingCart" target="ShoppingCart">
<t:binding.atom/>
</reference>
</component>
<component name="Catalog">
<implementation.java class="services.CatalogImpl"/>
<property name="currencyCode">USD</property>
<service name="Catalog">
<t:binding.jsonrpc/>
</service>
<reference name="currencyConverter"
target="CurrencyConverter"/>
</component>
<component name="ShoppingCart">
<implementation.java class="services.ShoppingCartImpl"/>
<service name="Collection">
<t:binding.atom/>
</service>
</component>
<component name="CurrencyConverter">
<implementation.java class="services.CurrencyConverterImpl"/>
</component>
</composite>
store.html
<html>
<head>
<title>Store</title>
<!-- include a single script, covering multiple bindings -->
<script type="text/javascript" src="sca.js"></script>
<script language="JavaScript">
<!-- Simplified creation of the client proxies -->
catalog = Reference("catalog");
shoppingCart = Reference("shoppingCart");
This introduces the following changes:
In store.composite
- The <implementation.resource> element directly points to store.html,
so when you look at the .composite you know what HTML page is actually used.
- The ufs component now declares correct references and wiring to other
service components in the assembly.
In store.html
- A single sca.js script is generated for the client to include, very
much like the generated scaDomain.js file, but covering multiple
bindings, and customized for this particular UFS component and the
references that were declared on it.
- The client code is simpler, you can do catalog = Reference("catalog")
or you could do something like catalog = references.catalog (where
references.catalog would be initialized in sca.js), but I think I prefer
the first form as it allows me to pick the name of the variable I'm
going to use and Reference("catalog") also allows execution of some
initialization code when the proxy is initialized.
These changes should be possible with minimum effort but I think they
will improve the sample a lot.
Thoughts?
--
Jean-Sebastien
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]