summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank')
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountService.java32
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountServiceImpl.java99
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/feed/AccountFeedImpl.java70
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/client/BigBankClient.java50
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/demo/BigBankServer.java130
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/security/BigbankPasswordCallbackHandler.java51
6 files changed, 432 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountService.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountService.java
new file mode 100644
index 0000000000..2cb8027874
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountService.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+
+@Remotable
+public interface AccountService {
+
+ public double getAccountReport(String customerID);
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountServiceImpl.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountServiceImpl.java
new file mode 100644
index 0000000000..4f0e3879dc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/AccountServiceImpl.java
@@ -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.
+ */
+package bigbank.account;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import stockquote.StockQuoteService;
+import bigbank.account.checking.CheckingAccountDetails;
+import bigbank.account.checking.CheckingAccountService;
+import bigbank.account.savings.SavingsAccountDetails;
+import bigbank.account.savings.SavingsAccountService;
+import bigbank.account.stock.StockAccountDetails;
+import bigbank.account.stock.StockAccountService;
+import calculator.CalculatorService;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+
+@Service(AccountService.class)
+public class AccountServiceImpl implements AccountService {
+
+ @Reference
+ protected SavingsAccountService savingsAcService;
+
+ @Reference
+ protected CheckingAccountService checkingAcService;
+
+ @Reference
+ protected StockAccountService stockAcService;
+
+ @Reference
+ protected StockQuoteService stockQuoteService;
+
+ @Reference
+ protected CalculatorService calculatorService;
+
+ @Property
+ protected String currency;
+
+ public double getAccountReport(String customerID) {
+
+ // Get the checking, savings and stock accounts from the AccountData
+ // service component
+ CheckingAccountDetails checking = null;
+ try {
+ checking = checkingAcService.getAccountDetails(customerID);
+ System.out.println("Checking account: " + checking);
+
+ SavingsAccountDetails savings = savingsAcService.getAccountDetails(customerID);
+ System.out.println("Savings account: " + savings);
+
+ StockAccountDetails stock = stockAcService.getAccountDetails(customerID);
+ System.out.println("Stock account: " + stock);
+
+ // Get the stock price in USD
+ double price = stockQuoteService.getQuote(stock.getSymbol());
+ System.out.println("Stock price for " + stock.getSymbol() + ": " + price);
+
+ // Convert to the configured currency
+ if (currency.equals("EURO")) {
+
+ // Use our fancy calculator service to convert to the target currency
+ price = calculatorService.multiply(price, 0.70);
+
+ System.out.println("Converted to " + currency + ": " + price);
+ }
+
+ // Calculate the value of the stock account
+ double stockValue = price * stock.getQuantity();
+
+ // Calculate the total balance of all accounts and return it
+ double balance = checking.getBalance() + savings.getBalance() + stockValue;
+
+ return balance;
+ } catch ( Throwable e ) {
+ e.printStackTrace();
+ return 0;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/feed/AccountFeedImpl.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/feed/AccountFeedImpl.java
new file mode 100644
index 0000000000..13d79a9c33
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/account/feed/AccountFeedImpl.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 bigbank.account.feed;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import bigbank.account.AccountService;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+
+@Service(Collection.class)
+public class AccountFeedImpl implements Collection<String, String> {
+
+ @Reference
+ protected AccountService accountService;
+
+ public Entry<String, String>[] getAll() {
+
+ // Add the Account report entry
+ String report = get("1234");
+ Entry<String, String> entry = new Entry<String, String>("1234", report);
+
+ return new Entry[] { entry } ;
+ }
+
+ public String get(String id) {
+
+ // Get the account report for the specified customer ID
+ double balance = accountService.getAccountReport(id);
+ String report = Double.toString(balance);
+
+ return report;
+ }
+
+ public void delete(String key) throws NotFoundException {
+ }
+
+ public String post(String key, String item) {
+ return null;
+ }
+
+ public void put(String key, String item) throws NotFoundException {
+ }
+
+ public Entry<String, String>[] query(String queryString) {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/client/BigBankClient.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/client/BigBankClient.java
new file mode 100644
index 0000000000..a7fa5ecc22
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/client/BigBankClient.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 bigbank.client;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+import bigbank.account.AccountService;
+
+/**
+ * This client program shows how to create an SCA runtime, start it,
+ * and locate and invoke a SCA component
+ */
+public class BigBankClient {
+
+ public static void main(String[] args) throws Exception {
+
+ SCADomain domain = SCADomain.newInstance("BigBank.composite");
+
+ AccountService accountService = domain.getService(AccountService.class, "AccountServiceComponent");
+
+ String customerID = "1234";
+
+ System.out.println("Calling account service for customer: " + customerID);
+ System.out.println();
+ double balance = accountService.getAccountReport(customerID);
+
+ System.out.println();
+ System.out.println("Balance: " + balance);
+
+ domain.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/demo/BigBankServer.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/demo/BigBankServer.java
new file mode 100644
index 0000000000..05360e07a5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/demo/BigBankServer.java
@@ -0,0 +1,130 @@
+/*
+ * 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.demo;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
+
+import bigbank.account.savings.SavingsAccountService;
+
+
+
+/**
+ * This client program shows how to create an SCA runtime, start it,
+ * and locate and invoke a SCA component
+ */
+public class BigBankServer {
+
+ public static void main(String[] args) throws Exception {
+ long timeout = -1L;
+ if (args.length > 0) {
+ timeout = Long.parseLong(args[0]);
+ }
+
+ System.out.println("Starting the Sample SCA BigBank server...");
+ ClassLoader cl = BigBankServer.class.getClassLoader();
+ EmbeddedSCADomain domain = new EmbeddedSCADomain(cl, "http://localhost");
+
+ //Start the domain
+ domain.start();
+
+ // Contribute the SCA contribution
+ ContributionService contributionService = domain.getContributionService();
+
+ URL javaContribURL = getContributionURL(SavingsAccountService.class);
+ Contribution bigbankAcContribution = contributionService.contribute("http://bigbank-account", javaContribURL, false);
+ for (Composite deployable : bigbankAcContribution.getDeployables()) {
+ domain.getDomainComposite().getIncludes().add(deployable);
+ domain.buildComposite(deployable);
+ }
+
+ URL bigbankContribUrl = getContributionURL(BigBankServer.class);
+ Contribution bigbankContribution = contributionService.contribute("http://bigbank", bigbankContribUrl, false);
+ for (Composite deployable : bigbankContribution.getDeployables()) {
+ domain.getDomainComposite().getIncludes().add(deployable);
+ domain.buildComposite(deployable);
+ }
+
+
+ //Start Components from composite
+ for (Composite deployable : bigbankAcContribution.getDeployables()) {
+ domain.getCompositeActivator().activate(deployable);
+ domain.getCompositeActivator().start(deployable);
+ }
+
+ for (Composite deployable : bigbankContribution.getDeployables()) {
+ domain.getCompositeActivator().activate(deployable);
+ domain.getCompositeActivator().start(deployable);
+ }
+
+ if (timeout < 0) {
+ System.out.println("Press Enter to Exit...");
+ System.in.read();
+ } else {
+ Thread.sleep(timeout);
+ }
+
+ contributionService.remove("http://bigbank-account");
+ contributionService.remove("http://bigbank");
+
+ // Stop Components from composite
+ for (Composite deployable : bigbankContribution.getDeployables()) {
+ domain.getCompositeActivator().stop(deployable);
+ domain.getCompositeActivator().deactivate(deployable);
+ }
+
+ domain.stop();
+
+ domain.close();
+
+
+ /*SCADomain domain = SCADomain.newInstance("BigBank.composite");
+
+ if (timeout < 0) {
+ System.out.println("Press Enter to Exit...");
+ System.in.read();
+ } else {
+ Thread.sleep(timeout);
+ }
+
+ domain.close();*/
+
+ System.out.println("Bye");
+ }
+
+ private static URL getContributionURL(Class<?> cls) throws MalformedURLException {
+ String flag = "/" + cls.getName().replace('.', '/') + ".class";
+ URL url = cls.getResource(flag);
+ String root = url.toExternalForm();
+ root = root.substring(0, root.length() - flag.length() + 1);
+ if (root.startsWith("jar:") && root.endsWith("!/")) {
+ root = root.substring(4, root.length() - 2);
+ }
+ url = new URL(root);
+ return url;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/security/BigbankPasswordCallbackHandler.java b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/security/BigbankPasswordCallbackHandler.java
new file mode 100644
index 0000000000..6d3b547939
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/demos/bigbank/src/main/java/bigbank/security/BigbankPasswordCallbackHandler.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.security;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.apache.ws.security.WSPasswordCallback;
+
+/**
+ * Sample userid passwd generation class
+ */
+public class BigbankPasswordCallbackHandler implements CallbackHandler {
+
+ public void handle(Callback[] callbacks) throws IOException,
+ UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+ WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
+ //System.out.println("*** Getting password for user ...." + pwcb.getIdentifer() + " & " + pwcb.getKey());
+ if ( pwcb.getUsage() == WSPasswordCallback.SIGNATURE ) {
+ System.out.println("*** Calling BIG-BANK Passwd Handler for SIGNING...." );
+ pwcb.setPassword("bbservice");
+ } else if ( pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN ) {
+ if ( pwcb.getIdentifer().equals("bbaservice")) {
+ System.out.println("*** Calling BIG-BANK Passwd Handler for setting AUTHENTICATION password...." );
+ pwcb.setPassword("bbaservice");
+ }
+ }
+ }
+ }
+
+}