diff options
Diffstat (limited to 'tags/java-M1-20060518/java/sampleapps/bigbank/account/src')
19 files changed, 2591 insertions, 0 deletions
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java new file mode 100644 index 0000000000..304244b7db --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/account/AccountServiceImpl.java @@ -0,0 +1,260 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.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 = 1.0f; + private String currency= "USD"; + + @Property + public void setCurrency(final String currency) { + this.currency= currency == null ? this.currency: currency.trim(); + + if ("USD".equals(this.currency)) + currencyConversion= 1.0f; + else if ("EURO".equals(this.currency)) + currencyConversion= 0.8f; + else{ + try { + currencyConversion = Float.parseFloat(this.currency); + } catch (Exception e) { + currencyConversion= 1.0f; + } + + } + + } + + 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<AccountSummary> 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<StockSummary> stocks = accountReport.getStockSummaries(); + if (stocks.size() < 1) + return accountReport; // nothing todo + HashSet<String> owned = new HashSet<String>(stocks.size()); + for (StockSummary stock : stocks) { + owned.add(stock.getSymbol()); + } + ArrayList<String> ownedStr = new ArrayList<String>(owned.size() * 5); + for (String s : owned) { + + ownedStr.add(s); + } + + Map<String, StockQuote> stockInfo = stockQuoteService.getQuotes((String[]) 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 * currencyConversion ; + + + } + private float toUSDollarfromCurrency(float value) { + + return value /currencyConversion ; + } + + + 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<String, StockQuote> 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); + } + } +} diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java new file mode 100644 index 0000000000..4c44ca307e --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataService.java @@ -0,0 +1,77 @@ +/** + * + * + * Licensed 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; + + + } diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java new file mode 100644 index 0000000000..39c319b7a5 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceDASImpl.java @@ -0,0 +1,397 @@ +/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.SQLException;
+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.ApplyChangesCommand;
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.CommandGroup;
+import org.apache.tuscany.das.rdb.Converter;
+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.DataGraphRoot;
+import com.bigbank.account.StockSummary;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.TypeHelper;
+
+@Service(AccountDataService.class)
+public class AccountDataServiceDASImpl implements AccountDataService {
+
+ 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();
+ Command select = Command.FACTORY.createCommand(
+ "SELECT firstName, lastName, loginID, password, id FROM customers where loginID = :loginID", mapping);
+ Connection conn = getConnection();
+ select.setConnection(conn);
+ select.setParameterValue("loginID", logonID);
+ TypeHelper helper = TypeHelper.INSTANCE;
+
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+ conn.close();
+
+ Collection customers = root.getCustomerProfileData();
+ 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 testgetCustomerByLoginIDThroughDASRead(final String logonID) throws Exception {
+
+ InputStream mapping = createConfigStream();
+
+ Command select = Command.FACTORY.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = :loginID",
+ mapping);
+ Connection conn = getConnection();
+ select.setConnection(conn);
+ select.setParameterValue("loginID", logonID);
+ TypeHelper helper = TypeHelper.INSTANCE;
+
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+ conn.close();
+
+ Collection customers = root.getCustomerProfileData();
+ CustomerProfileData customerProfileData = (CustomerProfileData) customers.iterator().next();
+ return customerProfileData;
+
+ }
+
+ public CustomerProfileData createAccount(CustomerProfileData customerProfile, boolean createSavings, boolean createCheckings)
+ throws RemoteException {
+
+ try {
+ Command insert = Command.FACTORY.createCommand("insert into customers (firstName,lastName,address,email, loginID, password ) values ('"
+ + customerProfile.getFirstName() + "', '" + customerProfile.getLastName() + "', '" + customerProfile.getAddress() + "', '"
+ + customerProfile.getEmail() + "', '" + customerProfile.getLoginID() + "', '" + customerProfile.getPassword() + "')");
+ insert.setConnection(getConnection());
+ insert.execute();
+ CustomerProfileData ret = getCustomerProfile(customerProfile.getLoginID());
+ String cid = ret.getId() + "";
+ if (createSavings) {
+ insert = Command.FACTORY.createCommand("insert into accounts (id,accountNumber, accountType, balance ) values (" + cid + ", '"
+ + AccountServiceImpl.SAVINGS_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_SAVINGS + "', " + 1.0F + ")");
+ insert.setConnection(getConnection());
+ insert.execute();
+
+ }
+ if (createCheckings) {
+ insert = Command.FACTORY.createCommand("insert into accounts (id,accountNumber, accountType, balance ) values (" + cid + ", '"
+ + AccountServiceImpl.CHECKING_ACCOUNT_PREFIX + cid + "', '" + AccountServiceImpl.ACCOUNT_TYPE_CHECKINGS + "', " + 1.0F + ")");
+ insert.setConnection(getConnection());
+ 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 {
+ CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(getConnection());
+ Command read = commandGroup.getCommand("all customers");
+
+ // select.setDataObjectModel();
+ TypeHelper helper = TypeHelper.INSTANCE;
+ read.setDataObjectModel(helper.getType(DataGraphRoot.class));
+ 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());
+
+ ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();
+ apply.execute(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();
+
+ Command select = Command.FACTORY.createCommand("SELECT accountNumber, accountType, balance FROM accounts where id = :id", mapping);
+ Connection conn = getConnection();
+ select.setConnection(conn);
+ select.setParameterValue("id", customerID);
+ TypeHelper helper = TypeHelper.INSTANCE;
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+ accountReport.getAccountSummaries().addAll(root.getAccountSummaries());
+
+ // Get Stocks
+
+ select = Command.FACTORY.createCommand(
+ "SELECT Symbol, quantity, purchasePrice, purchaseDate, purchaseLotNumber FROM stocks where id = :id", createConfigStream());
+ select.setConnection(conn);
+ select.setParameterValue("id", customerID);
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+
+ // select.addConverter("STOCKS.PURCHASEDATE", DateConverter.class.getName());
+
+ root = (DataGraphRoot) select.executeQuery();
+ accountReport.getStockSummaries().addAll(root.getStockSummaries());
+
+ 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 {
+ Command select = Command.FACTORY.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = :accountNumber",
+ createConfigStream());
+ Connection conn = getConnection();
+ select.setConnection(conn);
+ select.setParameterValue("accountNumber", account);
+ TypeHelper helper = TypeHelper.INSTANCE;
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+ Collection accounts = root.getAccountSummaries();
+ AccountSummary accountData = (AccountSummary) accounts.iterator().next();
+ float newbalance = accountData.getBalance() + ammount;
+ accountData.setBalance(newbalance);
+ // update department set companyid = ? where department.name = ?
+ CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(conn);
+ Command update = commandGroup.getCommand("update balance");
+ update.setParameterValue("BALANCE", new Float(newbalance));
+ update.setParameterValue("ACCOUNTNUMBER", 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 {
+ CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(getConnection());
+
+ Command read = commandGroup.getCommand("stockbylotSelect");
+ TypeHelper helper = TypeHelper.INSTANCE;
+ read.setDataObjectModel(helper.getType(DataGraphRoot.class));
+ read.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);// autoboxing :-)
+ DataGraphRoot root = (DataGraphRoot) read.executeQuery();
+ List stocks = root.getStockSummaries();
+ if (null != stocks && !stocks.isEmpty()) {
+ StockSummary stock = (StockSummary) stocks.get(0);
+ int newQuatity = Math.max(stock.getQuantity() - quantity, 0);
+ if (newQuatity < 1) {
+
+ Command delete = Command.FACTORY.createCommand("DELETE FROM STOCKS WHERE PURCHASELOTNUMBER = ?");
+ delete.setParameterValue(1, purchaseLotNumber);
+ delete.setConnection(getConnection());
+ delete.execute();
+
+ } else {
+
+ Command update = commandGroup.getCommand("stockbylot");
+
+ update.setParameterValue("QUANTITY", newQuatity);
+ update.setParameterValue("PURCHASELOTNUMBER", purchaseLotNumber);
+ update.execute();
+
+ stock.setQuantity(newQuatity);
+ }
+
+ }
+
+ return null;
+ } catch (Exception e) {
+ throw new RemoteException("sellStock", e);
+ }
+ }
+
+ public StockSummary purchaseStock(int id, StockSummary stock) throws RemoteException {
+
+ try {
+
+ Command insert = Command.FACTORY
+ .createCommand("insert into stocks (id, symbol, quantity, purchasePrice, purchaseDate) values (?,?,?,?,?)");
+ insert.setParameterValue(1, new Integer(id));
+ insert.setParameterValue(2, stock.getSymbol());
+ insert.setParameterValue(3, stock.getQuantity());
+ insert.setParameterValue(4, stock.getPurchasePrice());
+ insert.setParameterValue(5, DateConverter.INSTANCE.getColumnValue(stock.getPurchaseDate()));
+
+ insert.setConnection(getConnection());
+ 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 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();
+
+ }
+
+ }
+}
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..3b9a64dda5 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdata/AccountDataServiceImpl.java @@ -0,0 +1,99 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.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; + } +} diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java new file mode 100644 index 0000000000..42cf6dde2a --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/accountdb/AccountDBInit.java @@ -0,0 +1,452 @@ +/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.InputStream;
+import java.io.PrintStream;
+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 org.apache.tuscany.das.rdb.ApplyChangesCommand;
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.CommandGroup;
+import org.apache.tuscany.das.rdb.Converter;
+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 com.bigbank.account.AccountFactory;
+import com.bigbank.account.AccountSummary;
+import com.bigbank.account.CustomerProfileData;
+import com.bigbank.account.DataGraphRoot;
+import com.bigbank.account.StockSummary;
+import com.bigbank.account.purchaseStock;
+import com.bigbank.account.withdraw;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.TypeHelper;
+
+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:";
+
+ boolean deleteExisting = false;
+
+ protected String dbDirectory = null;
+
+
+ @Override
+ public void init() throws ServletException {
+ try {
+
+ registerTypes();
+ ServletConfig servletConfig = getServletConfig();
+ ServletContext servletContext = servletConfig.getServletContext();
+ this.dbDirectory = servletContext.getRealPath("WEB-INF/bigbankdb/accounts");
+ this.deleteExisting = false;
+
+ createDB(dbDirectory);
+
+
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ log(e.toString(), e);
+ throw new ServletException(e);
+ }
+ }
+
+ public AccountDBInit() {
+ }
+
+ public AccountDBInit(String dbDirectory, Boolean deleteExisting) {
+ this.dbDirectory = dbDirectory;
+ this.deleteExisting = deleteExisting;
+ }
+
+ public static void createDB(final String location) throws Exception {
+ Connection conn = null;
+ AccountDataServiceDASImpl.dbDirectory = location;
+ 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;
+ }
+ }
+ }
+
+ }
+
+ 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;
+ }
+
+ 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.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("basicStaticCustomer.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);
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception {
+ registerTypes();
+ String dbDirectory = null; // "c:/derbydbtest/foo";
+ Boolean deleteExisting = false;
+ for (String x : args) {
+ if ("-d".equals(x)) {
+ deleteExisting = true;
+ }
+ if (!x.startsWith("-")) {
+ dbDirectory = x;
+ }
+
+ }
+ AccountDBInit accountDBInit = new AccountDBInit(dbDirectory, deleteExisting);
+
+ createDB(dbDirectory);
+ accountDBInit.readDBstdout(System.out);
+
+
+ // Test withdrawl
+ withdraw wd = AccountFactory.INSTANCE.createwithdraw();
+ wd.setAccountNumber("134-43-39438");
+ wd.setAmount(1.00F);
+ // accountDBInit.testWithdrawThroughDAS(wd);
+
+ // test stock purchase.
+
+ purchaseStock sp = AccountFactory.INSTANCE.createpurchaseStock();
+ StockSummary stock= AccountFactory.INSTANCE.createStockSummary();
+ sp.setStock(stock);
+ stock.setSymbol("GOOG");
+ sp.setId(1);
+ stock.setQuantity(10);
+ accountDBInit.testStrockPurchaseThroughDAS(sp);
+
+ accountDBInit.readDBstdout(System.out);
+
+ System.out.flush();
+ }
+
+ protected void testStrockPurchaseThroughDAS(purchaseStock sp) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
+ SQLException {
+
+ CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(createConnection());
+ Command read = commandGroup.getCommand("all stocks");
+
+ DataObject root = read.executeQuery();
+
+ // Create a new stockPurchase
+ DataObject stockPurchase = root.createDataObject("STOCKS");
+ 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));
+ stockPurchase.set("PURCHASEDATE", new Date());
+
+ ApplyChangesCommand apply = commandGroup.getApplyChangesCommand();
+
+ apply.execute(root);
+
+
+
+ }
+
+ public CustomerProfileData testgetCustomerByLoginIDThroughDASRead(final String logonID) throws Exception {
+
+ InputStream mapping = createConfigStream();
+
+ Command select = Command.FACTORY.createCommand("SELECT firstName, lastName, loginID, password, id FROM customers where loginID = :loginID",
+ mapping);
+ Connection conn = createConnection();
+ select.setConnection(conn);
+ select.setParameterValue("loginID", logonID);
+ TypeHelper helper = TypeHelper.INSTANCE;
+
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+ conn.close();
+
+ Collection customers = root.getCustomerProfileData();
+ 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);
+ 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);
+ 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 void testWithdrawThroughDAS(withdraw wd) throws Exception {
+
+ Command select = Command.FACTORY.createCommand("SELECT accountNumber, balance FROM accounts where accountNumber = :accountNumber",
+ createConfigStream());
+ Connection conn = createConnection();
+ select.setConnection(conn);
+ select.setParameterValue("accountNumber", wd.getAccountNumber());
+ TypeHelper helper = TypeHelper.INSTANCE;
+
+ select.setDataObjectModel(helper.getType(DataGraphRoot.class));
+
+ DataGraphRoot root = (DataGraphRoot) select.executeQuery();
+
+ Collection accounts = root.getAccountSummaries();
+ AccountSummary account = (AccountSummary) accounts.iterator().next();
+ float newbalance = account.getBalance() - wd.getAmount();
+ account.setBalance(newbalance);
+ // update department set companyid = ? where department.name = ?
+
+ CommandGroup commandGroup = CommandGroup.FACTORY.createCommandGroup(createConfigStream());
+ commandGroup.setConnection(conn);
+ Command update = commandGroup.getCommand("update balance");
+ update.setParameterValue("BALANCE", new Float(newbalance));
+ update.setParameterValue("ACCOUNTNUMBER", wd.getAccountNumber());
+
+ update.execute();
+ conn.close();
+
+ }
+
+ public static class MyDateConverter implements Converter {
+
+ private static 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();
+
+ }
+
+ }
+
+}
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java new file mode 100644 index 0000000000..627ab7b379 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuote.java @@ -0,0 +1,223 @@ +/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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;
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @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;
+ }
+
+ 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();
+ }
+ 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/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java new file mode 100644 index 0000000000..b899d7cbd0 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteService.java @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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<String, StockQuote> getQuotes(String[] symbols) throws RemoteException; + +} diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java new file mode 100644 index 0000000000..039abde4bc --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteServiceImpl.java @@ -0,0 +1,66 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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<String, StockQuote> stocks = new Hashtable<String, StockQuote>(); + + public synchronized Map<String, StockQuote> getQuotes(String[] symbols) throws RemoteException { + Map<String, StockQuote> ret = new Hashtable<String, StockQuote>(); + 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, (StockQuote) sq.clone()); + } + + } + + return ret; + } + +} diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java new file mode 100644 index 0000000000..f5f481ca1b --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/java/bigbank/account/services/stockquote/StockQuoteWebservicexServiceImpl.java @@ -0,0 +1,150 @@ +/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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("MODULE")
+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<String, StockQuote> 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<StockQuote> listQuotes = new ArrayList<StockQuote>();
+ Hashtable<String, StockQuote> listQuoteHT = new Hashtable<String, StockQuote>();
+ 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/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml new file mode 100644 index 0000000000..e558e959fa --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/DasAccountConfiguration.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <Table name="CUSTOMERS" propertyName="CustomerProfileData">
+ <!-- Column name="firstName" primaryKey="true"/ -->
+ <Column name="FIRSTNAME"/>
+ <Column name="LASTNAME"/>
+ <Column name="ADDRESS"/>
+ <Column name="EMAIL"/>
+ <Column name="LOGINID"/>
+ <Column name="PASSWORD"/>
+ <Column name="ID"/>
+ </Table>
+
+ <Table name="ACCOUNTS" propertyName="AccountSummary">
+ <!-- Column name="firstName" primaryKey="true"/ -->
+ <Column name="ACCOUNTNUMBER"/>
+ <Column name="BALANCE"/>
+ </Table>
+
+
+
+ <Table name="STOCKS" propertyName="StockSummary" >
+ <Column name="ID"/>
+ <Column name="Symbol"/>
+ <Column name="quantity"/>
+ <Column name="purchasePrice"/>
+ <Column name="PURCHASEDATE" converterClassName="bigbank.account.services.accountdata.AccountDataServiceDASImpl$DateConverter"/>
+ </Table>
+
+
+ <Command name="update balance"
+ SQL="update ACCOUNTS set BALANCE = :BALANCE where ACCOUNTNUMBER = :ACCOUNTNUMBER"
+ kind="Update">
+ <Parameter name=":BALANCE"/>
+ <Parameter name=":ACCOUNTNUMBER"/>
+ </Command>
+
+
+ <Command name="all stocks" SQL="select * from stocks" kind="Select"/>
+ <Command name="all customers" SQL="select from CUSTOMERS" kind="Select"/>
+ <Command name="stockbylotSelect" SQL="select quantity from STOCKS WHERE purchaseLotNumber = :PURCHASELOTNUMBER" kind="Select" >
+ <Parameter name=":PURCHASELOTNUMBER"/>
+ </Command>
+ <Command name="stockbylot" SQL="update STOCKS set quantity = :QUANTITY WHERE purchaseLotNumber = :PURCHASELOTNUMBER" kind="Update" >
+ <Parameter name=":QUANTITY"/>
+ <Parameter name=":PURCHASELOTNUMBER"/>
+ </Command>
+
+</Config>
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/WebservicexService_stockquote.fragment b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/WebservicexService_stockquote.fragment new file mode 100644 index 0000000000..b52ba7fe06 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/WebservicexService_stockquote.fragment @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9"
+ xmlns:tuscany="http://org.apache.tuscany/xmlns/system/0.9"
+ xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ name="org.apache.tuscany.tomcat"
+ >
+
+
+<!-- WebservicexService -->
+ <component name="StockQuoteServiceComponent">
+ <implementation.java class="bigbank.account.services.stockquote.StockQuoteWebservicexServiceImpl"/>
+ <references>
+ <v:stockQuoteService>StockQuoteWebService</v:stockQuoteService>
+ </references>
+ </component>
+
+</moduleFragment>
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/mock_stockquote.fragment b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/mock_stockquote.fragment new file mode 100644 index 0000000000..b7c433d6a1 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/mock_stockquote.fragment @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9"
+ xmlns:tuscany="http://org.apache.tuscany/xmlns/system/0.9"
+ xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ name="org.apache.tuscany.tomcat">
+
+ <!-- Local -->
+ <component name="StockQuoteServiceComponent">
+ <implementation.java class="bigbank.account.services.stockquote.StockQuoteServiceImpl"/>
+ </component>
+
+</moduleFragment>
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.fragment b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.fragment new file mode 100644 index 0000000000..b7c433d6a1 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.fragment @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9"
+ xmlns:tuscany="http://org.apache.tuscany/xmlns/system/0.9"
+ xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ name="org.apache.tuscany.tomcat">
+
+ <!-- Local -->
+ <component name="StockQuoteServiceComponent">
+ <implementation.java class="bigbank.account.services.stockquote.StockQuoteServiceImpl"/>
+ </component>
+
+</moduleFragment>
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.module b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.module new file mode 100644 index 0000000000..b9234573e1 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.module @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<module xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9" + name="bigbank.account"> + + <import.sdo factory="com.bigbank.account.AccountFactory" /> + <import.sdo factory="net.x.webservice.WebserviceFactory" /> + + <import.wsdl wsdlLocation="wsdl/AccountService.wsdl"/> + <!-- import.wsdl wsdlLocation="wsdl/StockQuoteWebService.wsdl"/ --> + <import.wsdl wsdlLocation="wsdl/stockquotes.webservicex.wsdl"/> + + <entryPoint name="AccountService"> + <interface.java interface="com.bigbank.account.AccountService"/> + <binding.ws port="http://www.bigbank.com/account#wsdl.endpoint(AccountService/AccountServiceSOAP)"/> + <reference>AccountServiceComponent/AccountService</reference> + </entryPoint> + + <component name="AccountServiceComponent"> + <implementation.java class="bigbank.account.services.account.AccountServiceImpl"/> + <properties> + <v:currency>USD</v:currency> + </properties> + <references> + <v:accountDataService>AccountDataServiceComponent</v:accountDataService> + <v:stockQuoteService>StockQuoteServiceComponent</v:stockQuoteService> + </references> + </component> + + <component name="AccountDataServiceComponent"> + <implementation.java class="bigbank.account.services.accountdata.AccountDataServiceDASImpl"/> + </component> + + + <!-- Stock Quote Web Service --> + <externalService name="StockQuoteWebService"> + <interface.wsdl interface="http://www.webserviceX.NET/#wsdl.interface(StockQuoteSoap)"/> + <binding.ws port="http://www.webserviceX.NET/#wsdl.endpoint(StockQuote/StockQuoteSoap)"/> + </externalService> + +</module> diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.subsystem b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.subsystem new file mode 100644 index 0000000000..fd6ab20151 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/sca.subsystem @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed 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.
+ -->
+<subsystem xmlns="http://www.osoa.org/xmlns/sca/0.9"
+ name="sample-bigbank-account-subsystem">
+
+ <moduleComponent name="sample-bigbank-account" module="bigbank.account"/>
+
+</subsystem>
diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl new file mode 100644 index 0000000000..c44b826440 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/AccountService.wsdl @@ -0,0 +1,392 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. +--> +<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:account="http://www.bigbank.com/account" + targetNamespace="http://www.bigbank.com/account" + name="AccountService"> + + <wsdl:types> + <xsd:schema targetNamespace="http://www.bigbank.com/account" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:account="http://www.bigbank.com/account" + + > <!-- xmlns:sdojava="commonj.sdo/java" sdojava:package="org.apache.tuscany.samples.bigbank.account" --> + + + <xsd:complexType name="DataGraphRoot"> <!-- This was added temporarily for DAS + changes are on the way to lift this requirement --> + <xsd:sequence> + <xsd:element name="customerProfileData" type="account:CustomerProfileData" maxOccurs="unbounded" minOccurs="0" /> + <xsd:element name="StockSummaries" type="account:StockSummary" maxOccurs="unbounded" minOccurs="0" /> + <xsd:element name="AccountSummaries" type="account:AccountSummary" maxOccurs="unbounded" minOccurs="0" /> + </xsd:sequence> + </xsd:complexType> + + + <xsd:element name="getAccountReport"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="customerID" + type="xsd:int" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="getAccountReportResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="accountReport" + type="account:AccountReport" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:complexType name="AccountReport"> + <xsd:sequence> + <xsd:element name="accountSummaries" + type="account:AccountSummary" maxOccurs="unbounded" /> + <xsd:element name="stockSummaries" + type="account:StockSummary" maxOccurs="unbounded" /> + + </xsd:sequence> + </xsd:complexType> + <xsd:complexType name="AccountSummary"> + <xsd:attribute name="accountNumber" type="xsd:string" /> + <xsd:attribute name="accountType" type="xsd:string" /> + <xsd:attribute name="balance" type="xsd:float" /> + </xsd:complexType> + + <xsd:complexType name="StockSummary"> + <xsd:attribute name="purchaseLotNumber" type="xsd:int" /> + <!-- unique id for this purchase --> + <xsd:attribute name="symbol" type="xsd:string" /> + <xsd:attribute name="quantity" type="xsd:int" /> + <xsd:attribute name="purchaseDate" type="xsd:dateTime" /> + <xsd:attribute name="purchasePrice" type="xsd:float" /> + <xsd:attribute name="currentPrice" type="xsd:float" /> + <xsd:attribute name="company" type="xsd:string" /> + <xsd:attribute name="highPrice" type="xsd:float" /> + <xsd:attribute name="lowPrice" type="xsd:float" /> + + </xsd:complexType> + + <!-- Profile in data base --> + <xsd:element name="getCustomerProfile"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="loginID" type="xsd:string" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:complexType name="CustomerProfileData"> + <xsd:sequence> + <xsd:element name="firstName" type="xsd:string" /> + <xsd:element name="lastName" type="xsd:string" /> + <xsd:element name="address" type="xsd:string" /> + <xsd:element name="email" type="xsd:string" /> + <xsd:element name="loginID" type="xsd:string" /> + <xsd:element name="password" type="xsd:string" /> + <xsd:element name="id" type="xsd:int" /> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="getCustomerProfileResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="customerProfile" + type="account:CustomerProfileData" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:element name="withdraw"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="accountNumber" + type="xsd:string" /> + <xsd:element name="amount" type="xsd:float" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="withdrawResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="balance" type="xsd:float" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:element name="deposit"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="accountNumber" + type="xsd:string" /> + <xsd:element name="amount" type="xsd:float" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="depositResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="balance" type="xsd:float" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:element name="purchaseStock"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="id" type="xsd:int" /> + <xsd:element name="stock" type="account:StockSummary" />
+ </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:element name="purchaseStockResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="purchaseSummary" + type="account:StockSummary" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + + + <xsd:element name="sellStock"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="purchaseLotNumber" + type="xsd:int" /><!-- unique id for this purchase --> + <xsd:element name="quantity" type="xsd:int" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:element name="createAccount"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="customerProfile" + type="account:CustomerProfileData" /> + <xsd:element name="createSavings" + type="xsd:boolean" /> + <xsd:element name="createCheckings" + type="xsd:boolean" /> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + <xsd:element name="createAccountResponse"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="customerProfile" + type="account:CustomerProfileData" /> + </xsd:sequence> + </xsd:complexType> + + </xsd:element> + + </xsd:schema> + </wsdl:types> + <wsdl:message name="getAccountReportRequest"> + <wsdl:part element="account:getAccountReport" + name="getAccountReportRequest" /> + </wsdl:message> + <wsdl:message name="getAccountReportResponse"> + <wsdl:part element="account:getAccountReportResponse" + name="getAccountReportResponse" /> + </wsdl:message> + + <wsdl:message name="getCustomerProfileRequest"> + <wsdl:part element="account:getCustomerProfile" + name="getCustomerProfile" /> + </wsdl:message> + <wsdl:message name="getCustomerProfileResponse"> + <wsdl:part element="account:getCustomerProfileResponse" + name="getCustomerProfileResponse" /> + </wsdl:message> + + <wsdl:message name="withdrawRequest"> + <wsdl:part element="account:withdraw" name="withdrawRequest" /> + </wsdl:message> + + <wsdl:message name="withdrawResponse"> + <wsdl:part element="account:withdrawResponse" + name="withdrawResponse" /> + </wsdl:message> + + <wsdl:message name="depositRequest"> + <wsdl:part element="account:deposit" name="depositRequest" /> + </wsdl:message> + + <wsdl:message name="depositResponse"> + <wsdl:part element="account:depositResponse" + name="depositResponse" /> + </wsdl:message> + + <wsdl:message name="purchaseStockRequest"> + <wsdl:part element="account:purchaseStock" + name="purchaseStockRequest" /> + </wsdl:message> + + <wsdl:message name="purchaseStockResponse"> + <wsdl:part element="account:purchaseStockResponse" + name="purchaseStockResponse" /> + </wsdl:message> + + <wsdl:message name="sellStockRequest"> + <wsdl:part element="account:sellStock" name="sellStockRequest" /> + </wsdl:message> + + <wsdl:message name="createAccountRequest"> + <wsdl:part element="account:createAccount" name="createAccountRequest" /> + </wsdl:message> + + <wsdl:message name="createAccountResponse"> + <wsdl:part element="account:createAccountResponse" name="createAccountResponse" /> + </wsdl:message> + + <wsdl:portType name="AccountService"> + <wsdl:operation name="getAccountReport"> + <wsdl:input message="account:getAccountReportRequest" /> + <wsdl:output message="account:getAccountReportResponse" /> + </wsdl:operation> + + <wsdl:operation name="getCustomerProfile"> + <wsdl:input message="account:getCustomerProfileRequest" /> + <wsdl:output message="account:getCustomerProfileResponse" /> + </wsdl:operation> + + <wsdl:operation name="withdraw"> + <wsdl:input message="account:withdrawRequest" /> + <wsdl:output message="account:withdrawResponse" /> + </wsdl:operation> + + <wsdl:operation name="deposit"> + <wsdl:input message="account:depositRequest" /> + <wsdl:output message="account:depositResponse" /> + </wsdl:operation> + + <wsdl:operation name="purchaseStock"> + <wsdl:input message="account:purchaseStockRequest" /> + <wsdl:output message="account:purchaseStockResponse" /> + </wsdl:operation> + + <wsdl:operation name="sellStock"> + <wsdl:input message="account:sellStockRequest" /> + <wsdl:output message="account:purchaseStockResponse" /> + </wsdl:operation> + + + <wsdl:operation name="createAccount"> + <wsdl:input message="account:createAccountRequest" /> + <wsdl:output message="account:createAccountResponse" /> + </wsdl:operation> + + </wsdl:portType> + + + + <wsdl:binding name="AccountServiceSOAP" type="account:AccountService"> + <soap:binding style="document" + transport="http://schemas.xmlsoap.org/soap/http" /> + <wsdl:operation name="getAccountReport"> + <soap:operation + soapAction="http://www.bigbank.com/account/getAccountReport" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + <wsdl:operation name="getCustomerProfile"> + <soap:operation + soapAction="http://www.bigbank.com/account/getCustomerProfile" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="withdraw"> + <soap:operation + soapAction="http://www.bigbank.com/account/withdraw" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="deposit"> + <soap:operation + soapAction="http://www.bigbank.com/account/deposit" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="purchaseStock"> + <soap:operation + soapAction="http://www.bigbank.com/account/purchaseStock" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="sellStock"> + <soap:operation + soapAction="http://www.bigbank.com/account/sellStock" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="createAccount"> + <soap:operation + soapAction="http://www.bigbank.com/account/createAccount" /> + <wsdl:input> + <soap:body use="literal" /> + </wsdl:input> + <wsdl:output> + <soap:body use="literal" /> + </wsdl:output> + </wsdl:operation> + + </wsdl:binding> + <wsdl:service name="AccountService"> + <wsdl:port binding="account:AccountServiceSOAP" + name="AccountServiceSOAP"> + <soap:address + location="http://localhost:8080/sample-bigbank-account/services/AccountService" /> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl new file mode 100644 index 0000000000..e225678888 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/resources/wsdl/stockquotes.webservicex.wsdl @@ -0,0 +1,133 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.webserviceX.NET/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://www.webserviceX.NET/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> + <wsdl:types> + <s:schema elementFormDefault="qualified" + targetNamespace="http://www.webserviceX.NET/" > + <!-- + xmlns:sdojava="commonj.sdo/java" + sdojava:package="net.x.webservice" + --> + + + > + <s:element name="GetQuote"> + <s:complexType> + <s:sequence> + <s:element minOccurs="0" maxOccurs="1" name="symbol" type="s:string"/> + </s:sequence> + </s:complexType> + </s:element> + <s:element name="GetQuoteResponse"> + <s:complexType> + <s:sequence> + <s:element minOccurs="0" maxOccurs="1" name="GetQuoteResult" type="s:string"/> + </s:sequence> + </s:complexType> + </s:element> + <s:element name="string" nillable="true" type="s:string"/> + </s:schema> + </wsdl:types> + <wsdl:message name="GetQuoteSoapIn"> + <wsdl:part name="parameters" element="tns:GetQuote"/> + </wsdl:message> + <wsdl:message name="GetQuoteSoapOut"> + <wsdl:part name="parameters" element="tns:GetQuoteResponse"/> + </wsdl:message> + <wsdl:message name="GetQuoteHttpGetIn"> + <wsdl:part name="symbol" type="s:string"/> + </wsdl:message> + <wsdl:message name="GetQuoteHttpGetOut"> + <wsdl:part name="Body" element="tns:string"/> + </wsdl:message> + <wsdl:message name="GetQuoteHttpPostIn"> + <wsdl:part name="symbol" type="s:string"/> + </wsdl:message> + <wsdl:message name="GetQuoteHttpPostOut"> + <wsdl:part name="Body" element="tns:string"/> + </wsdl:message> + <wsdl:portType name="StockQuoteSoap"> + <wsdl:operation name="GetQuote"> + <documentation xmlns="http://schemas.xmlsoap.org/wsdl/">Get Stock quote for a company Symbol</documentation> + <wsdl:input message="tns:GetQuoteSoapIn"/> + <wsdl:output message="tns:GetQuoteSoapOut"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:portType name="StockQuoteHttpGet"> + <wsdl:operation name="GetQuote"> + <documentation xmlns="http://schemas.xmlsoap.org/wsdl/">Get Stock quote for a company Symbol</documentation> + <wsdl:input message="tns:GetQuoteHttpGetIn"/> + <wsdl:output message="tns:GetQuoteHttpGetOut"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:portType name="StockQuoteHttpPost"> + <wsdl:operation name="GetQuote"> + <documentation xmlns="http://schemas.xmlsoap.org/wsdl/">Get Stock quote for a company Symbol</documentation> + <wsdl:input message="tns:GetQuoteHttpPostIn"/> + <wsdl:output message="tns:GetQuoteHttpPostOut"/> + </wsdl:operation> + </wsdl:portType> + <wsdl:binding name="StockQuoteSoap" type="tns:StockQuoteSoap"> + <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> + <wsdl:operation name="GetQuote"> + <soap:operation soapAction="http://www.webserviceX.NET/GetQuote" style="document"/> + <wsdl:input> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:binding name="StockQuoteHttpGet" type="tns:StockQuoteHttpGet"> + <http:binding verb="GET"/> + <wsdl:operation name="GetQuote"> + <http:operation location="/GetQuote"/> + <wsdl:input> + <http:urlEncoded/> + </wsdl:input> + <wsdl:output> + <mime:mimeXml part="Body"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + <wsdl:binding name="StockQuoteHttpPost" type="tns:StockQuoteHttpPost"> + <http:binding verb="POST"/> + <wsdl:operation name="GetQuote"> + <http:operation location="/GetQuote"/> + <wsdl:input> + <mime:content type="application/x-www-form-urlencoded"/> + </wsdl:input> + <wsdl:output> + <mime:mimeXml part="Body"/> + </wsdl:output> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="StockQuote"> + <wsdl:port name="StockQuoteSoap" binding="tns:StockQuoteSoap"> + <soap:address location="http://www.webservicex.com/stockquote.asmx"/> + </wsdl:port> + <wsdl:port name="StockQuoteHttpGet" binding="tns:StockQuoteHttpGet"> + <http:address location="http://www.webservicex.com/stockquote.asmx"/> + </wsdl:port> + <wsdl:port name="StockQuoteHttpPost" binding="tns:StockQuoteHttpPost"> + <http:address location="http://www.webservicex.com/stockquote.asmx"/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..af8fae9d35 --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable. + + Licensed 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. + --> +<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + + <display-name>Tuscany Bigbank Account sample</display-name> + <servlet> + <!-- Initialize bigbank database --> + <servlet-name>AccountDBInit</servlet-name> + <servlet-class>bigbank.account.services.accountdb.AccountDBInit</servlet-class> + <load-on-startup>2</load-on-startup> + </servlet> + + +</web-app> diff --git a/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java new file mode 100644 index 0000000000..32308169ca --- /dev/null +++ b/tags/java-M1-20060518/java/sampleapps/bigbank/account/src/test/java/bigbank/account/client/AccountClient.java @@ -0,0 +1,57 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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.apache.tuscany.core.client.TuscanyRuntime; +import org.osoa.sca.CurrentModuleContext; +import org.osoa.sca.ModuleContext; +import org.osoa.sca.SCA; + +import com.bigbank.account.AccountReport; +import com.bigbank.account.AccountService; +import com.bigbank.account.AccountSummary; + +public class AccountClient extends SCA { + + public void start() { + } + + public void stop() { + } + + public static void main(String[] args) throws Exception { + TuscanyRuntime tuscany = new TuscanyRuntime("bigbank.account.testclient", null); + tuscany.start(); + ModuleContext moduleContext = CurrentModuleContext.getContext(); + + AccountService accountService = (AccountService) moduleContext.locateService("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()); + } + + } + +} |