geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r553672 - in /geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap: Convert.java TradeWSAction.java TradeWebSoapProxy.java
Date Fri, 06 Jul 2007 00:12:20 GMT
Author: gawor
Date: Thu Jul  5 17:12:19 2007
New Revision: 553672

URL: http://svn.apache.org/viewvc?view=rev&rev=553672
Log:
JAX-RPC trade service that does proper conversion between the types

Added:
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java
  (with props)
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java
  (with props)
Modified:
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWebSoapProxy.java

Added: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java?view=auto&rev=553672
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java
(added)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java
Thu Jul  5 17:12:19 2007
@@ -0,0 +1,168 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.samples.daytrader.soap;
+
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+
+import org.apache.geronimo.samples.daytrader.client.ws.AccountDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.AccountProfileDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.HoldingDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.MarketSummaryDataBeanWS;
+import org.apache.geronimo.samples.daytrader.client.ws.OrderDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.QuoteDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.RunStatsDataBean;
+
+public class Convert {
+	  
+    static OrderDataBean[] convertOrderDataBeanCollection(Collection col) {
+        OrderDataBean[] wsBeans = new OrderDataBean[col.size()];
+        int i = 0;
+        for (Object o : col) {
+            wsBeans[i++] = convertOrderDataBean((org.apache.geronimo.samples.daytrader.OrderDataBean)o);
           
+        }
+        return wsBeans;
+    }
+    
+    static OrderDataBean convertOrderDataBean(org.apache.geronimo.samples.daytrader.OrderDataBean
bean) {
+        OrderDataBean wsBean = new OrderDataBean();
+        wsBean.setOrderID(bean.getOrderID());
+        wsBean.setOrderType(bean.getOrderType());
+        wsBean.setOrderStatus(bean.getOrderStatus());
+        wsBean.setOpenDate(toCalendar(bean.getOpenDate()));
+        wsBean.setCompletionDate(toCalendar(bean.getCompletionDate()));
+        wsBean.setQuantity(bean.getQuantity());
+        wsBean.setPrice(bean.getPrice());
+        wsBean.setOrderFee(bean.getOrderFee());
+        wsBean.setSymbol(bean.getSymbol());
+        return wsBean;
+    }
+    
+    static QuoteDataBean[] convertQuoteDataBeanCollection(Collection col) {
+        QuoteDataBean[] wsBeans = new QuoteDataBean[col.size()];
+        int i = 0;
+        for (Object o : col) {
+            wsBeans[i++] = convertQuoteDataBean((org.apache.geronimo.samples.daytrader.QuoteDataBean)o);
           
+        }
+        return wsBeans;
+    }
+    
+    static QuoteDataBean convertQuoteDataBean(org.apache.geronimo.samples.daytrader.QuoteDataBean
bean) {
+        QuoteDataBean wsBean = new QuoteDataBean();
+        wsBean.setSymbol(bean.getSymbol());
+        wsBean.setCompanyName(bean.getCompanyName());
+        wsBean.setVolume(bean.getVolume());
+        wsBean.setPrice(bean.getPrice());
+        wsBean.setOpen(bean.getOpen());
+        wsBean.setLow(bean.getLow());
+        wsBean.setHigh(bean.getHigh());
+        wsBean.setChange(bean.getChange());
+        return wsBean;
+    }
+    
+    static RunStatsDataBean convertRunStatsDataBean(org.apache.geronimo.samples.daytrader.RunStatsDataBean
bean) {
+        RunStatsDataBean wsBean = new RunStatsDataBean();        
+        wsBean.setTradeUserCount(bean.getTradeUserCount());
+        wsBean.setNewUserCount(bean.getNewUserCount());
+        wsBean.setSumLoginCount(bean.getSumLoginCount());
+        wsBean.setSumLogoutCount(bean.getSumLogoutCount());
+        wsBean.setHoldingCount(bean.getHoldingCount());
+        wsBean.setOrderCount(bean.getOrderCount());
+        wsBean.setBuyOrderCount(bean.getBuyOrderCount());
+        wsBean.setSellOrderCount(bean.getSellOrderCount());
+        wsBean.setCancelledOrderCount(bean.getCancelledOrderCount());
+        wsBean.setOpenOrderCount(bean.getOpenOrderCount());
+        wsBean.setDeletedOrderCount(bean.getDeletedOrderCount());
+        return wsBean;
+    }
+    
+    static AccountDataBean convertAccountDataBean(org.apache.geronimo.samples.daytrader.AccountDataBean
bean) {
+        AccountDataBean wsBean = new AccountDataBean();
+        wsBean.setAccountID(bean.getAccountID());
+        wsBean.setLoginCount(bean.getLoginCount());
+        wsBean.setLogoutCount(bean.getLogoutCount());
+        wsBean.setLastLogin(toCalendar(bean.getLastLogin()));
+        wsBean.setCreationDate(toCalendar(bean.getCreationDate()));
+        wsBean.setBalance(bean.getBalance());
+        wsBean.setOpenBalance(bean.getOpenBalance());
+        wsBean.setProfileID(bean.getProfileID());
+        return wsBean;
+    }
+    
+    static AccountProfileDataBean convertAccountProfileDataBean(org.apache.geronimo.samples.daytrader.AccountProfileDataBean
bean) {
+        AccountProfileDataBean wsBean = new AccountProfileDataBean();
+        wsBean.setUserID(bean.getUserID());
+        wsBean.setPassword(bean.getPassword());
+        wsBean.setFullName(bean.getFullName());
+        wsBean.setAddress(bean.getAddress());
+        wsBean.setEmail(bean.getEmail());
+        wsBean.setCreditCard(bean.getCreditCard());
+        return wsBean;
+    }
+    
+    static org.apache.geronimo.samples.daytrader.AccountProfileDataBean convertAccountProfileDataBean(AccountProfileDataBean
wsBean) {
+        org.apache.geronimo.samples.daytrader.AccountProfileDataBean bean = new org.apache.geronimo.samples.daytrader.AccountProfileDataBean();
   
+        bean.setUserID(wsBean.getUserID());
+        bean.setPassword(wsBean.getPassword());
+        bean.setFullName(wsBean.getFullName());
+        bean.setAddress(wsBean.getAddress());
+        bean.setEmail(wsBean.getEmail());
+        bean.setCreditCard(wsBean.getCreditCard());
+        return bean;
+    }
+        
+    static HoldingDataBean[] convertHoldingDataBeanCollection(Collection col) {
+        HoldingDataBean[] wsBeans = new HoldingDataBean[col.size()];
+        int i = 0;
+        for (Object o : col) {
+            wsBeans[i++] = convertHoldingDataBean((org.apache.geronimo.samples.daytrader.HoldingDataBean)o);
           
+        }
+        return wsBeans;
+    }     
+        
+    static HoldingDataBean convertHoldingDataBean(org.apache.geronimo.samples.daytrader.HoldingDataBean
bean) {
+        HoldingDataBean wsBean = new HoldingDataBean();
+        wsBean.setHoldingID(bean.getHoldingID());
+        wsBean.setQuantity(bean.getQuantity());
+        wsBean.setPurchasePrice(bean.getPurchasePrice());
+        wsBean.setPurchaseDate(toCalendar(bean.getPurchaseDate()));
+        wsBean.setQuoteID(bean.getQuoteID());
+        return wsBean;
+    }
+    
+    static MarketSummaryDataBeanWS convertMarketSummaryDataBean(org.apache.geronimo.samples.daytrader.MarketSummaryDataBean
bean) {
+        MarketSummaryDataBeanWS wsBean = new MarketSummaryDataBeanWS();   
+        wsBean.setTopGainers(convertQuoteDataBeanCollection(bean.getTopGainers()));
+        wsBean.setTopLosers(convertQuoteDataBeanCollection(bean.getTopLosers()));       

+        wsBean.setTSIA(bean.getTSIA());
+        wsBean.setOpenTSIA(bean.getOpenTSIA());
+        wsBean.setVolume(bean.getVolume());
+        wsBean.setSummaryDate(toCalendar(bean.getSummaryDate()));        
+        return wsBean; 
+    }    
+    
+    static Calendar toCalendar(Date date) {
+        if (date == null) {
+            return null;
+        }
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        return cal;        
+    }
+}

