From 3dd7e2c4da9c80b8182a2d04dc129a67aa7910df Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:58 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835121 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/old/bigbank/account/pom.xml | 178 ++++ .../services/account/AccountServiceImpl.java | 279 +++++++ .../services/accountdata/AccountDataService.java | 87 ++ .../accountdata/AccountDataServiceDASImpl.java | 400 +++++++++ .../accountdata/AccountDataServiceImpl.java | 106 +++ .../services/accountdata/CustomerIdService.java | 98 +++ .../account/services/accountdb/AccountDBInit.java | 465 +++++++++++ .../AccountLoggerDataServiceImpl.java | 129 +++ .../accountlogger/AccountLoggerService.java | 47 ++ .../accountlogger/AccountLoggerServiceImpl.java | 216 +++++ .../account/services/stockquote/StockQuote.java | 228 ++++++ .../services/stockquote/StockQuoteService.java | 31 + .../services/stockquote/StockQuoteServiceImpl.java | 68 ++ .../StockQuoteWebservicexServiceImpl.java | 153 ++++ .../src/main/resources/DasAccountConfiguration.xml | 79 ++ .../src/main/resources/wsdl/AccountService.wsdl | 467 +++++++++++ .../resources/wsdl/stockquotes.webservicex.wsdl | 136 ++++ .../account/src/main/webapp/WEB-INF/default.scdl | 80 ++ .../account/src/main/webapp/WEB-INF/web.xml | 70 ++ .../java/bigbank/account/client/AccountClient.java | 56 ++ .../samples/old/bigbank/docs/Show.Image.html | 40 + .../samples/old/bigbank/docs/accountfiles.png | Bin 0 -> 15889 bytes .../samples/old/bigbank/docs/accountmodule.png | Bin 0 -> 33300 bytes .../samples/old/bigbank/docs/modualoverview.png | Bin 0 -> 6074 bytes .../samples/old/bigbank/docs/webclientfiles.png | Bin 0 -> 17123 bytes .../samples/old/bigbank/docs/webclientmodule.png | Bin 0 -> 10748 bytes .../sca-java-0.99/samples/old/bigbank/pom.xml | 44 + .../sca-java-0.99/samples/old/bigbank/readme.html | 894 +++++++++++++++++++++ .../samples/old/bigbank/webclient/pom.xml | 167 ++++ .../account/AccountServiceComponentImpl.java | 117 +++ .../services/profile/AccountLoginServiceImpl.java | 64 ++ .../webclient/services/profile/LoginService.java | 36 + .../webclient/services/profile/ProfileService.java | 42 + .../services/profile/ProfileServiceImpl.java | 69 ++ .../services/profile/SimpleLoginServiceImpl.java | 51 ++ .../webclient/tags/account/AccountLogTag.java | 120 +++ .../webclient/tags/account/AccountStatusTag.java | 135 ++++ .../webclient/tags/account/StockLogTag.java | 81 ++ .../webclient/tags/account/StockStatusTag.java | 85 ++ .../webclient/tags/sca/LoginBarrierTag.java | 101 +++ .../bigbank/webclient/tags/sca/ServiceTag.java | 107 +++ .../java/bigbank/webclient/ui/FormServlet.java | 161 ++++ .../java/bigbank/webclient/ui/LoginServlet.java | 96 +++ .../src/main/resources/wsdl/AccountService.wsdl | 466 +++++++++++ .../webclient/src/main/webapp/CustomerProfile.jsp | 100 +++ .../src/main/webapp/WEB-INF/bigbank-tags.tld | 127 +++ .../webclient/src/main/webapp/WEB-INF/default.scdl | 53 ++ .../webclient/src/main/webapp/WEB-INF/web.xml | 83 ++ .../webclient/src/main/webapp/accountLog.jsp | 99 +++ .../src/main/webapp/accountTransaction.jsp | 50 ++ .../bigbank/webclient/src/main/webapp/login.html | 60 ++ .../webclient/src/main/webapp/purchaseStock.jsp | 59 ++ .../webclient/src/main/webapp/stockSale.jsp | 56 ++ .../bigbank/webclient/src/main/webapp/summary.jsp | 144 ++++ .../webclient/client/TestAccountService.java | 45 ++ .../bigbank/webclient/client/TestLoginService.java | 42 + .../samples/old/binding-echo2-extension/README | 77 ++ .../samples/old/binding-echo2-extension/build.xml | 51 ++ .../samples/old/binding-echo2-extension/pom.xml | 78 ++ .../src/main/java/echo2/extension/EchoBinding.java | 60 ++ .../java/echo2/extension/EchoBindingInvoker.java | 44 + .../extension/EchoBindingProviderFactory.java | 56 ++ .../extension/EchoReferenceBindingProvider.java | 60 ++ .../extension/EchoServiceBindingProvider.java | 73 ++ .../src/main/java/echo2/server/EchoServer.java | 78 ++ .../java/echo2/server/EchoServiceListener.java | 55 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../src/test/java/echo2/Echo.java | 29 + .../src/test/java/echo2/EchoComponentImpl.java | 44 + .../src/test/java/echo2/EchoReferenceTestCase.java | 50 ++ .../src/test/java/echo2/EchoServiceTestCase.java | 50 ++ .../src/test/resources/EchoBinding.composite | 40 + .../old/implementation-crud2-extension/README | 87 ++ .../old/implementation-crud2-extension/build.xml | 51 ++ .../old/implementation-crud2-extension/pom.xml | 77 ++ .../src/main/java/crud2/CRUD.java | 54 ++ .../main/java/crud2/backend/ResourceManager.java | 90 +++ .../java/crud2/extension/CRUDImplementation.java | 128 +++ .../crud2/extension/CRUDImplementationInvoker.java | 70 ++ .../extension/CRUDImplementationProvider.java | 69 ++ .../CRUDImplementationProviderFactory.java | 49 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../src/test/java/crud2/CRUDTestCase.java | 68 ++ .../src/test/resources/crud2.composite | 30 + 86 files changed, 8861 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/CustomerIdService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerDataServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/DasAccountConfiguration.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/AccountService.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/Show.Image.html create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountfiles.png create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountmodule.png create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/modualoverview.png create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientfiles.png create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientmodule.png create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/readme.html create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/account/AccountServiceComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/AccountLoginServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/LoginService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/SimpleLoginServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountLogTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountStatusTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockLogTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockStatusTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/LoginBarrierTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/ServiceTag.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/FormServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/LoginServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/CustomerProfile.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/bigbank-tags.tld create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountLog.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountTransaction.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/login.html create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/purchaseStock.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/stockSale.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/summary.jsp create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestAccountService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestLoginService.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/README create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/build.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServer.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServiceListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/Echo.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/resources/EchoBinding.composite create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/README create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/build.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/CRUD.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/backend/ResourceManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/java/crud2/CRUDTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/resources/crud2.composite (limited to 'sca-java-1.x/branches/sca-java-0.99/samples/old') diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/pom.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/pom.xml new file mode 100644 index 0000000000..991935e07b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/pom.xml @@ -0,0 +1,178 @@ + + + + + org.apache.tuscany.samples.bigbank + bigbank-scenario + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + sample-bigbank-account + war + Tuscany BigBank Account Module + BigBank Scenario - Account Management Module + + + + + org.apache.tuscany.sca.kernel + tuscany-api + ${scaKernelVersion} + compile + + + org.apache.tuscany.sca.runtime.webapp + webapp-api + ${scaKernelVersion} + runtime + + + + + stax + stax-api + 1.0.1 + compile + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubatingversion> + compile + + + + + org.apache.tuscany.das + tuscany-das-rdb + ${dasVersion} + compile + + + javax.servlet + servlet-api + 2.5 + provided + + + org.apache.derby + derby + 10.1.2.1 + compile + + + junit + junit + 4.2 + test + + + + ${artifactId} + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubating + + + + + ${basedir}/src/main/resources/wsdl + true + true + true + + + generate + + + + + + org.apache.tuscany.sca.extensions.axis2.plugins + tuscany-plugin-wsdl2java + ${scaKernelVersion} + + + + + + ${basedir}/src/main/resources/wsdl/stockquotes.webservicex.wsdl + + StockQuoteSoap + + + + ${basedir}/src/main/resources/wsdl/AccountService.wsdl + + + + + generate + + + + + + org.apache.tuscany.sca.runtime.webapp + tuscany-war-plugin + ${scaKernelVersion} + + + tuscany-war + + tuscany-war + + + + + + + false + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + ${scaKernelVersion} + + + org.apache.tuscany.sca.extensions.axis2 + tuscany-axis2 + ${scaKernelVersion} + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java new file mode 100644 index 0000000000..74baa636f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java @@ -0,0 +1,279 @@ +/* + * 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. + */ + +package bigbank.account.services.account; + +import java.rmi.RemoteException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import bigbank.account.services.accountdata.AccountDataService; +import bigbank.account.services.stockquote.StockQuote; +import bigbank.account.services.stockquote.StockQuoteService; + +import com.bigbank.account.AccountLog; +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; +import com.bigbank.account.AccountSummary; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; + +@Service(interfaces = AccountService.class) +public class AccountServiceImpl implements AccountService { + + public static final String CHECKING_ACCOUNT_PREFIX = "134-43-394"; + + public static final String SAVINGS_ACCOUNT_PREFIX = "134-42-623"; + + public static final String ACCOUNT_TYPE_SAVINGS = "savings"; + + public static final String ACCOUNT_TYPE_CHECKINGS = "checkings"; + + public static final DateFormat tsformatXSDDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz"); + static { + AccountServiceImpl.tsformatXSDDateTime.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + private float currencyConversion = 0.0f; + + private String currency = "USD"; + + @Property + public void setCurrency(final String currency) { + this.currency = currency; + } + + float getCurrencyConversion() { + if (currencyConversion == 0.0F) { + if ("USD".equals(currency)) { + currencyConversion = 1.0f; + } else if ("EURO".equals(currency)) { + currencyConversion = 0.8f; + } else { + try { + currencyConversion = Float.parseFloat(currency); + } catch (Exception e) { + currencyConversion = 1.0f; + } + + } + + } + return currencyConversion; + + } + + private AccountDataService accountDataService; + + @Reference + public void setAccountDataService(AccountDataService accountDataService) { + this.accountDataService = accountDataService; + } + + private StockQuoteService stockQuoteService; + + @Reference + public void setStockQuoteService(StockQuoteService stockQuoteService) { + this.stockQuoteService = stockQuoteService; + } + + public AccountServiceImpl() { + } + + @SuppressWarnings("unchecked") + public AccountReport getAccountReport(int customerID) throws RemoteException { + + try { + AccountReport accountReport = accountDataService.getAccountReport(customerID); + // convert to local currency. + List accounts = accountReport.getAccountSummaries(); + for (AccountSummary accountSummary : accounts) { + accountSummary.setBalance(fromUSDollarToCurrency(accountSummary.getBalance())); + + } + return updateStockInformation(accountReport); + } catch (Exception e) { + e.printStackTrace(); + if (e instanceof RemoteException) { + throw (RemoteException) e; + } else { + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + } + + private AccountReport updateStockInformation(AccountReport accountReport) throws RemoteException { + List stocks = accountReport.getStockSummaries(); + if (stocks.size() < 1) { + return accountReport; // nothing todo + } + HashSet owned = new HashSet(stocks.size()); + for (StockSummary stock : stocks) { + owned.add(stock.getSymbol()); + } + ArrayList ownedStr = new ArrayList(owned.size() * 5); + for (String s : owned) { + + ownedStr.add(s); + } + + Map stockInfo = stockQuoteService.getQuotes(ownedStr.toArray(new String[owned.size()])); + + for (StockSummary stock : stocks) { + String symbol = stock.getSymbol(); + StockQuote stockquote = stockInfo.get(symbol); + if (stockquote == null) { + stock.setCurrentPrice(Float.NaN); + stock.setCompany("*not found*"); + stock.setHighPrice(Float.NaN); + stock.setLowPrice(Float.NaN); + + } else { + stock.setCurrentPrice(fromUSDollarToCurrency(convertToFloat(stockquote.getStockQuote()))); + stock.setCompany(stockquote.getCompanyName()); + stock.setHighPrice(fromUSDollarToCurrency(convertToFloat(stockquote.getDayHighPrice()))); + stock.setLowPrice(fromUSDollarToCurrency(convertToFloat(stockquote.getDayLowPrice()))); + } + } + + return accountReport; + } + + float convertToFloat(final String s) { + + try { + return Float.parseFloat(s); + } catch (Exception e) { + return Float.NaN; + } + + } + + private float fromUSDollarToCurrency(float value) { + return value * getCurrencyConversion(); + + } + + private float toUSDollarfromCurrency(float value) { + + return value / getCurrencyConversion(); + } + + public CustomerProfileData getCustomerProfile(String logonID) throws RemoteException { + + try { + return accountDataService.getCustomerProfile(logonID); + } catch (Exception e) { + e.printStackTrace(); + if (e instanceof RemoteException) { + throw (RemoteException) e; + } else { + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + } + + public float deposit(String account, float ammount) throws RemoteException { + try { + return accountDataService.deposit(account, toUSDollarfromCurrency(ammount)); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public StockSummary purchaseStock(int id, StockSummary stock) throws RemoteException { + try { + String symbol = stock.getSymbol(); + Map stockInfo = stockQuoteService.getQuotes(new String[] { symbol }); + + StockQuote stockQuote = stockInfo.get(symbol); + stock.setPurchasePrice(Float.parseFloat(stockQuote.getStockQuote())); + String purchaseDate = tsformatXSDDateTime.format(new Date()); + if (purchaseDate.endsWith("UTC")) { + purchaseDate = purchaseDate.substring(0, purchaseDate.length() - 3) + "Z"; + } + stock.setPurchaseDate(purchaseDate); + + return accountDataService.purchaseStock(id, stock); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException { + try { + return accountDataService.sellStock(purchaseLotNumber, quantity); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public float withdraw(String account, float ammount) throws RemoteException { + try { + return accountDataService.withdraw(account, toUSDollarfromCurrency(ammount)); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings) + throws RemoteException { + try { + return accountDataService.createAccount(customerProfile, createSavings, createCheckings); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public AccountLog getAccountLog(final int customerID) throws RemoteException { + return accountDataService.getAccountLog(customerID); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java new file mode 100644 index 0000000000..884127cd9e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java @@ -0,0 +1,87 @@ +/* + * 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. + */ +package bigbank.account.services.accountdata; + +public interface AccountDataService { + + /** + * Auto generated method signatures + * + * @param param0* + * @param param1* + * @param param2 + */ + public com.bigbank.account.StockSummary purchaseStock(int param0, com.bigbank.account.StockSummary parm1) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param4 + */ + public com.bigbank.account.CustomerProfileData getCustomerProfile(java.lang.String param4) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param6* + * @param param7 + */ + public float deposit(java.lang.String param6, float param7) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param9* + * @param param10* + * @param param11 + */ + public com.bigbank.account.CustomerProfileData createAccount(com.bigbank.account.CustomerProfileData param9, boolean param10, boolean param11) + throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param13* + * @param param14 + */ + public com.bigbank.account.StockSummary sellStock(int param13, int param14) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param16* + * @param param17 + */ + public float withdraw(java.lang.String param16, float param17) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param19 + */ + public com.bigbank.account.AccountReport getAccountReport(int param19) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param0 + */ + public com.bigbank.account.AccountLog getAccountLog(int param0) throws java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java new file mode 100644 index 0000000000..c346a3221f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java @@ -0,0 +1,400 @@ +/* + * 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. + */ +package bigbank.account.services.accountdata; + +import java.io.InputStream; +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.List; +import java.util.Properties; +import java.util.TimeZone; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.Converter; +import org.apache.tuscany.das.rdb.DAS; +import org.osoa.sca.annotations.Service; + +import bigbank.account.services.account.AccountServiceImpl; + +import com.bigbank.account.AccountFactory; +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountSummary; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; +import commonj.sdo.DataObject; + +@Service(CustomerIdService.class) +public class AccountDataServiceDASImpl implements CustomerIdService { // TODO fix this! + + static public String dbDirectory = null; + + public static final DateFormat tsformatXSDDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz"); + + public static final DateFormat sqlformatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSz"); + + static { + tsformatXSDDateTime.setTimeZone(TimeZone.getTimeZone("UTC")); + + } + + public CustomerProfileData getCustomerProfile(String logonID) throws RemoteException { + + try { + InputStream mapping = createConfigStream(); + Connection conn = getConnection(); + DAS das = DAS.FACTORY.createDAS(mapping, conn); + + Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?"); + + select.setParameter(1, logonID); + + DataObject root = select.executeQuery(); + conn.close(); + + Collection customers = root.getList("CustomerProfileData"); + CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next(); + + return customerProfileData; + } catch (Exception e) { + + e.printStackTrace(); + RemoteException re = new RemoteException("Failed to get customer profile'" + logonID + "' ", e); + re.printStackTrace(); + throw re; + } + } + + protected static final String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + + protected static final String protocol = "jdbc:derby:"; + + public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings) + throws RemoteException { + + try { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into customers (firstName,lastName,address,email, loginID, password ) values ('" + + customerProfile.getFirstName() + "', '" + customerProfile.getLastName() + "', '" + customerProfile.getAddress() + "', '" + + customerProfile.getEmail() + "', '" + customerProfile.getLoginID() + "', '" + customerProfile.getPassword() + "')"); + + insert.execute(); + CustomerProfileData ret = getCustomerProfile(customerProfile.getLoginID()); + String cid = ret.getId() + ""; + if (createSavings) { + insert = das.createCommand("insert into accounts (id,accountNumber, accountType, balance ) values (" + cid + ", '" + + AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_SAVINGS + "', " + 1.0F + ")"); + insert.execute(); + + } + if (createCheckings) { + insert = das.createCommand("insert into accounts (id,accountNumber, accountType, balance ) values (" + cid + ", '" + + AccountServiceImpl.CHECKING_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_CHECKINGS + "', " + 1.0F + ")"); + insert.execute(); + + } + + return ret; + } catch (Exception e) { + if (e instanceof RemoteException) { + throw (RemoteException) e; + } + throw new RemoteException("createAccount " + e.getClass().getName() + "'. " + e.getMessage(), e); + } + } + + public CustomerProfileData createAccountNOTWORKING(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings) + throws RemoteException { + try { + DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection()); + Command read = das.getCommand("all customers"); + + // select.setDataObjectModel(); + DataObject root = read.executeQuery(); + + // Create a new stockPurchase + DataObject customer = root.createDataObject("customerProfileData"); + + // THIS SEEMS TO BE THE ONLY WAY TO DO THIS .. NO WAY TO JUST ADD AN EXISTING CUSTOMER. + customer.set("firstName", customerProfile.getFirstName()); + customer.set("lastName", customerProfile.getLastName()); + customer.set("address", customerProfile.getAddress()); + customer.set("email", customerProfile.getEmail()); + customer.set("loginID", customerProfile.getLoginID()); + customer.set("password", customerProfile.getPassword()); + + das.applyChanges(root); + return getCustomerProfile(customerProfile.getLoginID()); + + } catch (Exception e) { + if (e instanceof RemoteException) { + throw (RemoteException) e; + } + throw new RemoteException("createAccount " + e.getClass().getName() + "'. " + e.getMessage(), e); + } + + } + + public AccountReport getAccountReport(final int customerID) throws RemoteException { + try { + final AccountFactory accountFactory = AccountFactory.INSTANCE; + final AccountReport accountReport = accountFactory.createAccountReport(); + InputStream mapping = createConfigStream(); + + Connection conn = getConnection(); + DAS das = DAS.FACTORY.createDAS(mapping, conn); + + Command select = das.createCommand("SELECT accountNumber, accountType, balance FROM accounts where id = ?"); + select.setParameter(1, customerID); + + DataObject root = select.executeQuery(); + accountReport.getAccountSummaries().addAll(root.getList("AccountSummary")); + + // Get Stocks + + select = das.createCommand("SELECT Symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber FROM stocks where id = ?"); + select.setParameter(1, customerID); + + // select.addConverter("STOCKS.PURCHASEDATE", DateConverter.class.getName()); + + root = select.executeQuery(); + accountReport.getStockSummaries().addAll(root.getList("StockSummary")); + + conn.close(); + + return accountReport; + } catch (Exception e) { + if (e instanceof RemoteException) { + throw (RemoteException) e; + } + throw new RemoteException("getAccountReport failed. customerID ('" + customerID + "')" + e.getClass().getName() + "'. " + e.getMessage(), + e); + } + } + + public float withdraw(String account, float ammount) throws RemoteException { + + return deposit(account, -ammount); + } + + public float deposit(String account, float ammount) throws RemoteException { + + try { + Connection conn = getConnection(); + DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn); + + Command select = das.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = ?"); + select.setParameter(1, account); + + DataObject root = select.executeQuery(); + Collection accounts = root.getList("AccountSummary"); + AccountSummary accountData = (AccountSummary) accounts.iterator().next(); + float newbalance = accountData.getBalance() + ammount; + accountData.setBalance(newbalance); + // update department set companyid = ? where department.name = ? + + Command update = das.getCommand("update balance"); + update.setParameter(1, new Float(newbalance)); + update.setParameter(2, account); + update.execute(); + conn.close(); + return newbalance; + } catch (Exception e) { + throw new RemoteException(e.getClass().getName(), e); + } + + } + + public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException { + try { + DAS das = DAS.FACTORY.createDAS(createConfigStream(), getConnection()); + + Command read = das.getCommand("stockbylotSelect"); + read.setParameter(1, purchaseLotNumber);// autoboxing :-) + DataObject root = read.executeQuery(); + List stocks = root.getList("StockSummary"); + if (null != stocks && !stocks.isEmpty()) { + StockSummary stock = (StockSummary) stocks.get(0); + int newQuatity = Math.max(stock.getQuantity() - quantity, 0); + if (newQuatity < 1) { + + Command delete = das.createCommand("DELETE FROM STOCKS WHERE PURCHASELOTNUMBER = ?"); + delete.setParameter(1, purchaseLotNumber); + delete.execute(); + + } else { + + Command update = das.getCommand("stockbylot"); + + update.setParameter(1, newQuatity); + update.setParameter(2, purchaseLotNumber); + update.execute(); + + stock.setQuantity(newQuatity); + } + return stock; + } + + return null; + } catch (Exception e) { + throw new RemoteException("sellStock", e); + } + } + + public StockSummary purchaseStock(int id, StockSummary stock) throws RemoteException { + + try { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into stocks (id, symbol, quantity, purchasePrice, purchaseDate) values (?,?,?,?,?)"); + insert.setParameter(1, new Integer(id)); + insert.setParameter(2, stock.getSymbol()); + insert.setParameter(3, stock.getQuantity()); + insert.setParameter(4, stock.getPurchasePrice()); + insert.setParameter(5, DateConverter.INSTANCE.getColumnValue(stock.getPurchaseDate())); + + insert.execute(); + + return stock; + } catch (Exception e) { + if (e instanceof RemoteException) { + throw (RemoteException) e; + } + throw new RemoteException("purchaseStock " + e.getClass().getName() + "'. " + e.getMessage(), e); + } + } + + protected Connection getConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { + Connection conn; + Class.forName(driver).newInstance(); + Properties props = new Properties(); + // props.put("user", "tuscany"); + // props.put("password", "tuscany"); + conn = DriverManager.getConnection(protocol + dbDirectory + ";create=true", props); + + conn.setAutoCommit(false); + return conn; + } + + protected InputStream createConfigStream() { + InputStream mapping = getClass().getClassLoader().getResourceAsStream("DasAccountConfiguration.xml"); + return mapping; + } + + public static class DateConverter implements Converter { + public final static DateConverter INSTANCE = new DateConverter(); + + public DateConverter() { // public empty constructor + } + + public Object getPropertyValue(Object columnData) { + + try { + + String ret = tsformatXSDDateTime.format(columnData); + if (ret.endsWith("UTC")) { + ret = ret.substring(0, ret.length() - 3) + "Z"; + } + return ret; + + } catch (Exception e) { + + e.printStackTrace(); + throw new IllegalArgumentException(e); + } + + } + + public Object getColumnValue(Object propertyData) { + + if (propertyData instanceof java.util.Date) { + // Need to convert back to local time for DB and remove timezone notation at the end.. + String ret = sqlformatDateTime.format(propertyData); + char lc = ret.charAt(ret.length() - 1); + while (!Character.isDigit(lc)) { + ret = ret.substring(0, ret.length() - 1); + lc = ret.charAt(ret.length() - 1); + } + return ret; + } else if (propertyData instanceof String) { + + try { + String time = (String) propertyData; + char last = time.charAt(time.length() - 1); + if (last == 'z' || last == 'Z') { + time = time.substring(0, time.length() - 1); + } + if (!time.endsWith("UTC")) { + time = time + "UTC"; + } + return getColumnValue(tsformatXSDDateTime.parse(time)); + } catch (ParseException e) { + throw new IllegalArgumentException("'" + propertyData + "' does not parse to date."); + } + } else { + throw new IllegalArgumentException(); + } + + } + + } + + public int getCustomerIdByPurchaseLotNumber(int purchaseLotNumber) throws RemoteException { + + return queryCustomerId("select id from stocks where purchaseLotNumber = " + purchaseLotNumber); + } + + public int getCustomerIdByAccount(String account) throws RemoteException { + + return queryCustomerId("select id from accounts where accountNumber = '" + account + "'"); + } + + private int queryCustomerId(String query) throws RemoteException { + + try { + Connection conn = getConnection(); + + Statement s = conn.createStatement(); + + ResultSet rs = s.executeQuery(query); + int id = -1; + if (rs.next()) { + id = rs.getInt("id"); + } + + conn.commit(); + + rs.close(); + s.close(); + conn.close(); + + return id; + + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass().getName(), e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..5e08cf634f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java @@ -0,0 +1,106 @@ +/* + * 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. + */ +package bigbank.account.services.accountdata; + +import java.rmi.RemoteException; +import java.util.List; + +import org.osoa.sca.annotations.Service; + +import com.bigbank.account.AccountFactory; +import com.bigbank.account.AccountLog; +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountSummary; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; + +@Service(AccountDataService.class) +public class AccountDataServiceImpl implements AccountDataService { + + public CustomerProfileData getCustomerProfile(String logonID) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public AccountReport getAccountReport(int customerID) { + final AccountFactory accountFactory = AccountFactory.INSTANCE; + AccountReport accountReport = accountFactory.createAccountReport(); + List accounts = accountReport.getAccountSummaries(); + + AccountSummary account = accountFactory.createAccountSummary(); + account.setAccountType("1111"); + account.setAccountNumber("22-22-22"); + account.setBalance(123.45F); + accounts.add(account); + + account = accountFactory.createAccountSummary(); + account.setAccountType("04-11-19"); + account.setAccountNumber("11-23"); + account.setBalance(543.21F); + accounts.add(account); + + List stocks = accountReport.getStockSummaries(); + StockSummary stock = accountFactory.createStockSummary(); + stock.setSymbol("IBM"); + stock.setPurchaseDate("1999-11-23"); + stock.setPurchaseLotNumber(101); + stock.setPurchasePrice(33.33F); + stock.setQuantity(10); + stocks.add(stock); + + stock = accountFactory.createStockSummary(); + stock.setSymbol("TUSK"); + stock.setPurchaseDate("2005-01-05"); + stock.setPurchaseLotNumber(102); + stock.setPurchasePrice(11.11F); + stock.setQuantity(4); + stocks.add(stock); + return accountReport; + } + + public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings) + throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public float deposit(String param6, float param7) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public StockSummary purchaseStock(int param0, StockSummary stock) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public StockSummary sellStock(int param13, int param14) throws RemoteException { + // TODO Auto-generated method stub + return null; + } + + public float withdraw(String param16, float param17) throws RemoteException { + // TODO Auto-generated method stub + return 0; + } + + public AccountLog getAccountLog(final int customerID) throws RemoteException { + throw new RemoteException("This method should not be called"); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/CustomerIdService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/CustomerIdService.java new file mode 100644 index 0000000000..b355a09008 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdata/CustomerIdService.java @@ -0,0 +1,98 @@ +/* + * 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. + */ +package bigbank.account.services.accountdata; + +import java.rmi.RemoteException; + +/** + * This interface allows access to a customer's id from the data service. + */ +public interface CustomerIdService { + + /* + * Return -1 if purchaseLotNumber not found + */ + public int getCustomerIdByPurchaseLotNumber(int purchaseLotNumber) throws RemoteException; + + /* + * Return -1 if account not found + */ + public int getCustomerIdByAccount(String account) throws RemoteException; + + // TODO (isilval) Fix this !!! + // Apparently, configuration can't deal with extends so I am adding the contents of AccountDataService here + + /** + * Auto generated method signatures + * + * @param param0* + * @param param1* + * @param param2 + */ + public com.bigbank.account.StockSummary purchaseStock(int param0, com.bigbank.account.StockSummary parm1) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param4 + */ + public com.bigbank.account.CustomerProfileData getCustomerProfile(java.lang.String param4) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param6* + * @param param7 + */ + public float deposit(java.lang.String param6, float param7) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param9* + * @param param10* + * @param param11 + */ + public com.bigbank.account.CustomerProfileData createAccount(com.bigbank.account.CustomerProfileData param9, boolean param10, boolean param11) + throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param13* + * @param param14 + */ + public com.bigbank.account.StockSummary sellStock(int param13, int param14) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param16* + * @param param17 + */ + public float withdraw(java.lang.String param16, float param17) throws java.rmi.RemoteException; + + /** + * Auto generated method signatures + * + * @param param19 + */ + public com.bigbank.account.AccountReport getAccountReport(int param19) throws java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java new file mode 100644 index 0000000000..1225c95f84 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java @@ -0,0 +1,465 @@ +/* + * 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. + */ +package bigbank.account.services.accountdb; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.Properties; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.Converter; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.sdo.util.SDOUtil; + +import bigbank.account.services.account.AccountServiceImpl; +import bigbank.account.services.accountdata.AccountDataServiceDASImpl; +import bigbank.account.services.accountlogger.AccountLoggerServiceImpl; + +import com.bigbank.account.AccountFactory; +import com.bigbank.account.AccountSummary; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; +import commonj.sdo.DataObject; +import com.bigbank.account.purchaseStock; +import com.bigbank.account.withdraw; + +public class AccountDBInit extends HttpServlet { + + private static final long serialVersionUID = -4795999792460944805L; + + protected static final String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + + protected static final String protocol = "jdbc:derby:"; + + protected String dbDirectory = null; + + protected String dasConfigFile = null; + + boolean deleteExisting = false; + + @Override + public void init() throws ServletException { + try { + + registerTypes(); + ServletConfig servletConfig = getServletConfig(); + ServletContext servletContext = servletConfig.getServletContext(); + dbDirectory = servletContext.getRealPath("WEB-INF/bigbankdb/accounts"); + dasConfigFile = servletContext.getRealPath("WEB-INF/classes/DasAccountConfiguration.xml"); + deleteExisting = false; + + createDB(dbDirectory); + + } catch (Exception e) { + + e.printStackTrace(); + log(e.toString(), e); + throw new ServletException(e); + } + } + + /* + * (non-Java-doc) + * + * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + + PrintWriter out = response.getWriter(); + + out.println(); + out.println("

BigBank database initialization servlet !

"); + out.println(); + } + + public AccountDBInit() { + } + + public AccountDBInit(String dbDirectory, String dasConfigFile, Boolean deleteExisting) { + this.dbDirectory = dbDirectory; + this.dasConfigFile = dasConfigFile; + this.deleteExisting = deleteExisting; + } + + private Connection createConnection() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { + return createConnection(dbDirectory); + } + + private static Connection createConnection(final String location) throws InstantiationException, IllegalAccessException, ClassNotFoundException, + SQLException { + Connection conn; + Class.forName(driver).newInstance(); + Properties props = new Properties(); + conn = DriverManager.getConnection(protocol + location + ";create=true", props); + + conn.setAutoCommit(false); + return conn; + } + + public static void createDB(final String location) throws Exception { + Connection conn = null; + AccountDataServiceDASImpl.dbDirectory = location; + AccountLoggerServiceImpl.dbDirectory = location; // TODO get rid of this (isilval) + Exception processessingException = null; + try { + conn = createConnection(location); + + creatTables(conn); + + int id = createCustomer(conn, "Test", "User", "304 Fox Trot ln, Apex, NC", "test@das.org", "test", "password"); + createAccount(conn, id, AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + id, AccountServiceImpl.ACCOUNT_TYPE_SAVINGS, 123.43F); + createAccount(conn, id, AccountServiceImpl.CHECKING_ACCOUNT_PREFIX + id, AccountServiceImpl.ACCOUNT_TYPE_CHECKINGS, 23.12F); + createStockPurchase(conn, id, "IBM", 33, 66.20F, "2005-11-23 13:22:02"); + createStockPurchase(conn, id, "DELL", 13, 12.74F, "2003-01-03 11:04:03"); + createStockPurchase(conn, id, "LU", 7, 2.74F, "2003-01-04 16:04:03"); + createStockPurchase(conn, id, "IBM", 22, 81.43F, "2004-02-03 13:04:33"); + + id = createCustomer(conn, "test2", "demo2", "Pleasant Plains Rd, ViewMount, CO", "test2@das.org", "test2", "password"); + createAccount(conn, id, AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + id, AccountServiceImpl.ACCOUNT_TYPE_SAVINGS, 924.40F); + createAccount(conn, id, AccountServiceImpl.CHECKING_ACCOUNT_PREFIX + id, AccountServiceImpl.ACCOUNT_TYPE_CHECKINGS, 33.26F); + createStockPurchase(conn, id, "FOO", 3, 6.20F, "2000-09-11 09:11:01"); + + conn.commit(); + + } catch (org.apache.derby.impl.jdbc.EmbedSQLException e) { + if (conn != null && !conn.isClosed()) { + conn.rollback(); + } + if (e.getErrorCode() == 20000 && "X0Y32".equalsIgnoreCase(e.getSQLState()) && -1 != e.getMessage().indexOf("already exists")) { + // this is ok the database is there. + + } else { + + e.printStackTrace(); + processessingException = e; + throw e; + } + } finally { + try { + if (null != conn && !conn.isClosed()) { + + conn.close(); + } + conn = null; + } catch (Exception e) { + e.printStackTrace(); + if (null != processessingException) { + throw e; + } + } + } + + } + + protected static void creatTables(Connection conn) throws Exception { + Statement s = conn.createStatement(); + + s + .execute("create table customers(firstName varchar(80) NOT NULL, lastName varchar(80), address varchar(180),email varchar(40),loginID varchar(80) NOT NULL UNIQUE, password varchar(80), id int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY)"); + + s.execute("create table accounts(id int NOT NULL, accountNumber varchar(80) NOT NULL UNIQUE, accountType varchar(80), balance real )"); + + s + .execute("create table stocks(id int NOT NULL, Symbol varchar(8) NOT NULL, quantity int NOT NULL, purchasePrice real NOT NULL, purchaseDate TIMESTAMP, purchaseLotNumber int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY )"); + + s + .execute("create table acctLog (logSeqNo int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, id int NOT NULL, accountNumber varchar(80) NOT NULL, actionType varchar(32) NOT NULL, amount real )"); + + s + .execute("create table stockLog (logSeqNo int NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, id int NOT NULL, Symbol varchar(8) NOT NULL, quantity int NOT NULL, actionType varchar(32) NOT NULL, purchaseLotNumber int NOT NULL )"); + + s.close(); + } + + protected static int createCustomer(Connection conn, final String firstName, final String lastName, final String address, final String email, + final String logonID, final String password) throws SQLException, Exception { + Statement s = conn.createStatement(); + + s.execute("insert into customers (firstName,lastName,address,email, loginID, password ) " + "values ('" + firstName + "', '" + lastName + + "', '" + address + "', '" + email + "', '" + logonID + "', '" + password + "')"); + + ResultSet rs = s.executeQuery("SELECT loginID, id FROM customers where loginID='" + logonID + "'"); + if (!rs.next()) { + throw new Exception("Wrong number of rows"); + } + int id = rs.getInt(2); + s.close(); + + return id; + } + + protected static void createAccount(Connection conn, int customerID, final String accountNumber, final String accountType, final float balance) + throws SQLException, Exception { + Statement s = conn.createStatement(); + + s.execute("insert into accounts (id,accountNumber, accountType, balance ) " + "values (" + customerID + ", '" + accountNumber + "', '" + + accountType + "', " + balance + ")"); + + s.close(); + } + + protected InputStream createConfigStream() { + InputStream mapping = getClass().getClassLoader().getResourceAsStream("DasAccountConfiguration.xml"); + return mapping; + } + + protected static void createStockPurchase(Connection conn, int customerID, final String stockSymbol, final int quantity, + final float purchasePrice, String purchaseDate) throws SQLException, Exception { + Statement s = conn.createStatement(); + + s.execute("insert into stocks (id, symbol, quantity, purchasePrice, purchaseDate ) values (" + customerID + ", '" + stockSymbol + "', " + + quantity + ", " + purchasePrice + ", '" + purchaseDate + "')"); + + s.close(); + + } + + protected static void registerTypes() { + SDOUtil.registerStaticTypes(AccountFactory.class); + // TODO remove + SDOUtil.registerStaticTypes(ConfigFactory.class); + + } + + public void testWithdrawThroughDAS(withdraw wd) throws Exception { + + Connection conn = createConnection(); + DAS das = DAS.FACTORY.createDAS(createConfigStream(), conn); + Command select = das.getCommand("get account"); + + select.setParameter(1, wd.getAccountNumber()); + + DataObject root = select.executeQuery(); + + Collection accounts = root.getList("AccountSummary"); + AccountSummary account = (AccountSummary) accounts.iterator().next(); + float newbalance = account.getBalance() - wd.getAmount(); + account.setBalance(newbalance); + // update department set companyid = ? where department.name = ? + + Command update = das.getCommand("update balance"); + update.setParameter(1, new Float(newbalance)); + update.setParameter(2, wd.getAccountNumber()); + + update.execute(); + conn.close(); + } + + protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException, + SQLException { + + DAS das = DAS.FACTORY.createDAS(createConfigStream(), createConnection()); + Command read = das.getCommand("all stocks"); + + DataObject root = read.executeQuery(); + + // Create a new stockPurchase + DataObject stockPurchase = root.createDataObject("StockSummary"); + stockPurchase.set("id", new Integer(sp.getId())); + stockPurchase.set("symbol", sp.getStock().getSymbol()); + stockPurchase.set("quantity", new Integer(sp.getStock().getQuantity())); + stockPurchase.set("purchasePrice", new Float(11.00)); + // String type = stockPurchase.getType().getProperty("purchaseDate").getType().toString(); + stockPurchase.setDate("purchaseDate", new Date()); + + das.applyChanges(root); + } + + public CustomerProfileData testgetCustomerByLoginIDThroughDASRead(final String logonID) throws Exception { + InputStream mapping = createConfigStream(); + Connection conn = createConnection(); + DAS das = DAS.FACTORY.createDAS(mapping, conn); + Command select = das.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = ?"); + + select.setParameter(1, logonID); + + DataObject root = select.executeQuery(); + conn.close(); + + Collection customers = root.getList("CustomerProfileData"); + CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next(); + System.out.println(customerProfileData); + System.out.flush(); + return customerProfileData; + + } + + protected void readDBstdout(PrintStream stream) throws Exception { + Connection conn = null; + try { + conn = createConnection(dbDirectory); + Statement s = conn.createStatement(); + ResultSet rs = s.executeQuery("SELECT firstName, lastName, loginID, password, id FROM customers ORDER BY lastName"); + while (rs.next()) { + stream.print(rs.getString(1)); + stream.print(" "); + stream.print(rs.getString(2)); + stream.print(" "); + stream.print(rs.getString(3)); + stream.print(" "); + stream.print(rs.getString(4)); + stream.print(" "); + stream.print(rs.getString(5)); + stream.println(); + int id = rs.getInt(5); + Statement s1 = conn.createStatement(); + ResultSet rs1 = s1.executeQuery("SELECT accountNumber, accountType, balance FROM accounts where id=" + id); + stream.println("====Customers accounts"); + while (rs1.next()) { + stream.print("\t"); + stream.print(rs1.getString(1)); + stream.print(" "); + stream.print(rs1.getString(2)); + stream.print(" "); + stream.print(rs1.getString(3)); + stream.println(); + } + rs1.close(); + rs1 = s1.executeQuery("SELECT symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber FROM stocks where id=" + id); + stream.println("====Customers Stocks"); + while (rs1.next()) { + stream.print("\t"); + stream.print(rs1.getString(1)); + stream.print(" "); + stream.print(rs1.getString(2)); + stream.print(" "); + stream.print(rs1.getString(3)); + stream.print(" "); + stream.print(rs1.getString(4)); + stream.print(" "); + stream.print(rs1.getString(5)); + stream.println(); + } + s1.close(); + stream.println(); + + } + s.close(); + conn.commit(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (conn != null) { + conn.close(); + } + conn = null; + } + + } + + public static class MyDateConverter implements Converter { + + private static final DateFormat tsformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + + public Object getPropertyValue(Object columnData) { + + try { + return tsformat.parse(columnData.toString()); + } catch (ParseException e) { + + e.printStackTrace(); + throw new IllegalArgumentException(e); + } + + } + + public Object getColumnValue(Object propertyData) { + + if (propertyData instanceof Date) { + return tsformat.format(propertyData); + } else { + throw new IllegalArgumentException(); + } + + } + + } + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + registerTypes(); + String dbDirectory = null; // "c:/derbydbtest/foo"; + String dasConfigFile = null; + Boolean deleteExisting = false; + for (String x : args) { + if ("-d".equals(x)) { + deleteExisting = true; + } + if (x.startsWith("-db:")) { + dbDirectory = x.substring("-db:".length()); + } + if (x.startsWith("-config:")) { + dasConfigFile = x.substring("-config:".length()); + ; + } + + } + AccountDBInit accountDBInit = new AccountDBInit(dbDirectory, dasConfigFile, deleteExisting); + + createDB(dbDirectory); + + accountDBInit.readDBstdout(System.out); + + // Test withdrawl + withdraw wd = AccountFactory.INSTANCE.createwithdraw(); + wd.setAccountNumber("134-43-3942"); + wd.setAmount(1.00F); + accountDBInit.testWithdrawThroughDAS(wd); + + accountDBInit.readDBstdout(System.out); + + // test stock purchase. + purchaseStock sp = AccountFactory.INSTANCE.createpurchaseStock(); + StockSummary stock = AccountFactory.INSTANCE.createStockSummary(); + stock.setSymbol("GOOG"); + stock.setQuantity(10); + stock.setPurchasePrice(25.00F); + sp.setId(1); + sp.setStock(stock); + + accountDBInit.testStrockPurchaseThroughDAS(sp); + + accountDBInit.readDBstdout(System.out); + + System.out.flush(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerDataServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerDataServiceImpl.java new file mode 100644 index 0000000000..2360344cd1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerDataServiceImpl.java @@ -0,0 +1,129 @@ +/* + * 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. + */ +package bigbank.account.services.accountlogger; + +import java.rmi.RemoteException; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import bigbank.account.services.accountdata.AccountDataService; +import bigbank.account.services.accountdata.CustomerIdService; + +import com.bigbank.account.AccountLog; +import com.bigbank.account.AccountReport; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; + +/** + * This class implements the Account Data Logger service component. + */ +@Service(AccountDataService.class) +public class AccountLoggerDataServiceImpl implements AccountDataService { + + private CustomerIdService accountDataService; // TODO fix this! + + @Reference + public void setAccountDataService(CustomerIdService accountDataService) { + this.accountDataService = accountDataService; + } + + private AccountLoggerService accountLoggerService; + + @Reference + public void setAccountLoggerService(AccountLoggerService accountLoggerService) { + this.accountLoggerService = accountLoggerService; + } + + public StockSummary purchaseStock(int id, StockSummary stock) throws RemoteException { + accountLoggerService.logPurchaseStock(id, stock); + + return accountDataService.purchaseStock(id, stock); + } + + public CustomerProfileData getCustomerProfile(String logonID) throws RemoteException { + + return accountDataService.getCustomerProfile(logonID); + } + + public float deposit(String account, float amount) throws RemoteException { + try { + if (!(accountDataService instanceof CustomerIdService)) { + throw new RemoteException("Can't use data service as customer id service"); + } + int id = accountDataService.getCustomerIdByAccount(account); + // int id = accountDataService.getCustomerIdByAccount(account); + accountLoggerService.logDeposit(id, account, amount); + + return accountDataService.deposit(account, amount); + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createChecking) + throws RemoteException { + + return accountDataService.createAccount(customerProfile, createSavings, createChecking); + } + + public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException { + try { + int id = accountDataService.getCustomerIdByPurchaseLotNumber(purchaseLotNumber); + StockSummary ss = accountDataService.sellStock(purchaseLotNumber, quantity); + if (ss != null) { + if (!(accountDataService instanceof CustomerIdService)) { + throw new RemoteException("Can't use data service as customer id service"); + } + accountLoggerService.logSellStock(id, ss, quantity); + } + return ss; + } catch (RemoteException e) { + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass() + " " + e.getMessage(), e); + } + } + + public float withdraw(String account, float amount) throws RemoteException { + if (!(accountDataService instanceof CustomerIdService)) { + throw new RemoteException("Can't use data service as customer id service"); + } + int id = accountDataService.getCustomerIdByAccount(account); + // int id = accountDataService.getCustomerIdByAccount(account); + accountLoggerService.logWithdrawal(id, account, amount); + + return accountDataService.withdraw(account, amount); + } + + public AccountReport getAccountReport(final int customerID) throws RemoteException { + + return accountDataService.getAccountReport(customerID); + } + + public AccountLog getAccountLog(final int customerID) throws RemoteException { + return accountLoggerService.getAccountLog(customerID); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerService.java new file mode 100644 index 0000000000..b9b2821d38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerService.java @@ -0,0 +1,47 @@ +/* + * 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. + */ +package bigbank.account.services.accountlogger; + +import java.rmi.RemoteException; + +import org.osoa.sca.annotations.OneWay; + +import com.bigbank.account.AccountLog; +import com.bigbank.account.StockSummary; + +/** + * This is the business interface of the Account Logger service component. + */ +public interface AccountLoggerService { + + @OneWay + public void logDeposit(int id, String account, float amount) throws RemoteException; + + @OneWay + public void logWithdrawal(int id, String account, float amount) throws RemoteException; + + @OneWay + public void logPurchaseStock(int id, StockSummary stock) throws RemoteException; + + @OneWay + public void logSellStock(int id, StockSummary stock, int quantity) throws RemoteException; + + public AccountLog getAccountLog(int id) throws RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerServiceImpl.java new file mode 100644 index 0000000000..8919aad311 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/accountlogger/AccountLoggerServiceImpl.java @@ -0,0 +1,216 @@ +/* + * 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. + */ +package bigbank.account.services.accountlogger; + +import java.io.InputStream; +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Properties; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.osoa.sca.annotations.Service; + +import com.bigbank.account.AccountFactory; +import com.bigbank.account.AccountLog; +import com.bigbank.account.StockSummary; +import commonj.sdo.DataObject; + +/** + * This class implements the Account Logger service component. + */ +@Service(AccountLoggerService.class) +public class AccountLoggerServiceImpl implements AccountLoggerService { + + public static final String ACCT_ACTION_TYPE_DEPOSIT = "deposit"; + + public static final String ACCT_ACTION_TYPE_WITHDRAW = "withdraw"; + + public static final String STOCK_ACTION_TYPE_PURCHASE = "purchase"; + + public static final String STOCK_ACTION_TYPE_SELL = "sell"; + + static public String dbDirectory = null; + + protected static final String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + + protected static final String protocol = "jdbc:derby:"; + + public void logDeposit(int id, String account, float amount) throws RemoteException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into acctLog (id, accountNumber, actionType, amount) values (?,?,?,?)"); + insert.setParameter(1, new Integer(id)); + insert.setParameter(2, account); + insert.setParameter(3, ACCT_ACTION_TYPE_DEPOSIT); + insert.setParameter(4, new Float(amount)); + + insert.execute(); + /* + * performLog("insert into acctLog (id, accountNumber, actionType, amount) values (" + id + ", '" + account + "', '" + + * ACCT_ACTION_TYPE_DEPOSIT + "', " + amount + ")"); + */ + } + + public void logWithdrawal(int id, String account, float amount) throws RemoteException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into acctLog (id, accountNumber, actionType, amount) values (?,?,?,?)"); + insert.setParameter(1, new Integer(id)); + insert.setParameter(2, account); + insert.setParameter(3, ACCT_ACTION_TYPE_WITHDRAW); + insert.setParameter(4, new Float(amount)); + + insert.execute(); + /* + * performLog("insert into acctLog (id ,accountNumber, actionType, amount) values (" + id + ", '" + account + "', '" + + * ACCT_ACTION_TYPE_WITHDRAW + "', " + amount + ")"); + */ + } + + public void logPurchaseStock(int id, StockSummary stock) throws RemoteException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into stockLog (id, Symbol, quantity, actionType, purchaseLotNumber) values (?,?,?,?,?)"); + insert.setParameter(1, new Integer(id)); + insert.setParameter(2, stock.getSymbol()); + insert.setParameter(3, new Integer(stock.getQuantity())); + insert.setParameter(4, STOCK_ACTION_TYPE_PURCHASE); + insert.setParameter(5, new Integer(stock.getPurchaseLotNumber())); + + insert.execute(); + /* + * performLog("insert into stockLog (id, Symbol, quantity, actionType, purchaseLotNumber) values (" + id + ", '" + stock.getSymbol() + "', " + + * stock.getQuantity() + ", '" + STOCK_ACTION_TYPE_PURCHASE + ", " + stock.getPurchaseLotNumber() + ")"); + */ + } + + public void logSellStock(int id, StockSummary stock, int quantity) throws RemoteException { + + String symbol = ((stock.getSymbol() != null) ? stock.getSymbol() : "null"); + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into stockLog (id, Symbol, quantity, actionType, purchaseLotNumber) values (?,?,?,?,?)"); + insert.setParameter(1, new Integer(id)); + insert.setParameter(2, symbol); + insert.setParameter(3, new Integer(quantity)); + insert.setParameter(4, STOCK_ACTION_TYPE_SELL); + insert.setParameter(5, new Integer(stock.getPurchaseLotNumber())); + + insert.execute(); + /* + * performLog("insert into stockLog (id, Symbol, quantity, actionType, purchaseLotNumber) values (" + id + ", '" + stock.getSymbol() + "', " + + * quantity + ", '" + STOCK_ACTION_TYPE_SELL + ", " + stock.getPurchaseLotNumber() + ")"); + */ + } + + private void performLog(String toLog) throws RemoteException { + + try { + Connection conn = getConnection(); + + Statement s = conn.createStatement(); + + s.execute(toLog); + + conn.commit(); + + System.out.println("SN id acctNo action amount"); + ResultSet rs = s.executeQuery("select * from acctLog"); + while (rs.next()) { + System.out.println(rs.getInt("logSeqNo") + " " + rs.getInt("id") + " " + rs.getString("accountNumber") + " " + + rs.getString("actionType") + " " + rs.getFloat("amount")); + } + + conn.commit(); + + System.out.println("SN Symbol qty action plot#"); + rs = s.executeQuery("select * from stockLog"); + while (rs.next()) { + System.out.println(rs.getInt("logSeqNo") + " " + rs.getString("Symbol") + " " + rs.getInt("quantity") + " " + + rs.getString("actionType") + " " + rs.getInt("purchaseLotNumber")); + } + + conn.commit(); + + s.close(); + + conn.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass().getName(), e); + } + + System.out.println("Logged " + toLog); + } + + protected Connection getConnection() throws RemoteException { + try { + Connection conn; + Class.forName(driver).newInstance(); + Properties props = new Properties(); + // props.put("user", "tuscany"); + // props.put("password", "tuscany"); + conn = DriverManager.getConnection(protocol + dbDirectory + ";create=true", props); + + conn.setAutoCommit(false); + return conn; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass().getName(), e); + } + } + + public AccountLog getAccountLog(final int customerID) throws RemoteException { + + try { + final AccountFactory accountFactory = AccountFactory.INSTANCE; + final AccountLog accountLog = accountFactory.createAccountLog(); + InputStream mapping = createConfigStream(); + + Connection conn = getConnection(); + DAS das = DAS.FACTORY.createDAS(mapping, conn); + Command select = das.createCommand("SELECT logSeqNo, accountNumber, actionType, amount FROM acctLog where id = ?"); + + select.setParameter(1, customerID); + + DataObject root = select.executeQuery(); + accountLog.getAccountLogEntries().addAll(root.getList("AccountLogEntry")); + + select = das.createCommand("SELECT logSeqNo, Symbol, quantity, actionType, purchaseLotNumber FROM stockLog where id = ?"); + select.setParameter(1, customerID); + root = select.executeQuery(); + accountLog.getStockLogEntries().addAll(root.getList("StockLogEntry")); + + conn.close(); + + return accountLog; + } catch (Exception e) { + if (e instanceof RemoteException) { + throw (RemoteException) e; + } + throw new RemoteException("getAccountLog failed. customerID ('" + customerID + "')" + e.getClass().getName() + "'. " + e.getMessage(), e); + } + } + + protected InputStream createConfigStream() { + InputStream mapping = getClass().getClassLoader().getResourceAsStream("DasAccountConfiguration.xml"); + return mapping; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java new file mode 100644 index 0000000000..c7498f093d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java @@ -0,0 +1,228 @@ +/* + * 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. + */ +package bigbank.account.services.stockquote; + +public class StockQuote { + + private String companyName; + + private String symbol; + + private String stockQuote; + + private String lastUpdated; + + private String change; + + private String openPrice; + + private String dayHighPrice; + + private String dayLowPrice; + + private String volume; + + private String marketCap; + + private String yearRange; + + private String exDividendDate; + + private String dividendYield; + + private String dividendPerShare; + + /** + * + * + * @generated + */ + protected StockQuote() { + super(); + } + + public String getCompanyName() { + return companyName; + } + + public void setCompanyName(String newCompanyName) { + companyName = newCompanyName; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String newStockTicker) { + symbol = newStockTicker; + } + + public String getStockQuote() { + return stockQuote; + } + + public void setStockQuote(String newStockQuote) { + stockQuote = newStockQuote; + } + + public String getLastUpdated() { + return lastUpdated; + } + + public void setLastUpdated(String newLastUpdated) { + lastUpdated = newLastUpdated; + } + + public String getChange() { + return change; + } + + public void setChange(String newChange) { + change = newChange; + } + + public String getOpenPrice() { + return openPrice; + } + + public void setOpenPrice(String newOpenPrice) { + openPrice = newOpenPrice; + } + + public String getDayHighPrice() { + return dayHighPrice; + } + + public void setDayHighPrice(String newDayHighPrice) { + dayHighPrice = newDayHighPrice; + } + + public String getDayLowPrice() { + return dayLowPrice; + } + + public void setDayLowPrice(String newDayLowPrice) { + dayLowPrice = newDayLowPrice; + } + + public String getVolume() { + return volume; + } + + public void setVolume(String newVolume) { + volume = newVolume; + } + + public String getMarketCap() { + return marketCap; + } + + public void setMarketCap(String newMarketCap) { + marketCap = newMarketCap; + } + + public String getYearRange() { + return yearRange; + } + + public void setYearRange(String newYearRange) { + yearRange = newYearRange; + } + + public String getExDividendDate() { + return exDividendDate; + } + + public void setExDividendDate(String newExDividendDate) { + exDividendDate = newExDividendDate; + } + + public String getDividendYield() { + return dividendYield; + } + + public void setDividendYield(String newDividendYield) { + dividendYield = newDividendYield; + } + + public String getDividendPerShare() { + return dividendPerShare; + } + + public void setDividendPerShare(String newDividendPerShare) { + dividendPerShare = newDividendPerShare; + } + + @Override + public String toString() { + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (companyName: "); + result.append(companyName); + result.append(", symbol: "); + result.append(symbol); + result.append(", stockQuote: "); + result.append(stockQuote); + result.append(", lastUpdated: "); + result.append(lastUpdated); + result.append(", change: "); + result.append(change); + result.append(", openPrice: "); + result.append(openPrice); + result.append(", dayHighPrice: "); + result.append(dayHighPrice); + result.append(", dayLowPrice: "); + result.append(dayLowPrice); + result.append(", volume: "); + result.append(volume); + result.append(", marketCap: "); + result.append(marketCap); + result.append(", yearRange: "); + result.append(yearRange); + result.append(", exDividendDate: "); + result.append(exDividendDate); + result.append(", dividendYield: "); + result.append(dividendYield); + result.append(", dividendPerShare: "); + result.append(dividendPerShare); + result.append(')'); + return result.toString(); + } + + @Override + public StockQuote clone() { + StockQuote ret = new StockQuote(); + ret.companyName = companyName; + ret.symbol = symbol; + ret.stockQuote = stockQuote; + ret.lastUpdated = lastUpdated; + ret.change = change; + ret.openPrice = openPrice; + ret.dayHighPrice = dayHighPrice; + ret.dayLowPrice = dayLowPrice; + ret.volume = volume; + ret.marketCap = marketCap; + ret.yearRange = yearRange; + ret.exDividendDate = exDividendDate; + ret.dividendYield = dividendYield; + ret.dividendPerShare = dividendPerShare; + return ret; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..9d5c243f9a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package bigbank.account.services.stockquote; + +import java.rmi.RemoteException; +import java.util.Map; + +/** + * This is the business interface of the HelloWorld service component. + */ +public interface StockQuoteService { + + public Map getQuotes(String[] symbols) throws RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java new file mode 100644 index 0000000000..b0c31d4d81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java @@ -0,0 +1,68 @@ +/* + * 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. + */ +package bigbank.account.services.stockquote; + +import java.rmi.RemoteException; +import java.util.Hashtable; +import java.util.Map; +import java.util.Random; + +/* Mock StockQuoteService */ + +public class StockQuoteServiceImpl implements StockQuoteService { + + static Random rn = new Random(); + + static Hashtable stocks = new Hashtable(); + + public synchronized Map getQuotes(String[] symbols) throws RemoteException { + Map ret = new Hashtable(); + for (String sym : symbols) { + sym = sym.toUpperCase(); + if (!ret.containsKey(sym)) { + StockQuote sq = stocks.get(sym); + if (sq == null) { + sq = new StockQuote(); + stocks.put(sym, sq); + sq.setSymbol(sym); + sq.setCompanyName(sym + " INC"); + float val = rn.nextFloat() * 97.0F + 3.0F; + sq.setStockQuote(val + ""); + sq.setDayHighPrice(val + ""); + sq.setDayLowPrice(val + ""); + sq.setOpenPrice(val + ""); + } else { + float diff = (rn.nextFloat() * 2.0F) - 1; + float newval = new Float(sq.getStockQuote()) + diff; // auto boxing cool. + sq.setStockQuote(newval + ""); + float dh = Math.max(newval, new Float(sq.getDayHighPrice())); + sq.setDayHighPrice(dh + ""); + float dl = Math.min(newval, new Float(sq.getDayLowPrice())); + sq.setDayLowPrice(dl + ""); + + } + ret.put(sym, sq.clone()); + } + + } + + return ret; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java new file mode 100644 index 0000000000..053f9d7f16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java @@ -0,0 +1,153 @@ +/* + * 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. + */ +package bigbank.account.services.stockquote; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import net.x.webservice.StockQuoteSoap; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the Stock quote service component. + */ +@Service(StockQuoteService.class) +@Scope("COMPOSITE") +public class StockQuoteWebservicexServiceImpl implements StockQuoteService { + + @Reference + public StockQuoteSoap stockQuoteService = null; // Injected by the SCA container. + + /** + * @throws RemoteException + * @see bigbank.account.services.stockquote.StockQuoteService#getQuotes(String[]) + */ + public Map getQuotes(final String[] symbols) throws RemoteException { + try { + assert null != stockQuoteService : "stockQuoteService was not set by the SCA runtime!"; + StringBuilder sb = new StringBuilder(5 * symbols.length); + for (String sym : symbols) { + if (sb.length() != 0) { + sb.append(' '); + } + sb.append(sym); + } + String stockdata = stockQuoteService.GetQuote(sb.toString()); + + InputStream in = new ByteArrayInputStream(stockdata.getBytes()); + XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLStreamReader parser = factory.createXMLStreamReader(in); + ArrayList listQuotes = new ArrayList(); + Hashtable listQuoteHT = new Hashtable(); + MapStock currentStock = null; + StringBuilder currentText = new StringBuilder(100); + for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { + String lname; + switch (event) { + case XMLStreamConstants.START_ELEMENT: + if (parser.getLocalName() == "Stock") { + + currentStock = new MapStock(); + listQuotes.add(currentStock); + } + break; + case XMLStreamConstants.END_ELEMENT: + lname = parser.getLocalName(); + String mname = "set" + lname; + try { + Method setter = MapStock.class.getMethod(mname, new Class[] { String.class }); + if (setter != null) { + setter.invoke(currentStock, currentText.toString()); + if (lname.equals("Symbol")) { + listQuoteHT.put(currentText.toString(), currentStock); + + } + } + } catch (NoSuchMethodException e) { + + } + // System.err.println(parser.getLocalName() + ":" + currentText.toString()); + currentText.setLength(0); + break; + case XMLStreamConstants.CHARACTERS: + // System.out.print(parser.getText()); + currentText.append(parser.getText()); + break; + case XMLStreamConstants.CDATA: + // System.out.print(parser.getText()); + currentText.append(parser.getText()); + break; + } // end switch + } // end while + parser.close(); + + return listQuoteHT; + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteException(e.getClass().getName() + e.getMessage(), e); + } + } + + public static class MapStock extends StockQuote { + + public void setLast(String val) { + super.setStockQuote(val); + } + + public void setDate(String val) { + }; + + public void setTime(String val) { + }; + + public void setHigh(String val) { + super.setDayHighPrice(val); + } + + public void setLow(String val) { + super.setDayLowPrice(val); + } + + public void setOpen(String val) { + super.setOpenPrice(val); + } + + public void setMktCap(String val) { + super.setMarketCap(val); + } + + public void setName(String val) { + super.setCompanyName(val); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/DasAccountConfiguration.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/DasAccountConfiguration.xml new file mode 100644 index 0000000000..ed1553eb40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/DasAccountConfiguration.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/AccountService.wsdl b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/AccountService.wsdl new file mode 100644 index 0000000000..5e8ced28e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/AccountService.wsdl @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl new file mode 100644 index 0000000000..16c980a30e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl @@ -0,0 +1,136 @@ + + + + + + + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get Stock quote for a company Symbol + + + + + + + Get Stock quote for a company Symbol + + + + + + + Get Stock quote for a company Symbol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/default.scdl b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/default.scdl new file mode 100644 index 0000000000..7c83a1a648 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/default.scdl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + AccountServiceComponent + + + + USD + + + + + AccountLoggerDataServiceComponent + StockQuoteServiceComponent + + + + + AccountDataServiceComponent + AccountLoggerServiceComponent + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..509e5a052d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,70 @@ + + + + + + + Tuscany Bigbank Account sample + + + + + + + tuscany.online + false + + + + + org.apache.tuscany.runtime.webapp.TuscanyContextListener + + + + TuscanyServlet + Tuscany Servlet + org.apache.tuscany.runtime.webapp.TuscanyServlet + + + + TuscanyServlet + /* + + + + + AccountDBInit + bigbank.account.services.accountdb.AccountDBInit + 2 + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java new file mode 100644 index 0000000000..28f9e762f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java @@ -0,0 +1,56 @@ +/* + * 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. + */ +package bigbank.account.client; + +import java.util.Iterator; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; +import com.bigbank.account.AccountSummary; + +public class AccountClient { + + public void start() { + } + + public void stop() { + } + + public static void main(String[] args) throws Exception { + + CompositeContext context = CurrentCompositeContext.getContext(); + + AccountService accountService = context.locateService(AccountService.class, "AccountServiceComponent"); + + AccountReport accountReport = accountService.getAccountReport(12345); + + for (Iterator i = accountReport.getAccountSummaries().iterator(); i.hasNext();) { + AccountSummary accountSummary = (AccountSummary) i.next(); + + System.out.println(accountSummary.getAccountNumber()); + System.out.println(accountSummary.getAccountType()); + System.out.println(accountSummary.getBalance()); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/Show.Image.html b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/Show.Image.html new file mode 100644 index 0000000000..9b18679abf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/Show.Image.html @@ -0,0 +1,40 @@ + + + + + + +
+ +
+ + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountfiles.png b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountfiles.png new file mode 100644 index 0000000000..9fc46488a0 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountfiles.png differ diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountmodule.png b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountmodule.png new file mode 100644 index 0000000000..d4209a01e3 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/accountmodule.png differ diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/modualoverview.png b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/modualoverview.png new file mode 100644 index 0000000000..7e6d7ba25e Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/modualoverview.png differ diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientfiles.png b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientfiles.png new file mode 100644 index 0000000000..b951ed2e5e Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientfiles.png differ diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientmodule.png b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientmodule.png new file mode 100644 index 0000000000..dfd3a34bfb Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/docs/webclientmodule.png differ diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/pom.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/pom.xml new file mode 100644 index 0000000000..b69e5dd06a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/pom.xml @@ -0,0 +1,44 @@ + + + + + org.apache.tuscany.sampleapps + tuscany-sca + 0.1-integration-incubating-SNAPSHOT + ../../pom.xml + + 4.0.0 + org.apache.tuscany.samples.bigbank + bigbank-scenario + pom + Tuscany BigBank Scenario Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + account + webclient + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/readme.html b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/readme.html new file mode 100644 index 0000000000..b5e90bb08f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/readme.html @@ -0,0 +1,894 @@ + + + + + + + + + Tuscany BigBank Sample Application + + + + + + +

Tuscany BigBank Sample Application

+ +

Overview

+ +

The Tuscany BigBank sample application  shows using + the Tuscany SCA runtime to build a  financial application. + There are two modules: webclient provides the front-end user + interface and account provides the back-end business services. + These are deployed as separate web applications

+ +

Location

+

This sample is located in the  + samples\applications\bigbank directory. There are two + subdirectories in that for the two modules account and webclient.

+ + +

Prerequisites

+ +

Obtain the following prerequisites and install according to + their documentation.

+ + + +

Building

+

This sample + can be built from the bigbank directory using Maven 2.0.4 with + the following command:

+

+  mvn
+

+ +

Setup

+

If you have enabled remote deployment in Tomcat by + adding the line:
+   <user username="admin" password="" + roles="manager"/>
+ into  <tomcat + dir>\conf\tomcat-users.xml  you can deploy the + WARs to Tomcat using the tomcat-maven-plugin:
+ mvn tomcat:deploy

+

Alternatively you can copy the WAR files to Tomcat's  + webapps directory.
+ + copy account\target\sample-bigbank-account.war <tomcat dir>\webapps
+ copy  + webclient\target\sample-bigbank-webclient.war <tomcat dir>\webapps
+

+ +

Running

+

Once you've started your web server, use your web + browser to view the following URL http://localhost:8080/sample-bigbank-webclient/
+ You can either use an already pre configured  account with + Login as test and + Password as password, or + you can  create a new account.
+ The demo is first configured to use a local mock stock quote + service that returns random stock data.  If you want to use + an actual stock quote provider follow these steps:

+ +
    +
  • Stop your server by issuing in the  <tomcat dir>\bin directory
  • + +
  • Issue shutdown + command to stop your web application server.
  • + +
  • Edit the account SCDL file <tomcat dir>\webapps\sample-bigbank-account\WEB-INF\default.scdl
  • + +
  • Change the SCDL wiring to remove the mock stock quote + service by commenting it out as follows:
    + <!--
    +     <component + name="StockQuoteServiceComponent">
    +         + <implementation.java + class="bigbank.account.services.stockquote.StockQuoteServiceImpl" + />
    +     </component>
    + -->
  • + +
  • Uncomment the real stockquote service section in lines 68 + to 80.
  • + +
  • Change to the directory  apache-tomcat-5.5.17\bin 
  • + +
  • issue startup +   command to start up the server in the + <tomcat dir>\bin + directory.
  • +
+

The sample should now be using the real stock quote + provider. 

+ +

Summary

This example illustrates using Tuscany runtime + in building a financial Web application using SCA programing + model.  The following key concepts are covered:

+ +
    +
  • Component implementations. that provide web + based  HTML user interface
  • + +
  • Component implementations that provide + local services in Java. Local services implement + internal application business logic such as tracking user state + and are not exposed remotely.
  • + +
  • Component implementations that have + configuration properties and service + references to other services
  • + +
  • Components that use and + configure the properties and + references of component implementations
  • + +
  • SCA Services to publish remotable services + via a Web Service binding.
  • + +
  • SCA References  to consume remotable + services via a Web Service binding
  • + +
  • Assembling implementation, components, entry points and + external service into composite components.
  • + +
  • Creating a module and all of its artifacts as part of a + web application to show a front-end access to SCA + services
  • + +
  • The use of Data Access services to persist and retrieve + Service Data Objects from Apache Derby.
  • + +
  • The use of  existing Web + services in  SCA.
  • +

BigBank sample provides the following user services: account + balance, making deposits and withdrawals  to purchase + and sell stock, and to view current stock value.
+ The sample is organized into two SCA modules: webclient and + account. The webclient module functionality is to provide user + information and obtain user input. The account module is used to + retrieve and store user information, account information, current + stock information and the purchasing and selling of stock. The + two modules interact via web services through SCA references and + services.

+
+ +
+ + + +
Webclient

+ + Webclient files
+ +

 

+ + + + + + + + + +
+ + + 
+ +
+ click to + enlarge +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Java + source files implementing SCA components and + interfaces.
+ AccountServiceComponentImpl.java Implements the account service.
AccountLoginServiceImpl.javaImplements the Login service.
LoginService.javaInterface for a services provided by a + login  service component.
ProfileService.javaInterface for a service provided by a profile + component.
ProfileServiceImpl.javaImplements the profile component.
SimpleLoginServiceImpl.javaA simple in memory login service.
+ Java + source files implementing Web HTML + interface.
AccountStatusTag.javaImplements a jsp tag that displays the + account information
StockStatusTag.javaImplements a jsp tag that displays the stock + information.
LoginBarrierTag.javaImplements a jsp tag that ensures the user is + logged in.
ServiceTag.javaPlaces an SCA service in the JSP page + context.
FormServlet.javaProcess user input and uses the + AccountService component.
LoginServlet.javaProcesses logging in and logout.
+ Files + that will be loaded as resources along + classpath.
AccountService.wsdlWSDL that  defines the account + service.
bigbank-tags.tldDefines the tag libs for the user + interface.
Files + located in WEB-INF directory.
default.scdlApplication's SCA SCDL file.
web.xmlApplication's web.xml file.
Generated + Files.
sdo sourceGenerated SDO. Created by tuscany-sdo-plugin + maven plugin.
wsdl2java-sourceGenerated SDO interface. Created by tuscany-plugin-wsdl2java + maven  plugin.
Build + files.
pom.xmlMaven build file.
+
+ +

 

+ +
Account

+ + Account module
+ +

 

+ + + + + + + + + +
+ + + 
+ +
+ click to + enlarge +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Java + source files implementing SCA components and + interfaces.
+ AccountServiceImpl.java Implements the account service + component.
AccountDataService.javaInterface defined for component implementing +  an account's data service.
AccountDataServiceDASImpl.javaA Data Access Service (DAS) implementation of + of the Account Data Service.
AccountDataServiceImpl.javaA Data Service implementation not using + DAS.
AccountDBInit.javaA utility to just create the database and it + table and fill in some initial data.
StockQuote.javaA class to hold the StockQuote + information.
StockQuoteService.javaInterface defined for a component + implementing a stock quote service.
StockQuoteServiceImpl.javaImplements a fake stock quote service.
StockQuoteWebservicexServiceImpl.javaImplements an actual stock quote + service.
+ Files + that will be loaded as resources along + classpath.
AccountService.wsdlWSDL that  defines the account + service
stockquotes.webservicex.wsdlActual stock quote service WSDL.
DasAccountConfiguration.xmlProvides any needed configuration info + including datasource properties, table + definitions,
Files + located in WEB-INF directory.
default.scdlApplication's SCA SCDL file.
web.xmlApplication's web.xml file.
Generated + Files.
sdo sourceGenerated SDO. Created by tuscany-sdo-plugin + maven plugin.
wsdl2java-sourceGenerated SDO interface. Created + by tuscany-plugin-wsdl2java + maven  plugin.
Build + files.
pom.xmlMaven build file.
+
+

+
+ + +
Pom.xml
+

The directions + for maven  how  to build the each module is located in + each module's directory in the pom.xml file.  The + application uses Java 1.5 and thus in the build  plugin + section needs the following compiler directives:

+             + <plugin>
+                 + <groupId>org.apache.maven.plugins</groupId>
+                 + <artifactId>maven-compiler-plugin</artifactId>
+                 + <configuration>
+                     + <source>1.5</source>
+ +                     + <target>1.5</target>
+ +                 + </configuration>
+             + </plugin>

+

Both webclient and account uses three maven + plugins: tuscany-sdo-plugintuscany-plugin-wsdl2java, + and tuscany-war-plugin. + The tuscany-sdo-plugin is provided by Tuscany 's SDO project + while the other two are provided by the Tuscany SCA project.

+

The tuscany-sdo-plugin +  references the WSDL's schema and generates all the files + located in target/sdo_source directory.  The application + uses these classes as a databinding instead of having to deal + directly with XML that  represents form as defined in the + WSDL's schema.

+

The tuscany-plugin-wsdl2java + plugin generates a Java interface in the target/wsdl2java-source + directory that is used to define the inteface (prottype) in the + wsdl.

+

The tuscany-war-plugin is + used to add both the Tuscany runtime and any Tuscany  + extensions required by the application in the war file.. Looking + at the pom.xml and search for  "tuscany-war-plugin" you'll find the + plugin.  Which extension you want loaded are specified in + the extensions section. The format + for this  closely follows Maven's artifact naming.  The + boolean loadExtensionDependencies + option if true will  resolve all dependencies for each + extension listed here and also include them in the war file. +  
+
+ +

Application

+ +
Web.xml

The web.xml + file in each module adds necessary "hooks" to initiate and + maintain the Tuscany SCA runtime in a web application host.
+  

+ + + + + + + + + + + + + + + + + + + + + +
+
+<listener>
+<listener-class>org.apache.tuscany.runtime.webapp.TuscanyContextListener</listener-class>
+</listener>
+
+
This class initializes the Tuscany runtime when the + applications is started and helps finalize the Tuscany + runtime when the application has ended.
+
+<servlet>
+<servlet-name>TuscanyServlet</servlet-name>
+<display-name>Tuscany Servlet</display-name>
+<servlet-class>org.apache.tuscany.runtime.webapp.TuscanyServlet</servlet-class>
+</servlet>
+
+
This class provides the web applications servlet + interface to SCA components.  The Axis websevices + binding extension requires this.
+
+<listener>
+<listener-class>org.apache.tuscany.runtime.webapp.TuscanySessionListener</listener-class>
+</listener>
+
+
This listener helps provide SCA session support .

+

The web application can be run in offline or online when + resolving dependencies required by the application or it's + required extensions. This is configured in the web.xml with the + context-param element with a parameter name tuscany.online. If  not + specified or set to true, dependencies are resolved by searching + the local war repository, the local Maven repository, and remote + repositories. If specified and set to false, the remote + repositories will not be searched.

+ +
SCDL
+

Each module's SCA + application SCDL is located in the web application  + WEB-INF/default.scdl file.  This is the default location, + but within the web.xml it is possible to override this with a + context-param element  with the name tuscany.applicationScdlPath. +  The Tuscany System SCDL can also be overridden with another + context-param element with the name tuscany.systemScdlPath.
+ The SCDL  used by the BigBank application is defined by + SCA Assembly Model V0.96 , SCA Client and Implementation Model for Java + (V0.95)  and the SCA Web Service bindings specifications.
+ There is one extension to SCDL used by BigBank that is specific + to Tuscany that is used by SDO databinding extension. +  The import.sdo element in the SCDL + specifies which  SDO factories to register the SDO types. +  In the case of BigBank the factory is the class generated + by the tuscany-sdo-plugin maven plugin. An + example of this follows:

+
+ <dbsdo:import.sdo xmlns:dbsdo="http://incubator.apache.org/tuscany/xmlns/databinding/sdo/1.0-incubator-M2"
+factory="com.bigbank.account.AccountFactory"/> 
+
+
+ +
Code

The Java code for the most part just implements the + Web interface and the SCA components necessary to implement the + business logic. The code uses Java 5.0 annotations as documented + by the SCA Client and Implementation Model for Java + (V0.95) specifications. The samples uses one annotation that + is an Tuscany extension that is used by the databinding framework + to identify that the components expect to SDO s for complex data + types. An example of this is seen in the AccountService interface + which has the @DataType(name="commonj.sdo.DataObject") + annotation.

+ +

RDB DAS

+ +

The Relational Database DAS (RDB DAS) is used in this sample to access relational data in terms + of SDOs. All the code pertaining to this usage is contained to two one files: + AccountDataServiceDASImpl.java and DasAccountConfiguration.xml. The java file provides code that + instantiates and invokes the DAS and the XML file provides RDB DAS configuration.

+ +

The sample demonstrates a few of the RDB DAS capabilities including:

+ +
    + +
  • reading a graph of SDOs based on a select query provided inline
  • +
  • reading a graph of SDOs based on a named select query defined in the config file
  • +
  • executing a named command to manually insert data
  • +
  • leveraging SDO Change Summary to by utilizing the DAS "applyChanges" method to flush graph modifications
  • +
  • utilizing the DAS column-converter framework
  • +
  • using the column/property name mapping (aliasing)
  • + +
+ +

This sample does not currently demonstrate a few other key DAS features including Object relationships, optimistic + concurrency control, and the use of convention over configuration. User level documentation for the RDB DAS can + be found in the RDBDAS User's Guide. +

+

This sample uses the RDB DAS as a utility. A future version of this sample will access the DAS as an SCA service. +

+ + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/pom.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/pom.xml new file mode 100644 index 0000000000..40e146685a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/pom.xml @@ -0,0 +1,167 @@ + + + + + org.apache.tuscany.samples.bigbank + bigbank-scenario + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + sample-bigbank-webclient + war + Tuscany BigBank Web Client Module + BigBank Scenario Sample - Web Front-End Module + + + + org.apache.tuscany.sca.kernel + tuscany-api + ${scaKernelVersion} + compile + + + + org.apache.tuscany.sdo + tuscany-sdo-api-r2.1 + 1.0-incubating + compile + + + + stax + stax-api + 1.0.1 + runtime + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubating + compile + + + + org.apache.tuscany.sca.runtime.webapp + webapp-api + ${scaKernelVersion} + runtime + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet + jsp-api + 2.0 + provided + + + + junit + junit + 4.2 + test + + + + + ${artifactId} + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubating + + + + ${basedir}/src/main/resources/wsdl/AccountService.wsdl + true + true + true + + + generate + + + + + + org.apache.tuscany.sca.extensions.axis2.plugins + tuscany-plugin-wsdl2java + ${scaKernelVersion} + + + + ${basedir}/src/main/resources/wsdl/AccountService.wsdl + + + generate + + + + + + org.apache.tuscany.sca.runtime.webapp + tuscany-war-plugin + ${scaKernelVersion} + + + tuscany-war + + tuscany-war + + + + + + + false + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + ${scaKernelVersion} + + + org.apache.tuscany.sca.extensions.axis2 + tuscany-axis2 + ${scaKernelVersion} + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/account/AccountServiceComponentImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/account/AccountServiceComponentImpl.java new file mode 100644 index 0000000000..a0f98f14f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/account/AccountServiceComponentImpl.java @@ -0,0 +1,117 @@ +/* + * 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. + */ +package bigbank.webclient.services.account; + +import java.rmi.RemoteException; + +import org.osoa.sca.ServiceUnavailableException; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import com.bigbank.account.AccountLog; +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; + +/** + */ +@Service(AccountService.class) +public class AccountServiceComponentImpl implements AccountService { + + private AccountService accountService; + + @Reference + public void setAccountService(AccountService accountService) { + this.accountService = accountService; + } + + /** + * + */ + public AccountServiceComponentImpl() { + super(); + } + + /** + * @see bigbank.account.services.account.AccountService#getAccountReport(java.lang.String) + */ + public AccountReport getAccountReport(int customerID) { + try { + return accountService.getAccountReport(customerID); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public StockSummary purchaseStock(int customerID, StockSummary stockSummary) throws RemoteException { + try { + return accountService.purchaseStock(customerID, stockSummary); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public CustomerProfileData getCustomerProfile(String param2) throws RemoteException { + try { + return accountService.getCustomerProfile(param2); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public float deposit(String account, float amount) throws RemoteException { + try { + return accountService.deposit(account, amount); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public StockSummary sellStock(int purchaseLotNumber, int quantity) throws RemoteException { + try { + return accountService.sellStock(purchaseLotNumber, quantity); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public float withdraw(String account, float amount) throws RemoteException { + try { + return accountService.withdraw(account, amount); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + + public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings) + throws RemoteException { + + return accountService.createAccount(customerProfile, createSavings, createCheckings); + } + + public AccountLog getAccountLog(int customerID) throws RemoteException { + try { + return accountService.getAccountLog(customerID); + } catch (Exception e) { + throw new ServiceUnavailableException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/AccountLoginServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/AccountLoginServiceImpl.java new file mode 100644 index 0000000000..d6c40e8dda --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/AccountLoginServiceImpl.java @@ -0,0 +1,64 @@ +/* + * 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. + */ +package bigbank.webclient.services.profile; + +import java.rmi.RemoteException; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import com.bigbank.account.AccountService; +import com.bigbank.account.CustomerProfileData; + +@Service(LoginService.class) +@Scope("COMPOSITE") +public class AccountLoginServiceImpl implements LoginService { + + public AccountService accountService; + + @Reference + public void setAccountService(AccountService accountService) { + this.accountService = accountService; + } + + public ProfileService profileService; + + @Reference + public void setProfileService(ProfileService profileService) { + this.profileService = profileService; + } + + public int login(String userName, String password) throws RemoteException { + + CustomerProfileData profileData = accountService.getCustomerProfile(userName); + + if (!password.equals(profileData.getPassword())) { + return INVALID_PASSWORD; + } + + profileService.setLoggedIn(true); + profileService.setFirstName(profileData.getFirstName()); + profileService.setLastName(profileData.getLastName()); + profileService.setId(profileData.getId()); + + return SUCCESS; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/LoginService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/LoginService.java new file mode 100644 index 0000000000..c688df2597 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/LoginService.java @@ -0,0 +1,36 @@ +/* + * 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. + */ +package bigbank.webclient.services.profile; + +import java.rmi.RemoteException; + +import org.apache.tuscany.api.annotation.DataType; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface LoginService { + + static final int SUCCESS = 1; + + static final int INVALID_LOGIN = -1; + + static final int INVALID_PASSWORD = -2; + + int login(String userName, String password) throws RemoteException; +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileService.java new file mode 100644 index 0000000000..551d80c935 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileService.java @@ -0,0 +1,42 @@ +/* + * 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. + */ +package bigbank.webclient.services.profile; + +import org.apache.tuscany.api.annotation.DataType; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface ProfileService { + + String getFirstName(); + + void setFirstName(String pName); + + String getLastName(); + + void setLastName(String pName); + + boolean isLoggedIn(); + + void setLoggedIn(boolean pStatus); + + int getId(); + + void setId(int pId); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileServiceImpl.java new file mode 100644 index 0000000000..5385a7c3fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/ProfileServiceImpl.java @@ -0,0 +1,69 @@ +/* + * 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. + */ +package bigbank.webclient.services.profile; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(ProfileService.class) +@Scope("SESSION") +public class ProfileServiceImpl implements ProfileService { + + private String firstName; + + public String getFirstName() { + return firstName; + } + + @Property + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + private String lastName; + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + private boolean loggedIn; + + public boolean isLoggedIn() { + return loggedIn; + } + + public void setLoggedIn(boolean status) { + loggedIn = status; + } + + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/SimpleLoginServiceImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/SimpleLoginServiceImpl.java new file mode 100644 index 0000000000..711c6ba0b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/services/profile/SimpleLoginServiceImpl.java @@ -0,0 +1,51 @@ +/* + * 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. + */ +package bigbank.webclient.services.profile; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(LoginService.class) +public class SimpleLoginServiceImpl implements LoginService { + + public ProfileService profileService; + + @Reference + public void setProfileService(ProfileService profileService) { + this.profileService = profileService; + } + + public int login(String userName, String password) { + + if (!"test".equals(userName)) { + return INVALID_LOGIN; + } + + if (!"password".equals(password)) { + return INVALID_PASSWORD; + } + + profileService.setLoggedIn(true); + profileService.setFirstName("John"); + profileService.setLastName("Doe"); + profileService.setId(12345); + + return SUCCESS; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountLogTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountLogTag.java new file mode 100644 index 0000000000..08751bdc3d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountLogTag.java @@ -0,0 +1,120 @@ +/* + * 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. + */ +package bigbank.webclient.tags.account; + +import java.util.Iterator; +import java.util.List; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import bigbank.webclient.services.profile.ProfileService; + +import com.bigbank.account.AccountLog; +import com.bigbank.account.AccountService; + +public class AccountLogTag extends TagSupport { + + public AccountLogTag() { + super(); + } + + private String mAccountService; + + public String getAccountService() { + return mAccountService; + } + + public void setAccountService(String pAccountService) { + mAccountService = pAccountService; + } + + private String mProfileService; + + public String getProfileService() { + return mProfileService; + } + + public void setProfileService(String pProfileService) { + mProfileService = pProfileService; + } + + private String mId; + + @Override + public String getId() { + return mId; + } + + @Override + public void setId(String pId) { + mId = pId; + } + + private Iterator mIterator; + + @Override + public int doStartTag() throws JspException { + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + + ProfileService profile = moduleContext.locateService(ProfileService.class, mProfileService); + + if (profile == null) { + throw new JspException("Profile [" + mProfileService + "] not found in current module context"); + } + + AccountService service = (AccountService) moduleContext.locateService(AccountService.class, mAccountService); + if (service == null) { + throw new JspException("Service [" + mAccountService + "] not found in current module context"); + } + List entries; + try { + AccountLog accountLog = service.getAccountLog(profile.getId()); + pageContext.setAttribute("StockLogEntries", accountLog.getStockLogEntries()); + entries = accountLog.getAccountLogEntries(); + } catch (Exception e) { + throw new JspException(e); + } + mIterator = entries.iterator(); + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_INCLUDE; + } else { + return SKIP_BODY; + } + } + + @Override + public int doAfterBody() { + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_AGAIN; + } else { + return SKIP_BODY; + } + } + + @Override + public void release() { + super.release(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountStatusTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountStatusTag.java new file mode 100644 index 0000000000..3733cc84dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/AccountStatusTag.java @@ -0,0 +1,135 @@ +/* + * 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. + */ +package bigbank.webclient.tags.account; + +import java.util.Iterator; +import java.util.List; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import bigbank.webclient.services.profile.ProfileService; + +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; + +/** + * Retrieves and iterates over account summary information for the current profile by accessing the remotable account service component + */ + +public class AccountStatusTag extends TagSupport { + + // ---------------------------------- + // Constructors + // ---------------------------------- + + public AccountStatusTag() { + super(); + } + + // ---------------------------------- + // Methods + // ---------------------------------- + + private String mAccountService; + + public String getAccountService() { + return mAccountService; + } + + public void setAccountService(String pAccountService) { + mAccountService = pAccountService; + } + + private String mProfileService; + + public String getProfileService() { + return mProfileService; + } + + public void setProfileService(String pProfileService) { + mProfileService = pProfileService; + } + + private String mId; + + @Override + public String getId() { + return mId; + } + + @Override + public void setId(String pId) { + mId = pId; + } + + private Iterator mIterator; + + @Override + public int doStartTag() throws JspException { + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + + ProfileService profile = moduleContext.locateService(ProfileService.class, mProfileService); + + if (profile == null) { + throw new JspException("Profile [" + mProfileService + "] not found in current module context"); + } + + AccountService service = (AccountService) moduleContext.locateService(AccountService.class, mAccountService); + + if (service == null) { + throw new JspException("Service [" + mAccountService + "] not found in current module context"); + } + List summaries; + try { + AccountReport accountReport = service.getAccountReport(profile.getId()); + pageContext.setAttribute("StockSummaries", accountReport.getStockSummaries()); + summaries = accountReport.getAccountSummaries(); + } catch (Exception e) { + throw new JspException(e); + } + mIterator = summaries.iterator(); + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_INCLUDE; + } else { + return SKIP_BODY; + } + } + + @Override + public int doAfterBody() { + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_AGAIN; + } else { + return SKIP_BODY; + } + } + + @Override + public void release() { + super.release(); + mId = null; + mIterator = null; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockLogTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockLogTag.java new file mode 100644 index 0000000000..ea2df8aa55 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockLogTag.java @@ -0,0 +1,81 @@ +/* + * 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. + */ +package bigbank.webclient.tags.account; + +import java.util.Iterator; +import java.util.List; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +public class StockLogTag extends TagSupport { + + public StockLogTag() { + super(); + } + + private String mId; + + @Override + public String getId() { + return mId; + } + + @Override + public void setId(String pId) { + mId = pId; + } + + private Iterator mIterator; + + @Override + public int doStartTag() throws JspException { + + List entries = (List) pageContext.getAttribute("StockLogEntries"); + if (null == entries) { + return SKIP_BODY; + } + mIterator = entries.iterator(); + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_INCLUDE; + } else { + return SKIP_BODY; + } + } + + @Override + public int doAfterBody() { + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_AGAIN; + } else { + pageContext.setAttribute("StockLogEntries", null); + return SKIP_BODY; + } + } + + @Override + public void release() { + pageContext.setAttribute("StockLogEntries", null); + super.release(); + mId = null; + mIterator = null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockStatusTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockStatusTag.java new file mode 100644 index 0000000000..b2c61193e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/account/StockStatusTag.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package bigbank.webclient.tags.account; + +import java.util.Iterator; +import java.util.List; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +/** + * Retrieves and iterates over account summary information for the current profile by accessing the remotable account service component + */ + +public class StockStatusTag extends TagSupport { + + public StockStatusTag() { + super(); + } + + private String mId; + + @Override + public String getId() { + return mId; + } + + @Override + public void setId(String pId) { + mId = pId; + } + + private Iterator mIterator; + + @Override + public int doStartTag() throws JspException { + + List summaries = (List) pageContext.getAttribute("StockSummaries"); + if (null == summaries) { + return SKIP_BODY; + } + mIterator = summaries.iterator(); + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_INCLUDE; + } else { + return SKIP_BODY; + } + } + + @Override + public int doAfterBody() { + if (mIterator.hasNext()) { + pageContext.setAttribute(mId, mIterator.next()); + return EVAL_BODY_AGAIN; + } else { + pageContext.setAttribute("StockSummaries", null); + return SKIP_BODY; + } + } + + @Override + public void release() { + pageContext.setAttribute("StockSummaries", null); + super.release(); + mId = null; + mIterator = null; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/LoginBarrierTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/LoginBarrierTag.java new file mode 100644 index 0000000000..6c50595d0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/LoginBarrierTag.java @@ -0,0 +1,101 @@ +/* + * 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. + */ +package bigbank.webclient.tags.sca; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import bigbank.webclient.services.profile.ProfileService; + +public class LoginBarrierTag extends TagSupport { + + public LoginBarrierTag() { + super(); + } + + private String mProfile; + + public String getProfile() { + return mProfile; + } + + public void setProfile(String pProfile) { + mProfile = pProfile; + } + + private String mUrl; + + public String getUrl() { + return mUrl; + } + + public void setUrl(String pUrl) { + mUrl = pUrl; + } + + int doPage = EVAL_PAGE; + + @Override + public int doStartTag() throws JspException { + if (mProfile == null || mProfile.length() < 1) { + throw new JspException("Invalid profile location specified"); + } + + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + + ProfileService profile = moduleContext.locateService(ProfileService.class, mProfile); + + if (profile == null) { + throw new JspException("Profile [" + mProfile + "] not found in current module context"); + } + + if (profile.isLoggedIn()) { + return EVAL_BODY_INCLUDE; + } else { + try { + doPage = SKIP_PAGE; + pageContext.forward(mUrl); + ((HttpServletResponse) (pageContext.getResponse())).sendRedirect("login.html"); + return SKIP_BODY; + } catch (ServletException e) { + throw new JspException("Unable to forward to [" + mUrl + "]"); + } catch (IOException e) { + throw new JspException("Unable to forward to [" + mUrl + "]"); + } + } + } + + @Override + public int doEndTag() throws JspException { + return doPage; + } + + @Override + public void release() { + super.release(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/ServiceTag.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/ServiceTag.java new file mode 100644 index 0000000000..d1263377c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/tags/sca/ServiceTag.java @@ -0,0 +1,107 @@ +/* + * 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. + */ +package bigbank.webclient.tags.sca; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +/** + * Places an SCA service in the JSP page context, making it available to other tags corresponding to its id value. + */ + +public class ServiceTag extends TagSupport { + + // ---------------------------------- + // Constructors + // ---------------------------------- + + public ServiceTag() { + super(); + } + + // ---------------------------------- + // Methods + // ---------------------------------- + + private String mName; + + /** + * Returns the name of the SCA service to import into the page context. + */ + public String getName() { + return mName; + } + + /** + * Sets name of the SCA service to import into the page context. + */ + public void setName(String pName) { + mName = pName; + } + + private String mId; + + /** + * Returns the id of the service in the page context + */ + @Override + public String getId() { + return mId; + } + + /** + * Sets the id of the service for the page context + */ + + @Override + public void setId(String pId) { + mId = pId; + } + + @Override + public int doStartTag() throws JspException { + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + + Object service = moduleContext.locateService(Object.class, mName); + + if (service == null) { + throw new JspException("Service [" + mName + "] not found in current module context"); + } + if (mId == null) { + // if the Id name was not specified, default to the basic name of the + // service + mId = mName; + } + pageContext.setAttribute(mId, service); + return EVAL_BODY_INCLUDE; + } + + @Override + public int doEndTag() throws JspException { + return EVAL_PAGE; + } + + @Override + public void release() { + super.release(); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/FormServlet.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/FormServlet.java new file mode 100644 index 0000000000..3acdbee845 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/FormServlet.java @@ -0,0 +1,161 @@ +/* + * 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. + */ +package bigbank.webclient.ui; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import bigbank.webclient.services.profile.ProfileService; + +import com.bigbank.account.AccountFactory; +import com.bigbank.account.AccountService; +import com.bigbank.account.CustomerProfileData; +import com.bigbank.account.StockSummary; + +public class FormServlet extends HttpServlet { + + // private ServletContext mContext; + // public void init(ServletConfig pCfg) throws ServletException { + // mContext = pCfg.getServletContext(); + // } + + @Override + public void doPost(HttpServletRequest pReq, HttpServletResponse pResp) throws ServletException { + + try { + final String action = pReq.getParameter("action"); + + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + AccountService accountServices = (AccountService) moduleContext.locateService(AccountService.class, "AccountServiceComponent"); + if (accountServices == null) { + throw new ServletException("AccountServiceComponent"); + } + ProfileService profileServices = null; + if (!"createAccount".equals(action)) { + profileServices = moduleContext.locateService(ProfileService.class, "ProfileServiceComponent"); + if (profileServices == null) { + throw new ServletException("ProfileServiceComponent not found."); + } + if (!profileServices.isLoggedIn()) { + throw new ServletException("User id '" + profileServices.getId() + "' not logged on."); + } + } + + if ("createAccount".equals(action)) { + createAccount(pReq, pResp, accountServices); + } else if ("account".equals(action)) { + accountTransaction(pReq, pResp, accountServices); + } else if ("stockPurchase".equals(action)) { + stockPurchase(pReq, pResp, profileServices, accountServices); + } else if ("stockSale".equals(action)) { + stockSale(pReq, pResp, profileServices, accountServices); + } else { + throw new IllegalArgumentException("Unknown action in Form servlet '" + action + "'."); + } + // mContext.getRequestDispatcher("summary.jsp").forward(pReq, pResp); + pResp.sendRedirect("summary.jsp"); + } catch (ServletException e) { + e.printStackTrace(); + throw e; + + } catch (Exception e) { + + throw new ServletException(e); + } + + } + + private void stockSale(HttpServletRequest req, HttpServletResponse resp, ProfileService profileServices, AccountService accountServices) + throws ServletException { + try { + if (!"cancel".equals(req.getParameter("cancel"))) { + + int quantity = Integer.parseInt(req.getParameter("quantity")); + int purchaseLotNumber = Integer.parseInt(req.getParameter("purchaseLotNumber")); + accountServices.sellStock(purchaseLotNumber, quantity); + } + + } catch (Exception e) { + + throw new ServletException("stockSale " + e.getMessage(), e); + } + + } + + private void stockPurchase(HttpServletRequest req, HttpServletResponse resp, ProfileService profileServices, AccountService accountServices) + throws ServletException { + try { + if (!"cancel".equals(req.getParameter("cancel"))) { + + String symbol = req.getParameter("symbol").trim().toUpperCase(); + int quantity = Integer.parseInt(req.getParameter("quantity")); + StockSummary stockSummry = AccountFactory.INSTANCE.createStockSummary(); + stockSummry.setSymbol(symbol); + stockSummry.setQuantity(quantity); + accountServices.purchaseStock(profileServices.getId(), stockSummry); + } + } catch (Exception e) { + throw new ServletException("stockPurchase " + e.getMessage(), e); + } + } + + private void accountTransaction(HttpServletRequest req, HttpServletResponse resp, AccountService accountServices) throws ServletException { + try { + if (!"cancel".equals(req.getParameter("cancel"))) { + String account = req.getParameter("account"); + String amount = req.getParameter("Amount"); + if ("deposit".equals(req.getParameter("actionType"))) { + accountServices.deposit(account, Float.parseFloat(amount)); + } else { + accountServices.withdraw(account, Float.parseFloat(amount)); + } + } + } catch (Exception e) { + throw new ServletException("accountTransaction " + e.getMessage(), e); + } + + } + + private void createAccount(HttpServletRequest pReq, HttpServletResponse pResp, AccountService accountServices) throws ServletException { + try { + CustomerProfileData customerProfileData = AccountFactory.INSTANCE.createCustomerProfileData(); + customerProfileData.setFirstName(pReq.getParameter("firstName")); + customerProfileData.setLastName(pReq.getParameter("lastName")); + customerProfileData.setAddress(pReq.getParameter("address")); + customerProfileData.setEmail(pReq.getParameter("email")); + customerProfileData.setLoginID(pReq.getParameter("loginID")); + customerProfileData.setPassword(pReq.getParameter("password")); + + CustomerProfileData resp = accountServices.createAccount(customerProfileData, "savings".equals(pReq.getParameter("savings")), "checkings" + .equals(pReq.getParameter("checkings"))); + LoginServlet.login(resp.getLoginID(), resp.getPassword()); + + } catch (IOException e) { + throw new ServletException(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/LoginServlet.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/LoginServlet.java new file mode 100644 index 0000000000..784cc4fb40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/java/bigbank/webclient/ui/LoginServlet.java @@ -0,0 +1,96 @@ +/* + * 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. + */ +package bigbank.webclient.ui; + +import java.io.IOException; +import java.rmi.RemoteException; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import bigbank.webclient.services.profile.LoginService; + +public class LoginServlet extends HttpServlet { + + @Override + public void init(ServletConfig pCfg) throws ServletException { + + } + + @Override + public void doPost(HttpServletRequest pReq, HttpServletResponse pResp) throws ServletException { + + if ("logout".equals(pReq.getParameter("logout")) || "logoutHIDDEN".equals(pReq.getParameter("logoutHIDDEN"))) { + HttpSession sess = pReq.getSession(); + if (sess != null) { + sess.invalidate(); + } + try { + pResp.sendRedirect("login.html"); + } catch (IOException e) { + + e.printStackTrace(); + throw new ServletException(e); + } + + } else { + pReq.getSession(); // make sure session started. + String login = pReq.getParameter("login"); + String password = pReq.getParameter("password"); + try { + int resp = login(login, password); + if (resp == LoginService.SUCCESS) { + + pResp.sendRedirect("summary.jsp"); + } else { + + pResp.sendRedirect("login.html"); + } + } catch (IOException e) { + throw new ServletException(e); + } + } + } + + static int login(final String login, final String password) throws ServletException { + + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + LoginService loginMgr = moduleContext.locateService(LoginService.class, "LoginServiceComponent"); + + if (loginMgr == null) { + throw new ServletException("LoginManager not found"); + } + + try { + return loginMgr.login(login, password); + } catch (RemoteException e) { + + throw new ServletException(e); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl new file mode 100644 index 0000000000..980c0cf279 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/resources/wsdl/AccountService.wsdl @@ -0,0 +1,466 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/CustomerProfile.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/CustomerProfile.jsp new file mode 100644 index 0000000000..2dc17a8867 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/CustomerProfile.jsp @@ -0,0 +1,100 @@ + +<%-- + 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. + --%> + + + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + +<%-- LINK href="theme/Master.css" rel="stylesheet" type="text/css" --%> +BigBank- Customer Account + +

Customer Account
+
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
First name
Last name
Address
email
 
Checkings
Savings
 
Logon ID
Password
+
+   +
+


+

+ + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/bigbank-tags.tld b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/bigbank-tags.tld new file mode 100644 index 0000000000..a3d92a2e46 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/bigbank-tags.tld @@ -0,0 +1,127 @@ + + + + 1.0 + 2.0 + BigBank Tags + Tag library containing BigBank tags + + service + bigbank.webclient.tags.sca.ServiceTag + JSP + Places a reference to an SCA Service in the page context + + id + true + false + + + name + true + false + + + + login + bigbank.webclient.tags.sca.LoginBarrierTag + JSP + Redirects if user is not logged in + + profile + true + false + + + url + true + false + + + + + accountStatus + bigbank.webclient.tags.account.AccountStatusTag + JSP + Accesses and iterates the account service + + id + true + false + + + accountService + true + false + + + profileService + true + false + + + + stockStatus + bigbank.webclient.tags.account.StockStatusTag + JSP + Accesses and iterates the stocks + + id + true + false + + + + + accountLog + bigbank.webclient.tags.account.AccountLogTag + JSP + Accesses and iterates the accounts log + + id + true + false + + + accountService + true + false + + + profileService + true + false + + + + stockLog + bigbank.webclient.tags.account.StockLogTag + JSP + Accesses and iterates the stocks log + + id + true + false + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/default.scdl b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/default.scdl new file mode 100644 index 0000000000..cf42086edb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/default.scdl @@ -0,0 +1,53 @@ + + + + + + + + + + + AccountServiceComponent + ProfileServiceComponent + + + Anonymous + + + + + + + + + AccountService + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..398767e345 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,83 @@ + + + + + + Tuscany Bigbank Web UI sample + + login.html + + + + TuscanyFilter + org.apache.tuscany.runtime.webapp.TuscanyFilter + + + TuscanyFilter + /* + + + + tuscany.online + false + + + + + org.apache.tuscany.runtime.webapp.TuscanyContextListener + + + + org.apache.tuscany.runtime.webapp.TuscanySessionListener + + + + org.apache.tuscany.runtime.webapp.TuscanyRequestListener + + + + LoginServlet + bigbank.webclient.ui.LoginServlet + 1 + + + FormServlet + bigbank.webclient.ui.FormServlet + 0 + + + + LoginServlet + /loginAction/* + + + FormServlet + /FormServlet/* + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountLog.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountLog.jsp new file mode 100644 index 0000000000..6e91a14dcc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountLog.jsp @@ -0,0 +1,99 @@ +<%-- + 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. + --%> + + <%@ page import="com.bigbank.account.AccountLogEntry" %> + <%@ page import="com.bigbank.account.StockLogEntry" %> + <%@ page session="true" %> + <%@ page autoFlush="true" %> + <%@ taglib uri="/WEB-INF/bigbank-tags.tld" prefix="sca" %> + + + BigBank Account and Stock Log + + + + Account Log + + + + + + + + + + + + + + + + +
SeqAccountActionAmount
+ + + + + + + +
+ + + +
+ Stock Log + + + + + + + + <%-- spacer --%> + + + + + + + + + <%-- spacer --%> + + + + + + +
SeqSymbolQuantity  ActionPurchaseLotNumber
+ + + + + +    + + + +
+ + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountTransaction.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountTransaction.jsp new file mode 100644 index 0000000000..4017834867 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/accountTransaction.jsp @@ -0,0 +1,50 @@ + +<%-- + 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. + --%> + + + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +BigBank - <%=request.getParameter("account") %> + + +

Account <%= request.getParameter("account") %>
+
+
+

+
+ + + +Amount to <%=request.getParameter("transaction")%>
+
+
+
+      +
+ + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/login.html b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/login.html new file mode 100644 index 0000000000..a1a5440a4f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/login.html @@ -0,0 +1,60 @@ + + +Welcome to Big Bank + + + +
+ + + + +
Please login in to access your account
+ + + + + + + + + + + +   + +   + +
Login(test)
Password(password)
+
+


+
+
+
New to Big Bank? Please open a new account with us. +
+

+ + +

+ + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/purchaseStock.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/purchaseStock.jsp new file mode 100644 index 0000000000..90c3a813b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/purchaseStock.jsp @@ -0,0 +1,59 @@ + +<%-- + 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. + --%> + + + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + +BigBank- Stock purchase + +

Stock purchase
+
+

+
+ + + + + + + + + + + + + + + + + + + +
Symbol
Quantity
+
+   +
+


+

+ + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/stockSale.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/stockSale.jsp new file mode 100644 index 0000000000..a2b08f4352 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/stockSale.jsp @@ -0,0 +1,56 @@ + +<%-- + 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. + --%> + + + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + +BigBank- Stock sale + +

Stock sale
+
+

+
+ + + + + + + + + + + + + + + + +
Quantity
+
+   +
+


+

+ + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/summary.jsp b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/summary.jsp new file mode 100644 index 0000000000..f31ded242f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/main/webapp/summary.jsp @@ -0,0 +1,144 @@ +<%-- + 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. + --%> + + <%@ page import="com.bigbank.account.AccountSummary" %> + <%@ page import="com.bigbank.account.StockSummary" %> + <%@ page session="true" %> + <%@ page autoFlush="true" %> +<%@ taglib uri="/WEB-INF/bigbank-tags.tld" prefix="sca" %> + + + + + BigBank Account Summary + + + + Account Information for +
+ + + +    +
+ + + + + + + + + + + + + + + + + + + + + +
Account Balance
+ + + + + + + + + + +
+ + + +
+
+ Stocks:     
+
+ + + + + + + + <%-- spacer --%> + + + + + + <%-- spacer --%> + + + +
+
+ + + + <%-- spacer --%> + + + + + + + + <%-- spacer --%> + + + + +
SymbolQuantityPurchase Date  Purchase PriceCurrent PriceCompany NameToday HighToday Low   <%-- sell button --%>
+ + + + + +    + + + + + + + + + +    +
+ +
+ +
+
+ Account and Stock Logs:     
+
+ + + + +
diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestAccountService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestAccountService.java new file mode 100644 index 0000000000..d5ece151de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestAccountService.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package bigbank.webclient.client; + +import java.util.List; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + + +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; + +public class TestAccountService { + + + public static void main(String[] args) throws Exception { + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + + AccountService accountService = (AccountService) moduleContext.locateService(AccountService.class, "AccountServiceComponent"); + + AccountReport report = accountService.getAccountReport(12345); + List summaries = report.getAccountSummaries(); + + System.out.println("retrieved " + summaries.size() + " summaries"); + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestLoginService.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestLoginService.java new file mode 100644 index 0000000000..9af80e99db --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/bigbank/webclient/src/test/java/bigbank/webclient/client/TestLoginService.java @@ -0,0 +1,42 @@ +/* + * 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. + */ +package bigbank.webclient.client; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + + +import bigbank.webclient.services.profile.LoginService; + +public class TestLoginService { + + + + public static void main(String[] args) throws Exception { + + CompositeContext moduleContext = CurrentCompositeContext.getContext(); + LoginService loginService = moduleContext.locateService(LoginService.class, "LoginServiceComponent"); + + if (loginService.login("test", "password") == LoginService.SUCCESS) { + System.out.println("Success"); + } else { + System.out.println("Failure"); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/README b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/README new file mode 100644 index 0000000000..65077c5881 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/README @@ -0,0 +1,77 @@ +Binding Echo Sample +=================== +This sample demonstrates how new bindings are constructed for Apache Tuscany +SCA using the lazy-loading approach where extensions are loaded only when they +are encountered during the processing of a composite defintion (SCDL) + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the echo binding that this sample provides +please see the binding-echo sample that provides the necessary client and +application code to bring up an application that uses this binding + +Sample Overview +--------------- +This sample contains a implementation of an SCA binding that simply echoes back +any messages that are sent to it. + +binding-echo2-extension/ + src/ + main/ + java/ + echo2/ + extension/ - The bindings model classes, runtime classes + server/ - A dummy server that the binding is plugged into + resources/ + META-INF/ + services/ + org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor - specifies the + artifact processors to be loaded + org.apache.tuscany.sca.provider.BindingProviderFactory - specifies the model classes for this binding + test/ + java/ + echo2/ - test code + resources/ + EchoBinding.composite - the SCA assembly used by the unit test + build.xml - the Ant build file + pom.xml - the Maven build file + + +Building The Sample Using Ant +----------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd binding-echo2-extension +ant compile + +See the binding-echo sample to run a sample that uses this binding. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd binding-echo2-extension +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running echo.EchoReferenceTestCase +Returned message: foo +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.111 sec +Running echo.EchoServiceTestCase +Returned message: foo +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.121 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/build.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/build.xml new file mode 100644 index 0000000000..cfbdb1e1d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/pom.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/pom.xml new file mode 100644 index 0000000000..8d0f31dd23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.99-incubating-SNAPSHOT + ../../pom.xml + + sample-binding-echo2-extension + Apache Tuscany Echo Binding Extension Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 0.99-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.99-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.99-incubating-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.99-incubating-SNAPSHOT + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBinding.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBinding.java new file mode 100644 index 0000000000..d6439bfa13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBinding.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package echo2.extension; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Implementation of the Echo binding model. + */ +public class EchoBinding implements Binding { + + private String name; + private String uri; + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + // The sample binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingInvoker.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingInvoker.java new file mode 100644 index 0000000000..70a6e4a43a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingInvoker.java @@ -0,0 +1,44 @@ +/* + * 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. + */ +package echo2.extension; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for the sample echo binding. + */ +public class EchoBindingInvoker implements Invoker { + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + + // echo back the first parameter, a real binding would invoke some API for flowing the request + Object result = args[0]; + + msg.setBody(result); + + } catch (Exception e) { + msg.setFaultBody(e); + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingProviderFactory.java new file mode 100644 index 0000000000..f750641d1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoBindingProviderFactory.java @@ -0,0 +1,56 @@ +/* + * 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. + */ + +package echo2.extension; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + + +/** + * Implementation of the Echo binding model. + */ +public class EchoBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + + public EchoBindingProviderFactory(ExtensionPointRegistry registry) { + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = factories.getFactory(MessageFactory.class); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, EchoBinding binding) { + return new EchoReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, EchoBinding binding) { + return new EchoServiceBindingProvider(component, service, binding, messageFactory); + } + + public Class getModelType() { + return EchoBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoReferenceBindingProvider.java new file mode 100644 index 0000000000..27659f79a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoReferenceBindingProvider.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package echo2.extension; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the Echo binding provider. + */ +public class EchoReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public EchoReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + EchoBinding binding) { + this.reference = reference; + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + if (isCallback) { + throw new UnsupportedOperationException(); + } else { + return new EchoBindingInvoker(); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoServiceBindingProvider.java new file mode 100644 index 0000000000..65ba66b5a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/extension/EchoServiceBindingProvider.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +package echo2.extension; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import echo2.server.EchoServer; +import echo2.server.EchoServiceListener; + +/** + * Implementation of the Echo binding provider. + */ +public class EchoServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private EchoBinding binding; + private MessageFactory messageFactory; + + public EchoServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, EchoBinding binding, MessageFactory messageFactory) { + this.component = component; + this.service = service; + this.binding = binding; + this.messageFactory = messageFactory; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public void start() { + + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + InvocationChain chain = wire.getInvocationChains().get(0); + + // Register with the hosting server + String uri = binding.getURI(); + EchoServer.getServer().register(uri, new EchoServiceListener(chain.getHeadInvoker(), messageFactory)); + } + + public void stop() { + + // Unregister from the hosting server + String uri = component.getURI() + "/" + binding.getName(); + EchoServer.getServer().unregister(uri); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServer.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServer.java new file mode 100644 index 0000000000..fff8ad564f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServer.java @@ -0,0 +1,78 @@ +/* + * 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. + */ + +package echo2.server; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +/** + * A sample Echo server, showing how to integrate service bindings. + */ +public class EchoServer { + + public static EchoServer server; + + private Map services = new HashMap(); + + public static void start() { + } + + public static void stop() { + } + + public static EchoServer getServer() { + if (server == null) + server = new EchoServer(); + return server; + } + + /** + * Register a service under the given name. + * + * @param service + * @param name + */ + public void register(String uri, EchoServiceListener service) { + if (services.isEmpty()) { + start(); + } + services.put(uri, service); + } + + public void unregister(String uri) { + services.remove(uri); + if (services.isEmpty()) { + stop(); + } + } + + /** + * Dispatch an incoming interaction to the corresponding service. + * + * @param uri + * @param input + * @return + */ + public String sendReceive(String uri, String input) throws InvocationTargetException { + return services.get(uri).sendReceive(input); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServiceListener.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServiceListener.java new file mode 100644 index 0000000000..c0010c4ccf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/java/echo2/server/EchoServiceListener.java @@ -0,0 +1,55 @@ +/* + * 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. + */ +package echo2.server; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * The EchoService listener + */ +public class EchoServiceListener { + private Invoker invoker; + private MessageFactory messageFactory; + + public EchoServiceListener(Invoker invoker, MessageFactory messageFactory) { + super(); + this.invoker = invoker; + this.messageFactory = messageFactory; + } + + public String sendReceive(String input) throws InvocationTargetException { + + // Create a request message + Message request = messageFactory.createMessage(); + request.setBody(new Object[] {input}); + + // Dispatch and get the response + Message response = invoker.invoke(request); + Object body = response.getBody(); + if (response.isFault()) { + throw new InvocationTargetException((Throwable)body); + } + return (String)body; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..6671e5d9aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://echo2#binding.echo,model=echo2.extension.EchoBinding diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..e487bf98da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the binding extension +echo2.extension.EchoBindingProviderFactory;model=echo2.extension.EchoBinding diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/Echo.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/Echo.java new file mode 100644 index 0000000000..4dbe0f9539 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/Echo.java @@ -0,0 +1,29 @@ +/* + * 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. + */ +package echo2; + +/** + * Interface of our sample Echo service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoComponentImpl.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoComponentImpl.java new file mode 100644 index 0000000000..83b2db8064 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoComponentImpl.java @@ -0,0 +1,44 @@ +/* + * 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. + */ +package echo2; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + + +/** + * A simple client component that uses a reference with an Echo binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + private Echo echoReference; + + @Constructor + public EchoComponentImpl(@Reference(name = "echoReference", required = true) Echo echoReference) { + this.echoReference = echoReference; + } + + public String echo(String msg) { + String result = echoReference.echo(msg); + System.out.println("Returned message: "+ result); + return result; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoReferenceTestCase.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoReferenceTestCase.java new file mode 100644 index 0000000000..e9a9e1590f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoReferenceTestCase.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +package echo2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev$ $Date$ + */ +public class EchoReferenceTestCase extends TestCase { + + private SCADomain scaDomain; + private Echo service; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + service = scaDomain.getService(Echo.class, "EchoComponent"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testEchoBinding() { + String result = service.echo("foo"); + assertEquals(result, "foo"); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoServiceTestCase.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoServiceTestCase.java new file mode 100644 index 0000000000..077c4fb51d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/java/echo2/EchoServiceTestCase.java @@ -0,0 +1,50 @@ +/* + * 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. + */ +package echo2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo2.server.EchoServer; + +/** + * @version $Rev$ $Date$ + */ +public class EchoServiceTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testEchoBinding() throws Exception { + String result = EchoServer.getServer().sendReceive("http://tempuri.org", "foo"); + assertEquals(result, "foo"); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/resources/EchoBinding.composite b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/resources/EchoBinding.composite new file mode 100644 index 0000000000..ebd79c736d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/binding-echo2-extension/src/test/resources/EchoBinding.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/README b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/README new file mode 100644 index 0000000000..973c13d00c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/README @@ -0,0 +1,87 @@ +Implementation CRUD Sample +========================== +This sample demonstrates how new implementation types are constructed for +Apache Tuscany SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the CRUD implementation type that this sample provides +please see the implementation-crud sample that provides the necessary client +code to bring up an application that uses this implementation extension. + +Sample Overview +--------------- +This sample contains a CRUD implementation type as an example of how to create +new implementation types. Components using this implementation type always +expose the same Create, Retrieve, Update and Delete interface. This sample +uses a singleton ResourceManager to perform the CRUD operations but of course +a real component would provide a real implementation. + +implementation-crud-extension/ + src/ + main/ + java/ + crud/ - implementation model interfaces + backend/ - fake component implementation + impl/ - implementations of the model interfaces + module/ - gets the implementation-crud module registered + with the SCA runtime + provider/ - runtime implementation + resources/ + META-INF/ + services/ + org.apache.sca.tuscany.sca.core.ModuleActivator - specifies the + module activation class to call + test/ + java/ + crud/ + CRUDTestCase.java - JUnit test case + resources/ + crud.composite - the SCA assembly used during unit testing + + build.xml - the Ant build file + pom.xml - the Maven build file + +Building The Sample Extension Using Ant +----------------------------------------- +With the binary distribution the sample extension can be built using Ant as +follows + +cd implementation-crud-extension +ant compile + +See the implementation-crud sample to run a sample that uses this +implementation extension. + +Building The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built +using Maven as follows. + +cd implementation-crud-extension +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running crud.CRUDTestCase +Starting CRUDServiceComponent +create(ABC) in tmp +retrieve(0) +update(0) +retrieve(0) +delete(0) +retrieve(0) +Stopping CRUDServiceComponent +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.212 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/build.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/build.xml new file mode 100644 index 0000000000..0f1a0a2270 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/pom.xml b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/pom.xml new file mode 100644 index 0000000000..3bc75bfd58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.99-incubating-SNAPSHOT + ../../pom.xml + + sample-implementation-crud2-extension + Apache Tuscany CRUD Implementation Extension Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 0.99-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 0.99-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.99-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.99-incubating-SNAPSHOT + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/CRUD.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/CRUD.java new file mode 100644 index 0000000000..49ed376809 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/CRUD.java @@ -0,0 +1,54 @@ +/* + * 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. + */ +package crud2; + +/** + * The service interface of the single CRUD service provided by CRUD components. + */ +public interface CRUD { + + /** + * Create a new resource. + * @param resource + * @return + */ + String create(Object resource); + + /** + * Retrieve a resource. + * @param id + * @return + */ + Object retrieve(String id); + + /** + * Update a resource. + * @param id + * @param resource + * @return + */ + Object update(String id, Object resource); + + /** + * Delete a resource. + * @param id + */ + void delete(String id); + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/backend/ResourceManager.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/backend/ResourceManager.java new file mode 100644 index 0000000000..aa94cd55b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/backend/ResourceManager.java @@ -0,0 +1,90 @@ +/* + * 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. + */ + +package crud2.backend; + +import java.util.HashMap; +import java.util.Map; + +/** + * A fake resource manager implementation used as a backend by the sample + * CRUD component implementation. + */ +public class ResourceManager { + private static int counter; + private static final Map store = new HashMap(); + private String directory; + + /** + * Constructs a new resource manager. + * + * @param directory the directory where to persist resources + */ + public ResourceManager(String directory) { + super(); + this.directory = directory; + } + + /** + * Creates a new resource. + * + * @param resource + * @return + */ + public String createResource(Object resource) { + System.out.println("create(" + resource + ") in " + directory); + String key = String.valueOf(counter++); + store.put(key, resource); + return key; + } + + /** + * Deletes a resource. + * + * @param id + */ + public void deleteResource(String id) { + System.out.println("delete(" + id + ")"); + store.remove(id); + } + + /** + * Retrieves a resource. + * + * @param id + * @return + */ + public Object retrieveResource(String id) { + System.out.println("retrieve(" + id + ")"); + return store.get(id); + } + + /** + * Updates a resource. + * + * @param id + * @param resource + * @return + */ + public Object updateResource(String id, Object resource) { + System.out.println("update(" + id + ")"); + return store.put(id, resource); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementation.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementation.java new file mode 100644 index 0000000000..0887a98df6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementation.java @@ -0,0 +1,128 @@ +/* + * 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. + */ +package crud2.extension; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +import crud2.CRUD; + + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +public class CRUDImplementation implements Implementation { + + private Service crudService; + private String directory; + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementation() { + + // CRUD implementation always provide a single service exposing + // the CRUD Java interface, create the model representing that + // fixed service here + + // Create a default service named CRUD + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + crudService = assemblyFactory.createService(); + crudService.setName("CRUD"); + + // Create a Java interface model for the CRUD Java interface + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + JavaInterface javaInterface; + try { + javaInterface = javaFactory.createJavaInterface(CRUD.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + + // Create a Java interface contract model and set it + // into the service + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + crudService.setInterfaceContract(interfaceContract); + } + + public String getDirectory() { + return directory; + } + + public void setDirectory(String directory) { + this.directory = directory; + } + + public ConstrainingType getConstrainingType() { + // The sample CRUD implementation does not support constrainingTypes + return null; + } + + public List getProperties() { + // The sample CRUD implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + // The sample CRUD implementation provides a single fixed CRUD service + return Collections.singletonList(crudService); + } + + public List getReferences() { + // The sample CRUD implementation does not support properties + return Collections.emptyList(); + } + + public String getURI() { + // The sample CRUD implementation does not have a URI + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The sample CRUD implementation does not support constrainingTypes + } + + public void setURI(String uri) { + // The sample CRUD implementation does not have a URI + } + + public boolean isUnresolved() { + // The sample CRUD implementation is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample CRUD implementation is always resolved + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationInvoker.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationInvoker.java new file mode 100644 index 0000000000..3040dac612 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationInvoker.java @@ -0,0 +1,70 @@ +/* + * 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. + */ + +package crud2.extension; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import crud2.backend.ResourceManager; + +/** + * Implements a target invoker for CRUD component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. In this example we are simply delegating the + * CRUD operation invocations to the corresponding methods on our fake + * resource manager. + */ +public class CRUDImplementationInvoker implements Invoker { + private Operation operation; + private ResourceManager resourceManager; + + public CRUDImplementationInvoker(Operation operation, ResourceManager resourceManager) { + this.operation = operation; + this.resourceManager = resourceManager; + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = null; + + if (operation.getName().equals("create")) { + resp = resourceManager.createResource(args[0]); + + } else if (operation.getName().equals("retrieve")) { + resp = resourceManager.retrieveResource((String)args[0]); + + } else if (operation.getName().equals("update")) { + resp = resourceManager.updateResource((String)args[0], args[1]); + + } else if (operation.getName().equals("delete")) { + resourceManager.deleteResource((String)args[0]); + } + + msg.setBody(resp); + } catch (Exception e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProvider.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProvider.java new file mode 100644 index 0000000000..1135ce75cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProvider.java @@ -0,0 +1,69 @@ +/* + * 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. + */ +package crud2.extension; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import crud2.backend.ResourceManager; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + * The sample CRUD implementation is not a full blown implementation, it only + * supports a subset of what a component implementation can support: - a single + * fixed service (as opposed to a list of services typed by different + * interfaces) - a directory attribute used to specify where a CRUD component is + * going to persist resources - no references or properties - no policy intents + * or policy sets + */ +public class CRUDImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + private CRUDImplementation implementation; + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + this.component = component; + this.implementation = implementation; + } + + public void start() { + System.out.println("Starting " + component.getName()); + } + + public void stop() { + System.out.println("Stopping " + component.getName()); + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + CRUDImplementationInvoker invoker = new CRUDImplementationInvoker(operation, new ResourceManager(implementation.getDirectory())); + return invoker; + } + + public Invoker createCallbackInvoker(Operation operation) { + CRUDImplementationInvoker invoker = new CRUDImplementationInvoker(operation, new ResourceManager(implementation.getDirectory())); + return invoker; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProviderFactory.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProviderFactory.java new file mode 100644 index 0000000000..a4d92ccedd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/java/crud2/extension/CRUDImplementationProviderFactory.java @@ -0,0 +1,49 @@ +/* + * 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. + */ +package crud2.extension; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + * The sample CRUD implementation is not a full blown implementation, it only + * supports a subset of what a component implementation can support: - a single + * fixed service (as opposed to a list of services typed by different + * interfaces) - a directory attribute used to specify where a CRUD component is + * going to persist resources - no references or properties - no policy intents + * or policy sets + */ +public class CRUDImplementationProviderFactory implements ImplementationProviderFactory { + + public CRUDImplementationProviderFactory(ExtensionPointRegistry registry) { + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return CRUDImplementation.class; + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + return new CRUDImplementationProvider(component, implementation); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..4b922f4d28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://crud2#implementation.crud,model=crud2.extension.CRUDImplementation diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..5ac1827889 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the implementation extension +crud2.extension.CRUDImplementationProviderFactory;model=crud2.extension.CRUDImplementation diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/java/crud2/CRUDTestCase.java b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/java/crud2/CRUDTestCase.java new file mode 100644 index 0000000000..3bc86cef80 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/java/crud2/CRUDTestCase.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +package crud2; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import crud2.CRUD; + +/** + * Tests the CRUD service + */ +public class CRUDTestCase extends TestCase { + + private SCADomain scaDomain; + private CRUD crudService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("crud2.composite"); + crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + + public void testCRUD() throws Exception { + String id = crudService.create("ABC"); + Object result = crudService.retrieve(id); + assertEquals("ABC", result); + crudService.update(id, "EFG"); + result = crudService.retrieve(id); + assertEquals("EFG", result); + crudService.delete(id); + result = crudService.retrieve(id); + assertNull(result); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/resources/crud2.composite b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/resources/crud2.composite new file mode 100644 index 0000000000..5aa4b3c7d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/samples/old/implementation-crud2-extension/src/test/resources/crud2.composite @@ -0,0 +1,30 @@ + + + + + + + + + -- cgit v1.2.3