On 10/11/07, Ana Belén Antón Gironés <[EMAIL PROTECTED]> wrote:
>
> Dear all,
>
> I am new using SCA and using TUSCANY and I am a little lost.
>
> I have download apache-tuscany-sca-1.0-incubating and I am working with
> Java
> [jre 1.5.0_11]. I would like use SCA for my application but I would like
> to
> kow before if it is possible that my "service implementation" returns a
> "java object". So, not only simple types and arrays.
>
> Thank you very much in advance for your help.
>
> Best regards,
>
> Ana Belen.
>
Hi Ana Belen, welcome to Tuscany.
Yes a service can return a Java object. There is a sample you can look at
called simple-bigbank. You will find it in the samples directory. Here, in
the directory samples\simple-bigbank\src\main\java\bigbank\account, there
is a service interface that looks like.
public interface AccountService {
public AccountReport getAccountReport(String customerID);
}
an AccountReport class that looks like
public class AccountReport {
private List<String> summaries;
private String currency;
public AccountReport(String currency, List<String> summaries) {
this.currency = currency;
this.summaries = summaries;
}
public List getAccountSummaries() { return summaries; }
public String getCurrency() { return currency; }
@Override
public String toString() {
return "currency: "+ currency + ", " + summaries;
}
}
and a service implementation that looks like.
public class AccountServiceImpl implements AccountService {
@Reference
public AccountDataService accountDataService;
@Reference
public StockQuoteService stockQuoteService;
@Property
public String currency;
public AccountReport getAccountReport(String s) {
List<String> summaries = new ArrayList<String>();
CheckingAccount ca = accountDataService.getCheckingAccount(s);
summaries.add(ca.getSummary());
SavingsAccount sa = accountDataService.getSavingsAccount(s);
summaries.add(sa.getSummary());
StockAccount sk = accountDataService.getStockAccount(s);
double price = stockQuoteService.getQuote(sk.getSymbol());
sk.setBalance(sk.getQuantity() * price);
summaries.add(sk.getSummary());
AccountReport report = new AccountReport(currency, summaries);
return report;
}
If you look at the composite file
(samples\simple-bigbank\src\main\resources\Account.composite) you can see
how the AccountService is constructed in the SCA application.
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://account"
name="Account">
<service name="AccountService" promote="AccountServiceComponent"/>
<component name="AccountServiceComponent">
<implementation.java class="bigbank.account.AccountServiceImpl"/>
<reference name="accountDataService"
target="AccountDataServiceComponent"/>
<property name="currency">USD</property>
</component>
<component name="AccountDataServiceComponent">
<implementation.java class="
bigbank.accountdata.AccountDataServiceImpl"/>
</component>
<reference name="stockQuoteService"
promote="AccountServiceComponent/stockQuoteService"/>
</composite>
The README tells you how to run the sample if you want to try it for
yourself.
Hope this helps. Come back here if you need more help or info.
Regards
Simon