Propchange: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/Convert.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java?view=auto&rev=553672
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java
(added)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java
Thu Jul  5 17:12:19 2007
@@ -0,0 +1,209 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.samples.daytrader.soap;
+
+import java.math.BigDecimal;
+import java.rmi.RemoteException;
+
+import javax.ejb.FinderException;
+
+import org.apache.geronimo.samples.daytrader.TradeAction;
+import org.apache.geronimo.samples.daytrader.client.ws.AccountDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.AccountProfileDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.HoldingDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.MarketSummaryDataBeanWS;
+import org.apache.geronimo.samples.daytrader.client.ws.OrderDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.QuoteDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.RunStatsDataBean;
+import org.apache.geronimo.samples.daytrader.client.ws.TradeWSServices;
+
+/** 
+ * This is a TradeAction wrapper to handle web service handling
+ * of collections.  Instead this class uses typed arrays.
+ */
+public class TradeWSAction implements TradeWSServices {
+	TradeAction trade;
+	
+	public TradeWSAction() {
+		trade = new TradeAction();
+	}
+
+	public MarketSummaryDataBeanWS getMarketSummary() throws RemoteException {
+		try {
+            return Convert.convertMarketSummaryDataBean(trade.getMarketSummary());
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public OrderDataBean buy(String userID, String symbol, double quantity, int orderProcessingMode)
throws RemoteException {
+		try {
+            return Convert.convertOrderDataBean(trade.buy(userID, symbol, quantity, orderProcessingMode));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public OrderDataBean sell(String userID, Integer holdingID, int orderProcessingMode) throws
RemoteException {
+		try {
+            return Convert.convertOrderDataBean(trade.sell(userID, holdingID, orderProcessingMode));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+
+	public void queueOrder(Integer orderID, boolean twoPhase) throws RemoteException {
+		trade.queueOrder(orderID, twoPhase);
+	}
+	
+	public OrderDataBean completeOrder(Integer orderID, boolean twoPhase) throws RemoteException
{
+		return Convert.convertOrderDataBean(trade.completeOrder(orderID, twoPhase));
+	}
+
+	public void cancelOrder(Integer orderID, boolean twoPhase) throws RemoteException {
+		trade.cancelOrder(orderID, twoPhase);
+	}
+	
+	public void orderCompleted(String userID, Integer orderID) throws RemoteException {
+		try {
+            trade.orderCompleted(userID, orderID);
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public OrderDataBean[] getOrders(String userID) throws RemoteException {
+        try {
+            return Convert.convertOrderDataBeanCollection(trade.getOrders(userID));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public OrderDataBean[] getClosedOrders(String userID) throws RemoteException {
+        try {
+            return Convert.convertOrderDataBeanCollection(trade.getClosedOrders(userID));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public QuoteDataBean createQuote(String symbol, String companyName, BigDecimal price) throws
RemoteException {
+		try {
+            return Convert.convertQuoteDataBean(trade.createQuote(symbol, companyName, price));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public QuoteDataBean getQuote(String symbol) throws RemoteException {
+		try {
+            return Convert.convertQuoteDataBean(trade.getQuote(symbol));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public QuoteDataBean[] getAllQuotes() throws RemoteException {
+		try {
+            return Convert.convertQuoteDataBeanCollection(trade.getAllQuotes());
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public QuoteDataBean updateQuotePriceVolume(String symbol, BigDecimal newPrice, double sharesTraded)
throws RemoteException {
+		try {
+            return Convert.convertQuoteDataBean(trade.updateQuotePriceVolume(symbol, newPrice,
sharesTraded));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public HoldingDataBean[] getHoldings(String userID) throws RemoteException {
+		try {
+            return Convert.convertHoldingDataBeanCollection(trade.getHoldings(userID));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public HoldingDataBean getHolding(Integer holdingID) throws RemoteException {
+		try {
+            return Convert.convertHoldingDataBean(trade.getHolding(holdingID));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public AccountDataBean getAccountData(String userID) throws RemoteException {
+		try {
+            return Convert.convertAccountDataBean(trade.getAccountData(userID));
+        } catch (FinderException e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public AccountProfileDataBean getAccountProfileData(String userID) throws RemoteException
{
+		try {
+            return Convert.convertAccountProfileDataBean(trade.getAccountProfileData(userID));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public AccountProfileDataBean updateAccountProfile(AccountProfileDataBean profileData) throws
RemoteException {
+		try {
+            return Convert.convertAccountProfileDataBean(trade.updateAccountProfile(Convert.convertAccountProfileDataBean(profileData)));
+        } catch (Exception e) {
+            throw new RemoteException("", e);            
+        }
+	}
+	
+	public AccountDataBean login(String userID, String password) throws RemoteException {
+		try {
+            return Convert.convertAccountDataBean(trade.login(userID, password));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public void logout(String userID) throws RemoteException {
+		try {
+            trade.logout(userID);
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public AccountDataBean register(String userID, String password, String fullname, String
address, String email, String creditcard, BigDecimal openBalance) throws RemoteException {
+		try {
+            return Convert.convertAccountDataBean(trade.register(userID, password, fullname,
address, email, creditcard, openBalance));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }
+	}
+	
+	public RunStatsDataBean resetTrade(boolean deleteAll) throws RemoteException {
+		try {
+            return Convert.convertRunStatsDataBean(trade.resetTrade(deleteAll));
+        } catch (Exception e) {
+            throw new RemoteException("", e);
+        }                
+	}    
+    
+}

Propchange: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWSAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWebSoapProxy.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWebSoapProxy.java?view=diff&rev=553672&r1=553671&r2=553672
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWebSoapProxy.java
(original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/soap/TradeWebSoapProxy.java
Thu Jul  5 17:12:19 2007
@@ -142,7 +142,7 @@
 	public Collection getClosedOrders(String userID) throws Exception, RemoteException {
 		Object[] orders = getTrade().getClosedOrders(userID);
 		ArrayList ordersRet = new ArrayList();
-		if (orders.length == 0) {
+		if (orders == null || orders.length == 0) {
 			return ordersRet;
 		}
 		for (int ii = 0; ii < orders.length; ii++) {



Mime
View raw message